Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/rws/interface_expression_conversion_to_gamma___and_no…
Browse files Browse the repository at this point in the history
…rmalization' of git://trac.sagemath.org/sage into t/22326/jacobi_p_polynomials_without_pexpect_maxima
  • Loading branch information
rwst committed Feb 9, 2017
2 parents bf876cb + 648e498 commit e82d2d2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sage/libs/pynac/pynac.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ cdef extern from "sage/libs/pynac/wrap.h":
object py_object_from_numeric(GEx e) except +

# Algorithms
GEx g_gcd "gcd"(GEx a, GEx b) except +
GEx g_gcd "gcd"(GEx a, GEx b) except +
GEx to_gamma(GEx expr) except +
GEx gamma_normalize(GEx expr) except +

# Pattern matching wildcards
GEx g_wild "wild"(unsigned int label) except +
Expand Down
47 changes: 47 additions & 0 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9614,6 +9614,53 @@ cdef class Expression(CommutativeRingElement):

factorial_simplify = simplify_factorial

def to_gamma(self):
"""
Convert factorial, binomial, and Pochhammer symbol
expressions to their gamma function equivalents.
EXAMPLES::
sage: m,n = var('m n', domain='integer')
sage: factorial(n).to_gamma()
gamma(n + 1)
sage: binomial(m,n).to_gamma()
gamma(m + 1)/(gamma(m - n + 1)*gamma(n + 1))
"""
cdef GEx x
sig_on()
try:
x = to_gamma(self._gobj)
finally:
sig_off()
return new_Expression_from_GEx(self._parent, x)

def gamma_normalize(self):
"""
Return the expression with any gamma functions that have
a common base converted to that base.
Addtionally the expression is normalized so any fractions
can be simplified through cancellation.
EXAMPLES::
sage: m,n = var('m n', domain='integer')
sage: (gamma(n+2)/gamma(n)).gamma_normalize()
(n + 1)*n
sage: (gamma(n+2)*gamma(n)).gamma_normalize()
(n + 1)*n*gamma(n)^2
sage: (gamma(n+2)*gamma(m-1)/gamma(n)/gamma(m+1)).gamma_normalize()
(n + 1)*n/((m - 1)*m)
"""
cdef GEx x
sig_on()
try:
x = gamma_normalize(self._gobj)
finally:
sig_off()
return new_Expression_from_GEx(self._parent, x)

def expand_sum(self):
r"""
For every symbolic sum in the given expression, try to expand it,
Expand Down

0 comments on commit e82d2d2

Please sign in to comment.