### upper incomplete gamma function in fenics

185
views
0
5 months ago by
Does FEniCS/dolfin have a built-in function for calculating the upper incomplete gamma function?

The general form of the function is

\Gamma(a, x) = \int_{x}^{\infty} t^{a-1} e^{-t} dt
Community: FEniCS Project

1
5 months ago by
Not that I know of.  The UFL manual is here:

and Ctrl+F "gamma" doesn't find anything relevant.  Depending on your purpose, you might be able to get away with wrapping SciPy's function in a user-defined Expression.  For example, if $a$ is a constant, and $x$ is a spatial coordinate, you could do something like this:

from dolfin import *
from scipy.special import gammaincc as scipyGamma
mesh = UnitIntervalMesh(10)

a = 1.0

class UpperIncompleteGamma(Expression):
def eval(self,values,x):
values[0] = scipyGamma(a,x[0])

# can be used in UFL
gamma = UpperIncompleteGamma(degree=2)

# test:
x = 1.234
fenicsGamma = [0.0,]
gamma.eval(fenicsGamma,Point(x))

print("scipy: "+str(scipyGamma(a,x)))
print("fenics: "+str(fenicsGamma[0]))
​

EDIT:  Note that SciPy's version is "regularized", if that matters:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.gammaincc.html#scipy.special.gammaincc

It looks like a normalizing factor of $\Gamma(a)$.

Hi David, for inline $\LaTeX$ use $ to open and $ to close.
written 5 months ago by Michal Habera
Thanks David.
mpmath also has the gammainc function built-in, and is not normalized like scipy.
written 5 months ago by Soroushr