state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
case succ.refine_3
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto ?succ.refine_1 atTop (π (GammaAux m (s + 1) / s))
β’ Tendsto (GammaSeq s) atTop (π ((fun s => GammaAux m (s + 1) / s) s))
case succ.refine_1
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
β’ β β β
case succ.refine_2
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
n : β
hn : n β 0
β’ GammaSeq (s + 1) n / s = ?succ.refine_1 n | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
| pick_goal 3 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case succ.refine_2
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
n : β
hn : n β 0
β’ GammaSeq (s + 1) n / s = ?succ.refine_1 n | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· | exact GammaSeq_add_one_left s hn | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case succ.refine_3
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s))
β’ Tendsto (GammaSeq s) atTop (π ((fun s => GammaAux m (s + 1) / s) s)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
| conv at this => arg 1; intro n; rw [mul_comm] | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s))
| Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => | arg 1; intro n; rw [mul_comm] | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s))
| Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => | arg 1; intro n; rw [mul_comm] | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s))
| Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => | arg 1 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s))
| fun n => βn / (βn + 1 + s) * GammaSeq s n | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; | intro n | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => βn / (βn + 1 + s) * GammaSeq s n) atTop (π (GammaAux m (s + 1) / s))
n : β
| βn / (βn + 1 + s) * GammaSeq s n | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; | rw [mul_comm] | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case succ.refine_3
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => GammaSeq s n * (βn / (βn + 1 + s))) atTop (π (GammaAux m (s + 1) / s))
β’ Tendsto (GammaSeq s) atTop (π ((fun s => GammaAux m (s + 1) / s) s)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
| rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => GammaSeq s n * (βn / (βn + 1 + s))) atTop (π (GammaAux m (s + 1) / s * 1))
β’ Tendsto (fun n => βn / (βn + 1 + s)) atTop (π 1) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
| simp_rw [add_assoc] | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
m : β
IH : β (s : β), -βm < s.re β Tendsto (GammaSeq s) atTop (π (GammaAux m s))
s : β
hs : -βm < (s + 1).re
this : Tendsto (fun n => GammaSeq s n * (βn / (βn + 1 + s))) atTop (π (GammaAux m (s + 1) / s * 1))
β’ Tendsto (fun n => βn / (βn + (1 + s))) atTop (π 1) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
| exact tendsto_coe_nat_div_add_atTop (1 + s) | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.351_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
β’ GammaSeq z n * GammaSeq (1 - z) n = βn / (βn + 1 - z) * (1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
| have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
β’ β (a b c d : β), a * b * (c * d) = a * c * (b * d) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by | intros | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aβ bβ cβ dβ : β
β’ aβ * bβ * (cβ * dβ) = aβ * cβ * (bβ * dβ) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; | ring | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
β’ GammaSeq z n * GammaSeq (1 - z) n = βn / (βn + 1 - z) * (1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
| rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two] | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
β’ βn ^ z * βn ^ (1 - z) * βn ! ^ 2 /
((β j in Finset.range (n + 1), (z + βj)) * β j in Finset.range (n + 1), (1 - z + βj)) =
βn / (βn + 1 - z) * (1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
| have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one] | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
β’ βn ^ z * βn ^ (1 - z) = βn | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
| rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one] | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
this : βn ^ z * βn ^ (1 - z) = βn
β’ βn ^ z * βn ^ (1 - z) * βn ! ^ 2 /
((β j in Finset.range (n + 1), (z + βj)) * β j in Finset.range (n + 1), (1 - z + βj)) =
βn / (βn + 1 - z) * (1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
| rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc] | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
this : βn ^ z * βn ^ (1 - z) = βn
β’ βn * βn ! ^ 2 / ((β x in Finset.range n, (z + β(x + 1)) * (1 - z + βx)) * (z * (βn + 1 - z))) =
βn / (βn + 1 - z) * (1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
| have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
this : βn ^ z * βn ^ (1 - z) = βn
β’ β (j : β), (z + β(j + 1)) * (1 - z + βj) = β((j + 1) ^ 2) * (1 - z ^ 2 / (βj + 1) ^ 2) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
| intro j | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
this : βn ^ z * βn ^ (1 - z) = βn
j : β
β’ (z + β(j + 1)) * (1 - z + βj) = β((j + 1) ^ 2) * (1 - z ^ 2 / (βj + 1) ^ 2) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
| push_cast | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
this : βn ^ z * βn ^ (1 - z) = βn
j : β
β’ (z + (βj + 1)) * (1 - z + βj) = (βj + 1) ^ 2 * (1 - z ^ 2 / (βj + 1) ^ 2) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
| have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
this : βn ^ z * βn ^ (1 - z) = βn
j : β
β’ βj + 1 β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by | rw [β Nat.cast_succ, Nat.cast_ne_zero] | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
this : βn ^ z * βn ^ (1 - z) = βn
j : β
β’ Nat.succ j β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; | exact Nat.succ_ne_zero j | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
thisβ : βn ^ z * βn ^ (1 - z) = βn
j : β
this : βj + 1 β 0
β’ (z + (βj + 1)) * (1 - z + βj) = (βj + 1) ^ 2 * (1 - z ^ 2 / (βj + 1) ^ 2) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
| field_simp | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
thisβ : βn ^ z * βn ^ (1 - z) = βn
j : β
this : βj + 1 β 0
β’ (z + (βj + 1)) * (1 - z + βj) * (βj + 1) ^ 2 = (βj + 1) ^ 2 * ((βj + 1) ^ 2 - z ^ 2) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; | ring | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
thisβ : βn ^ z * βn ^ (1 - z) = βn
this : β (j : β), (z + β(j + 1)) * (1 - z + βj) = β((j + 1) ^ 2) * (1 - z ^ 2 / (βj + 1) ^ 2)
β’ βn * βn ! ^ 2 / ((β x in Finset.range n, (z + β(x + 1)) * (1 - z + βx)) * (z * (βn + 1 - z))) =
βn / (βn + 1 - z) * (1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
| simp_rw [this] | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
thisβ : βn ^ z * βn ^ (1 - z) = βn
this : β (j : β), (z + β(j + 1)) * (1 - z + βj) = β((j + 1) ^ 2) * (1 - z ^ 2 / (βj + 1) ^ 2)
β’ βn * βn ! ^ 2 / ((β x in Finset.range n, β((x + 1) ^ 2) * (1 - z ^ 2 / (βx + 1) ^ 2)) * (z * (βn + 1 - z))) =
βn / (βn + 1 - z) * (1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
| rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div] | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
thisβ : βn ^ z * βn ^ (1 - z) = βn
this : β (j : β), (z + β(j + 1)) * (1 - z + βj) = β((j + 1) ^ 2) * (1 - z ^ 2 / (βj + 1) ^ 2)
β’ β (a b c d : β), a * b * (c * d) = a * (d * (b * c)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by | intros | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
thisβ : βn ^ z * βn ^ (1 - z) = βn
this : β (j : β), (z + β(j + 1)) * (1 - z + βj) = β((j + 1) ^ 2) * (1 - z ^ 2 / (βj + 1) ^ 2)
aβ bβ cβ dβ : β
β’ aβ * bβ * (cβ * dβ) = aβ * (dβ * (bβ * cβ)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; | ring | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h
z : β
n : β
hn : n β 0
aux : β (a b c d : β), a * b * (c * d) = a * c * (b * d)
thisβ : βn ^ z * βn ^ (1 - z) = βn
this : β (j : β), (z + β(j + 1)) * (1 - z + βj) = β((j + 1) ^ 2) * (1 - z ^ 2 / (βj + 1) ^ 2)
β’ βn ! ^ 2 β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
| exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n) | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.395_0.in2QiCFW52coQT2 | theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
β’ Gamma z * Gamma (1 - z) = βΟ / sin (βΟ * z) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
| have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
pi_ne : βΟ β 0
β’ Gamma z * Gamma (1 - z) = βΟ / sin (βΟ * z) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
| by_cases hs : sin (βΟ * z) = 0 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
z : β
pi_ne : βΟ β 0
hs : sin (βΟ * z) = 0
β’ Gamma z * Gamma (1 - z) = βΟ / sin (βΟ * z) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
| rw [hs, div_zero] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
z : β
pi_ne : βΟ β 0
hs : sin (βΟ * z) = 0
β’ Gamma z * Gamma (1 - z) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
| rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
z : β
pi_ne : βΟ β 0
hs : β k, -z * βΟ = βk * βΟ
β’ Gamma z * Gamma (1 - z) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
| obtain β¨k, hkβ© := hs | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos.intro
z : β
pi_ne : βΟ β 0
k : β€
hk : -z * βΟ = βk * βΟ
β’ Gamma z * Gamma (1 - z) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
| rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos.intro
z : β
pi_ne : βΟ β 0
k : β€
hk : z = -βk
β’ Gamma z * Gamma (1 - z) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
| rw [hk] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos.intro
z : β
pi_ne : βΟ β 0
k : β€
hk : z = -βk
β’ Gamma (-βk) * Gamma (1 - -βk) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
| cases k | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos.intro.ofNat
z : β
pi_ne : βΟ β 0
aβ : β
hk : z = -β(Int.ofNat aβ)
β’ Gamma (-β(Int.ofNat aβ)) * Gamma (1 - -β(Int.ofNat aβ)) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· | rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos.intro.negSucc
z : β
pi_ne : βΟ β 0
aβ : β
hk : z = -β(Int.negSucc aβ)
β’ Gamma (-β(Int.negSucc aβ)) * Gamma (1 - -β(Int.negSucc aβ)) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· | rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
β’ Gamma z * Gamma (1 - z) = βΟ / sin (βΟ * z) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
| refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _ | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
β’ Tendsto (fun x => GammaSeq z x * GammaSeq (1 - z) x) atTop (π (βΟ / sin (βΟ * z))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
| have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
β’ βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by | rw [one_mul] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
this : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
β’ Tendsto (fun x => GammaSeq z x * GammaSeq (1 - z) x) atTop (π (βΟ / sin (βΟ * z))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
| convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _) | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg.convert_3
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
this : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
β’ Tendsto (fun n => βn / (βn + 1 - z)) atTop (π 1) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· | convert tendsto_coe_nat_div_add_atTop (1 - z) using 1 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
this : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
β’ (fun n => βn / (βn + 1 - z)) = fun n => βn / (βn + (1 - z)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; | ext1 n | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3.h
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
this : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
n : β
β’ βn / (βn + 1 - z) = βn / (βn + (1 - z)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; | rw [add_sub_assoc] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg.convert_4
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
this : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
β’ Tendsto (fun n => 1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) atTop (π (βΟ / sin (βΟ * z))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· | have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
this : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
β’ βΟ / sin (βΟ * z) = 1 / (sin (βΟ * z) / βΟ) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by | field_simp | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg.convert_4
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
thisβ : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
this : βΟ / sin (βΟ * z) = 1 / (sin (βΟ * z) / βΟ)
β’ Tendsto (fun n => 1 / (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2))) atTop (π (βΟ / sin (βΟ * z))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
| convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne) | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg.convert_4.convert_5
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
thisβ : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
this : βΟ / sin (βΟ * z) = 1 / (sin (βΟ * z) / βΟ)
β’ Tendsto (fun x => z * β j in Finset.range x, (1 - z ^ 2 / (βj + 1) ^ 2)) atTop (π (sin (βΟ * z) / βΟ)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
| rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg.convert_4.convert_5
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
thisβ : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
this : βΟ / sin (βΟ * z) = 1 / (sin (βΟ * z) / βΟ)
β’ Tendsto (fun n => (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2)) * βΟ) atTop (π (sin (βΟ * z))) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
| convert tendsto_euler_sin_prod z using 1 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
thisβ : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
this : βΟ / sin (βΟ * z) = 1 / (sin (βΟ * z) / βΟ)
β’ (fun n => (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2)) * βΟ) = fun n =>
βΟ * z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
| ext1 n | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3.h
z : β
pi_ne : βΟ β 0
hs : Β¬sin (βΟ * z) = 0
thisβ : βΟ / sin (βΟ * z) = 1 * (βΟ / sin (βΟ * z))
this : βΟ / sin (βΟ * z) = 1 / (sin (βΟ * z) / βΟ)
n : β
β’ (z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2)) * βΟ =
βΟ * z * β j in Finset.range n, (1 - z ^ 2 / (βj + 1) ^ 2) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; | rw [mul_comm, β mul_assoc] | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.419_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
| by_cases h_im : s.im = 0 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· | have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
β’ s = βs.re | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
| conv_lhs => rw [β Complex.re_add_im s] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
| s | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => | rw [β Complex.re_add_im s] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
| s | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => | rw [β Complex.re_add_im s] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
| s | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => | rw [β Complex.re_add_im s] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
β’ βs.re + βs.im * I = βs.re | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
| rw [h_im, ofReal_zero, zero_mul, add_zero] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
this : s = βs.re
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
| rw [this, Gamma_ofReal, ofReal_ne_zero] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
this : s = βs.re
β’ Real.Gamma s.re β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
| refine' Real.Gamma_ne_zero fun n => _ | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
s : β
hs : β (m : β), s β -βm
h_im : s.im = 0
this : s = βs.re
n : β
β’ s.re β -βn | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
| specialize hs n | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
s : β
h_im : s.im = 0
this : s = βs.re
n : β
hs : s β -βn
β’ s.re β -βn | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
| contrapose! hs | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case pos
s : β
h_im : s.im = 0
this : s = βs.re
n : β
hs : s.re = -βn
β’ s = -βn | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
| rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· | have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
β’ sin (βΟ * s) β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
| rw [Complex.sin_ne_zero_iff] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
β’ β (k : β€), βΟ * s β βk * βΟ | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
| intro k | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
k : β€
β’ βΟ * s β βk * βΟ | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
| apply_fun im | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
k : β€
β’ (βΟ * s).im β (βk * βΟ).im | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
| rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im] | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
k : β€
β’ Ο * s.im β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
| exact mul_ne_zero Real.pi_pos.ne' h_im | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
this : sin (βΟ * s) β 0
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
| have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
this : sin (βΟ * s) β 0
A : βΟ / sin (βΟ * s) β 0
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
| rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case neg
s : β
hs : β (m : β), s β -βm
h_im : Β¬s.im = 0
this : sin (βΟ * s) β 0
A : Gamma s β 0 β§ Gamma (1 - s) β 0
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
| exact A.1 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.446_0.in2QiCFW52coQT2 | /-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
β’ Gamma s = 0 β β m, s = -βm | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
| constructor | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.469_0.in2QiCFW52coQT2 | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case mp
s : β
β’ Gamma s = 0 β β m, s = -βm | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· | contrapose! | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.469_0.in2QiCFW52coQT2 | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case mp
s : β
β’ (β (m : β), s β -βm) β Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; | exact Gamma_ne_zero | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.469_0.in2QiCFW52coQT2 | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case mpr
s : β
β’ (β m, s = -βm) β Gamma s = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· | rintro β¨m, rflβ© | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.469_0.in2QiCFW52coQT2 | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case mpr.intro
m : β
β’ Gamma (-βm) = 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; | exact Gamma_neg_nat_eq_zero m | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.469_0.in2QiCFW52coQT2 | theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : 0 < s.re
β’ Gamma s β 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
| refine' Gamma_ne_zero fun m => _ | /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.475_0.in2QiCFW52coQT2 | /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
hs : 0 < s.re
m : β
β’ s β -βm | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
| contrapose! hs | /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.475_0.in2QiCFW52coQT2 | /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
m : β
hs : s = -βm
β’ s.re β€ 0 | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
| simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _ | /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.475_0.in2QiCFW52coQT2 | /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
β’ Tendsto (GammaSeq s) atTop (π (Gamma s)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
| suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s) | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.492_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
this : Tendsto (Complex.ofReal' β GammaSeq s) atTop (π (Complex.Gamma βs))
β’ Tendsto (GammaSeq s) atTop (π (Gamma s))
case this s : β β’ Tendsto (Complex.ofReal' β GammaSeq s) atTop (π (Complex.Gamma βs)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
| exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.492_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case this
s : β
β’ Tendsto (Complex.ofReal' β GammaSeq s) atTop (π (Complex.Gamma βs)) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
| convert Complex.GammaSeq_tendsto_Gamma s | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.492_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3
s : β
β’ Complex.ofReal' β GammaSeq s = Complex.GammaSeq βs | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
| ext1 n | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.492_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3.h
s : β
n : β
β’ (Complex.ofReal' β GammaSeq s) n = Complex.GammaSeq (βs) n | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
| dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq] | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.492_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3.h
s : β
n : β
β’ β(βn ^ s * βn ! / β j in Finset.range (n + 1), (s + βj)) = βn ^ βs * βn ! / β j in Finset.range (n + 1), (βs + βj) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
| push_cast | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.492_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case h.e'_3.h
s : β
n : β
β’ β(βn ^ s) * βn ! / β x in Finset.range (n + 1), (βs + βx) = βn ^ βs * βn ! / β x in Finset.range (n + 1), (βs + βx) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
| rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast] | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.492_0.in2QiCFW52coQT2 | /-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
β’ Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
| simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one] | /-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.503_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
β’ Complex.Gamma βs * Complex.Gamma (1 - βs) = βΟ / Complex.sin (βΟ * βs) | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
| exact Complex.Gamma_mul_Gamma_one_sub s | /-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.503_0.in2QiCFW52coQT2 | /-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
s : β
β’ (Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
exact Complex.Gamma_mul_Gamma_one_sub s
#align real.Gamma_mul_Gamma_one_sub Real.Gamma_mul_Gamma_one_sub
end Real
end GammaReflection
section InvGamma
open scoped Real
namespace Complex
/-! ## The reciprocal Gamma function
We show that the reciprocal Gamma function `1 / Ξ(s)` is entire. These lemmas show that (in this
case at least) mathlib's conventions for division by zero do actually give a mathematically useful
answer! (These results are useful in the theory of zeta and L-functions.) -/
/-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
| rcases ne_or_eq s 0 with (h | rfl) | /-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.527_0.in2QiCFW52coQT2 | /-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case inl
s : β
h : s β 0
β’ (Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
exact Complex.Gamma_mul_Gamma_one_sub s
#align real.Gamma_mul_Gamma_one_sub Real.Gamma_mul_Gamma_one_sub
end Real
end GammaReflection
section InvGamma
open scoped Real
namespace Complex
/-! ## The reciprocal Gamma function
We show that the reciprocal Gamma function `1 / Ξ(s)` is entire. These lemmas show that (in this
case at least) mathlib's conventions for division by zero do actually give a mathematically useful
answer! (These results are useful in the theory of zeta and L-functions.) -/
/-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· | rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ h] | /-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.527_0.in2QiCFW52coQT2 | /-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case inr
β’ (Gamma 0)β»ΒΉ = 0 * (Gamma (0 + 1))β»ΒΉ | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
exact Complex.Gamma_mul_Gamma_one_sub s
#align real.Gamma_mul_Gamma_one_sub Real.Gamma_mul_Gamma_one_sub
end Real
end GammaReflection
section InvGamma
open scoped Real
namespace Complex
/-! ## The reciprocal Gamma function
We show that the reciprocal Gamma function `1 / Ξ(s)` is entire. These lemmas show that (in this
case at least) mathlib's conventions for division by zero do actually give a mathematically useful
answer! (These results are useful in the theory of zeta and L-functions.) -/
/-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ h]
Β· | rw [zero_add, Gamma_zero, inv_zero, zero_mul] | /-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ h]
Β· | Mathlib.Analysis.SpecialFunctions.Gamma.Beta.527_0.in2QiCFW52coQT2 | /-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
β’ Differentiable β fun s => (Gamma s)β»ΒΉ | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
exact Complex.Gamma_mul_Gamma_one_sub s
#align real.Gamma_mul_Gamma_one_sub Real.Gamma_mul_Gamma_one_sub
end Real
end GammaReflection
section InvGamma
open scoped Real
namespace Complex
/-! ## The reciprocal Gamma function
We show that the reciprocal Gamma function `1 / Ξ(s)` is entire. These lemmas show that (in this
case at least) mathlib's conventions for division by zero do actually give a mathematically useful
answer! (These results are useful in the theory of zeta and L-functions.) -/
/-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ h]
Β· rw [zero_add, Gamma_zero, inv_zero, zero_mul]
#align complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one Complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one
/-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
| suffices : β n : β, β (s : β) (_ : -s.re < n), DifferentiableAt β (fun u : β => (Gamma u)β»ΒΉ) s | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.535_0.in2QiCFW52coQT2 | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
this : β (n : β) (s : β), -s.re < βn β DifferentiableAt β (fun u => (Gamma u)β»ΒΉ) s
β’ Differentiable β fun s => (Gamma s)β»ΒΉ
case this β’ β (n : β) (s : β), -s.re < βn β DifferentiableAt β (fun u => (Gamma u)β»ΒΉ) s | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
exact Complex.Gamma_mul_Gamma_one_sub s
#align real.Gamma_mul_Gamma_one_sub Real.Gamma_mul_Gamma_one_sub
end Real
end GammaReflection
section InvGamma
open scoped Real
namespace Complex
/-! ## The reciprocal Gamma function
We show that the reciprocal Gamma function `1 / Ξ(s)` is entire. These lemmas show that (in this
case at least) mathlib's conventions for division by zero do actually give a mathematically useful
answer! (These results are useful in the theory of zeta and L-functions.) -/
/-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ h]
Β· rw [zero_add, Gamma_zero, inv_zero, zero_mul]
#align complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one Complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one
/-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
suffices : β n : β, β (s : β) (_ : -s.re < n), DifferentiableAt β (fun u : β => (Gamma u)β»ΒΉ) s
| exact fun s =>
let β¨n, hβ© := exists_nat_gt (-s.re)
this n s h | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
suffices : β n : β, β (s : β) (_ : -s.re < n), DifferentiableAt β (fun u : β => (Gamma u)β»ΒΉ) s
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.535_0.in2QiCFW52coQT2 | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case this
β’ β (n : β) (s : β), -s.re < βn β DifferentiableAt β (fun u => (Gamma u)β»ΒΉ) s | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
exact Complex.Gamma_mul_Gamma_one_sub s
#align real.Gamma_mul_Gamma_one_sub Real.Gamma_mul_Gamma_one_sub
end Real
end GammaReflection
section InvGamma
open scoped Real
namespace Complex
/-! ## The reciprocal Gamma function
We show that the reciprocal Gamma function `1 / Ξ(s)` is entire. These lemmas show that (in this
case at least) mathlib's conventions for division by zero do actually give a mathematically useful
answer! (These results are useful in the theory of zeta and L-functions.) -/
/-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ h]
Β· rw [zero_add, Gamma_zero, inv_zero, zero_mul]
#align complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one Complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one
/-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
suffices : β n : β, β (s : β) (_ : -s.re < n), DifferentiableAt β (fun u : β => (Gamma u)β»ΒΉ) s
exact fun s =>
let β¨n, hβ© := exists_nat_gt (-s.re)
this n s h
| intro n | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
suffices : β n : β, β (s : β) (_ : -s.re < n), DifferentiableAt β (fun u : β => (Gamma u)β»ΒΉ) s
exact fun s =>
let β¨n, hβ© := exists_nat_gt (-s.re)
this n s h
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.535_0.in2QiCFW52coQT2 | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
case this
n : β
β’ β (s : β), -s.re < βn β DifferentiableAt β (fun u => (Gamma u)β»ΒΉ) s | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Ξ(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : β` with `s β {-n : n β β}` we have `Ξ s β 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β β` of the sequence
`n β¦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = Ο / sin Ο s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt Ο`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology BigOperators Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Ξ (u, v)`, defined as `β« x:β in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : β) : β :=
β« x : β in (0)..1, (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : β} (hu : 0 < re u) (v : β) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : β) β€ 1 / 2)] at hx
apply ContinuousAt.cpow
Β· exact (continuous_const.sub continuous_ofReal).continuousAt
Β· exact continuousAt_const
Β· rw [sub_re, one_re, ofReal_re, sub_pos]
exact Or.inl (hx.2.trans_lt (by norm_num : (1 / 2 : β) < 1))
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1) : β β β) volume 0 1 := by
refine' (betaIntegral_convergent_left hu v).trans _
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
Β· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> Β· push_cast; ring
Β· norm_num
Β· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : β) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : β => (x : β) ^ (u - 1) * (1 - (x : β)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, β intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel'', neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, β sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : β} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
Β· rwa [sub_re, one_re, β sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : β) {a : β} (ha : 0 < a) :
β« x in (0)..a, (x : β) ^ (s - 1) * ((a : β) - x) ^ (t - 1) =
(a : β) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : β) β 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : β) ^ (s + t - 1) = a * ((a : β) ^ (s - 1) * (a : β) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, β intervalIntegral.integral_const_mul, β real_smul, β zero_div a, β
div_self ha.ne', β intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
rw [mul_mul_mul_comm]
congr 1
Β· rw [β mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel' _ ha']
Β· rw [(by norm_cast : (1 : β) - β(x / a) = β(1 - x / a)), β
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel' _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul β β)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, β conv_int, β integral_mul_right (betaIntegral _ _)]
refine' set_integral_congr measurableSet_Ioi fun x hx => _
rw [mul_assoc, β betaIntegral_scaled s t hx, β intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
Β· rw [β Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : β} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) β 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : β β β := fun x => (x : β) ^ u * (1 - (x : β)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine' (ContinuousAt.continuousOn fun x hx => _).mul (ContinuousAt.continuousOn fun x hx => _)
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
Β· refine' (continuousAt_cpow_const_of_re_pos (Or.inl _) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : β x : β, x β Ioo (0 : β) 1 β
HasDerivAt F (u * ((x : β) ^ (u - 1) * (1 - (x : β)) ^ v) -
v * ((x : β) ^ u * (1 - (x : β)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : β => y ^ u) (u * (x : β) ^ (u - 1)) βx := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β)) (Or.inl ?_)
simp only [id_eq, mul_one] at this
Β· exact this
Β· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : β => (1 - y) ^ v) (-v * (1 - (x : β)) ^ (v - 1)) βx := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β))) (Or.inl ?_)
swap; Β· rw [id.def, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id.def] at A
have B : HasDerivAt (fun y : β => 1 - y) (-1) βx := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (βx) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel, add_sub_cancel] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne.def, true_and_iff,
sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne.def, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
Β· rw [betaIntegral, betaIntegral, β sub_eq_zero]
convert int_ev <;> ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
Β· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : β} (hu : 0 < re u) (n : β) :
betaIntegral u (n + 1) = n ! / β j : β in Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
Β· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
Β· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; Β· rw [β ofReal_nat_cast, ofReal_re]; positivity
rw [mul_comm u _, β eq_div_iff] at this
swap; Β· contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; Β· rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, β
mul_div_assoc, β div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β} (hs : 0 < re s) (n : β) :
GammaSeq s n = (n : β) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, β mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : β) {n : β} (hn : n β 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, β mul_assoc,
β mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
Β· refine' Finset.prod_congr (by rfl) fun x _ => _
push_cast; ring
Β· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : β} (hs : 0 < re s) {n : β} (hn : n β 0) :
GammaSeq s n = β« x : β in (0)..n, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) := by
have : β x : β, x = x / n * n := by intro x; rw [div_mul_cancel]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => β((1 - x) ^ n) * β(x * βn) ^ (s - 1) : β β β) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel,
β intervalIntegral.integral_const_mul, β intervalIntegral.integral_const_mul]
swap; Β· exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine' set_integral_congr measurableSet_Ioc fun x hx => _
push_cast
have hn' : (n : β) β 0 := Nat.cast_ne_zero.mpr hn
have A : (n : β) ^ s = (n : β) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : β) * βn) ^ (s - 1) = (x : β) ^ (s - 1) * (n : β) ^ (s - 1) := by
rw [β ofReal_nat_cast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_nat_cast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β} (hs : 0 < re s) :
Tendsto (fun n : β => β« x : β in (0)..n, ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)) atTop
(π <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : β β β β β := fun n =>
indicator (Ioc 0 (n : β)) fun x : β => ((1 - x / n) ^ n : β) * (x : β) ^ (s - 1)
-- integrability of f
have f_ible : β n : β, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, β IntegrableOn, β
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : β) β€ n)]
apply IntervalIntegrable.continuousOn_mul
Β· refine' intervalIntegral.intervalIntegrable_cpow' _
rwa [sub_re, one_re, β zero_sub, sub_lt_sub_iff_right]
Β· apply Continuous.continuousOn
exact IsROrC.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const βn)).pow n)
-- pointwise limit of f
have f_tends : β x : β, x β Ioi (0 : β) β
Tendsto (fun n : β => f n x) atTop (π <| β(Real.exp (-x)) * (x : β) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
show βαΆ n : β in atTop, β((1 - x / n) ^ n) * (x : β) ^ (s - 1) = f n x
Β· refine' Eventually.mp (eventually_ge_atTop βxββ) (eventually_of_forall fun n hn => _)
rw [Nat.ceil_le] at hn
dsimp only
rw [indicator_of_mem]
exact β¨hx, hnβ©
Β· simp_rw [mul_comm]
refine' (Tendsto.comp (continuous_ofReal.tendsto _) _).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, β sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
Β· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : β) _)),
intervalIntegral.integral_of_le (by positivity : 0 β€ (n : β)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
Β· intro n
refine' (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ fun x hx => _)
dsimp only
rcases lt_or_le (n : β) x with (hxn | hxn)
Β· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg_of_nonneg (le_of_lt hx) _
Β· rw [indicator_of_mem (mem_Ioc.mpr β¨mem_Ioi.mp hx, hxnβ©), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices β m : β, -βm < re s β Tendsto (GammaSeq s) atTop (π <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
Β· refine' (Nat.lt_floor_add_one _).trans_le _
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
Β· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [β Gamma_eq_GammaAux]
Β· refine' Tendsto.congr' _ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine' (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => _)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
Β· rwa [Nat.cast_zero, neg_lt_zero]
Β· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, β sub_eq_add_neg, sub_lt_iff_lt_add, β one_re, β add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [β mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β)] at this
simp_rw [add_assoc]
exact tendsto_coe_nat_div_add_atTop (1 + s)
#align complex.Gamma_seq_tendsto_Gamma Complex.GammaSeq_tendsto_Gamma
end Complex
end LimitFormula
section GammaReflection
/-! ## The reflection formula -/
namespace Complex
theorem GammaSeq_mul (z : β) {n : β} (hn : n β 0) :
GammaSeq z n * GammaSeq (1 - z) n =
n / (n + β1 - z) * (β1 / (z * β j in Finset.range n, (β1 - z ^ 2 / ((j : β) + 1) ^ 2))) := by
-- also true for n = 0 but we don't need it
have aux : β a b c d : β, a * b * (c * d) = a * c * (b * d) := by intros; ring
rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, β pow_two]
have : (n : β) ^ z * (n : β) ^ (1 - z) = n := by
rw [β cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel'_right, cpow_one]
rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, β Finset.prod_mul_distrib,
Nat.cast_zero, add_zero, add_comm (1 - z) n, β add_sub_assoc]
have : β j : β, (z + β(j + 1)) * (β1 - z + βj) =
((j + 1) ^ 2 :) * (β1 - z ^ 2 / ((j : β) + 1) ^ 2) := by
intro j
push_cast
have : (j : β) + 1 β 0 := by rw [β Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j
field_simp; ring
simp_rw [this]
rw [Finset.prod_mul_distrib, β Nat.cast_prod, Finset.prod_pow,
Finset.prod_range_add_one_eq_factorial, Nat.cast_pow,
(by intros; ring : β a b c d : β, a * b * (c * d) = a * (d * (b * c))), β div_div,
mul_div_cancel, β div_div, mul_comm z _, mul_one_div]
exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| Nat.factorial_ne_zero n)
#align complex.Gamma_seq_mul Complex.GammaSeq_mul
/-- Euler's reflection formula for the complex Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (z : β) : Gamma z * Gamma (1 - z) = Ο / sin (Ο * z) := by
have pi_ne : (Ο : β) β 0 := Complex.ofReal_ne_zero.mpr pi_ne_zero
by_cases hs : sin (βΟ * z) = 0
Β· -- first deal with silly case z = integer
rw [hs, div_zero]
rw [β neg_eq_zero, β Complex.sin_neg, β mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs
obtain β¨k, hkβ© := hs
rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false_iff,
neg_eq_iff_eq_neg] at hk
rw [hk]
cases k
Β· rw [Int.ofNat_eq_coe, Int.cast_ofNat, Complex.Gamma_neg_nat_eq_zero, zero_mul]
Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel',
Complex.Gamma_neg_nat_eq_zero, mul_zero]
refine' tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) _
have : βΟ / sin (βΟ * z) = 1 * (Ο / sin (Ο * z)) := by rw [one_mul]
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn =>
(GammaSeq_mul z hn).symm)) (Tendsto.mul _ _)
Β· convert tendsto_coe_nat_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc]
Β· have : βΟ / sin (βΟ * z) = 1 / (sin (Ο * z) / Ο) := by field_simp
convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne)
rw [β tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancel _ pi_ne]
convert tendsto_euler_sin_prod z using 1
ext1 n; rw [mul_comm, β mul_assoc]
#align complex.Gamma_mul_Gamma_one_sub Complex.Gamma_mul_Gamma_one_sub
/-- The Gamma function does not vanish on `β` (except at non-positive integers, where the function
is mathematically undefined and we set it to `0` by convention). -/
theorem Gamma_ne_zero {s : β} (hs : β m : β, s β -m) : Gamma s β 0 := by
by_cases h_im : s.im = 0
Β· have : s = βs.re := by
conv_lhs => rw [β Complex.re_add_im s]
rw [h_im, ofReal_zero, zero_mul, add_zero]
rw [this, Gamma_ofReal, ofReal_ne_zero]
refine' Real.Gamma_ne_zero fun n => _
specialize hs n
contrapose! hs
rwa [this, β ofReal_nat_cast, β ofReal_neg, ofReal_inj]
Β· have : sin (βΟ * s) β 0 := by
rw [Complex.sin_ne_zero_iff]
intro k
apply_fun im
rw [ofReal_mul_im, β ofReal_int_cast, β ofReal_mul, ofReal_im]
exact mul_ne_zero Real.pi_pos.ne' h_im
have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this
rw [β Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A
exact A.1
#align complex.Gamma_ne_zero Complex.Gamma_ne_zero
theorem Gamma_eq_zero_iff (s : β) : Gamma s = 0 β β m : β, s = -m := by
constructor
Β· contrapose!; exact Gamma_ne_zero
Β· rintro β¨m, rflβ©; exact Gamma_neg_nat_eq_zero m
#align complex.Gamma_eq_zero_iff Complex.Gamma_eq_zero_iff
/-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/
theorem Gamma_ne_zero_of_re_pos {s : β} (hs : 0 < re s) : Gamma s β 0 := by
refine' Gamma_ne_zero fun m => _
contrapose! hs
simpa only [hs, neg_re, β ofReal_nat_cast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _
#align complex.Gamma_ne_zero_of_re_pos Complex.Gamma_ne_zero_of_re_pos
end Complex
namespace Real
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We
will show that this tends to `Ξ(s)` as `n β β`. -/
noncomputable def GammaSeq (s : β) (n : β) :=
(n : β) ^ s * n ! / β j : β in Finset.range (n + 1), (s + j)
#align real.Gamma_seq Real.GammaSeq
/-- Euler's limit formula for the real Gamma function. -/
theorem GammaSeq_tendsto_Gamma (s : β) : Tendsto (GammaSeq s) atTop (π <| Gamma s) := by
suffices : Tendsto ((β) β GammaSeq s : β β β) atTop (π <| Complex.Gamma s)
exact (Complex.continuous_re.tendsto (Complex.Gamma βs)).comp this
convert Complex.GammaSeq_tendsto_Gamma s
ext1 n
dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq]
push_cast
rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_nat_cast]
#align real.Gamma_seq_tendsto_Gamma Real.GammaSeq_tendsto_Gamma
/-- Euler's reflection formula for the real Gamma function. -/
theorem Gamma_mul_Gamma_one_sub (s : β) : Gamma s * Gamma (1 - s) = Ο / sin (Ο * s) := by
simp_rw [β Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, β
Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one]
exact Complex.Gamma_mul_Gamma_one_sub s
#align real.Gamma_mul_Gamma_one_sub Real.Gamma_mul_Gamma_one_sub
end Real
end GammaReflection
section InvGamma
open scoped Real
namespace Complex
/-! ## The reciprocal Gamma function
We show that the reciprocal Gamma function `1 / Ξ(s)` is entire. These lemmas show that (in this
case at least) mathlib's conventions for division by zero do actually give a mathematically useful
answer! (These results are useful in the theory of zeta and L-functions.) -/
/-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/
theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β) :
(Gamma s)β»ΒΉ = s * (Gamma (s + 1))β»ΒΉ := by
rcases ne_or_eq s 0 with (h | rfl)
Β· rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ h]
Β· rw [zero_add, Gamma_zero, inv_zero, zero_mul]
#align complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one Complex.one_div_Gamma_eq_self_mul_one_div_Gamma_add_one
/-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
suffices : β n : β, β (s : β) (_ : -s.re < n), DifferentiableAt β (fun u : β => (Gamma u)β»ΒΉ) s
exact fun s =>
let β¨n, hβ© := exists_nat_gt (-s.re)
this n s h
intro n
| induction' n with m hm | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ := by
suffices : β n : β, β (s : β) (_ : -s.re < n), DifferentiableAt β (fun u : β => (Gamma u)β»ΒΉ) s
exact fun s =>
let β¨n, hβ© := exists_nat_gt (-s.re)
this n s h
intro n
| Mathlib.Analysis.SpecialFunctions.Gamma.Beta.535_0.in2QiCFW52coQT2 | /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where
Gamma itself is not). -/
theorem differentiable_one_div_Gamma : Differentiable β fun s : β => (Gamma s)β»ΒΉ | Mathlib_Analysis_SpecialFunctions_Gamma_Beta |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.