Skip to content

hyp1f1 explodes for large arguments. Recurrence relation unstable. #5349

Open
@cossio

Description

@cossio

hyp1f1 explodes for modestly large arguments. For example:

scipy.special.hyp1f1(30, 70, 20j)

returns

(-1748.2243027213672+51.441200608645886j)

which is completely wrong (whenever 1 < a < b and z is purely imaginary, abs(1F1(a,b,z)) <= 1).

This doesn't seem to be insoluble, since the package mpmath (also open sourced here on GitHub) returns what seems to be the correct answer:

mpmath.hyp1f1(30, 70, 20j)
mpc(real='-0.32066129006007188', imag='0.38180277645752586')

(I assume this is correct because Mathematica returns the same result. It would be very unlikely if they were both wrong and returned the same answer).

Moreover, I did a simple test. Simply using the Taylor series expansion gives the correct result. The problem with scipy's implementation seems to be in using a recurrence relation to lower the value of 'a' until it is < 2. The recurrence relation relation used is Abramowitz 13.4.1, but I think this is unstable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.special

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions