import escape as esc
esc.require("0.9.8")
import numpy as np
Loading material database from C:\dev\escape-core\python\src\escape\scattering\..\data\mdb\materials.db
Gamma Functors¶
Gamma functions appear in statistics, peak shapes, and scattering (e.g. size distributions, normalized intensities). In practice they show up whenever a model uses cumulative probabilities, distribution tails, or normalization factors. ESCAPE provides the true (complete) gamma and the regularized incomplete gamma functions P and Q.
True gamma¶
The true gamma is defined as $\Gamma(z)=\int_0^\infty t^{z-1}\exp(-t)\,dt$. It is defined for positive real $z$ and by analytic continuation elsewhere; when evaluated outside the allowed domain, the implementation returns NaN.
X = esc.var("X")
tg = esc.tgamma(X)
coords = np.linspace(-6, 6, 1000)
tg.show(coordinates=coords).config(xlabel="X", ylabel="Y", title="True Gamma")
Incomplete gamma functions¶
There are four incomplete gamma functions: two regularized (normalized) ones that return values in $[0, 1]$, and two non-normalized ones that return values in $[0, \Gamma(a)]$. Use normalized forms for cumulative-type quantities; use non-normalized when you need the raw integral. The API is esc.gamma_p(a, X, normalized=...) and esc.gamma_q(a, X, normalized=...), where a is a parameter and X is the variable.
The first regularized type (lower incomplete) is:
$P(z, a)=\frac{1}{\Gamma(a)}\int_0^z t^{a-1}\exp(-t)\,dt$
a = esc.par("a", 1)
gp = esc.gamma_p(a, X, normalized=True)
# if you don't need normalization, set the *normalized* argument to False.
coords = np.linspace(0, 6, 1000)
gp.show(coordinates=coords).config(xlabel="X", ylabel="Y", title="P(X, a)")
The second regularized type (upper incomplete) is:
$Q(z, a)=\frac{1}{\Gamma(a)}\int_z^\infty t^{a-1}\exp(-t)\,dt$
gq = esc.gamma_q(a, X, normalized=True)
# if you don't need normalization, set the *normalized* argument to False.
coords = np.linspace(0, 6, 1000)
gq.show(coordinates=coords).config(xlabel="X", ylabel="Y", title="Q(X, a)")