I am playing with the python library mpmath, in particular evaluating the incomplete gamma function. This is part of a root finding routine but its evaluation is extremely slow for some combinations of complex-valued arguments.
import mpmath as mp
from mpmath import gammainc
def Gamma(a,z0,z1):
return gammainc(a,a=z0,b=z1,regularized=False)
Here the evaluation of the mpmath.gammainc
function gets stuck:
>> Gamma(mp.mpc(12.5+17.5j), mp.mpf(0.0), mp.mpf(-12.5))
On the other hand, Mathematica returns me the result almost instantly:
In[1]:= Gamma[12.5 + 17.5 I, 0, -12.5]
Out[1]:= 2.38012*10^-7 + 5.54827*10^-7 I
In other cases, for different arguments mpmath
and Mathematica
return the same output:
Mathematica
In[2]: Gamma[3.5 I, 0, 10]
Out[2]:= 0.0054741 + 0.000409846 I
Python mpmath
>> Gamma(3.5j,0,10)
mpc(real='0.0054741038497352953', imag='0.00040984640431357779')
Do you have some idea of the reason of this behaviour? Can this be considered a problem of mpmath
or is this a mathematical problem of quadrature?
Unfortunately scipy
does not offer an implementation of gamma
functions for complex arguments, so it not an option.