Function of #cas

gamma

The exact value of the Gamma function at an integer or a half-integer, with a theorem about Mathlib’s Real.Gamma.

#cas (gamma q)
gives the exact value of Γ(q) at an integer or a half-integer q and proves Real.Gamma q = v.

gamma computes the exact special values of Γ, the ones you would look up in a table. At a positive integer the value is a factorial, and at a half-integer it is a rational multiple of π. Each answer comes with a theorem about Mathlib’s Real.Gamma, so it means exactly what Mathlib means, down to Mathlib’s value 0 at the poles.

Details and Options

  • q is a closed rational expression whose value is an integer or a half-integer with |q|≤10012, such as 5, (5/2) or (-3/2). Other rationals, irrational numbers and symbols are refused.
  • At a positive integer the theorem is Real.Gamma q = v with v=(q−1)!. At a half-integer it is Real.Gamma q = a * √Real.pi / b with integers a and b.
  • The proof is one rewrite with a closed formula and a step of Mathlib’s tactic norm_num. The formulas are Real.Gamma_nat_eq_factorial, Γ(n+1)=n!, Mathlib’s Real.Gamma_nat_add_half, Γ(k+12)=(2k−1)!!π/2k, and CAS.Analysis.SpecialFunctions.Gamma_half_sub_nat, Γ(12−k)=(−2)kπ/(2k−1)!!.
  • At an integer q≤0, a pole of Γ, the theorem is Real.Gamma q = 0, Mathlib’s value there (Real.Gamma_neg_nat_eq_zero), and the Output line says so.
  • The call is evaluated when it is the whole input of #cas.
  • The tactic cas proves Real.Gamma q = v with the same closed formulas.
  • There are no options.

Examples (11)#

Basic Examples (2)

At a half-integer the value is a rational multiple of π:

In[1]:=
#cas (gamma (5/2))
Out[1]=

exact value of Γ

3π4
3√π/4
Input (rational number)
5/2

Checked by Lean’s kernel: Gamma by a closed formula

Real.Gamma (5 / 2) = 3 * √Real.pi / 4
The certificate: 1 checked step
  1. Gamma by a closed formula

    Real.Gamma (5 / 2) = 3 * √Real.pi / 4

    Checked by Lean’s kernel


At a positive integer it is a factorial, Γ(5)=4!:

In[2]:=
#cas (gamma 5)
Out[2]=

exact value of Γ

24
Input (rational number)
5

Checked by Lean’s kernel: Gamma by a closed formula

Real.Gamma 5 = 24
The certificate: 1 checked step
  1. Gamma by a closed formula

    Real.Gamma 5 = 24

    Checked by Lean’s kernel

Scope (3)

At a negative half-integer the formula is Γ(12−k)=(−2)kπ/(2k−1)!!, here with k=2:

In[3]:=
#cas (gamma (-3/2))
Out[3]=

exact value of Γ

4π3
4√π/3
Input (rational number)
-3/2

Checked by Lean’s kernel: Gamma by a closed formula

Real.Gamma (-(3 / 2)) = 4 * √Real.pi / 3
The certificate: 1 checked step
  1. Gamma by a closed formula

    Real.Gamma (-(3 / 2)) = 4 * √Real.pi / 3

    Checked by Lean’s kernel


The value at 12 is π:

In[4]:=
#cas (gamma (1/2))
Out[4]=

exact value of Γ

π
√π
Input (rational number)
1/2

Checked by Lean’s kernel: Gamma by a closed formula

Real.Gamma (1 / 2) = √Real.pi
The certificate: 1 checked step
  1. Gamma by a closed formula

    Real.Gamma (1 / 2) = √Real.pi

    Checked by Lean’s kernel


At a pole the report gives Mathlib’s value 0 and says that the point is a pole:

In[5]:=
#cas (gamma (-3))
Out[5]=

exact value of Γ

0 (Mathlib's value at the pole -3; Mathematica: ComplexInfinity)
Input (rational number)
-3

Checked by Lean’s kernel: Mathlib's Gamma at a pole

Real.Gamma (-3) = 0
The certificate: 1 checked step
  1. Mathlib's Gamma at a pole

    Real.Gamma (-3) = 0

    Checked by Lean’s kernel

Applications (1)

The tactic cas proves the same values inside a proof, and only the three standard axioms are used:

In[6]:=
theorem gamma_seven_halves : Real.Gamma (7 / 2) = 15 / 8 * √Real.pi := by
  cas

#print axioms gamma_seven_halves
Out[6]=

gamma_seven_halves depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (1)

The recurrence Γ(q+1)=qΓ(q) takes Γ(52)=34π to 52·34π=158π:

In[7]:=
#cas (gamma (7/2))
Out[7]=

exact value of Γ

15π8
15√π/8
Input (rational number)
7/2

Checked by Lean’s kernel: Gamma by a closed formula

Real.Gamma (7 / 2) = 15 * √Real.pi / 8
The certificate: 1 checked step
  1. Gamma by a closed formula

    Real.Gamma (7 / 2) = 15 * √Real.pi / 8

    Checked by Lean’s kernel

Possible Issues (4)

The call computes exact values at integers and half-integers only, and 13 is neither:

In[8]:=
#cas (gamma (1/3))
Out[8]=

Error

gamma: exact values are computed at integers and half-integers; `1/3` is neither

The argument is a number, not a symbol:

In[9]:=
#cas (gamma x)
Out[9]=

Error

gamma needs a closed expression; free symbols: x

The call is evaluated as the whole input, not inside a larger expression:

In[10]:=
#cas (2 * gamma (5/2))
Out[10]=

Error

unsupported symbolic function 'gamma'; expected abs, sin, cos, tan, sinh, cosh, tanh, atan/arctan, asin/arcsin, acos/arccos, exp, log, or sqrt. `gamma x` is evaluated as the whole input of `#cas (gamma x)`

The argument lies within |q|≤10012:

In[11]:=
#cas (gamma (1003/2))
Out[11]=

Error

gamma: exact values are computed for |q| ≤ 1001/2; `1003/2` is outside that range

See Also

factorial · binomial · zeta · BernoulliB · cas