import Mathlib.MeasureTheory.Function.L2Space import Mathlib.Probability.ProductMeasure import Mathlib.MeasureTheory.Function.AEEqOfIntegral namespace OAI namespace FiniteFactor open MeasureTheory Filter open scoped Topology ENNReal noncomputable section /-- Nested orthogonal projections with bounded squared norms converge strongly. For product densities, normalization supplies the displayed inner identity. -/ theorem exists_limit_of_nested_inner {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] (f : ℕ → E) (C : ℝ) (hbound : ∀ n, ‖f n‖ ^ 2 ≤ C) (hinner : ∀ n m, n ≤ m → inner ℝ (f n) (f m) = ‖f n‖ ^ 2) : ∃ g : E, Tendsto f atTop (𝓝 g) ∧ ‖g‖ ^ 2 ≤ C := by have hdist (n m : ℕ) (hnm : n ≤ m) : ‖f m - f n‖ ^ 2 = ‖f m‖ ^ 2 - ‖f n‖ ^ 2 := by rw [norm_sub_sq_real, real_inner_comm, hinner n m hnm] ring have hmono : Monotone (fun n => ‖f n‖ ^ 2) := by intro n m hnm have := sq_nonneg ‖f m - f n‖ rw [hdist n m hnm] at this linarith have hbdd : BddAbove (Set.range (fun n => ‖f n‖ ^ 2)) := ⟨C, by rintro _ ⟨n, rfl⟩; exact hbound n⟩ have hc := (tendsto_atTop_ciSup hmono hbdd).cauchySeq have hf : CauchySeq f := by rw [Metric.cauchySeq_iff] at hc ⊢ intro ε hε obtain ⟨N, hN⟩ := hc (ε^2) (sq_pos_of_pos hε) refine ⟨N, fun n hn m hm => ?_⟩ have hh := hN n hn m hm rw [Real.dist_eq] at hh rw [dist_eq_norm] rcases le_total n m with hnm | hmn · have hd := hdist n m hnm rw [norm_sub_rev] at hd have hle := le_abs_self (‖f m‖ ^ 2 - ‖f n‖ ^ 2) rw [abs_sub_comm] at hh nlinarith [norm_nonneg (f n - f m)] · have hd := hdist m n hmn have hle := le_abs_self (‖f n‖ ^ 2 - ‖f m‖ ^ 2) nlinarith [norm_nonneg (f n - f m)] obtain ⟨g, hg⟩ := cauchySeq_tendsto_of_complete hf exact ⟨g, hg, le_of_tendsto (hg.norm.pow 2) (Eventually.of_forall hbound)⟩ theorem l2_norm_sq {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} (f : Lp ℝ 2 μ) : ‖f‖ ^ 2 = ∫ x, f x ^ 2 ∂μ := by rw [← real_inner_self_eq_norm_sq, L2.inner_def] simp only [RCLike.inner_apply, conj_trivial, sq] theorem l2_inner_toLp {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {f g : Ω → ℝ} (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) : inner ℝ (hf.toLp f) (hg.toLp g) = ∫ x, f x * g x ∂μ := by rw [L2.inner_def] apply integral_congr_ae filter_upwards [hf.coeFn_toLp, hg.coeFn_toLp] with x hx hy simp [hx, hy, RCLike.inner_apply, mul_comm] theorem l2_tendsto_setIntegral {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsFiniteMeasure μ] {f : ℕ → Lp ℝ 2 μ} {g : Lp ℝ 2 μ} (h : Tendsto f atTop (𝓝 g)) {S : Set Ω} (hS : MeasurableSet S) : Tendsto (fun n => ∫ x in S, f n x ∂μ) atTop (𝓝 (∫ x in S, g x ∂μ)) := by have ht := tendsto_const_nhds.inner h (𝕜 := ℝ) (x := indicatorConstLp 2 hS (measure_ne_top μ S) (1 : ℝ)) simpa only [L2.inner_indicatorConstLp_eq_setIntegral_inner, RCLike.inner_apply, conj_trivial, mul_one] using ht /-- An actual nonnegative L2 function, obtained by completeness, with convergence of integrals on every measurable set. No limiting density is assumed. -/ theorem exists_nonneg_L2_limit {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsFiniteMeasure μ] (f : ℕ → Ω → ℝ) (hf : ∀ n, MemLp (f n) 2 μ) (hnon : ∀ n, ∀ᵐ x ∂μ, 0 ≤ f n x) (C : ℝ) (hbound : ∀ n, (∫ x, f n x ^ 2 ∂μ) ≤ C) (hinner : ∀ n m, n ≤ m → (∫ x, f n x * f m x ∂μ) = ∫ x, f n x ^ 2 ∂μ) : ∃ g : Ω → ℝ, MemLp g 2 μ ∧ (∀ᵐ x ∂μ, 0 ≤ g x) ∧ (∫ x, g x ^ 2 ∂μ) ≤ C ∧ ∀ S, MeasurableSet S → Tendsto (fun n => ∫ x in S, f n x ∂μ) atTop (𝓝 (∫ x in S, g x ∂μ)) := by let F (n : ℕ) := (hf n).toLp (f n) have hsq (n : ℕ) : ‖F n‖ ^ 2 = ∫ x, f n x ^ 2 ∂μ := by rw [l2_norm_sq] exact integral_congr_ae ((hf n).coeFn_toLp.mono fun x hx => congrArg (fun r : ℝ => r^2) hx) obtain ⟨g, hg, hgb⟩ := exists_limit_of_nested_inner F C (fun n => (hsq n).trans_le (hbound n)) (fun n m hnm => by rw [l2_inner_toLp, hinner n m hnm, hsq n]) have hsets (S : Set Ω) (hS : MeasurableSet S) : Tendsto (fun n => ∫ x in S, f n x ∂μ) atTop (𝓝 (∫ x in S, g x ∂μ)) := by have heq (n : ℕ) : (∫ x in S, F n x ∂μ) = ∫ x in S, f n x ∂μ := setIntegral_congr_ae hS ((hf n).coeFn_toLp.mono fun x hx _ => hx) simpa only [heq] using l2_tendsto_setIntegral hg hS refine ⟨g, (Lp.memLp g), ?_, (l2_norm_sq g) ▸ hgb, hsets⟩ exact ae_nonneg_of_forall_setIntegral_nonneg ((Lp.memLp g).integrable (by norm_num)) (fun S hS _ => ge_of_tendsto (hsets S hS) (Eventually.of_forall fun n => integral_nonneg_of_ae (ae_restrict_of_ae (hnon n)))) end end FiniteFactor end OAI