Skip to content
fn

gammaincc

→Tensor
gammaincc(input: Tensor, other: Tensor)

Regularized upper incomplete gamma function Q(a,x)Q(a, x).

Q(a,x)=1Γ(a)∫x∞ta−1e−t dt=1−P(a,x)Q(a, x) = \frac{1}{\Gamma(a)} \int_x^\infty t^{a-1} e^{-t}\, dt = 1 - P(a, x)

Evaluated directly rather than as 1 - gammainc, so a small upper tail keeps its relative precision.

Parameters

inputTensor
Shape a≥0a \geq 0.
otherTensor
Lower limit x≥0x \geq 0; broadcast against input.

Returns

Tensor

Q(a,x)∈[0,1]Q(a, x) \in [0, 1], in the promoted dtype of the two.

Raises

NotImplementedError
From backward, when input requires a gradient: only other is differentiable, with ∂Q/∂x=−xa−1e−x/Γ(a)\partial Q / \partial x = -x^{a-1} e^{-x} / \Gamma(a).

Notes

The branches and edge values mirror gammainc's: Q(a,0)=1Q(a, 0) = 1, Q(a,∞)=0Q(a, \infty) = 0, Q(0,x)=0Q(0, x) = 0 for x>0x > 0, Q(∞,x)=1Q(\infty, x) = 1 for a finite x. For a tiny shape the reference framework evaluates ln⁡Γ(1+a)\ln\Gamma(1 + a) after rounding 1+a1 + a to 1 and loses the Euler-Mascheroni term: at a=10−30a = 10^{-30} its value is 4.4% above the one mpmath computes at x=10−6x = 10^{-6}, 103% above at x=0.5x = 0.5 and 286% above at x=1.05x = 1.05. Here that term is kept, and the value agrees with mpmath's to float64 rounding.

Examples

>>> import lucid
>>> from lucid.special import gammaincc
>>> gammaincc(lucid.tensor([1.0, 2.0]), lucid.tensor([1.0, 10.0]))
tensor([0.3679, 0.0004994])

Used by 1