Skip to content

unexpected return from falling factorial function #521

@jacksonvanover

Description

@jacksonvanover

When the second argument is negative infinity, ff returns a zero regardless of the first argument. When the second argument is a positive infinity, ff returns a NaN which seems more appropriate; I don't believe the falling factorial function is well-defined with infinite second arguments. The fp namespace appears to behave in a more expected manner, throwing an error.

>>> mp.ff(1, -inf)
mpf('0.0')
>>> fp.ff(1, -inf)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/mpmath/functions/factorials.py", line 77, in ff
    return ctx.gammaprod([x1], [xn1])
  File "/usr/local/lib/python3.6/dist-packages/mpmath/functions/factorials.py", line 36, in gammaprod
    for x in regular_den: p /= ctx.gamma(x)
  File "/usr/local/lib/python3.6/dist-packages/mpmath/math2.py", line 30, in f
    return f_real(x)
  File "/usr/local/lib/python3.6/dist-packages/mpmath/math2.py", line 199, in _gamma_real
    _intx = int(x)
OverflowError: cannot convert float infinity to integer
>>> mp.ff(1, inf)
mpf('nan')
>>> fp.ff(1, inf)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/mpmath/functions/factorials.py", line 77, in ff
    return ctx.gammaprod([x1], [xn1])
  File "/usr/local/lib/python3.6/dist-packages/mpmath/functions/factorials.py", line 13, in gammaprod
    for x in b: [regular_den, poles_den][ctx.isnpint(x)].append(x)
  File "/usr/local/lib/python3.6/dist-packages/mpmath/ctx_fp.py", line 105, in isnpint
    return x <= 0.0 and round(x) == x
OverflowError: cannot convert float infinity to integer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions