math / data /lean /OAI /Probability /DirectionalWalk /AxisCubes.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
15.3 kB
import OAI.Probability.DirectionalWalk.CommonBands
namespace OAI
open MeasureTheory ProbabilityTheory Filter Preorder
open scoped ENNReal BigOperators Topology
namespace DirectionalZeroOne
open scoped Classical
abbrev CubeSite (d R : β„•) := Fin d β†’ Set.Icc (-(R : β„€)) (R : β„€)
abbrev AxisCubeSite {d : β„•} (e : Step d) (N R : β„•) :=
{z : CubeSite d R // axisHeight e (fun i => z i) = (N : β„€)-1}
lemma card_cubeSite (d R : β„•) : Fintype.card (CubeSite d R) = (2*R+1)^d := by
simp only [CubeSite,Fintype.card_fun,Fintype.card_fin]
congr 1
rw [Fintype.card_ofFinset (Finset.Icc (-(R : β„€)) R) (by simp),Int.card_Icc]
omega
lemma card_axisCubeSite_le {d : β„•} (e : Step d) (N R : β„•) :
Fintype.card (AxisCubeSite e N R) ≀ (2*R+1)^d := by
rw [← card_cubeSite d R]
exact Fintype.card_subtype_le _
lemma axisCubeSite_nonempty {d : β„•} (e : Step d) (N R : β„•) (hN : 0 < N) (hR : N ≀ R) :
Nonempty (AxisCubeSite e N R) := by
let z : Site d := (N-1 : β„•) β€’ stepVector e
have hbd (i : Fin d) : z i ∈ Set.Icc (-(R : β„€)) (R : β„€) := by
dsimp [z,stepVector]
simp only [Int.natCast_sub hN]
split_ifs <;> constructor <;> omega
exact ⟨⟨(fun i => ⟨z i,hbd i⟩),by
change axisHeight e z = _
dsimp [z,axisHeight,stepVector]
cases e.2 <;> simp only [Bool.false_eq_true,↓reduceIte] <;>
omega⟩⟩
noncomputable def axisCubeEnumeration {d : β„•} (e : Step d) (N R : β„•) :
Fin (Fintype.card (AxisCubeSite e N R)) β†’ Site d :=
fun q i => ((Fintype.equivFin (AxisCubeSite e N R)).symm q).val i
lemma axisCubeEnumeration_injective {d : β„•} (e : Step d) (N R : β„•) :
Function.Injective (axisCubeEnumeration e N R) := by
intro q r h
apply (Fintype.equivFin (AxisCubeSite e N R)).symm.injective
apply Subtype.ext
funext i
exact Subtype.ext (congr_fun h i)
lemma axisCubeEnumeration_height {d : β„•} (e : Step d) (N R : β„•)
(q : Fin (Fintype.card (AxisCubeSite e N R))) :
axisHeight e (axisCubeEnumeration e N R q) = (N : β„€)-1 :=
((Fintype.equivFin (AxisCubeSite e N R)).symm q).property
lemma axisCubeEnumeration_surjective {d : β„•} (e : Step d) (N R : β„•) (z : Site d)
(hz : axisHeight e z = (N : β„€)-1) (hbd : βˆ€ i, |z i| ≀ (R : β„€)) :
βˆƒ q, axisCubeEnumeration e N R q = z := by
let a : AxisCubeSite e N R := ⟨fun i => ⟨z i,abs_le.mp (hbd i)⟩,hz⟩
refine ⟨Fintype.equivFin _ a,?_⟩
change (fun i => (((Fintype.equivFin (AxisCubeSite e N R)).symm
((Fintype.equivFin (AxisCubeSite e N R)) a)).val i : β„€)) = z
rw [Equiv.symm_apply_apply]
lemma abs_wordEnd_coord_le_radius {d : β„•} (a : Word d) (h0 : wordPath a 0 = 0) (i : Fin d) :
|(wordEnd a i : ℝ)| ≀ slabRadius a := by
have hh := norm_wordPath_le_radius a (j := a.1) le_rfl
rw [h0,sub_zero] at hh
have hc : |(wordEnd a i : ℝ)| ≀ β€–euclideanSite (wordPath a a.1)β€– := by
simpa [euclideanSite,wordEnd] using PiLp.norm_apply_le (euclideanSite (wordPath a a.1)) i
exact hc.trans hh
lemma reversePrefix_endpoint_coord {d n : β„•} (Z : β„• β†’ Word d)
(h0 : βˆ€ j < n, wordPath (Z j) 0 = 0) (i : Fin d) :
|(wordEnd (concatenateList (reverseTapeList (tapePrefix n Z))) i : ℝ)| ≀
βˆ‘ j ∈ Finset.range n, slabRadius (Z j) := by
have he : wordEnd (concatenateList (reverseTapeList (tapePrefix n Z))) =
βˆ‘ j ∈ Finset.range n, wordEnd (Z j) := by
change wordEnd (concatenateWords n (fun j : Fin n => Z j.rev)) = _
rw [concatenateWords_end]
exact (Equiv.sum_comp Fin.revPerm (fun j : Fin n => wordEnd (Z j))).trans
(Fin.sum_univ_eq_sum_range (fun j => wordEnd (Z j)) n)
rw [he]
simp only [Finset.sum_apply,Int.cast_sum]
exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum
(fun j hj => abs_wordEnd_coord_le_radius _ (h0 j (Finset.mem_range.mp hj)) i))
lemma cutIndex_le_height {Ξ± : Type*} (L : Ξ± β†’ β„•) (Z : β„• β†’ Ξ±)
(hL : βˆ€ i, 0 < L (Z i)) (N : β„•) (hC : Z ∈ renewalCut L N) :
cutListIndex L N Z ≀ N := by
have he := cutListIndex_spec L N Z hL hC
have hh := (tapeHeight_strictMono L Z hL).id_le (cutListIndex L N Z)
rwa [he] at hh
lemma reversed_cut_endpoint_radius {d : β„•} (e : Step d) (Z : β„• β†’ Word d)
(hZ : βˆ€ i, RegenerationWord (axisDirection e) (Z i)) (N : β„•)
(hC : Z ∈ tapeCut (axisDirection e) N) (i : Fin d) :
|((wordEnd (concatenateList (reverseTapeList (cutList (slabRecords (axisDirection e)) N Z))) i : β„€) : ℝ)| ≀
βˆ‘ j ∈ Finset.range N, slabRadius (Z j) := by
have hh := reversePrefix_endpoint_coord Z (n := cutListIndex (slabRecords (axisDirection e)) N Z)
(fun j _ => (hZ j).2.1) i
refine hh.trans ?_
apply Finset.sum_le_sum_of_subset_of_nonneg
Β· exact Finset.range_mono (cutIndex_le_height _ Z (fun j => slabRecords_pos _ _ (hZ j)) N hC)
Β· intro j _ _
exact slabRadius_nonneg _
lemma commonDepth_add {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±) (r s : β„•) :
commonDepth L Z (r+s) = commonDepth L Z r +
commonDepth L ((commonRestart L)^[r] Z) s := by
rw [commonDepth,Finset.sum_range_add]
congr 1
apply Finset.sum_congr rfl
intro i _
rw [Nat.add_comm r i,Function.iterate_add_apply]
lemma commonDepth_strictMono {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±)
(he : βˆ€ r, βˆƒ H, 0 < H ∧ ((commonRestart L)^[r] Z) ∈ commonCut L H) :
StrictMono (commonDepth L Z) := by
apply strictMono_nat_of_lt_succ
intro r
rw [commonDepth_succ]
have hh := (firstCommonWidth_spec L _ (he r)).1
omega
lemma common_iterates_shift {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±)
(hZ : βˆ€ b i, 0 < L b (Z (b,i)))
(he : βˆ€ r, βˆƒ H, 0 < H ∧ ((commonRestart L)^[r] Z) ∈ commonCut L H) (r : β„•) :
(commonRestart L)^[r] Z = twoShift (fun b => (nthCommonList L r Z b).1) Z := by
rw [← (commonDepth_spec L Z hZ he r).2.1]
rfl
lemma nthCommonList_data {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±)
(hZ : βˆ€ b i, 0 < L b (Z (b,i)))
(he : βˆ€ r, βˆƒ H, 0 < H ∧ ((commonRestart L)^[r] Z) ∈ commonCut L H) (r : β„•) :
(βˆ€ b, listHeight (L b) (nthCommonList L r Z b) = commonDepth L Z r) ∧
Z ∈ twoCylinder (nthCommonList L r Z) := by
exact (commonCutList_atom_iff L _ Z hZ _).mp ⟨(commonDepth_spec L Z hZ he r).1,rfl⟩
lemma nthCommonList_append {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±)
(hZ : βˆ€ b i, 0 < L b (Z (b,i)))
(he : βˆ€ r, βˆƒ H, 0 < H ∧ ((commonRestart L)^[r] Z) ∈ commonCut L H) (r s : β„•) (b : Bool) :
nthCommonList L (r+s) Z b = appendTapeList (nthCommonList L r Z b)
(nthCommonList L s ((commonRestart L)^[r] Z) b) := by
have hr := nthCommonList_data L Z hZ he r
let Y := (commonRestart L)^[r] Z
have hYZ : βˆ€ b i, 0 < L b (Y (b,i)) := by
dsimp only [Y]
rw [common_iterates_shift L Z hZ he r]
exact fun b i => hZ b _
have hYe : βˆ€ s, βˆƒ H, 0 < H ∧ ((commonRestart L)^[s] Y) ∈ commonCut L H := by
intro s
dsimp only [Y]
rw [← Function.iterate_add_apply]
exact he (s+r)
have hs := nthCommonList_data L Y hYZ hYe s
have hshift : Y = twoShift (fun b => (nthCommonList L r Z b).1) Z := common_iterates_shift L Z hZ he r
have hl : listHeight (L b) (appendTapeList (nthCommonList L r Z b) (nthCommonList L s Y b)) =
commonDepth L Z (r+s) := by
rw [listHeight_append,hr.1 b,hs.1 b,commonDepth_add]
have hc : (fun i => Z (b,i)) ∈ tapeCylinder
(appendTapeList (nthCommonList L r Z b) (nthCommonList L s Y b)) := by
rw [tapeCylinder_append]
refine ⟨hr.2 b,?_⟩
intro i
exact (congr_fun hshift (b,i)).symm.trans (hs.2 b i)
exact ((cutList_atom_iff (L b) _ _ (hZ b) _).mpr ⟨hl,hc⟩).2
lemma appendTapeList_prefix {Ξ± : Type*} (Z : β„• β†’ Ξ±) (m n : β„•) :
appendTapeList (tapePrefix m Z) (tapePrefix n (fun i => Z (m+i))) = tapePrefix (m+n) Z := by
change (⟨m+n,Fin.append (fun i : Fin m => Z i) (fun i : Fin n => Z (m+i))⟩ : TapeList α) =
⟨m+n,fun i => Z i⟩
congr 1
funext i
refine Fin.addCases (fun j => ?_) (fun j => ?_) i <;> simp
lemma listTotal_append {Ξ± G : Type*} [AddCommMonoid G] (D : Ξ± β†’ G) (a b : TapeList Ξ±) :
listTotal D (appendTapeList a b) = listTotal D a + listTotal D b := by
change (βˆ‘ i : Fin (a.1+b.1), D (Fin.append a.2 b.2 i)) = _
rw [Fin.sum_univ_add]
simp only [Fin.append_left,Fin.append_right]
rfl
lemma listTotal_reverse {Ξ± G : Type*} [AddCommMonoid G] (D : Ξ± β†’ G) (a : TapeList Ξ±) :
listTotal D (reverseTapeList a) = listTotal D a := by
exact Equiv.sum_comp Fin.revPerm (fun i => D (a.2 i))
lemma iid_lintegral_sum {Ξ± : Type*} [MeasurableSpace Ξ±] (Ξ½ : Measure Ξ±)
[IsProbabilityMeasure Ξ½] (f : Ξ± β†’ ℝβ‰₯0∞) (hf : Measurable f) (n : β„•) :
(∫⁻ Z, βˆ‘ j ∈ Finset.range n, f (Z j) βˆ‚Measure.infinitePi (fun _ : β„• => Ξ½)) =
(n : ℝβ‰₯0∞) * ∫⁻ a, f a βˆ‚Ξ½ := by
rw [lintegral_finsetSum (Finset.range n) (f := fun (j : β„•) (Z : β„• β†’ Ξ±) => f (Z j)) (fun j _ => hf.comp (measurable_pi_apply j))]
have he (j : β„•) : (∫⁻ Z, f (Z j) βˆ‚Measure.infinitePi (fun _ : β„• => Ξ½)) = ∫⁻ a, f a βˆ‚Ξ½ := by
rw [← lintegral_map' hf.aemeasurable (measurable_pi_apply j).aemeasurable,Measure.infinitePi_map_eval]
simp only [he,Finset.sum_const,Finset.card_range,nsmul_eq_mul]
lemma iid_radius_large {d : β„•} (Ξ½ : Measure (Word d)) [IsProbabilityMeasure Ξ½]
(n : β„•) (hn : 0 < n) :
Measure.infinitePi (fun _ : β„• => Ξ½)
{Z | (n : ℝ)^2 ≀ βˆ‘ j ∈ Finset.range n, slabRadius (Z j)} ≀
(∫⁻ a, ENNReal.ofReal (slabRadius a) βˆ‚Ξ½) / (n : ℝβ‰₯0∞) := by
let f : (β„• β†’ Word d) β†’ ℝβ‰₯0∞ := fun Z => βˆ‘ j ∈ Finset.range n, ENNReal.ofReal (slabRadius (Z j))
have hf : Measurable f := Finset.measurable_sum _ (fun j _ =>
(measurable_of_countable (fun a : Word d => ENNReal.ofReal (slabRadius a))).comp (measurable_pi_apply j))
have hne : (n : ℝβ‰₯0∞) β‰  0 := by exact_mod_cast Nat.ne_zero_of_lt hn
have htop : (n : ℝβ‰₯0∞) β‰  ∞ := ENNReal.natCast_ne_top n
have hset : {Z | (n : ℝ)^2 ≀ βˆ‘ j ∈ Finset.range n, slabRadius (Z j)} =
{Z | (n : ℝβ‰₯0∞)^2 ≀ f Z} := by
ext Z
dsimp only [Set.mem_ofPred_eq,f]
rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ => slabRadius_nonneg (Z j))]
have he : ENNReal.ofReal ((n : ℝ)^2) = (n : ℝβ‰₯0∞)^2 := by
rw [ENNReal.ofReal_pow (Nat.cast_nonneg n),ENNReal.ofReal_natCast]
rw [← he,ENNReal.ofReal_le_ofReal_iff (Finset.sum_nonneg (fun j _ => slabRadius_nonneg (Z j)))]
rw [hset]
have hh := meas_ge_le_lintegral_div (ΞΌ := Measure.infinitePi (fun _ : β„• => Ξ½)) hf.aemeasurable (pow_ne_zero _ hne) (by finiteness : (n : ℝβ‰₯0∞)^2 β‰  ∞)
refine hh.trans_eq ?_
change ((∫⁻ Z, βˆ‘ j ∈ Finset.range n, ENNReal.ofReal (slabRadius (Z j)) βˆ‚Measure.infinitePi (fun _ : β„• => Ξ½)) / (n : ℝβ‰₯0∞)^2) = _
rw [iid_lintegral_sum Ξ½ (fun a => ENNReal.ofReal (slabRadius a)) (measurable_of_countable _) n,pow_two,ENNReal.mul_div_mul_left _ _ hne htop]
lemma tapeList_ext {Ξ± : Type*} {a b : TapeList Ξ±} (hl : a.1 = b.1)
(h : βˆ€ i hi hj, a.2 ⟨i,hi⟩ = b.2 ⟨i,hj⟩) : a = b := by
rcases a with ⟨m,a⟩
rcases b with ⟨n,b⟩
dsimp only at hl
subst n
exact congrArg (Sigma.mk m) (funext (fun i => h i i.isLt i.isLt))
lemma reverseTapeList_append {Ξ± : Type*} (a b : TapeList Ξ±) :
reverseTapeList (appendTapeList a b) = appendTapeList (reverseTapeList b) (reverseTapeList a) := by
apply tapeList_ext (Nat.add_comm a.1 b.1)
intro i hi hj
exact Fin.append_rev a.2 b.2 ⟨i,hi⟩
lemma slice_sum {G : Type*} [AddCommGroup G] (f : β„• β†’ G) (a n : β„•) :
(βˆ‘ j ∈ Finset.range n, f (a+j)) =
(βˆ‘ j ∈ Finset.range (a+n), f j) - (βˆ‘ j ∈ Finset.range a, f j) := by
rw [Finset.sum_range_add]
abel
lemma reverseSlice_departure {d : β„•} (Z : β„• β†’ Word d) (a n i t : β„•)
(h0 : βˆ€ j, wordPath (Z j) 0 = 0) (hai : a ≀ i) (hin : i < a+n) (ht : t < (Z i).1) :
βˆƒ u < (concatenateList (reverseTapeList (tapePrefix n (fun j => Z (a+j))))).1,
wordPath (concatenateList (reverseTapeList (tapePrefix n (fun j => Z (a+j))))) u =
(βˆ‘ j ∈ Finset.range (a+n), wordEnd (Z j)) -
(βˆ‘ j ∈ Finset.range (i+1), wordEnd (Z j)) + wordPath (Z i) t := by
let q : Fin n := ⟨i-a,by omega⟩
have hq : a+q.val = i := by dsimp [q];omega
let u := (βˆ‘ j : Fin n with j < q.rev, (Z (a+j.rev)).1)+t
have hu := concatenateWords_departure (fun j : Fin n => Z (a+j.rev)) q.rev t
(by simpa only [Fin.rev_rev,hq] using ht)
refine ⟨u,hu,?_⟩
have he := reversePrefix_site (fun j => Z (a+j)) (fun j _ => h0 _) q t
(by simpa only [hq] using ht.le)
change wordPath (concatenateList (reverseTapeList (tapePrefix n (fun j => Z (a+j))))) u = _ at he
rw [he,slice_sum (fun j => wordEnd (Z j)) a n,slice_sum (fun j => wordEnd (Z j)) a (q.val+1),hq]
have hh : a+(q.val+1) = i+1 := by omega
rw [hh]
abel
lemma forwardSlice_departure {d : β„•} (Z : β„• β†’ Word d) (a n i t : β„•)
(h0 : βˆ€ j, wordPath (Z j) 0 = 0) (hai : a ≀ i) (hin : i < a+n) (ht : t < (Z i).1) :
βˆƒ u < (concatenateList (tapePrefix n (fun j => Z (a+j)))).1,
wordPath (concatenateList (tapePrefix n (fun j => Z (a+j)))) u =
(βˆ‘ j ∈ Finset.range i, wordEnd (Z j)) -
(βˆ‘ j ∈ Finset.range a, wordEnd (Z j)) + wordPath (Z i) t := by
let q : Fin n := ⟨i-a,by omega⟩
have hq : a+q.val = i := by dsimp [q];omega
let u := (βˆ‘ j : Fin n with j < q, (Z (a+j)).1)+t
have hu := concatenateWords_departure (fun j : Fin n => Z (a+j)) q t (by simpa only [hq] using ht)
refine ⟨u,hu,?_⟩
have he := concatenateWords_site (fun j : Fin n => Z (a+j)) (fun j => h0 _) q t
(by simpa only [hq] using ht.le)
change wordPath (concatenateList (tapePrefix n (fun j => Z (a+j)))) u = _ at he
rw [he,hq]
have hsum : (βˆ‘ j : Fin n with j < q, wordEnd (Z (a+j))) =
βˆ‘ j ∈ Finset.range q.val, wordEnd (Z (a+j)) :=
fin_prefix_sum_range (fun j => wordEnd (Z (a+j))) q.val (by omega)
rw [hsum,slice_sum (fun j => wordEnd (Z j)) a q.val,hq]
lemma common_iterate_positive {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±)
(hZ : βˆ€ b i, 0 < L b (Z (b,i)))
(he : βˆ€ r, βˆƒ H, 0 < H ∧ ((commonRestart L)^[r] Z) ∈ commonCut L H) (r : β„•) :
βˆ€ b i, 0 < L b (((commonRestart L)^[r] Z) (b,i)) := by
rw [common_iterates_shift L Z hZ he r]
exact fun b i => hZ b _
lemma common_iterate_exists {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±)
(he : βˆ€ r, βˆƒ H, 0 < H ∧ ((commonRestart L)^[r] Z) ∈ commonCut L H) (r : β„•) :
βˆ€ s, βˆƒ H, 0 < H ∧ ((commonRestart L)^[s] ((commonRestart L)^[r] Z)) ∈ commonCut L H := by
intro s
rw [← Function.iterate_add_apply]
exact he (s+r)
lemma nthCommon_length_add {Ξ± : Type*} (L : Bool β†’ Ξ± β†’ β„•) (Z : TwoTape Ξ±)
(hZ : βˆ€ b i, 0 < L b (Z (b,i)))
(he : βˆ€ r, βˆƒ H, 0 < H ∧ ((commonRestart L)^[r] Z) ∈ commonCut L H) (r s : β„•) (b : Bool) :
(nthCommonList L (r+s) Z b).1 = (nthCommonList L r Z b).1 +
(nthCommonList L s ((commonRestart L)^[r] Z) b).1 := by
rw [nthCommonList_append L Z hZ he r s b]
rfl
end DirectionalZeroOne
end OAI