Skip to content

Hang in hypergeometric function with NaN input #479

Description

@jacksonvanover

mpmath version: 1.1.0

When the fourth argument to the hypergeometric function 2F1 is a NaN, a hang is
caused in some, but not all, cases. This behavior is the same in both the fp and mp contexts.

Example:

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mpmath import *
>>> import numpy as np
>>> mp.hyp2f1(0.5, 0.5, 0.5, np.nan)
mpf('nan')
>>> mp.hyp2f1(0.5, 2.2, 0.5, np.nan)
mpf('nan')
>>> mp.hyp2f1(0.4, 2.2, 0.5, np.nan)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jvanover/.local/lib/python3.6/site-packages/mpmath/functions/hypergeometric.py", line 251, in hyp2f1
    return ctx.hyper([a,b],[c],z,**kwargs)
  File "/home/jvanover/.local/lib/python3.6/site-packages/mpmath/functions/hypergeometric.py", line 226, in hyper
    if   q == 1: return ctx._hyp2f1(a_s, b_s, z, **kwargs)
  File "/home/jvanover/.local/lib/python3.6/site-packages/mpmath/functions/hypergeometric.py", line 473, in _hyp2f1
    v = _hyp2f1_gosper(ctx,a,b,c,z,**kwargs)
  File "/home/jvanover/.local/lib/python3.6/site-packages/mpmath/functions/hypergeometric.py", line 380, in _hyp2f1_gosper
    kakbz = (k+a)*(k+b)*z / (4*(k+1)*kch*(k+c1h))
  File "/home/jvanover/.local/lib/python3.6/site-packages/mpmath/rational.py", line 176, in __mul__
    return create_reduced(a*t, b)
  File "/home/jvanover/.local/lib/python3.6/site-packages/mpmath/rational.py", line 20, in create_reduced
    if q <= 4 and abs(key[0]) < 100:
KeyboardInterrupt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions