Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Rising Factorial #39409

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5259,12 +5259,25 @@ def rising_factorial(x, a):
- Jaap Spies (2006-03-05)
"""
from sage.structure.element import Expression
from sage.rings.integer import Integer
x = py_scalar_to_element(x)
a = py_scalar_to_element(a)

# Handle negative integer x and non-negative integer a
if isinstance(x, Integer) and x < 0 and isinstance(a, Integer) and a >= 0:
if a > -x: # If a > |x|, the product includes zero
return x.parent().zero()
else:
# Compute the product for a <= |x|
return prod((x + i for i in range(a)), z=x.parent().one())

# General case for non-negative integer a
if (isinstance(a, Integer) or
(isinstance(a, Expression) and
a.is_integer())) and a >= 0:
return prod(((x + i) for i in range(a)), z=x.parent().one())

# Fallback to gamma function for other cases
from sage.functions.all import gamma
return gamma(x + a) / gamma(x)

Expand Down
Loading