math / data /lean /OAI /Probability /FKMaps /MarkedSpines.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
29.5 kB
import OAI.Probability.FKMaps.SpineBounds
namespace OAI
noncomputable section
open Set Filter MeasureTheory ProbabilityTheory
open scoped Topology BigOperators ENNReal NNReal
namespace FKCRT.TreeCoding
namespace PlaneTree
lemma Profile.walkSum {t v a} (h : Profile t v a) :
(incrementWord (t.degrees.take v)).sum=(a.map (fun z => (z.2:β„€))).sum := by
induction h with
| root t => simp [incrementWord]
| @child pre t post v a h ih =>
rw [degrees_take_child pre t post h.bound.le]
simp only [incrementWord,List.map_cons,List.sum_cons,List.map_append,List.sum_append]
change ((pre++t::post).length:β„€)-1+((incrementWord (forestDegrees pre)).sum+
(incrementWord (t.degrees.take v)).sum) = _
rw [(forest_properties pre).1,ih]
simp only [List.length_append,List.length_cons,Nat.cast_add,Nat.cast_one]
omega
end PlaneTree
lemma codeSpineSum_one {N : β„•} (d : Code N) {v : β„•} (hv : v≀N) :
codeSpineSum (fun _ => 1) d v=(height d.val v:ℝ) := by
unfold codeSpineSum recordSpineSum
simp only [Finset.sum_const,nsmul_eq_mul,mul_one]
congr 1
rw [record_count_reverse]
apply Eq.trans (recordHeight_congr_prefix hv (fun k hk => integerSum_arrayStream_bridge ⟨d.val,d.property.1⟩ hk))
exact (height_eq_recordHeight d.val hv).symm
lemma code_profile_height {N : β„•} (d : Code N) {v a}
(h : PlaneTree.Profile (PlaneTree.ofCode d) v a) : height d.val v=a.length := by
have hv : v≀N := by have := h.bound; rw [PlaneTree.ofCode_size] at this; omega
have hh := h.spineSum (fun _ => (1:ℝ))
rw [← code_profileSum d _ hv,codeSpineSum_one d hv] at hh
simpa using hh
lemma code_profile_walk {N : β„•} (d : Code N) {v a}
(h : PlaneTree.Profile (PlaneTree.ofCode d) v a) :
walk d.val v=(a.map (fun z => (z.2:β„€))).sum := by
rw [← h.walkSum,PlaneTree.ofCode_degrees,PlaneTree.incrementWord,List.map_take]
change walk d.val v=prefixSum _ v
rw [List.map_ofFn]
exact (degreeList_prefixSum d.val v).symm
/-- Mirror exploration counts the left siblings on exactly the same ancestral path. -/
lemma code_spine_mirror_identity {N : β„•} (d : Code N) {v : β„•} (hv : v<N) :
βˆƒ w<N,height (PlaneTree.mirrored d).val w=height d.val v ∧
codeSpineSum (fun z => (z.1:ℝ)) d v=
(walk d.val v:ℝ)+(walk (PlaneTree.mirrored d).val w:ℝ)+height d.val v := by
obtain ⟨a,ha⟩ := PlaneTree.exists_profile (PlaneTree.ofCode d) (by simpa [PlaneTree.ofCode_size] using hv)
obtain ⟨w,hw⟩ := ha.mirrored
rw [← PlaneTree.ofCode_mirrored] at hw
refine ⟨w,by have := hw.bound; simpa [PlaneTree.ofCode_size] using this,?_,?_⟩
Β· rw [code_profile_height _ hw,code_profile_height _ ha,List.length_map]
Β· rw [code_profileSum d _ hv.le,ha.spineSum,code_profile_walk _ ha,
code_profile_walk _ hw,code_profile_height _ ha]
have hs : βˆ€ z∈a,(z.1:ℝ)=(z.2:ℝ)+((PlaneTree.flipSlot z).2:ℝ)+1 := by
intro z hz
have := ha.slots z hz
dsimp [PlaneTree.flipSlot]
exact_mod_cast (show z.1=z.2+(z.1-1-z.2)+1 by omega)
simp only [List.map_map]
push_cast
simp only [List.map_map,Function.comp_def,Int.cast_natCast]
clear ha hw
induction a with
| nil => simp
| cons z a ih =>
simp only [List.map_cons,List.sum_cons,List.length_cons,Nat.cast_add,Nat.cast_one]
have he := hs z (by simp)
have hi := ih (fun z hz => hs z (by simp [hz]))
linarith
/-- Uniform path sum of offspring degrees needs only the original second moment.
This is the deterministic two-sided exploration truncation bound, not a third-moment estimate. -/
theorem CriticalEvenOffspring.uniform_degree_spine_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 | βˆƒ v<2*n+1,
Ξ΅*Real.sqrt ((2*n+1:β„•):ℝ)< |codeSpineSum (fun z => (z.1:ℝ)) d v-
(p.variance+1)*height d.val v|}) atTop (𝓝 0) := by
have ht := p.uniform_height_error_limit hB (half_pos hΞ΅)
apply squeeze_zero (fun _ => measureReal_nonneg) _ (by simpa only [zero_add] using ht.add ht)
intro n
let N := 2*n+1
let E := {d : Code N | βˆƒ j<N, (Ξ΅/2)*Real.sqrt (N:ℝ)<
|(walk d.val j:ℝ)-(p.variance/2)*height d.val j|}
have hsub : {d : Code N | βˆƒ v<N,Ξ΅*Real.sqrt (N:ℝ)<
|codeSpineSum (fun z => (z.1:ℝ)) d v-(p.variance+1)*height d.val v|}
βŠ† Eβˆͺ(PlaneTree.mirrorEquiv N ⁻¹' E) := by
rintro d ⟨v,hv,hbad⟩
by_contra hn
have hn' := not_or.mp hn
obtain ⟨w,hw,hh,hs⟩ := code_spine_mirror_identity d hv
have h1 : |(walk d.val v:ℝ)-(p.variance/2)*height d.val v|≀(Ξ΅/2)*Real.sqrt (N:ℝ) := by
by_contra hc; exact hn'.1 ⟨v,hv,lt_of_not_ge hc⟩
have h2 : |(walk (PlaneTree.mirrored d).val w:ℝ)-(p.variance/2)*height d.val v|≀
(Ξ΅/2)*Real.sqrt (N:ℝ) := by
by_contra hc
apply hn'.2
refine ⟨w,hw,?_⟩
change (Ξ΅/2)*Real.sqrt (N:ℝ)<
|(walk (PlaneTree.mirrored d).val w:ℝ)-(p.variance/2)*height (PlaneTree.mirrored d).val w|
rw [hh]
exact lt_of_not_ge hc
rw [hs] at hbad
have he : (walk d.val v:ℝ)+(walk (PlaneTree.mirrored d).val w:ℝ)+height d.val v-
(p.variance+1)*height d.val v = ((walk d.val v:ℝ)-(p.variance/2)*height d.val v)+
((walk (PlaneTree.mirrored d).val w:ℝ)-(p.variance/2)*height d.val v) := by ring
rw [he] at hbad
have := abs_add_le ((walk d.val v:ℝ)-(p.variance/2)*height d.val v)
((walk (PlaneTree.mirrored d).val w:ℝ)-(p.variance/2)*height d.val v)
linarith
calc
_ ≀ (p.codeLaw n).real (Eβˆͺ(PlaneTree.mirrorEquiv N ⁻¹' E)) := measureReal_mono hsub
_ ≀ (p.codeLaw n).real E+(p.codeLaw n).real (PlaneTree.mirrorEquiv N ⁻¹' E) := measureReal_union_le _ _
_ = _ := by rw [(PlaneTree.mirrorEquiv_preserving p n).measureReal_preimage (Set.to_countable E).measurableSet.nullMeasurableSet]
end FKCRT.TreeCoding
end
noncomputable section
open Set Filter MeasureTheory ProbabilityTheory
open scoped Topology BigOperators ENNReal NNReal
namespace FKCRT.TreeCoding
def spineTail (m : β„•) (z : β„•Γ—β„•) : ℝ := if m < z.1 then (z.1:ℝ) else 0
def spineTrunc (m : β„•) (b : β„•Γ—β„• β†’ ℝ) (z : β„•Γ—β„•) : ℝ := if z.1 ≀ m then b z else 0
lemma spineTail_nonneg (m : β„•) (z : β„•Γ—β„•) : 0 ≀ spineTail m z := by
unfold spineTail; split_ifs <;> positivity
lemma spineTail_le (m : β„•) (z : β„•Γ—β„•) : spineTail m z ≀ z.1 := by
unfold spineTail; split_ifs
Β· exact le_rfl
Β· positivity
lemma spineTrunc_bound (m : β„•) (b : β„•Γ—β„• β†’ ℝ) (hb : βˆ€ z,|b z| ≀ z.1) (z : β„•Γ—β„•) :
|spineTrunc m b z| ≀ m := by
unfold spineTrunc
split_ifs with h
Β· exact (hb z).trans (by exact_mod_cast h)
Β· simp
lemma spineTrunc_tail_bound (m : β„•) (b : β„•Γ—β„• β†’ ℝ) (hb : βˆ€ z,|b z| ≀ z.1) (z : β„•Γ—β„•) :
|b z-spineTrunc m b z| ≀ spineTail m z := by
by_cases h : z.1 ≀ m
Β· simp [spineTrunc,spineTail,h,not_lt.mpr h]
Β· simp [spineTrunc,spineTail,h,lt_of_not_ge h,hb]
lemma CriticalEvenOffspring.spine_integrable_dom (p : CriticalEvenOffspring) (b : β„•Γ—β„• β†’ ℝ)
(hb : βˆ€ z,|b z| ≀ z.1) : Integrable b p.spineLaw := by
exact p.spine_integrable_fst.mono' (measurable_of_countable b).aestronglyMeasurable
(ae_of_all _ (fun z => by simpa only [Real.norm_eq_abs] using hb z))
lemma CriticalEvenOffspring.spine_tail_integral_tendsto (p : CriticalEvenOffspring) :
Tendsto (fun m => ∫ z,spineTail m z βˆ‚p.spineLaw) atTop (𝓝 0) := by
have hh := tendsto_integral_of_dominated_convergence (ΞΌ := p.spineLaw) (f := fun _ => (0:ℝ)) (fun z : β„•Γ—β„• => (z.1:ℝ))
(fun m => (measurable_of_countable (spineTail m)).aestronglyMeasurable)
p.spine_integrable_fst
(fun m => ae_of_all _ (fun z => by simpa only [Real.norm_eq_abs,abs_of_nonneg (spineTail_nonneg m z)] using spineTail_le m z))
(ae_of_all _ (fun z => by
apply tendsto_const_nhds.congr'
filter_upwards [eventually_ge_atTop z.1] with m hm
simp [spineTail,not_lt.mpr hm]))
simpa using hh
lemma codeSpineSum_sub {N : β„•} (d : Code N) (b c : β„•Γ—β„• β†’ ℝ) (v : β„•) :
codeSpineSum (fun z => b z-c z) d v=codeSpineSum b d v-codeSpineSum c d v := by
simp [codeSpineSum,recordSpineSum,Finset.sum_sub_distrib]
lemma codeSpineSum_abs_le {N : β„•} (d : Code N) (b c : β„•Γ—β„• β†’ ℝ) (v : β„•)
(h : βˆ€ z,|b z| ≀ c z) : |codeSpineSum b d v| ≀ codeSpineSum c d v := by
unfold codeSpineSum recordSpineSum
exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun _ _ => h _))
lemma CriticalEvenOffspring.spineTrunc_integral_error (p : CriticalEvenOffspring)
(m : β„•) (b : β„•Γ—β„• β†’ ℝ) (hb : βˆ€ z,|b z| ≀ z.1) :
|(∫ z,b z βˆ‚p.spineLaw)-(∫ z,spineTrunc m b z βˆ‚p.spineLaw)| ≀ ∫ z,spineTail m z βˆ‚p.spineLaw := by
have hi := p.spine_integrable_dom b hb
have hj := p.spine_integrable_dom (spineTrunc m b) (fun z => by
unfold spineTrunc; split_ifs <;> simp [hb z])
rw [← integral_sub hi hj]
apply (abs_integral_le_integral_abs).trans
apply integral_mono (hi.sub hj).abs (p.spine_integrable_dom (spineTail m) (fun z => by
rw [abs_of_nonneg (spineTail_nonneg m z)]; exact spineTail_le m z))
exact spineTrunc_tail_bound m b hb
lemma spineTail_eq (m : β„•) : spineTail m=(fun z => (z.1:ℝ)-spineTrunc m (fun z => (z.1:ℝ)) z) := by
funext z
by_cases h : z.1 ≀ m <;> simp [spineTail,spineTrunc,h,not_lt.mpr,lt_of_not_ge]
lemma spine_tail_control {N : β„•} (p : CriticalEvenOffspring) (d : Code N)
(b : β„•Γ—β„• β†’ ℝ) (hb : βˆ€ z,|b z| ≀ z.1) (m v : β„•) :
|codeSpineSum b d v-(∫ z,b z βˆ‚p.spineLaw)*height d.val v| ≀
|codeSpineSum (spineTrunc m b) d v-(∫ z,spineTrunc m b z βˆ‚p.spineLaw)*height d.val v|+
|codeSpineSum (fun z => (z.1:ℝ)) d v-(p.variance+1)*height d.val v|+
|codeSpineSum (spineTrunc m (fun z => (z.1:ℝ))) d v-
(∫ z,spineTrunc m (fun z => (z.1:ℝ)) z βˆ‚p.spineLaw)*height d.val v|+
2*(∫ z,spineTail m z βˆ‚p.spineLaw)*height d.val v := by
let h : ℝ := height d.val v
have h0 : 0 ≀ h := by dsimp [h]; positivity
have hd := codeSpineSum_abs_le d (fun z => b z-spineTrunc m b z) (spineTail m) v (spineTrunc_tail_bound m b hb)
rw [codeSpineSum_sub] at hd
have he := p.spineTrunc_integral_error m b hb
have hi : (∫ z,spineTail m z βˆ‚p.spineLaw)=p.variance+1-
∫ z,spineTrunc m (fun z => (z.1:ℝ)) z βˆ‚p.spineLaw := by
rw [spineTail_eq,integral_sub p.spine_integrable_fst (p.spine_integrable_dom _ (fun z => by
unfold spineTrunc; split_ifs <;> simp))]
rw [p.spine_integral_fst]
have hs : codeSpineSum (spineTail m) d v=codeSpineSum (fun z => (z.1:ℝ)) d v-
codeSpineSum (spineTrunc m (fun z => (z.1:ℝ))) d v := by
rw [spineTail_eq,codeSpineSum_sub]
have he1 := abs_add_le (codeSpineSum (spineTrunc m b) d v-(∫ z,spineTrunc m b z βˆ‚p.spineLaw)*h)
((codeSpineSum b d v-codeSpineSum (spineTrunc m b) d v)-
((∫ z,b z βˆ‚p.spineLaw)-(∫ z,spineTrunc m b z βˆ‚p.spineLaw))*h)
have he2 := abs_sub (codeSpineSum b d v-codeSpineSum (spineTrunc m b) d v)
(((∫ z,b z βˆ‚p.spineLaw)-(∫ z,spineTrunc m b z βˆ‚p.spineLaw))*h)
rw [abs_mul,abs_of_nonneg h0] at he2
have he3 := mul_le_mul_of_nonneg_right he h0
have hsum : codeSpineSum (spineTrunc m b) d v-(∫ z,spineTrunc m b z βˆ‚p.spineLaw)*h+
((codeSpineSum b d v-codeSpineSum (spineTrunc m b) d v)-
((∫ z,b z βˆ‚p.spineLaw)-(∫ z,spineTrunc m b z βˆ‚p.spineLaw))*h)=
codeSpineSum b d v-(∫ z,b z βˆ‚p.spineLaw)*h := by ring
rw [hs] at hd
rw [hsum] at he1
have hK := le_abs_self (codeSpineSum (fun z => (z.1:ℝ)) d v-(p.variance+1)*h)
have hk := neg_le_abs (codeSpineSum (spineTrunc m (fun z => (z.1:ℝ))) d v-
(∫ z,spineTrunc m (fun z => (z.1:ℝ)) z βˆ‚p.spineLaw)*h)
change _ ≀ _+_+_+2*(∫ z,spineTail m z βˆ‚p.spineLaw)*h
nlinarith
end FKCRT.TreeCoding
end
noncomputable section
open Set Filter MeasureTheory ProbabilityTheory
open scoped Topology BigOperators ENNReal NNReal
namespace FKCRT.TreeCoding
/-- The full finite-variance all-vertex ancestral LLN for any deterministic slot label
bounded in absolute value by the offspring count. No third moment or exponential upper tail. -/
theorem CriticalEvenOffspring.uniform_integrable_spine_limit (p : CriticalEvenOffspring)
{Ξ© : Type*} [MeasurableSpace Ξ©] {P : Measure Ξ©} [IsProbabilityMeasure P]
{B : ℝβ‰₯0 β†’ Ξ© β†’ ℝ} (hB : IsBrownianReal B P)
(b : β„•Γ—β„• β†’ ℝ) (hb : βˆ€ z,|b z| ≀ z.1) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) :
Tendsto (fun n => (p.codeLaw n).real {d | βˆƒ v < 2*n+1,
Ξ΅*Real.sqrt ((2*n+1:β„•):ℝ) < |codeSpineSum b d v-(∫ z,b z βˆ‚p.spineLaw)*height d.val v|})
atTop (𝓝 0) := by
apply tendsto_order.2
constructor
Β· intro a ha
exact Eventually.of_forall (fun _ => ha.trans_le measureReal_nonneg)
intro Ξ· hΞ·
obtain ⟨C,hC,hheight⟩ := p.code_height_tight hB (by positivity : 0 < η/4)
obtain ⟨m,hm⟩ := (p.spine_tail_integral_tendsto.eventually
(gt_mem_nhds (by positivity : (0:ℝ) < Ξ΅/(8*C)))).exists
have ht0 : 0 ≀ ∫ z,spineTail m z βˆ‚p.spineLaw := integral_nonneg (spineTail_nonneg m)
have hK := p.uniform_degree_spine_limit hB (by positivity : 0 < Ξ΅/4)
have hbR := p.uniform_bounded_spine_limit hB (spineTrunc m b)
(R := (m:ℝ)+1) (by positivity) (fun z => (spineTrunc_bound m b hb z).trans (by linarith))
(by positivity : 0 < Ξ΅/4)
have hkR := p.uniform_bounded_spine_limit hB (spineTrunc m (fun z => (z.1:ℝ)))
(R := (m:ℝ)+1) (by positivity) (fun z =>
(spineTrunc_bound m (fun z => (z.1:ℝ)) (fun z => by simp) z).trans (by linarith))
(by positivity : 0 < Ξ΅/4)
filter_upwards [hheight,hK.eventually (gt_mem_nhds (by positivity : (0:ℝ) < Ξ·/4)),
hbR.eventually (gt_mem_nhds (by positivity : (0:ℝ) < Ξ·/4)),
hkR.eventually (gt_mem_nhds (by positivity : (0:ℝ) < Ξ·/4))] with n hh hK hbR hkR
let N := 2*n+1
let s := Real.sqrt (N:ℝ)
let A0 := {d : Code N | βˆƒ v ≀ N,C*s < height d.val v}
let A1 := {d : Code N | βˆƒ v < N,(Ξ΅/4)*s <
|codeSpineSum (fun z => (z.1:ℝ)) d v-(p.variance+1)*height d.val v|}
let A2 := {d : Code N | βˆƒ v ≀ N,(Ξ΅/4)*s <
|codeSpineSum (spineTrunc m b) d v-(∫ z,spineTrunc m b z βˆ‚p.spineLaw)*height d.val v|}
let A3 := {d : Code N | βˆƒ v ≀ N,(Ξ΅/4)*s <
|codeSpineSum (spineTrunc m (fun z => (z.1:ℝ))) d v-
(∫ z,spineTrunc m (fun z => (z.1:ℝ)) z βˆ‚p.spineLaw)*height d.val v|}
have hsub : {d : Code N | βˆƒ v < N,Ξ΅*s <
|codeSpineSum b d v-(∫ z,b z βˆ‚p.spineLaw)*height d.val v|}βŠ†(A0βˆͺA1)βˆͺ(A2βˆͺA3) := by
rintro d ⟨v,hv,hbad⟩
by_contra hn
simp only [Set.mem_union,not_or] at hn
have hhv : (height d.val v:ℝ) ≀ C*s := by
by_contra h; exact hn.1.1 ⟨v,hv.le,lt_of_not_ge h⟩
have hKv : |codeSpineSum (fun z => (z.1:ℝ)) d v-(p.variance+1)*height d.val v| ≀ (Ξ΅/4)*s := by
by_contra h; exact hn.1.2 ⟨v,hv,lt_of_not_ge h⟩
have hbv : |codeSpineSum (spineTrunc m b) d v-
(∫ z,spineTrunc m b z βˆ‚p.spineLaw)*height d.val v| ≀ (Ξ΅/4)*s := by
by_contra h; exact hn.2.1 ⟨v,hv.le,lt_of_not_ge h⟩
have hkv : |codeSpineSum (spineTrunc m (fun z => (z.1:ℝ))) d v-
(∫ z,spineTrunc m (fun z => (z.1:ℝ)) z βˆ‚p.spineLaw)*height d.val v| ≀ (Ξ΅/4)*s := by
by_contra h; exact hn.2.2 ⟨v,hv.le,lt_of_not_ge h⟩
have ht : 2*(∫ z,spineTail m z βˆ‚p.spineLaw)*height d.val v ≀ (Ξ΅/4)*s := by
have hm' : (∫ z,spineTail m z βˆ‚p.spineLaw)*(8*C) ≀ Ξ΅ := (le_div_iffβ‚€ (by positivity)).mp hm.le
have hs : 0 ≀ s := Real.sqrt_nonneg _
have h1 := mul_le_mul_of_nonneg_left hhv (show 0 ≀ 2*(∫ z,spineTail m z βˆ‚p.spineLaw) by positivity)
have h2 := mul_le_mul_of_nonneg_right hm' hs
nlinarith
have hc := spine_tail_control p d b hb m v
linarith
have hprob : (p.codeLaw n).real {d : Code N | βˆƒ v < N,Ξ΅*s <
|codeSpineSum b d v-(∫ z,b z βˆ‚p.spineLaw)*height d.val v|} ≀
(p.codeLaw n).real A0+(p.codeLaw n).real A1+(p.codeLaw n).real A2+(p.codeLaw n).real A3 := by
apply (measureReal_mono hsub).trans
have h01 := measureReal_union_le (ΞΌ := p.codeLaw n) A0 A1
have h23 := measureReal_union_le (ΞΌ := p.codeLaw n) A2 A3
have htop := measureReal_union_le (ΞΌ := p.codeLaw n) (A0βˆͺA1) (A2βˆͺA3)
linarith
change (p.codeLaw n).real A0 ≀ Ξ·/4 at hh
change (p.codeLaw n).real A1 < Ξ·/4 at hK
change (p.codeLaw n).real A2 < Ξ·/4 at hbR
change (p.codeLaw n).real A3 < Ξ·/4 at hkR
exact hprob.trans_lt (by linarith)
end FKCRT.TreeCoding
end
noncomputable section
open Set Filter MeasureTheory ProbabilityTheory
open scoped Topology BigOperators ENNReal NNReal
namespace FKCRT.TreeCoding
abbrev SpineRecords {N : β„•} (d : Code N) (v : β„•) :=
β†₯(weakRecords (integerSum (reverseFirst v (arrayStream (codeEmbedding N d)))) v)
def spineRecordType {N : β„•} (d : Code N) (v : β„•) (t : SpineRecords d v) : β„•Γ—β„• :=
recordTypeAt (reverseFirst v (arrayStream (codeEmbedding N d))) t.val
lemma spineRecord_bounds {N : β„•} (d : Code N) (v : β„•) (t : SpineRecords d v) :
1 ≀ t.val ∧ t.val ≀ v := by
have h := (mem_weakRecords _ _ _).mp t.property
exact ⟨h.1,h.2.1⟩
def spineRecordVertex {N : β„•} (d : Code N) {v : β„•} (hv : v ≀ N) (t : SpineRecords d v) : Fin N :=
⟨v-t.val,by have h := spineRecord_bounds d v t; omega⟩
lemma spineRecordVertex_injective {N : β„•} (d : Code N) {v : β„•} (hv : v ≀ N) :
Function.Injective (spineRecordVertex d hv) := by
intro t u he
have ht := spineRecord_bounds d v t
have hu := spineRecord_bounds d v u
apply Subtype.ext
have h := congrArg Fin.val he
dsimp [spineRecordVertex] at h
omega
lemma spineRecordType_fst {N : β„•} (d : Code N) {v : β„•} (hv : v ≀ N) (t : SpineRecords d v) :
(spineRecordType d v t).1=(d.val (spineRecordVertex d hv t)).val := by
have ht := spineRecord_bounds d v t
have hlt : t.val-1 < v := by omega
have he : v-1-(t.val-1)=v-t.val := by omega
simp [spineRecordType,recordTypeAt,reverseFirst,reverseIndex,hlt,he,arrayStream,
show v-t.val < N by omega,codeEmbedding,bridgeEmbedding,spineRecordVertex]
rfl
lemma spineRecords_card {N : β„•} (d : Code N) {v : β„•} (hv : v ≀ N) :
Fintype.card (SpineRecords d v)=height d.val v := by
have h := codeSpineSum_one d hv
simp only [codeSpineSum,recordSpineSum,Finset.sum_const,nsmul_eq_mul,mul_one] at h
rw [Fintype.card_coe]
exact_mod_cast h
variable {A : Type*} [MeasurableSpace A]
def codeMarkLaw (ΞΊ : β„• β†’ Measure A) {N : β„•} (d : Code N) : Measure (Fin N β†’ A) :=
Measure.pi (fun i => ΞΊ (d.val i).val)
instance codeMarkLaw_probability (ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)]
{N : β„•} (d : Code N) : IsProbabilityMeasure (codeMarkLaw ΞΊ d) := by
unfold codeMarkLaw; infer_instance
def markedSpineSum {N : β„•} (b : (β„•Γ—β„•) β†’ A β†’ ℝ) (d : Code N) {v : β„•}
(hv : v ≀ N) (a : Fin N β†’ A) : ℝ :=
βˆ‘ t : SpineRecords d v,b (spineRecordType d v t) (a (spineRecordVertex d hv t))
omit [MeasurableSpace A] in
lemma markedSpineSum_deterministic {N : β„•} (b : β„•Γ—β„• β†’ ℝ) (d : Code N) {v : β„•}
(hv : v ≀ N) (a : Fin N β†’ A) :
markedSpineSum (fun z _ => b z) d hv a=codeSpineSum b d v := by
unfold markedSpineSum codeSpineSum recordSpineSum
exact Finset.sum_coe_sort _ (fun t => b (recordTypeAt (reverseFirst v (arrayStream (codeEmbedding N d))) t))
lemma measurable_markedSpineSum {N : β„•} (b : (β„•Γ—β„•) β†’ A β†’ ℝ)
(hb : βˆ€ z,Measurable (b z)) (d : Code N) {v : β„•} (hv : v ≀ N) :
Measurable (markedSpineSum b d hv) := by
exact Finset.measurable_sum _ (fun t _ => (hb _).comp (measurable_pi_apply _))
/-- Conditional on the actual tree, distinct ancestors carry independent correctly sampled marks. -/
lemma markedSpine_iIndep {N : β„•} (ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)]
(d : Code N) {v : β„•} (hv : v ≀ N) :
iIndepFun (fun t : SpineRecords d v => fun a : Fin N β†’ A => a (spineRecordVertex d hv t))
(codeMarkLaw ΞΊ d) := by
exact (iIndepFun_pi (ΞΌ := fun i => ΞΊ (d.val i).val)
(X := fun _ => id) (fun _ => measurable_id.aemeasurable)).precomp (spineRecordVertex_injective d hv)
lemma markedSpine_hasLaw {N : β„•} (ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)]
(d : Code N) {v : β„•} (hv : v ≀ N) (t : SpineRecords d v) :
HasLaw (fun a : Fin N β†’ A => a (spineRecordVertex d hv t))
(ΞΊ (spineRecordType d v t).1) (codeMarkLaw ΞΊ d) := by
rw [spineRecordType_fst d hv t]
exact (measurePreserving_eval (fun i => ΞΊ (d.val i).val) _).hasLaw
/-- Bounded random marks concentrate round their conditional ancestral means. -/
lemma markedSpine_deviation {N : β„•} (ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)]
(b : (β„•Γ—β„•) β†’ A β†’ ℝ) (hb : βˆ€ z,Measurable (b z)) {R : ℝ}
(hbound : βˆ€ z a,|b z a| ≀ R) (d : Code N) {v : β„•} (hv : v ≀ N)
{r : ℝ} (hr : 0 ≀ r) :
(codeMarkLaw ΞΊ d).real {a | r ≀ |markedSpineSum b d hv a-
codeSpineSum (fun z => ∫ a,b z a βˆ‚ΞΊ z.1) d v|} ≀
2*Real.exp (-r^2/(2*(height d.val v)*R^2)) := by
let Y : SpineRecords d v β†’ (Fin N β†’ A) β†’ ℝ := fun t a =>
b (spineRecordType d v t) (a (spineRecordVertex d hv t))-
∫ a,b (spineRecordType d v t) a βˆ‚ΞΊ (spineRecordType d v t).1
have hind : iIndepFun Y (codeMarkLaw ΞΊ d) :=
(markedSpine_iIndep ΞΊ d hv).comp (fun t a => b (spineRecordType d v t) a-
∫ a,b (spineRecordType d v t) a βˆ‚ΞΊ (spineRecordType d v t).1)
(fun t => (hb _).sub measurable_const)
have hG : βˆ€ t,HasSubgaussianMGF (Y t) ((β€–(R:ℝ)-(-R)β€–β‚Š/2)^2) (codeMarkLaw ΞΊ d) := by
intro t
have hh := hasSubgaussianMGF_of_mem_Icc (ΞΌ := codeMarkLaw ΞΊ d)
((hb _).comp (measurable_pi_apply _)).aemeasurable
(ae_of_all _ (fun a => abs_le.mp (hbound (spineRecordType d v t) (a (spineRecordVertex d hv t)))))
have he := (markedSpine_hasLaw ΞΊ d hv t).integral_comp (hb (spineRecordType d v t)).aestronglyMeasurable
rw [he] at hh
simpa only [Function.comp_def,Y] using hh
have hp := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun (s := Finset.univ) hind (fun t _ => hG t) hr
have hn := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun (s := Finset.univ)
(hind.comp (fun _ x => -x) (fun _ => measurable_neg)) (fun t _ => (hG t).neg) hr
have he (a : Fin N β†’ A) : markedSpineSum b d hv a-
codeSpineSum (fun z => ∫ a,b z a βˆ‚ΞΊ z.1) d v=βˆ‘ t,Y t a := by
rw [← markedSpineSum_deterministic (A := A) _ d hv a]
unfold markedSpineSum
exact (Finset.sum_sub_distrib _ _).symm
have hsub : {a : Fin N β†’ A | r ≀ |markedSpineSum b d hv a-
codeSpineSum (fun z => ∫ a,b z a βˆ‚ΞΊ z.1) d v|} βŠ†
{a | r ≀ βˆ‘ t,Y t a} βˆͺ {a | r ≀ βˆ‘ t,-Y t a} := by
intro a ha
change r ≀ |_| at ha
rw [he] at ha
rcases le_abs.mp ha with h | h
Β· exact Or.inl h
Β· exact Or.inr (by simpa only [Set.mem_ofPred_eq,Finset.sum_neg_distrib] using h)
have hle := (measureReal_mono (ΞΌ := codeMarkLaw ΞΊ d) hsub).trans (measureReal_union_le _ _)
simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] at hp hn
push_cast at hp hn
simp only [Real.norm_eq_abs,div_pow,sq_abs,show (R- -R)^2/2^2=R^2 by ring,
spineRecords_card d hv,Function.comp_def] at hp hn
simp only [mul_assoc]
linarith
end FKCRT.TreeCoding
end
noncomputable section
open Set Filter MeasureTheory ProbabilityTheory
open scoped Topology BigOperators ENNReal NNReal
namespace FKCRT.TreeCoding
variable {A : Type*} [MeasurableSpace A]
def codeMarkKernel (ΞΊ : β„• β†’ Measure A) (N : β„•) : Kernel (Code N) (Fin N β†’ A) :=
⟨codeMarkLaw κ,measurable_of_countable _⟩
instance codeMarkKernel_markov (ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)] (N : β„•) :
IsMarkovKernel (codeMarkKernel κ N) := ⟨fun _ => codeMarkLaw_probability _ _⟩
def CriticalEvenOffspring.markedCodeLaw (p : CriticalEvenOffspring) (ΞΊ : β„• β†’ Measure A) (n : β„•) :
Measure (Code (2*n+1) Γ— (Fin (2*n+1) β†’ A)) := p.codeLaw n βŠ—β‚˜ codeMarkKernel ΞΊ (2*n+1)
instance CriticalEvenOffspring.markedCodeLaw_probability (p : CriticalEvenOffspring)
(ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)] (n : β„•) :
IsProbabilityMeasure (p.markedCodeLaw ΞΊ n) := by unfold CriticalEvenOffspring.markedCodeLaw; infer_instance
lemma compProd_real_bound {Ξ± Ξ² : Type*} [MeasurableSpace Ξ±] [MeasurableSpace Ξ²]
(ΞΌ : Measure Ξ±) [IsProbabilityMeasure ΞΌ] (ΞΊ : Kernel Ξ± Ξ²) [IsMarkovKernel ΞΊ]
{E : Set (Ξ±Γ—Ξ²)} (hE : MeasurableSet E) {C : ℝ} (hC : 0 ≀ C)
(hb : βˆ€ x,(ΞΊ x).real (Prod.mk x ⁻¹' E) ≀ C) : (ΞΌ βŠ—β‚˜ ΞΊ).real E ≀ C := by
have he : (ΞΌ βŠ—β‚˜ ΞΊ) E ≀ ENNReal.ofReal C := by
rw [Measure.compProd_apply hE]
calc
_ ≀ ∫⁻ _,ENNReal.ofReal C βˆ‚ΞΌ := lintegral_mono (fun x => by
rw [← ofReal_measureReal]
exact ENNReal.ofReal_le_ofReal (hb x))
_ = _ := by simp
exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top he).trans_eq (ENNReal.toReal_ofReal hC)
lemma CriticalEvenOffspring.markedCodeLaw_fst (p : CriticalEvenOffspring)
(ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)] (n : β„•) (E : Set (Code (2*n+1))) :
(p.markedCodeLaw κ n).real (Prod.fst ⁻¹' E)=(p.codeLaw n).real E := by
have hh : Prod.fst ⁻¹' E=EΓ—Λ’(Set.univ : Set (Fin (2*n+1) β†’ A)) := by ext x; simp
unfold Measure.real
rw [hh,CriticalEvenOffspring.markedCodeLaw,Measure.compProd_apply_prod (Set.to_countable E).measurableSet MeasurableSet.univ]
simp
lemma measurable_marked_spine_joint {N : β„•} (b : (β„•Γ—β„•) β†’ A β†’ ℝ) (hb : βˆ€ z,Measurable (b z))
{v : β„•} (hv : v ≀ N) :
Measurable (fun x : Code N Γ— (Fin N β†’ A) => markedSpineSum b x.1 hv x.2) :=
measurable_from_prod_countable_right (fun d => measurable_markedSpineSum b hb d hv)
omit [MeasurableSpace A] in
lemma markedSpineSum_zero_height {N : β„•} (b : (β„•Γ—β„•) β†’ A β†’ ℝ) (d : Code N)
{v : β„•} (hv : v ≀ N) (hh : height d.val v=0) (a : Fin N β†’ A) :
markedSpineSum b d hv a=0 := by
have hc : Fintype.card (SpineRecords d v)=0 := (spineRecords_card d hv).trans hh
let : IsEmpty (SpineRecords d v) := Fintype.card_eq_zero_iff.mp hc
simp [markedSpineSum]
lemma marked_short_spine_bound {N : β„•} (ΞΊ : β„• β†’ Measure A) [βˆ€ k,IsProbabilityMeasure (ΞΊ k)]
(b : (β„•Γ—β„•) β†’ A β†’ ℝ) (hb : βˆ€ z,Measurable (b z)) {R : ℝ} (hR : 0 < R)
(hbound : βˆ€ z a,|b z a| ≀ R) (d : Code N) (K : β„•) {r : ℝ} (hr : 0 < r) :
(codeMarkLaw ΞΊ d).real {a | βˆƒ v : Fin (N+1),height d.val v.val ≀ K ∧
r ≀ |markedSpineSum b d (Nat.le_of_lt_succ v.isLt) a-
codeSpineSum (fun z => ∫ a,b z a βˆ‚ΞΊ z.1) d v.val|} ≀
(N+1:ℝ)*2*Real.exp (-r^2/(2*K*R^2)) := by
let E : Fin (N+1) β†’ Set (Fin N β†’ A) := fun v => {a | height d.val v.val ≀ K ∧
r ≀ |markedSpineSum b d (Nat.le_of_lt_succ v.isLt) a-
codeSpineSum (fun z => ∫ a,b z a βˆ‚ΞΊ z.1) d v.val|}
have he : {a | βˆƒ v : Fin (N+1),height d.val v.val ≀ K ∧
r ≀ |markedSpineSum b d (Nat.le_of_lt_succ v.isLt) a-
codeSpineSum (fun z => ∫ a,b z a βˆ‚ΞΊ z.1) d v.val|}=⋃ v,E v := by ext a; simp [E]
rw [he]
apply (measureReal_iUnion_fintype_le E).trans
calc
_ ≀ βˆ‘ _ : Fin (N+1),2*Real.exp (-r^2/(2*K*R^2)) := Finset.sum_le_sum (by
intro v _
by_cases hh : height d.val v.val ≀ K
Β· by_cases h0 : height d.val v.val=0
Β· have hE : E v=βˆ… := by
ext a
have hz := markedSpineSum_zero_height b d (Nat.le_of_lt_succ v.isLt) h0 a
have hm := markedSpineSum_zero_height (fun z (_ : A) => ∫ a,b z a βˆ‚ΞΊ z.1) d
(Nat.le_of_lt_succ v.isLt) h0 a
rw [markedSpineSum_deterministic] at hm
simp [E,hz,hm,not_le.mpr hr]
rw [hE,measureReal_empty]
positivity
Β· have hpos : 0 < (height d.val v.val:ℝ) := by exact_mod_cast Nat.pos_of_ne_zero h0
have hKpos : 0 < (K:ℝ) := hpos.trans_le (by exact_mod_cast hh)
have hm := markedSpine_deviation ΞΊ b hb hbound d (Nat.le_of_lt_succ v.isLt) hr.le
have hes : E v={a | r ≀ |markedSpineSum b d (Nat.le_of_lt_succ v.isLt) a-
codeSpineSum (fun z => ∫ a,b z a βˆ‚ΞΊ z.1) d v.val|} := by ext a; simp [E,hh]
rw [hes]
apply hm.trans
apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num)
rw [neg_div,neg_div]
apply neg_le_neg
apply div_le_div_of_nonneg_left (sq_nonneg r) (by positivity)
have hle : (height d.val v.val:ℝ) ≀ K := by exact_mod_cast hh
nlinarith [mul_le_mul_of_nonneg_right hle (sq_nonneg R)]
Β· have hE : E v=βˆ… := by ext a; simp [E,hh]
rw [hE,measureReal_empty]
positivity)
_ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,Nat.cast_add,Nat.cast_one]; ring
end FKCRT.TreeCoding
end
end OAI