import OAI.Probability.FKMaps.HeightBounds namespace OAI noncomputable section open Set Filter MeasureTheory ProbabilityTheory open scoped Topology BigOperators ENNReal NNReal namespace FKCRT.TreeCoding def codeEmbedding (N : ℕ) : Code N ↪ (Fin N → ℕ) := ⟨fun d => bridgeEmbedding N ⟨d.val,d.property.1⟩, fun _ _ h => Subtype.ext (congrArg (fun b : Bridge N => b.val) ((bridgeEmbedding N).injective h))⟩ lemma CriticalEvenOffspring.code_probability_le_stream (p : CriticalEvenOffspring) (n : ℕ) (E : Set (Code (2*n+1))) (A : Set (ℕ → ℕ)) (hEA : ∀ d ∈ E, ∀ x, streamPrefix (2*n+1) x=codeEmbedding (2*n+1) d → x∈A) : (p.codeLaw n).real E ≤ p.streamLaw.real A / codePartition p (2*n+1) := by classical let N := 2*n+1 let C : Code N → Set (ℕ → ℕ) := fun d => if d∈E then streamPrefix N ⁻¹' {codeEmbedding N d} else ∅ have hm (d) : MeasurableSet (C d) := by dsimp [C] split_ifs · exact (measurableSet_singleton _).preimage (measurable_streamPrefix N) · exact MeasurableSet.empty have hd : Pairwise (fun d e => Disjoint (C d) (C e)) := by intro d e hde dsimp [C] split_ifs <;> try simp exact (Set.disjoint_singleton.mpr ((codeEmbedding N).injective.ne hde)).preimage _ have he (d : Code N) : p.streamLaw.real (C d) = if d∈E then codeWeight p d else 0 := by dsimp [C] split_ifs · rw [(p.streamPrefix_hasLaw N).measurePreserving (measurable_streamPrefix N) |>.measureReal_preimage (measurableSet_singleton _).nullMeasurableSet] exact p.iid_bridge_singleton ⟨d.val,d.property.1⟩ · simp have hb : (∑ d : Code N, if d∈E then codeWeight p d else 0) ≤ p.streamLaw.real A := by rw [← show p.streamLaw.real (⋃ d, C d)=∑ d : Code N, if d∈E then codeWeight p d else 0 by rw [measureReal_iUnion_fintype hd hm]; simp only [he]] apply measureReal_mono (h₂ := measure_ne_top _ _) rintro x ⟨_,⟨d,rfl⟩,hx⟩ dsimp [C] at hx split_ifs at hx with hE · exact hEA d hE x hx · exact hx.elim rw [← integral_indicator_one (μ := p.codeLaw n) (show MeasurableSet E from trivial),p.code_integral] apply (le_div_iff₀ (codePartition_odd_pos p n)).mpr have heq : (∑ d : Code (2*n+1), (codeWeight p d/codePartition p (2*n+1)) * E.indicator (fun _ => (1:ℝ)) d)*codePartition p (2*n+1)= ∑ d : Code (2*n+1), if d∈E then codeWeight p d else 0 := by rw [Finset.sum_mul] apply Finset.sum_congr rfl intro d _ dsimp [Set.indicator] split_ifs · field_simp [(codePartition_odd_pos p n).ne'] · simp change (∑ d : Code (2*n+1), (codeWeight p d/codePartition p (2*n+1)) * E.indicator (fun _ => (1:ℝ)) d)*codePartition p (2*n+1) ≤ _ rw [heq] exact hb lemma recordHeight_congr_prefix {S T : ℕ → ℤ} {N j : ℕ} (hj : j ≤ N) (hST : ∀ k ≤ N, S k=T k) : recordHeight S 0 j=recordHeight T 0 j := by unfold recordHeight congr 1 ext k simp only [mem_reverseRecords] constructor <;> rintro ⟨hk0,hkj,hk⟩ <;> refine ⟨hk0,hkj,?_⟩ <;> intro r hkr hrj · rw [← hST k (by omega),← hST r (by omega)] exact hk r hkr hrj · rw [hST k (by omega),hST r (by omega)] exact hk r hkr hrj def codeHeightModulusFailure {N : ℕ} (m : ℕ) (c : ℝ) : Set (Code N) := {d | ∃ a b, a ≤ b ∧ b ≤ N ∧ (∀ u v, a ≤ u → u ≤ b → a ≤ v → v ≤ b → (walk d.val u:ℝ)-(walk d.val v:ℝ) ?_⟩ apply (p.code_probability_le_stream n _ _ (fun _ hd _ hx => codeHeightModulusFailure_stream hd hx)).trans apply div_le_div_of_nonneg_right _ (codePartition_nonneg p _) have hnn : 0 ≤ ((2*n+1:ℕ)+1:ℝ)*ρ^m := by positivity have hh' : p.streamLaw (heightModulusFailure (2*n+1) m (c*m)) ≤ ENNReal.ofReal (((2*n+1:ℕ)+1:ℝ)*ρ^m) := by rw [ENNReal.ofReal_mul (by positivity : 0 ≤ ((2*n+1:ℕ)+1:ℝ)), show ((2*n+1:ℕ):ℝ)+1=((2*n+1+1:ℕ):ℝ) by push_cast; rfl, ENNReal.ofReal_natCast] exact hb (2*n+1) m have hh := ENNReal.toReal_mono ENNReal.ofReal_ne_top hh' simpa only [measureReal_def,ENNReal.toReal_ofReal hnn] using hh lemma CriticalEvenOffspring.code_geometric_vanish (p : CriticalEvenOffspring) {ε ρ : ℝ} (hε : 0<ε) (hρ : 0 ≤ ρ) (hρ1 : ρ<1) : Tendsto (fun n => ((2*n+1:ℕ)+1:ℝ)*ρ^⌈ε*Real.sqrt ((2*n+1:ℕ):ℝ)⌉₊ / codePartition p (2*n+1)) atTop (𝓝 0) := by let s : ℕ → ℝ := fun n => Real.sqrt ((2*n+1:ℕ):ℝ) have hs0 (n) : 0 ≤ s n := Real.sqrt_nonneg _ have h5 := polynomial_geometric_ceil odd_sqrt_tendsto hs0 hε hρ hρ1 5 have h3 := polynomial_geometric_ceil odd_sqrt_tendsto hs0 hε hρ hρ1 3 have hpos : 0 < 2/(p.sigma*Real.sqrt (2*Real.pi)) := div_pos (by norm_num) (mul_pos p.sigma_pos (Real.sqrt_pos.mpr (by positivity))) have ht := (h5.add h3).div p.codePartition_asymptotic hpos.ne' simp only [zero_add,zero_div] at ht convert ht using 1 funext n have hs : s n^2=((2*n+1:ℕ):ℝ) := Real.sq_sqrt (by positivity) have hsne : s n≠0 := (Real.sqrt_pos.mpr (by positivity : (0:ℝ)<((2*n+1:ℕ):ℝ))).ne' dsimp only [Pi.div_apply] rw [show (2*n+1:ℝ)=((2*n+1:ℕ):ℝ) by push_cast; rfl] change (((2*n+1:ℕ):ℝ)+1)*ρ^⌈ε*s n⌉₊/codePartition p (2*n+1)= ((s n)^5*ρ^⌈ε*s n⌉₊+(s n)^3*ρ^⌈ε*s n⌉₊)/ (((2*n+1:ℕ):ℝ)*s n*codePartition p (2*n+1)) have he : (s n)^5*ρ^⌈ε*s n⌉₊+(s n)^3*ρ^⌈ε*s n⌉₊ = (((2*n+1:ℕ):ℝ)+1)*ρ^⌈ε*s n⌉₊ * (((2*n+1:ℕ):ℝ)*s n) := by calc _ = ((s n)^2+1)*ρ^⌈ε*s n⌉₊*((s n)^2*s n) := by ring _ = _ := by rw [hs] rw [he] push_cast rw [mul_comm _ (codePartition p (2*n+1)),mul_div_mul_right] exact mul_ne_zero (by positivity) hsne end FKCRT.TreeCoding end noncomputable section open Set Filter MeasureTheory ProbabilityTheory open scoped Topology BigOperators ENNReal NNReal namespace FKCRT.TreeCoding abbrev ClosePairs (δ : ℝ) := {st : unitInterval × unitInterval // dist st.1 st.2 ≤ δ} instance (δ : ℝ) : CompactSpace (ClosePairs δ) := isCompact_iff_compactSpace.mp ((isClosed_le (continuous_fst.dist continuous_snd) continuous_const).isCompact) def oscillationPath (δ : ℝ) (f : C(unitInterval,ℝ)) : C(ClosePairs δ,ℝ) := ⟨fun st => f st.val.1-f st.val.2, by fun_prop⟩ def pathOscillation (δ : ℝ) (f : C(unitInterval,ℝ)) : ℝ := ‖oscillationPath δ f‖ lemma pathOscillation_nonneg (δ : ℝ) (f : C(unitInterval,ℝ)) : 0 ≤ pathOscillation δ f := norm_nonneg _ lemma pathOscillation_le {δ M : ℝ} (hM : 0 ≤ M) (f : C(unitInterval,ℝ)) (h : ∀ s t, dist s t ≤ δ → |f s-f t| ≤ M) : pathOscillation δ f ≤ M := by apply (ContinuousMap.norm_le _ hM).mpr intro st exact h st.val.1 st.val.2 st.property lemma sub_le_pathOscillation {δ : ℝ} (f : C(unitInterval,ℝ)) {s t : unitInterval} (hst : dist s t ≤ δ) : |f s-f t| ≤ pathOscillation δ f := (oscillationPath δ f).norm_coe_le_norm ⟨(s,t),hst⟩ lemma pathOscillation_lipschitz (δ : ℝ) : LipschitzWith 2 (pathOscillation δ) := by apply LipschitzWith.of_dist_le_mul intro f g apply (dist_norm_norm_le (oscillationPath δ f) (oscillationPath δ g)).trans rw [dist_eq_norm] apply (ContinuousMap.norm_le _ (by positivity)).mpr intro st change |(f st.val.1-f st.val.2)-(g st.val.1-g st.val.2)| ≤ (2:ℝ≥0)*‖f-g‖ have h1 := (f-g).norm_coe_le_norm st.val.1 have h2 := (f-g).norm_coe_le_norm st.val.2 change |f st.val.1-g st.val.1| ≤ ‖f-g‖ at h1 change |f st.val.2-g st.val.2| ≤ ‖f-g‖ at h2 have ht := abs_sub ((f-g) st.val.1) ((f-g) st.val.2) simp only [ContinuousMap.sub_apply] at ht have he : (f st.val.1-f st.val.2)-(g st.val.1-g st.val.2)= (f st.val.1-g st.val.1)-(f st.val.2-g st.val.2) := by ring rw [he] change _ ≤ 2*‖f-g‖ linarith lemma pathOscillation_vanish (f : C(unitInterval,ℝ)) : Tendsto (fun j : ℕ => pathOscillation (1/(j+1:ℝ)) f) atTop (𝓝 0) := by rw [Metric.tendsto_nhds] intro ε hε obtain ⟨δ,hδ,hd⟩ := Metric.uniformContinuous_iff.mp (CompactSpace.uniformContinuous_of_continuous f.continuous) (ε/2) (by positivity) have ht : Tendsto (fun j : ℕ => 1/(j+1:ℝ)) atTop (𝓝 0) := tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop.atTop_add tendsto_const_nhds) filter_upwards [ht.eventually (gt_mem_nhds hδ)] with j hj rw [Real.dist_eq,sub_zero,abs_of_nonneg (pathOscillation_nonneg _ _)] apply lt_of_le_of_lt (pathOscillation_le (by positivity : 0 ≤ ε/2) f ?_) (by linarith) intro s t hst exact (hd (hst.trans_lt hj)).le local instance : MeasurableSpace C(unitInterval,ℝ) := borel _ local instance : BorelSpace C(unitInterval,ℝ) := ⟨rfl⟩ def oscillationGauge (δ ε : ℝ) (f : C(unitInterval,ℝ)) := min 1 (pathOscillation δ f/ε) lemma oscillationGauge_continuous (δ ε : ℝ) : Continuous (oscillationGauge δ ε) := continuous_const.min ((pathOscillation_lipschitz δ).continuous.div_const ε) lemma oscillationGauge_nonneg (δ : ℝ) {ε : ℝ} (hε : 0 ≤ ε) (f : C(unitInterval,ℝ)) : 0 ≤ oscillationGauge δ ε f := le_min (by norm_num) (div_nonneg (pathOscillation_nonneg _ _) hε) lemma oscillationGauge_abs_le (δ : ℝ) {ε : ℝ} (hε : 0 ≤ ε) (f : C(unitInterval,ℝ)) : |oscillationGauge δ ε f| ≤ 1 := by rw [abs_of_nonneg (oscillationGauge_nonneg δ hε f)] exact min_le_left _ _ lemma oscillationGauge_integral_vanish {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {X : Ω → C(unitInterval,ℝ)} (hX : AEMeasurable X μ) {ε : ℝ} (hε : 0<ε) : Tendsto (fun j : ℕ => ∫ ω, oscillationGauge (1/(j+1:ℝ)) ε (X ω) ∂μ) atTop (𝓝 0) := by have hh := tendsto_integral_of_dominated_convergence (fun _ : Ω => (1:ℝ)) (F := fun j ω => oscillationGauge (1/(j+1:ℝ)) ε (X ω)) (f := fun _=>0) (fun j => ((oscillationGauge_continuous _ ε).measurable.comp_aemeasurable hX).aestronglyMeasurable) (integrable_const _) (fun _ => ae_of_all μ (fun _ => oscillationGauge_abs_le _ hε.le _)) (by apply ae_of_all intro ω have ht := tendsto_const_nhds.min ((pathOscillation_vanish (X ω)).div_const ε) (f := fun _ : ℕ => (1:ℝ)) simpa only [oscillationGauge,zero_div,min_eq_right (by norm_num : (0:ℝ) ≤ 1)] using ht) simpa only [integral_zero] using hh lemma oscillation_probability_le_gauge {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {X : Ω → C(unitInterval,ℝ)} (hX : Measurable X) (δ : ℝ) {ε : ℝ} (hε : 0<ε) : μ.real {ω | ε oscillationGauge δ ε (X ω)) μ := Integrable.of_bound ((oscillationGauge_continuous _ _).measurable.comp hX).aestronglyMeasurable 1 (ae_of_all μ (fun _ => oscillationGauge_abs_le _ hε.le _)) let E := {ω | ε hosc s t (haj.trans hjs) (hsk.trans hkb) (haj.trans hjt) (htk.trans hkb),hn⟩ obtain h₁|h₁ := le_total u v · have hh' := hh h₁ hau hvb have h2 : (height d.val v:ℝ) ≤ height d.val u+m := by exact_mod_cast hh'.1 have h3 : (height d.val u:ℝ) ≤ height d.val v+m := by exact_mod_cast hh'.2 exact abs_le.mpr ⟨by linarith,by linarith⟩ · have hh' := hh h₁ hav hub have h2 : (height d.val u:ℝ) ≤ height d.val v+m := by exact_mod_cast hh'.1 have h3 : (height d.val v:ℝ) ≤ height d.val u+m := by exact_mod_cast hh'.2 exact abs_le.mpr ⟨by linarith,by linarith⟩ lemma error_le_error_add {w₁ w₂ h₁ h₂ ν a b : ℝ} (hν : 0 ≤ ν) (hw : |w₁-w₂| ≤ a) (hh : |h₁-h₂| ≤ b) : |w₁-ν*h₁| ≤ |w₂-ν*h₂|+a+ν*b := by have he : w₁-ν*h₁=(w₂-ν*h₂)+(w₁-w₂)-ν*(h₁-h₂) := by ring rw [he] have ht := (abs_sub ((w₂-ν*h₂)+(w₁-w₂)) (ν*(h₁-h₂))).trans (add_le_add (abs_add_le (w₂-ν*h₂) (w₁-w₂)) le_rfl) rw [abs_mul,abs_of_nonneg hν] at ht nlinarith lemma badHeightFraction_interval_lower {N r a : ℕ} (har : a+r ≤ N) {ν t : ℝ} (d : Code N) (hbad : ∀ k ⟨a+k.val,by omega⟩ let S := Finset.univ.filter (fun k : Fin N => t< |(walk d.val k.val:ℝ)-ν*height d.val k.val|) have hm : ∀ k : Fin r, f k∈S := fun k => Finset.mem_filter.mpr ⟨Finset.mem_univ _,hbad k.val k.isLt⟩ have hf : Function.Injective f := by intro i j hij have hh := congrArg Fin.val hij dsimp [f] at hh exact Fin.ext (by omega) have hc : r ≤ S.card := by have hh := Finset.card_le_card (show Finset.univ.image f ⊆ S by intro k hk obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hk exact hm i) simpa only [Finset.card_image_of_injective _ hf,Finset.card_univ,Fintype.card_fin] using hh unfold badHeightFraction apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg N) rw [← Finset.sum_filter] simpa only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] using (show (r:ℝ) ≤ S.card by exact_mod_cast hc) lemma uniform_error_of_average {N m r : ℕ} {ν c a t : ℝ} (d : Code N) (hν : 0 ≤ ν) (hr : r ≤ N) (hgood : d∉codeHeightModulusFailure m c) (hosc : ∀ u v, u ≤ N → v ≤ N → (u:ℤ)-v ≤ r → (v:ℤ)-u ≤ r → |(walk d.val u:ℝ)-(walk d.val v:ℝ)| ≤ a) (hac : a ?_) · exact (not_lt_of_ge hfrac) havg have hH := height_pair_control hgood hbr hlocal hbj hjbr (by omega : b ≤ b+k) (by omega : b+k ≤ b+r) have hW := hw j (b+k) hbj hjbr (by omega) (by omega) have he := error_le_error_add hν hW hH linarith end FKCRT.TreeCoding end noncomputable section open Set Filter MeasureTheory ProbabilityTheory open scoped Topology BigOperators ENNReal NNReal namespace FKCRT.TreeCoding local instance : MeasurableSpace C(unitInterval,ℝ) := borel _ local instance : BorelSpace C(unitInterval,ℝ) := ⟨rfl⟩ lemma CriticalEvenOffspring.codeWalk_converges (p : CriticalEvenOffspring) {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] {B : ℝ≥0 → Ω → ℝ} (hB : IsBrownianReal B P) : TendstoInDistribution (fun n (d : Code (2*n+1)) => walkPolygon p.sigma d.val) atTop (fun ω => vervaat (bridgePath B ω)) p.codeLaw P := by have hX (n : ℕ) : AEMeasurable (fun d : Code (2*n+1) => walkPolygon p.sigma d.val) (p.codeLaw n) := (measurable_of_countable _).aemeasurable have hY := (p.iidVervaat_CLT hB).aemeasurable_limit refine ⟨hX,hY,?_⟩ apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr intro F change Tendsto (fun n => ∫ f,F f ∂(p.codeLaw n).map (fun d => walkPolygon p.sigma d.val)) atTop (𝓝 (∫ f,F f ∂P.map (fun ω => vervaat (bridgePath B ω)))) simp_rw [integral_map (hX _) F.continuous.aestronglyMeasurable, integral_map hY F.continuous.aestronglyMeasurable,p.code_integral] exact p.codeWalk_CLT hB F lemma gridPoint_dist_le {N r u v : ℕ} (_hN : 0 badHeightFraction_nonneg ν a d)) (Integrable.of_finite) t simpa only [mul_comm] using hh /-- Exact conditioned critical finite-variance height/walk coupling, uniformly at every depth-first vertex. Only the stated second moment is used. -/ theorem CriticalEvenOffspring.uniform_height_error_limit (p : CriticalEvenOffspring) {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] {B : ℝ≥0 → Ω → ℝ} (hB : IsBrownianReal B P) {ε : ℝ} (hε : 0<ε) : Tendsto (fun n => (p.codeLaw n).real {d | ∃ j<2*n+1, ε*Real.sqrt ((2*n+1:ℕ):ℝ)< |(walk d.val j:ℝ)-(p.variance/2)*height d.val j|}) atTop (𝓝 0) := by obtain ⟨c,ρ,hc,hρ,hρ1,hmod⟩ := p.code_height_modulus_bound let ν := p.variance/2 have hν : 0<ν := half_pos p.variance_pos let κ := ε/(8*ν) have hκ : 0<κ := div_pos hε (by positivity) have hκeq : ν*κ=ε/8 := by dsimp [κ]; field_simp let θ := min (ε/(4*p.sigma)) (c*κ/(2*p.sigma)) have hσ := p.sigma_pos have hθ : 0<θ := lt_min (div_pos hε (by positivity)) (div_pos (mul_pos hc hκ) (by positivity)) have hθε : θ*p.sigma ≤ ε/4 := by calc _ ≤ (ε/(4*p.sigma))*p.sigma := mul_le_mul_of_nonneg_right (min_le_left _ _) hσ.le _ = _ := by field_simp have hθc : θ*p.sigma ≤ c*κ/2 := by calc _ ≤ (c*κ/(2*p.sigma))*p.sigma := mul_le_mul_of_nonneg_right (min_le_right _ _) hσ.le _ = _ := by field_simp have hgeo := p.code_geometric_vanish hκ hρ.le hρ1 apply tendsto_order.2 constructor · intro a ha exact Eventually.of_forall fun _ => ha.trans_le measureReal_nonneg intro η hη obtain ⟨δ₀,hδ₀,hwalk⟩ := continuousPath_modulus_tight (p.codeWalk_converges hB) (fun _ => measurable_of_countable _) hθ (by positivity : 0<η/3) let δ := min δ₀ 1 have hδ : 0<δ := lt_min hδ₀ (by norm_num) have hδ1 : δ ≤ 1 := min_le_right _ _ have hδδ₀ : δ ≤ δ₀ := min_le_left _ _ have hmean := (p.average_height_error_limit (by positivity : 0<ε/4)).div_const (δ/2) simp only [zero_div] at hmean have hlargeν : ∀ᶠ n in atTop, ν ≤ ε/8*Real.sqrt ((2*n+1:ℕ):ℝ) := (odd_sqrt_tendsto.const_mul_atTop (by positivity : 0<ε/8)).eventually_ge_atTop ν have hlarger : ∀ᶠ n in atTop, 2 ≤ δ*((2*n+1:ℕ):ℝ) := ((tendsto_natCast_atTop_atTop.comp odd_size_tendsto).const_mul_atTop hδ).eventually_ge_atTop 2 filter_upwards [hwalk,hlargeν,hlarger, hgeo.eventually (gt_mem_nhds (by positivity : (0:ℝ)<η/3)), hmean.eventually (gt_mem_nhds (by positivity : (0:ℝ)<η/3))] with n hwn hνn hrn hgn han let N := 2*n+1 let s := Real.sqrt (N:ℝ) let m := ⌈κ*s⌉₊ let r := ⌊δ*N⌋₊ have hN : 0 t*s) hκeq change ν ≤ ε/8*s at hνn dsimp [m] nlinarith have hcm : θ*(p.sigma*s)0, Tendsto (fun n => (μ n).real {ω | ε < dist (X n ω) (Y n ω)}) atTop (𝓝 0)) : TendstoInDistribution Y atTop Z μ ν := by refine ⟨hY,hXZ.aemeasurable_limit,?_⟩ apply tendsto_iff_forall_lipschitz_integral_tendsto.mpr rintro F ⟨M,hM⟩ ⟨L,hL⟩ have hZ := hXZ.aemeasurable_limit have hmid := tendsto_iff_forall_lipschitz_integral_tendsto.mp hXZ.tendsto F ⟨M,hM⟩ ⟨L,hL⟩ change Tendsto (fun n => ∫ x,F x ∂(μ n).map (Y n)) atTop (𝓝 (∫ x,F x ∂ν.map Z)) change Tendsto (fun n => ∫ x,F x ∂(μ n).map (X n)) atTop (𝓝 (∫ x,F x ∂ν.map Z)) at hmid simp_rw [integral_map (hY _) hL.continuous.aestronglyMeasurable, integral_map hZ hL.continuous.aestronglyMeasurable] simp_rw [integral_map (hXZ.forall_aemeasurable _) hL.continuous.aestronglyMeasurable, integral_map hZ hL.continuous.aestronglyMeasurable] at hmid have hM0 : 0≤M := by obtain ⟨ω⟩ := nonempty_of_isProbabilityMeasure ν simpa using hM (Z ω) (Z ω) rw [Metric.tendsto_nhds] intro ε hε let δ := ε/(4*((L:ℝ)+1)) have hδ : 0<δ := by dsimp [δ]; positivity have hLd : (L:ℝ)*δ ≤ ε/4 := by dsimp [δ]; rw [← mul_div_assoc,div_le_iff₀ (by positivity : 0<4*((L:ℝ)+1))] nlinarith [L.coe_nonneg] have htail := (hclose (δ/2) (half_pos hδ)).const_mul M simp only [mul_zero] at htail filter_upwards [htail.eventually (gt_mem_nhds (by positivity : (0:ℝ)<ε/4)), (Metric.tendsto_nhds.mp hmid) (ε/4) (by positivity)] with n hn hnmid have he := integral_lipschitz_approx_bound (hY n) (hXZ.forall_aemeasurable n) hM hL hδ.le have hs : (μ n).real {ω | δ ≤ dist (Y n ω) (X n ω)} ≤ (μ n).real {ω | δ/2 < dist (X n ω) (Y n ω)} := by apply measureReal_mono _ (measure_ne_top _ _) intro ω hω change δ ≤ dist (Y n ω) (X n ω) at hω change δ/2 < dist (X n ω) (Y n ω) rw [dist_comm] at hω exact lt_of_lt_of_le (by linarith) hω have hh := mul_le_mul_of_nonneg_left hs hM0 have ht := abs_sub_le (∫ ω,F (Y n ω) ∂μ n) (∫ ω,F (X n ω) ∂μ n) (∫ ω,F (Z ω) ∂ν) rw [Real.dist_eq] at hnmid ⊢ linarith def diagonalPath (f : C(unitInterval,ℝ)) : C(unitInterval,ℝ×ℝ) := f.prodMk f lemma diagonalPath_lipschitz : LipschitzWith 1 diagonalPath := by apply LipschitzWith.of_dist_le_mul intro f g simp only [NNReal.coe_one,one_mul] apply (ContinuousMap.dist_le (dist_nonneg)).mpr intro t change max (dist (f t) (g t)) (dist (f t) (g t)) ≤ dist f g simpa only [max_self] using ContinuousMap.dist_apply_le_dist (f := f) (g := g) t lemma jointCode_close {N : ℕ} (hN : 0 (walk d.val i.val:ℝ)/(p.sigma*Real.sqrt N)) (fun i => p.sigma*height d.val i.val/(2*Real.sqrt N)) hε (fun i => ?_) · apply (ContinuousMap.dist_le hε).mpr intro t change max (dist (walkPolygon p.sigma d.val t) (walkPolygon p.sigma d.val t)) (dist (walkPolygon p.sigma d.val t) (interpolation N (fun i => p.sigma*height d.val i.val/(2*Real.sqrt N)) t)) ≤ ε rw [dist_self,max_eq_right (dist_nonneg)] exact (ContinuousMap.dist_apply_le_dist t).trans (by simpa only [walkPolygon,dist_eq_norm] using hb) have he : (walk d.val i.val:ℝ)/(p.sigma*Real.sqrt N)- p.sigma*height d.val i.val/(2*Real.sqrt N) = ((walk d.val i.val:ℝ)-(p.variance/2)*height d.val i.val)/(p.sigma*Real.sqrt N) := by field_simp nlinarith [congrArg (fun x : ℝ => x*(height d.val i.val:ℝ)) hsq] rw [he,abs_div,abs_of_pos (mul_pos hs hsqrt)] apply (div_le_iff₀ (mul_pos hs hsqrt)).mpr simpa only [mul_assoc] using h i.val (Nat.le_of_lt_succ i.isLt) lemma CriticalEvenOffspring.joint_diagonal_close (p : CriticalEvenOffspring) {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] {B : ℝ≥0 → Ω → ℝ} (hB : IsBrownianReal B P) {ε : ℝ} (hε : 0<ε) : Tendsto (fun n => (p.codeLaw n).real {d | ε < dist (diagonalPath (walkPolygon p.sigma d.val)) (jointCode p.sigma d)}) atTop (𝓝 0) := by have hsmall := p.uniform_height_error_limit hB (mul_pos hε p.sigma_pos) apply squeeze_zero' (Eventually.of_forall (fun _ => measureReal_nonneg)) _ hsmall have hlarge : ∀ᶠ n in atTop, 1 ≤ (ε*p.sigma)*Real.sqrt ((2*n+1:ℕ):ℝ) := (odd_sqrt_tendsto.const_mul_atTop (mul_pos hε p.sigma_pos)).eventually_ge_atTop 1 filter_upwards [hlarge] with n hn apply measureReal_mono _ (measure_ne_top _ _) intro d hd by_contra hh have he : ∀ j<2*n+1, |(walk d.val j:ℝ)-(p.variance/2)*height d.val j| ≤ (ε*p.sigma)*Real.sqrt ((2*n+1:ℕ):ℝ) := by simpa only [Set.mem_ofPred_eq,not_exists,not_and,not_lt] using hh apply not_lt_of_ge (jointCode_close (by omega) p d hε.le (fun j hj => ?_)) hd by_cases hj' : j<2*n+1 · exact he j hj' · have hjj : j=2*n+1 := by omega subst j simpa only [d.property.1,height_terminal,Nat.cast_zero,mul_zero,sub_zero,Int.cast_neg, Int.cast_one,abs_neg,abs_one] using hn /-- Full joint walk/height convergence to the same Vervaat bridge excursion. Identification with the standard Bessel3 excursion uses its finite-dimensional laws. -/ theorem CriticalEvenOffspring.jointCode_vervaat_CLT (p : CriticalEvenOffspring) {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] {B : ℝ≥0 → Ω → ℝ} (hB : IsBrownianReal B P) : TendstoInDistribution (fun n (d : Code (2*n+1)) => jointCode p.sigma d) atTop (fun ω => diagonalPath (vervaat (bridgePath B ω))) p.codeLaw P := by have hc := (p.codeWalk_converges hB).continuous_comp diagonalPath_lipschitz.continuous exact tendstoInDistribution_of_close hc (fun _ => (measurable_of_countable _).aemeasurable) (fun _ hε => p.joint_diagonal_close hB hε) end FKCRT.TreeCoding end end OAI