Skip to content

Commit

Permalink
added aseries for gamma, and other series methods for incomplete gamma
Browse files Browse the repository at this point in the history
fucntions

Signed-off-by: arnabnandikgp <arnabnandi2002@gmail.com>
  • Loading branch information
arnabnandikgp committed Aug 26, 2024
1 parent b354658 commit 8eb7f61
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
9 changes: 9 additions & 0 deletions sympy/functions/special/error_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,15 @@ def _eval_rewrite_as_Si(self, nu, z, **kwargs):
_eval_rewrite_as_Chi = _eval_rewrite_as_Si
_eval_rewrite_as_Shi = _eval_rewrite_as_Si

def _eval_as_leading_term(self, x, logx=None, cdir=0):
nu, z = self.args
if nu == 1:
arg = -log(z) - EulerGamma
if nu.is_real and nu > 1:
arg = 1/(nu - 1)
return arg.as_leading_term(x, logx=logx)
return super()._eval_as_leading_term(x, logx, cdir)

def _eval_nseries(self, x, n, logx, cdir=0):
if not self.args[0].has(x):
nu = self.args[0]
Expand Down
28 changes: 28 additions & 0 deletions sympy/functions/special/gamma_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ def _eval_as_leading_term(self, x, logx=None, cdir=0):
return self.func(x0)
raise PoleError()

def _eval_aseries(self, n, args0, x, logx):
point = args0[0]
if point is S.Infinity:
z = self.args[0]
r = exp((log(z)*(z - S.Half) - z + log(2*pi)/2).expand())
l = [bernoulli(2*k) / (2*k*(2*k - 1)*z**(2*k - 1)) for k in range(1, n)]
return (exp(Add(*l))._eval_nseries(x, n, logx))*r
return super()._eval_aseries(n, args0, x, logx)


###############################################################################
################## LOWER and UPPER INCOMPLETE GAMMA FUNCTIONS #################
Expand Down Expand Up @@ -380,15 +389,30 @@ def _eval_aseries(self, n, args0, x, logx):
return coeff*sum_expr + o
return super()._eval_aseries(n, args0, x, logx)

def _eval_nseries(self, x, n, logx, cdir=0):
from sympy.series.order import O
s, z = self.args
if z.has(x):
coeff = z**s*exp(-z)*gamma(s)
sum_expr = sum(z**k/gamma(s + k + 1) for k in range(n - 1))
o = O(z**s*s**(-n))
return coeff*sum_expr + o
return super()._eval_nseries(x, n, logx)

def _eval_rewrite_as_uppergamma(self, s, x, **kwargs):
return gamma(s) - uppergamma(s, x)

_eval_rewrite_as_tractable = _eval_rewrite_as_uppergamma

def _eval_rewrite_as_expint(self, s, x, **kwargs):
from sympy.functions.special.error_functions import expint
if s.is_integer and s.is_nonpositive:
return self
return self.rewrite(uppergamma).rewrite(expint)

def _eval_as_leading_term(self, x, logx=None, cdir=0):
return self.rewrite(uppergamma)._eval_as_leading_term(x, logx=logx, cdir=cdir)

def _eval_is_zero(self):
x = self.args[1]
if x.is_zero:
Expand Down Expand Up @@ -556,6 +580,10 @@ def _eval_rewrite_as_expint(self, s, x, **kwargs):
from sympy.functions.special.error_functions import expint
return expint(1 - s, x)*x**s

def _eval_as_leading_term(self, x, logx=None, cdir=0):
from sympy.functions.special.error_functions import expint
return self.rewrite(expint)._eval_as_leading_term(x, logx=logx, cdir=cdir)


###############################################################################
###################### POLYGAMMA and LOGGAMMA FUNCTIONS #######################
Expand Down
4 changes: 4 additions & 0 deletions sympy/functions/special/tests/test_gamma_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def test_gamma_series():
-1/(x + 1) + EulerGamma - 1 + (x + 1)*(-1 - pi**2/12 - EulerGamma**2/2 + \
EulerGamma) + (x + 1)**2*(-1 - pi**2/12 - EulerGamma**2/2 + EulerGamma**3/6 - \
polygamma(2, 1)/6 + EulerGamma*pi**2/12 + EulerGamma) + O((x + 1)**3, (x, -1))
assert gamma(x + 1).series(x, oo, 3) == sqrt(2)*sqrt(pi)*sqrt(x + 1)*(-23/(288*x**2) + \
1/(12*x) + 1 + O(x**(-3), (x, oo)))*exp(x*log(x + 1) - x - 1)
assert gamma(x).series(x, oo, 3) == sqrt(2)*sqrt(pi)*(1/(288*x**2) + 1/(12*x) + 1 + \
O(x**(-3), (x, oo)))*sqrt(1/x)*exp(-x*log(1/x) - x)


def tn_branch(s, func):
Expand Down
12 changes: 11 additions & 1 deletion sympy/series/tests/test_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
atan, cos, cot, csc, sec, sin, tan)
from sympy.functions.special.bessel import (besseli, bessely, besselj, besselk)
from sympy.functions.special.error_functions import (Ei, erf, erfc, erfi, fresnelc, fresnels)
from sympy.functions.special.gamma_functions import (digamma, gamma, uppergamma)
from sympy.functions.special.gamma_functions import (digamma, gamma, lowergamma, uppergamma)
from sympy.functions.special.hyper import meijerg
from sympy.integrals.integrals import (Integral, integrate)
from sympy.series.limits import (Limit, limit)
Expand Down Expand Up @@ -392,6 +392,16 @@ def test_bessel_functions_at_infinity():
assert limit(besselk(0, x), x, oo) == 0


def test_lowergamma_at_origin():
a, x = symbols('a x')
assert limit(lowergamma(a, x), a, 0) == oo
assert limit(lowergamma(a, x), a, 0, '-') == -oo
assert limit(lowergamma(I*a, x), a, 0) == -oo*I
assert limit(lowergamma(I*a, x), a, 0, '-') == oo*I
assert limit(lowergamma(a, 1), a, 0) == oo
assert limit(x*lowergamma(x, 1)/gamma(x + 1), x, 0) == 1


@XFAIL
def test_doit2():
f = Integral(2 * x, x)
Expand Down

0 comments on commit 8eb7f61

Please sign in to comment.