-- Mathlib/MeasureTheory/Integral/Lebesgue.lean
/-- If an antitone sequence of functions has a lower bound and the sequence of integrals of these
functions tends to the integral of the lower bound, then the sequence of functions converges
almost everywhere to the lower bound. -/
lemma tendsto_of_lintegral_tendsto_of_antitone {α : Type*} {mα : MeasurableSpace α}
    {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} {μ : Measure α}
    (hf_meas : ∀ n, AEMeasurable (f n) μ)
    (hf_tendsto : Tendsto (fun i ↦ ∫⁻ a, f i a ∂μ) atTop (𝓝 (∫⁻ a, F a ∂μ)))
    (hf_mono : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a))
    (h_bound : ∀ᵐ a ∂μ, ∀ i, F a ≤ f i a) (h0 : ∫⁻ a, f 0 a ∂μ ≠ ∞) :
    ∀ᵐ a ∂μ, Tendsto (fun i ↦ f i a) atTop (𝓝 (F a))

Proof state:
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
h_exists : ∀ᵐ (a : α) ∂μ, ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
F' : α → ℝ≥0∞ := fun a => if h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l) then h.choose else ⊤
hF'_tendsto : ∀ᵐ (a : α) ∂μ, Tendsto (fun i => f i a) atTop (𝓝 (F' a))
⊢ ∀ᵐ (a : α) ∂μ, Tendsto (fun i => f i a) atTop (𝓝 (F a))

Tactic:
suffices F' =ᵐ[μ] F by
  filter_upwards [this, hF'_tendsto] with a h_eq h_tendsto using h_eq ▸ h_tendsto

Result:
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
h_exists : ∀ᵐ (a : α) ∂μ, ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
F' : α → ℝ≥0∞ := fun a => if h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l) then h.choose else ⊤
hF'_tendsto : ∀ᵐ (a : α) ∂μ, Tendsto (fun i => f i a) atTop (𝓝 (F' a))
⊢ F' =ᶠ[ae μ] F

Proof state:
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
h_exists : ∀ᵐ (a : α) ∂μ, ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
F' : α → ℝ≥0∞ := fun a => if h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l) then h.choose else ⊤
⊢ ∀ᵐ (a : α) ∂μ, Tendsto (fun i => f i a) atTop (𝓝 (F' a))

Tactic:
filter_upwards [h_exists] with a ha

Result:
case h
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
h_exists : ∀ᵐ (a : α) ∂μ, ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
F' : α → ℝ≥0∞ := fun a => if h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l) then h.choose else ⊤
a : α
ha : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
⊢ Tendsto (fun i => f i a) atTop (𝓝 (F' a))

Proof state:
case h
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
a : α
h_mono : Antitone fun i => f i a
⊢ ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)

Tactic:
rcases _root_.tendsto_of_antitone h_mono with h | h

Result:
case h.inl
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
a : α
h_mono : Antitone fun i => f i a
h : Tendsto (fun i => f i a) atTop atBot
⊢ ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)

case h.inr
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
a : α
h_mono : Antitone fun i => f i a
h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
⊢ ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)

Proof state:
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
h_exists : ∀ᵐ (a : α) ∂μ, ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
F' : α → ℝ≥0∞ := fun a => if h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l) then h.choose else ⊤
hF'_tendsto : ∀ᵐ (a : α) ∂μ, Tendsto (fun i => f i a) atTop (𝓝 (F' a))
⊢ F' =ᶠ[ae μ] F

Tactic:
have hF'_le : F ≤ᵐ[μ] F' := by
  filter_upwards [h_bound, hF'_tendsto] with a h_le h_tendsto
  exact ge_of_tendsto' h_tendsto (fun m ↦ h_le _)

Result:
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
h_exists : ∀ᵐ (a : α) ∂μ, ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
F' : α → ℝ≥0∞ := fun a => if h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l) then h.choose else ⊤
hF'_tendsto : ∀ᵐ (a : α) ∂μ, Tendsto (fun i => f i a) atTop (𝓝 (F' a))
hF'_le : F ≤ᶠ[ae μ] F'
⊢ F' =ᶠ[ae μ] F

Proof state:
case h
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
h_exists : ∀ᵐ (a : α) ∂μ, ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
F' : α → ℝ≥0∞ := fun a => if h : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l) then h.choose else ⊤
a : α
ha : ∃ l, Tendsto (fun i => f i a) atTop (𝓝 l)
⊢ Tendsto (fun i => f i a) atTop (𝓝 ha.choose)

Tactic:
exact ha.choose_spec

Result:
no goals

Proof state:
case h.inl
α : Type u_5
mα : MeasurableSpace α
f : ℕ → α → ℝ≥0∞
F : α → ℝ≥0∞
μ : Measure α
hf_meas : ∀ (n : ℕ), AEMeasurable (f n) μ
hf_tendsto : Tendsto (fun i => ∫⁻ (a : α), f i a ∂μ) atTop (𝓝 (∫⁻ (a : α), F a ∂μ))
hf_mono : ∀ᵐ (a : α) ∂μ, Antitone fun i => f i a
h_bound : ∀ᵐ (a : α) ∂μ, ∀ (i : ℕ), F a ≤ f i a
h0 : ∫⁻ (a : α), f 0 a ∂μ ≠ ⊤
h_int_finite : ∫⁻ (a : α), F a ∂μ ≠ ⊤
a : α
h_mono : Antitone fun i => f i a
h : Tendsto (fun i => f i a) atTop atBot
⊢ pure ⊥ ≤ 𝓝 0

Tactic:
exact pure_le_nhds _

Result:
no goals