-- Mathlib/MeasureTheory/Constructions/BorelSpace/Metrizable.lean
theorem measurable_limit_of_tendsto_metrizable_ae {ι} [Countable ι] [Nonempty ι] {μ : Measure α}
    {f : ι → α → β} {L : Filter ι} [L.IsCountablyGenerated] (hf : ∀ n, AEMeasurable (f n) μ)
    (h_ae_tendsto : ∀ᵐ x ∂μ, ∃ l : β, Tendsto (fun n => f n x) L (𝓝 l)) :
    ∃ f_lim : α → β, Measurable f_lim ∧ ∀ᵐ x ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Proof state:
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Tactic:
rcases eq_or_neBot L with (rfl | hL)

Result:
case inl
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
hf : ∀ (n : ι), AEMeasurable (f n) μ
inhabited_h : Inhabited ι
inst✝ : ⊥.IsCountablyGenerated
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) ⊥ (𝓝 l)
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) ⊥ (𝓝 (f_lim x))

case inr
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
hL : L.NeBot
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Proof state:
case inr
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
hL : L.NeBot
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Tactic:
let p : α → (ι → β) → Prop := fun x f' => ∃ l : β, Tendsto (fun n => f' n) L (𝓝 l)

Result:
case inr
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
hL : L.NeBot
p : α → (ι → β) → Prop := fun x f' => ∃ l, Tendsto (fun n => f' n) L (𝓝 l)
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Proof state:
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Tactic:
inhabit ι

Result:
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Proof state:
case inr
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
hL : L.NeBot
p : α → (ι → β) → Prop := fun x f' => ∃ l, Tendsto (fun n => f' n) L (𝓝 l)
hp_mem : ∀ x ∈ aeSeqSet hf p, p x fun n => f n x
h_ae_eq : ∀ᵐ (x : α) ∂μ, ∀ (n : ι), aeSeq hf p n x = f n x
f_lim : α → β := fun x => if h : x ∈ aeSeqSet hf p then Exists.choose ⋯ else ⋯.some
hf_lim : ∀ (x : α), Tendsto (fun n => aeSeq hf p n x) L (𝓝 (f_lim x))
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Tactic:
have h_ae_tendsto_f_lim : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x)) :=
  h_ae_eq.mono fun x hx => (hf_lim x).congr hx

Result:
case inr
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
hL : L.NeBot
p : α → (ι → β) → Prop := fun x f' => ∃ l, Tendsto (fun n => f' n) L (𝓝 l)
hp_mem : ∀ x ∈ aeSeqSet hf p, p x fun n => f n x
h_ae_eq : ∀ᵐ (x : α) ∂μ, ∀ (n : ι), aeSeq hf p n x = f n x
f_lim : α → β := fun x => if h : x ∈ aeSeqSet hf p then Exists.choose ⋯ else ⋯.some
hf_lim : ∀ (x : α), Tendsto (fun n => aeSeq hf p n x) L (𝓝 (f_lim x))
h_ae_tendsto_f_lim : ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))
⊢ ∃ f_lim, Measurable f_lim ∧ ∀ᵐ (x : α) ∂μ, Tendsto (fun n => f n x) L (𝓝 (f_lim x))

Proof state:
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
hL : L.NeBot
p : α → (ι → β) → Prop := fun x f' => ∃ l, Tendsto (fun n => f' n) L (𝓝 l)
hp_mem : ∀ x ∈ aeSeqSet hf p, p x fun n => f n x
h_ae_eq : ∀ᵐ (x : α) ∂μ, ∀ (n : ι), aeSeq hf p n x = f n x
f_lim : α → β := fun x => if h : x ∈ aeSeqSet hf p then Exists.choose ⋯ else ⋯.some
⊢ ∀ (x : α), Tendsto (fun n => aeSeq hf p n x) L (𝓝 (f_lim x))

Tactic:
intro x

Result:
α : Type u_1
β : Type u_2
inst✝⁷ : MeasurableSpace α
inst✝⁶ : TopologicalSpace β
inst✝⁵ : PseudoMetrizableSpace β
inst✝⁴ : MeasurableSpace β
inst✝³ : BorelSpace β
ι : Type u_3
inst✝² : Countable ι
inst✝¹ : Nonempty ι
μ : Measure α
f : ι → α → β
L : Filter ι
inst✝ : L.IsCountablyGenerated
hf : ∀ (n : ι), AEMeasurable (f n) μ
h_ae_tendsto : ∀ᵐ (x : α) ∂μ, ∃ l, Tendsto (fun n => f n x) L (𝓝 l)
inhabited_h : Inhabited ι
hL : L.NeBot
p : α → (ι → β) → Prop := fun x f' => ∃ l, Tendsto (fun n => f' n) L (𝓝 l)
hp_mem : ∀ x ∈ aeSeqSet hf p, p x fun n => f n x
h_ae_eq : ∀ᵐ (x : α) ∂μ, ∀ (n : ι), aeSeq hf p n x = f n x
f_lim : α → β := fun x => if h : x ∈ aeSeqSet hf p then Exists.choose ⋯ else ⋯.some
x : α
⊢ Tendsto (fun n => aeSeq hf p n x) L (𝓝 (f_lim x))