-- Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean
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)

Proof state:
case h.inl
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
f_tends : ∀ x ∈ Ioi 0, Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))
n : ℕ
x : ℝ
hx : x ∈ Ioi 0
hxn : ↑n < x
⊢ ‖(Ioc 0 ↑n).indicator (fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) x‖ ≤ rexp (-x) * x ^ (s.re - 1)

Tactic:
rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
  mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]

Result:
case h.inl
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
f_tends : ∀ x ∈ Ioi 0, Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))
n : ℕ
x : ℝ
hx : x ∈ Ioi 0
hxn : ↑n < x
⊢ 0 ≤ x ^ (s.re - 1)

Proof state:
case h
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
x : ℝ
hx : x ∈ Ioi 0
n : ℕ
hn : x ≤ ↑n
⊢ ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1) = f n x

Tactic:
dsimp only [f]

Result:
case h
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
x : ℝ
hx : x ∈ Ioi 0
n : ℕ
hn : x ≤ ↑n
⊢ ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1) = (Ioc 0 ↑n).indicator (fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) x

Proof state:
case hg
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ ContinuousOn (fun x => ↑((1 - x / ↑n) ^ n)) (uIcc 0 ↑n)

Tactic:
apply Continuous.continuousOn

Result:
case hg.h
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ Continuous fun x => ↑((1 - x / ↑n) ^ n)

Proof state:
s : ℂ
hs : 0 < s.re
⊢ Tendsto (fun n => ∫ (x : ℝ) in 0 ..↑n, ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) atTop (𝓝 (Gamma s))

Tactic:
rw [Gamma_eq_integral hs]

Result:
s : ℂ
hs : 0 < s.re
⊢ Tendsto (fun n => ∫ (x : ℝ) in 0 ..↑n, ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) atTop (𝓝 s.GammaIntegral)

Proof state:
case hg.h
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ Continuous fun x => ↑((1 - x / ↑n) ^ n)

Tactic:
exact RCLike.continuous_ofReal.comp ((continuous_const.sub (continuous_id'.div_const (n : ℝ))).pow n)

Result:
no goals

Proof state:
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
⊢ ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))

Tactic:
intro n

Result:
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ Integrable (f n) (volume.restrict (Ioi 0))

Proof state:
case h
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
f_tends : ∀ x ∈ Ioi 0, Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))
n : ℕ
x : ℝ
hx : x ∈ Ioi 0
⊢ ‖(Ioc 0 ↑n).indicator (fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) x‖ ≤ rexp (-x) * x ^ (s.re - 1)

Tactic:
rcases lt_or_le (n : ℝ) x with (hxn | hxn)

Result:
case h.inl
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
f_tends : ∀ x ∈ Ioi 0, Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))
n : ℕ
x : ℝ
hx : x ∈ Ioi 0
hxn : ↑n < x
⊢ ‖(Ioc 0 ↑n).indicator (fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) x‖ ≤ rexp (-x) * x ^ (s.re - 1)

case h.inr
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
f_tends : ∀ x ∈ Ioi 0, Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))
n : ℕ
x : ℝ
hx : x ∈ Ioi 0
hxn : x ≤ ↑n
⊢ ‖(Ioc 0 ↑n).indicator (fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) x‖ ≤ rexp (-x) * x ^ (s.re - 1)

Proof state:
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ Integrable (f n) (volume.restrict (Ioi 0))

Tactic:
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)]

Result:
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ IntervalIntegrable (fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) volume 0 ↑n

Proof state:
case hf
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ IntervalIntegrable (fun x => ↑x ^ (s - 1)) volume 0 ↑n

Tactic:
refine intervalIntegral.intervalIntegrable_cpow' ?_

Result:
case hf
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
n : ℕ
⊢ -1 < (s - 1).re

Proof state:
case h.inr
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
f_tends : ∀ x ∈ Ioi 0, Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))
n : ℕ
x : ℝ
hx : x ∈ Ioi 0
hxn : x ≤ ↑n
⊢ (1 - x / ↑n) ^ n ≤ rexp (-x)

Tactic:
exact one_sub_div_pow_le_exp_neg hxn

Result:
no goals

Proof state:
s : ℂ
hs : 0 < s.re
⊢ Tendsto (fun n => ∫ (x : ℝ) in 0 ..↑n, ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) atTop (𝓝 s.GammaIntegral)

Tactic:
let f : ℕ → ℝ → ℂ := fun n =>
  indicator (Ioc 0 (n : ℝ)) fun x : ℝ => ((1 - x / n) ^ n : ℝ) * (x : ℂ) ^ (s - 1)

Result:
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
⊢ Tendsto (fun n => ∫ (x : ℝ) in 0 ..↑n, ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)) atTop (𝓝 s.GammaIntegral)

Proof state:
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
x : ℝ
hx : x ∈ Ioi 0
⊢ Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))

Tactic:
apply Tendsto.congr'

Result:
case hl
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
x : ℝ
hx : x ∈ Ioi 0
⊢ ?f₁ =ᶠ[atTop] fun n => f n x

case h
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
x : ℝ
hx : x ∈ Ioi 0
⊢ Tendsto ?f₁ atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))

case f₁
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
x : ℝ
hx : x ∈ Ioi 0
⊢ ℕ → ℂ

Proof state:
s : ℂ
hs : 0 < s.re
f : ℕ → ℝ → ℂ := fun n => (Ioc 0 ↑n).indicator fun x => ↑((1 - x / ↑n) ^ n) * ↑x ^ (s - 1)
f_ible : ∀ (n : ℕ), Integrable (f n) (volume.restrict (Ioi 0))
f_tends : ∀ x ∈ Ioi 0, Tendsto (fun n => f n x) atTop (𝓝 (↑(rexp (-x)) * ↑x ^ (s - 1)))
n : ℕ
⊢ 0 ≤ ↑n

Tactic:
positivity

Result:
no goals