Download data/lean/OAI/Probability/DirectionalWalk/AxisCubes.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/DirectionalWalk/AxisCubes.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/DirectionalWalk/AxisCubes.lean
-
curl -L -o AxisCubes.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/DirectionalWalk/AxisCubes.lean
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 | |