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