import OAI.Analysis.FiniteFactor.Coupling.Prefix namespace OAI namespace FiniteFactor open MeasureTheory Filter Finset open scoped Topology ENNReal noncomputable section namespace CouplingParameters /-- Uniformly square-integrable finite endpoint densities produce an actual infinite-product density, with the same square-integral bound. -/ theorem infiniteEndpoint_density_of_prefix_bound {ι : Type*} (p : ι → CouplingParameters) (right : ι → Bool) (I : ℕ → Finset ι) (hmono : Monotone I) (hcover : ∀ J : Finset ι, ∃ n, J ⊆ I n) (C : ℝ) (hb : ∀ n, (∫ x, prefixDensity p right (I n) x ^ 2 ∂Measure.infinitePi (fun _ : ι => unitIntervalMeasure)) ≤ C) : ∃ g : (ι → ℝ) → ℝ, MemLp g 2 (Measure.infinitePi (fun _ : ι => unitIntervalMeasure)) ∧ (∀ᵐ x ∂Measure.infinitePi (fun _ : ι => unitIntervalMeasure), 0 ≤ g x) ∧ (∫ x, g x ^ 2 ∂Measure.infinitePi (fun _ : ι => unitIntervalMeasure)) ≤ C ∧ Measure.infinitePi (fun i => (p i).selectedLaw true (right i)) = (Measure.infinitePi (fun _ : ι => unitIntervalMeasure)).withDensity (fun x => ENNReal.ofReal (g x)) := by let μ := Measure.infinitePi (fun _ : ι => unitIntervalMeasure) obtain ⟨g, hg, hnon, hgb, hsets⟩ := exists_nonneg_L2_limit (fun n => prefixDensity p right (I n)) (fun n => prefixDensity_memLp p right (I n)) (fun n => Eventually.of_forall (prefixDensity_nonneg p right (I n))) C hb (fun n m hnm => prefixDensity_inner p right (hmono hnm)) refine ⟨g, hg, hnon, hgb, ?_⟩ apply (Measure.isProjectiveLimit_infinitePi (fun i => (p i).selectedLaw true (right i))).unique intro J apply Measure.ext intro S hS rw [Measure.map_apply (measurable_restrict J) hS, withDensity_apply _ (hS.preimage (measurable_restrict J)), ← ofReal_integral_eq_lintegral_ofReal (hg.integrable (by norm_num)).restrict (ae_restrict_of_ae hnon)] obtain ⟨N, hN⟩ := hcover J have he : ∀ n ≥ N, ENNReal.ofReal (∫ x in (J.restrict (π := fun _ : ι => ℝ)) ⁻¹' S, prefixDensity p right (I n) x ∂μ) = Measure.pi (fun i : J => (p i).selectedLaw true (right i)) S := by intro n hn exact prefixDensity_cylinder_of_subset p right (hN.trans (hmono hn)) hS have ht := (ENNReal.continuous_ofReal.tendsto _).comp (hsets ((J.restrict (π := fun _ : ι => ℝ)) ⁻¹' S) (hS.preimage (measurable_restrict J))) exact tendsto_nhds_unique ht (tendsto_atTop_of_eventually_const he) end CouplingParameters end end FiniteFactor end OAI