Download data/lean/OAI/Combinatorics/FiniteCircle/MaskSeparation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 16 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/FiniteCircle/MaskSeparation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/FiniteCircle/MaskSeparation.lean
-
curl -L -o MaskSeparation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/FiniteCircle/MaskSeparation.lean
16 kB
| import OAI.Combinatorics.FiniteCircle.CircleWords | |
| namespace OAI | |
| namespace FiniteCircle | |
| open scoped BigOperators List | |
| abbrev MaskResidues (h : β) (p : β β β β β) (l : β) := (k : Fin h) β ZMod (p l k) | |
| noncomputable def maskPhaseHom (h : β) (p : β β β β β) (M l : β) | |
| (hd : β k : Fin h, p l k β£ M) : MaskResidues h p l β+ (MaskTag h p l β ZMod M) where | |
| toFun z j := (β k, subcircle (hd k) (z k)) + j.2.val β’ subcircle (hd j.1) (z j.1) | |
| map_zero' := by funext j; simp | |
| map_add' z u := by | |
| funext j | |
| simp only [Pi.add_apply, map_add, Finset.sum_add_distrib, nsmul_add] | |
| abel | |
| theorem maskPhaseHom_natCast (h : β) (p : β β β β β) (M l a : β) | |
| (hd : β k : Fin h, p l k β£ M) (hn : β k : Fin h, 0 < p l k) : | |
| maskPhaseHom h p M l hd (fun k => (a : ZMod (p l k))) = maskGamma h p M l a := by | |
| funext j | |
| change (β k, subcircle (hd k) (a : ZMod (p l k))) + | |
| j.2.val β’ subcircle (hd j.1) (a : ZMod (p l j.1)) = _ | |
| have he (k : Fin h) : subcircle (hd k) (a : ZMod (p l k)) = | |
| ((M/p l k*(a%p l k) : β) : ZMod M) := by | |
| let : NeZero (p l k) := β¨(hn k).ne'β© | |
| rw [subcircle_val, ZMod.val_natCast] | |
| simp_rw [he] | |
| simp only [maskGamma, nsmul_eq_mul, Nat.cast_mul] | |
| ring | |
| theorem sum_fin_zmod {p : β} [NeZero p] (g : ZMod p β β) : | |
| β b : Fin p, g (b.val : ZMod p) = β b : ZMod p, g b := by | |
| refine Fintype.sum_equiv (ZMod.finEquiv p).toEquiv _ _ ?_ | |
| intro b | |
| congr 1 | |
| cases p with | |
| | zero => exact Fin.elim0 b | |
| | succ p => | |
| change (b.val : ZMod (p+1)) = b | |
| exact ZMod.natCast_zmod_val (show ZMod (p+1) from b) | |
| noncomputable def maskCost (h : β) (p : β β β β β) (M : β) | |
| (hd : β l (k : Fin h), p l k β£ M) (hn : β l (k : Fin h), 0 < p l k) : | |
| β β PhaseCost (ZMod M) | |
| | 0 => circlePhaseCost M | |
| | l+1 => by | |
| let : β k : Fin h, NeZero (p (l+1) k) := fun k => β¨(hn _ k).ne'β© | |
| exact (maskCost h p M hd hn l).step (maskPhaseHom h p M (l+1) (hd _)) | |
| theorem maskCost_le_half {h M : β} {p : β β β β β} [NeZero M] | |
| (hh : 0 < h) (hd : β l (k : Fin h), p l k β£ M) (hn : β l (k : Fin h), 0 < p l k) | |
| (l : β) (x : ZMod M) : maskCost h p M hd hn l x β€ 1/2 := by | |
| induction l with | |
| | zero => exact circleCost_le_half x | |
| | succ l ih => | |
| let : β k : Fin h, NeZero (p (l+1) k) := fun k => β¨(hn _ k).ne'β© | |
| let : Nonempty (MaskTag h p (l+1)) := β¨β¨β¨0,hhβ©,β¨0,hn _ β¨0,hhβ©β©β©β© | |
| exact ((maskCost h p M hd hn l).infAverage_le_self _ x).trans ih | |
| theorem card_maskTag (h : β) (p : β β β β β) (l : β) : | |
| Fintype.card (MaskTag h p l) = β k : Fin h, p l k := by | |
| simp only [MaskTag, Fintype.card_sigma, Fintype.card_fin] | |
| theorem mask_average_formula {h M l : β} {p : β β β β β} | |
| (hd : β k : Fin h, p l k β£ M) (hn : β k : Fin h, 0 < p l k) | |
| (f : PhaseCost (ZMod M)) (x : ZMod M) (z : MaskResidues h p l) : | |
| f.average (maskPhaseHom h p M l hd) x z = | |
| (β k : Fin h, β b : Fin (p l k), | |
| f (x+(β k,subcircle (hd k) (z k))+b.val β’ subcircle (hd k) (z k))) / | |
| (β k : Fin h, (p l k : β)) := by | |
| let : β k : Fin h, NeZero (p l k) := fun k => β¨(hn k).ne'β© | |
| simp only [PhaseCost.average, card_maskTag, Nat.cast_sum, Fintype.sum_sigma] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro k _ | |
| apply Finset.sum_congr rfl | |
| intro b _ | |
| congr 1 | |
| change x+((β k,subcircle (hd k) (z k))+b.val β’ subcircle (hd k) (z k)) = _ | |
| abel | |
| theorem mask_active_average_lower {h M l : β} {p : β β β β β} | |
| (hh : 0 < h) (hd : β k : Fin h, p l k β£ M) | |
| (hp : β k : Fin h, (p l k).Prime) | |
| (hlo : β k : Fin h, h^3 β€ p l k) (hhi : β k : Fin h, p l k β€ 2*h^3) | |
| (f : PhaseCost (ZMod M)) (x : ZMod M) (z : MaskResidues h p l) | |
| (Q : β) (hQ : 0 β€ Q) | |
| (hq : β k : Fin h, z k β 0 β Q β€ f (subcircle (hd k) 1)) : | |
| (((Finset.univ.filter (fun k : Fin h => z k β 0)).card : β)/(4*h))*Q β€ | |
| f.average (maskPhaseHom h p M l hd) x z := by | |
| classical | |
| let : β k : Fin h, NeZero (p l k) := fun k => β¨(hp k).ne_zeroβ© | |
| let S := Finset.univ.filter (fun k : Fin h => z k β 0) | |
| let T : β := β k : Fin h, (p l k : β) | |
| let B (k : Fin h) : β := β b : Fin (p l k), | |
| f (x+(β j,subcircle (hd j) (z j))+b.val β’ subcircle (hd k) (z k)) | |
| have hB (k : Fin h) : 0 β€ B k := Finset.sum_nonneg (fun _ _ => f.nonneg _) | |
| have hT : 0 < T := by | |
| apply Finset.sum_pos | |
| Β· intro k _; exact_mod_cast (hp k).pos | |
| Β· exact Finset.univ_nonempty_iff.mpr β¨β¨0,hhβ©β© | |
| have hTu : T β€ 2*(h:β)^4 := by | |
| calc | |
| T β€ β _k : Fin h, (2:β)*h^3 := Finset.sum_le_sum (fun k _ => by exact_mod_cast hhi k) | |
| _ = _ := by simp; ring | |
| have hkb (k : Fin h) (hk : k β S) : (h:β)^3*Q β€ 2*B k := by | |
| have ha := f.prime_grid_bound (hp k) (subcircle (hd k)) | |
| (x+β j,subcircle (hd j) (z j)) (z k) ((Finset.mem_filter.mp hk).2) | |
| have he : B k = β b : ZMod (p l k), | |
| f (x+(β j,subcircle (hd j) (z j))+b.val β’ subcircle (hd k) (z k)) := by | |
| symm | |
| rw [β sum_fin_zmod] | |
| apply Finset.sum_congr rfl | |
| intro b _ | |
| rw [ZMod.val_natCast, Nat.mod_eq_of_lt b.isLt] | |
| rw [β he] at ha | |
| calc | |
| (h:β)^3*Q β€ (p l k : β)*Q := mul_le_mul_of_nonneg_right (by exact_mod_cast hlo k) hQ | |
| _ β€ (p l k : β)*f (subcircle (hd k) 1) := mul_le_mul_of_nonneg_left (hq k ((Finset.mem_filter.mp hk).2)) (by positivity) | |
| _ β€ _ := ha | |
| have hsum : (S.card : β)*(h:β)^3*Q β€ 2*β k : Fin h, B k := by | |
| calc | |
| _ = β _k β S, (h:β)^3*Q := by simp; ring | |
| _ β€ β k β S, 2*B k := Finset.sum_le_sum hkb | |
| _ β€ β k : Fin h, 2*B k := Finset.sum_le_sum_of_subset_of_nonneg | |
| (Finset.subset_univ _) (fun k _ _ => mul_nonneg (by norm_num) (hB k)) | |
| _ = _ := (Finset.mul_sum ..).symm | |
| rw [mask_average_formula hd (fun k => (hp k).pos)] | |
| change (S.card : β)/(4*h)*Q β€ (β k : Fin h, B k)/T | |
| rw [le_div_iffβ hT] | |
| have hh' : (0:β) < h := by exact_mod_cast hh | |
| have hb : 0 β€ (S.card : β)/(4*h)*Q := by positivity | |
| calc | |
| _ β€ ((S.card : β)/(4*h)*Q)*(2*(h:β)^4) := mul_le_mul_of_nonneg_left hTu hb | |
| _ = ((S.card : β)*(h:β)^3*Q)/2 := by field_simp; ring | |
| _ β€ _ := by linarith | |
| theorem mask_inactive_average_lower {h M l : β} {p : β β β β β} | |
| (hh : 0 < h) (hd : β k : Fin h, p l k β£ M) | |
| (hp : β k : Fin h, (p l k).Prime) | |
| (hlo : β k : Fin h, h^3 β€ p l k) (hhi : β k : Fin h, p l k β€ 2*h^3) | |
| (f : PhaseCost (ZMod M)) (x : ZMod M) (z : MaskResidues h p l) | |
| (hs : 2*(Finset.univ.filter (fun k : Fin h => z k β 0)).card β€ h) : | |
| (1/4:β)*f (x+β k,subcircle (hd k) (z k)) β€ | |
| f.average (maskPhaseHom h p M l hd) x z := by | |
| classical | |
| let N := Finset.univ.filter (fun k : Fin h => z k = 0) | |
| let T : β := β k : Fin h, (p l k : β) | |
| let B (k : Fin h) : β := β b : Fin (p l k), | |
| f (x+(β j,subcircle (hd j) (z j))+b.val β’ subcircle (hd k) (z k)) | |
| let Q := f (x+β k,subcircle (hd k) (z k)) | |
| have hQ : 0 β€ Q := f.nonneg _ | |
| have hB (k : Fin h) : 0 β€ B k := Finset.sum_nonneg (fun _ _ => f.nonneg _) | |
| have hT : 0 < T := by | |
| apply Finset.sum_pos | |
| Β· intro k _; exact_mod_cast (hp k).pos | |
| Β· exact Finset.univ_nonempty_iff.mpr β¨β¨0,hhβ©β© | |
| have hTu : T β€ 2*(h:β)^4 := by | |
| calc | |
| T β€ β _k : Fin h, (2:β)*h^3 := Finset.sum_le_sum (fun k _ => by exact_mod_cast hhi k) | |
| _ = _ := by simp; ring | |
| have hN : (h:β) β€ 2*N.card := by | |
| have hc := Finset.card_filter_add_card_filter_not (s := Finset.univ) (fun k : Fin h => z k = 0) | |
| simp only [Finset.card_univ, Fintype.card_fin] at hc | |
| change N.card + (Finset.univ.filter (fun k : Fin h => z k β 0)).card = h at hc | |
| exact_mod_cast (show h β€ 2*N.card by omega) | |
| have hkb (k : Fin h) (hk : k β N) : (h:β)^3*Q β€ B k := by | |
| have hz := (Finset.mem_filter.mp hk).2 | |
| have he : B k = (p l k : β)*Q := by | |
| simp [B, Q, hz] | |
| rw [he] | |
| exact mul_le_mul_of_nonneg_right (by exact_mod_cast hlo k) hQ | |
| have hsum : (N.card : β)*(h:β)^3*Q β€ β k : Fin h, B k := by | |
| calc | |
| _ = β _k β N, (h:β)^3*Q := by simp; ring | |
| _ β€ β k β N, B k := Finset.sum_le_sum hkb | |
| _ β€ β k : Fin h, B k := Finset.sum_le_sum_of_subset_of_nonneg | |
| (Finset.subset_univ _) (fun k _ _ => hB k) | |
| rw [mask_average_formula hd (fun k => (hp k).pos)] | |
| change (1/4:β)*Q β€ (β k : Fin h, B k)/T | |
| rw [le_div_iffβ hT] | |
| calc | |
| _ β€ ((1/4:β)*Q)*(2*(h:β)^4) := mul_le_mul_of_nonneg_left hTu (by positivity) | |
| _ = ((h:β)/2)*h^3*Q := by ring | |
| _ β€ (N.card : β)*h^3*Q := by gcongr; linarith | |
| _ β€ _ := hsum | |
| theorem mask_minimizer_options {h M l : β} {p : β β β β β} | |
| [β k : Fin h, NeZero (p l k)] | |
| (hh : 0 < h) (hd : β k : Fin h, p l k β£ M) | |
| (hp : β k : Fin h, (p l k).Prime) | |
| (hlo : β k : Fin h, h^3 β€ p l k) (hhi : β k : Fin h, p l k β€ 2*h^3) | |
| (f : PhaseCost (ZMod M)) (x : ZMod M) : | |
| β z : MaskResidues h p l, | |
| (let S := Finset.univ.filter (fun k : Fin h => z k β 0) | |
| (β Q : β, 0 β€ Q β (β k β S, Q β€ f (subcircle (hd k) 1)) β | |
| (S.card : β)/(4*h)*Q β€ f.infAverage (maskPhaseHom h p M l hd) x) β§ | |
| (2*S.card β€ h β (1/4:β)*f (x+β k,subcircle (hd k) (z k)) β€ | |
| f.infAverage (maskPhaseHom h p M l hd) x)) := by | |
| classical | |
| let : β k : Fin h, NeZero (p l k) := fun k => β¨(hp k).ne_zeroβ© | |
| obtain β¨z,hzβ© := f.exists_average_eq (maskPhaseHom h p M l hd) x | |
| refine β¨z, ?_β© | |
| dsimp only | |
| rw [hz] | |
| constructor | |
| Β· intro Q hQ hq | |
| exact mask_active_average_lower hh hd hp hlo hhi f x z Q hQ | |
| (fun k hk => hq k (by simp [hk])) | |
| Β· exact mask_inactive_average_lower hh hd hp hlo hhi f x z | |
| theorem deficit_cast {Ξ² : Type*} (x y : List Ξ²) : (deficit x y : β) = (x.length:β) - lcs x y := by | |
| exact Nat.cast_sub (lcs_le_length_left x y) | |
| theorem deficit_taggedRow_lower {J Ξ² : Type*} [Fintype J] [DecidableEq J] | |
| (js : List J) (hn : js.Nodup) (hall : β j, j β js) (W U : J β List Ξ²) : | |
| (β j : J, (deficit (W j) (U j) : β)) β€ | |
| deficit (taggedRow js W) (taggedRow js U) := by | |
| have hc := lcs_taggedRow_le js hn hall W U | |
| have hcr : (lcs (taggedRow js W) (taggedRow js U) : β) β€ β j : J, (lcs (W j) (U j) : β) := by exact_mod_cast hc | |
| simp_rw [deficit_cast] | |
| rw [Finset.sum_sub_distrib, length_taggedRow js hn hall W, Nat.cast_sum] | |
| linarith | |
| theorem maskLength_pos {h M R : β} {p : β β β β β} | |
| (hh : 0 < h) (hM : 0 < M) (hR : 0 < R) (hn : β l (k : Fin h), 0 < p l k) | |
| (l : β) : 0 < maskLength h p R M l := by | |
| induction l with | |
| | zero => exact hM | |
| | succ l ih => | |
| unfold maskLength | |
| apply Nat.mul_pos (Nat.mul_pos hR (Finset.prod_pos (fun k _ => hn _ k))) | |
| apply Nat.mul_pos _ ih | |
| rw [length_maskTags] | |
| exact Finset.sum_pos (fun k _ => hn _ k) (Finset.univ_nonempty_iff.mpr β¨β¨0,hhβ©β©) | |
| theorem mask_separation {h M R : β} {p : β β β β β} [NeZero M] | |
| (he : M = 2*(M/2)) (hh : 0 < h) (hR : 0 < R) | |
| (hd : β l (k : Fin h), p l k β£ M) (hn : β l (k : Fin h), 0 < p l k) | |
| (ht : β l, 4 β€ (maskTags h p l).length) | |
| (l : β) (v : MaskState h p M l) (ΞΈ : ZMod M) : | |
| (1/((2:β)^l*4))*(maskLength h p R M l)*maskCost h p M hd hn l ΞΈ β€ | |
| (deficit (maskWord h p R M l v) | |
| (maskWord h p R M l (shiftMaskState h p M l v ΞΈ)) : β) := by | |
| classical | |
| induction l generalizing ΞΈ with | |
| | zero => | |
| change ZMod M at v | |
| change (1/((2:β)^0*4))*M*circleCost ΞΈ β€ | |
| (deficit (maskWord h p R M 0 v) (maskWord h p R M 0 (v+ΞΈ)) : β) | |
| rw [maskWord_zero_eq, maskWord_zero_eq] | |
| calc | |
| _ = (M:β)*circleCost ΞΈ/4 := by norm_num; ring | |
| _ β€ _ := halfCircle_separation he v ΞΈ | |
| | succ l ih => | |
| let : β k : Fin h, NeZero (p (l+1) k) := fun k => β¨(hn _ k).ne'β© | |
| let L := maskLength h p R M l | |
| let t := (maskTags h p (l+1)).length | |
| let N := R*period h p (l+1) | |
| let f := maskCost h p M hd hn l | |
| let Ο := maskPhaseHom h p M (l+1) (hd _) | |
| let Ο := (1/((2:β)^l*4))*maskCost h p M hd hn (l+1) ΞΈ | |
| have hL : 0 < L := maskLength_pos hh (NeZero.pos M) hR hn l | |
| have hp2 : 1 β€ (2:β)^l := one_le_powβ (by norm_num) | |
| have hΟ : Ο β€ 1/2 := by | |
| have hc := maskCost_le_half hh hd hn (l+1) ΞΈ | |
| have hc0 := (maskCost h p M hd hn (l+1)).nonneg ΞΈ | |
| dsimp [Ο] | |
| have hi : 1/((2:β)^l*4) β€ 1 := (div_le_one (by positivity)).mpr (by nlinarith) | |
| calc | |
| _ β€ 1*maskCost h p M hd hn (l+1) ΞΈ := mul_le_mul_of_nonneg_right hi hc0 | |
| _ β€ _ := by simpa using hc | |
| have hx : (maskWord h p R M (l+1) v).length = (t*L)*N := by | |
| rw [length_maskWord] | |
| change N*(t*L) = (t*L)*N | |
| exact Nat.mul_comm _ _ | |
| have hy : (maskWord h p R M (l+1) (shiftMaskState h p M (l+1) v ΞΈ)).length = (t*L)*N := by | |
| rw [length_maskWord] | |
| change N*(t*L) = (t*L)*N | |
| exact Nat.mul_comm _ _ | |
| have hr := row_separation hL (ht (l+1)) hx hy | |
| (fun x => (maskTags h p (l+1)).idxOf x.1) | |
| (tag_get_maskWord h p R M l v hL (by have := ht (l+1); omega)) | |
| (tag_get_maskWord h p R M l _ hL (by have := ht (l+1); omega)) Ο hΟ | |
| have hrows : β i j : Fin N, Ο*(t*L) β€ | |
| (deficit (segment (maskWord h p R M (l+1) v) (i.val*(t*L)) (t*L)) | |
| (segment (maskWord h p R M (l+1) (shiftMaskState h p M (l+1) v ΞΈ)) | |
| (j.val*(t*L)) (t*L)) : β) := by | |
| intro a b | |
| rw [segment_maskWord, segment_maskWord] | |
| let z : MaskResidues h p (l+1) := fun k => (b.val : ZMod (p (l+1) k)) - (a.val : ZMod (p (l+1) k)) | |
| have hz (j : MaskTag h p (l+1)) : Ο z j = | |
| maskGamma h p M (l+1) b j - maskGamma h p M (l+1) a j := by | |
| change Ο ((fun k : Fin h => (b.val : ZMod (p (l+1) k))) - (fun k : Fin h => (a.val : ZMod (p (l+1) k)))) j = _ | |
| rw [map_sub, Pi.sub_apply] | |
| exact congrArgβ (Β·-Β·) (congrFun (maskPhaseHom_natCast h p M (l+1) b (hd _) (hn _)) j) | |
| (congrFun (maskPhaseHom_natCast h p M (l+1) a (hd _) (hn _)) j) | |
| have hind (j : MaskTag h p (l+1)) := ih | |
| (shiftMaskState h p M l (v j) (maskGamma h p M (l+1) a j)) (ΞΈ+Ο z j) | |
| have hstate (j : MaskTag h p (l+1)) : | |
| shiftMaskState h p M l (shiftMaskState h p M l (v j) (maskGamma h p M (l+1) a j)) (ΞΈ+Ο z j) = | |
| shiftMaskState h p M l (shiftMaskState h p M l (v j) ΞΈ) (maskGamma h p M (l+1) b j) := by | |
| rw [shiftMaskState_add, shiftMaskState_add, hz] | |
| congr 1 | |
| abel | |
| simp_rw [hstate] at hind | |
| have hsum := Finset.sum_le_sum (s := Finset.univ) (fun j _ => hind j) | |
| have hdef := deficit_taggedRow_lower (maskTags h p (l+1)) (nodup_maskTags ..) | |
| (mem_maskTags h p (l+1)) | |
| (fun j => maskWord h p R M l (shiftMaskState h p M l (v j) (maskGamma h p M (l+1) a j))) | |
| (fun j => maskWord h p R M l (shiftMaskState h p M l (shiftMaskState h p M l (v j) ΞΈ) (maskGamma h p M (l+1) b j))) | |
| apply le_trans _ (hsum.trans hdef) | |
| rw [β Finset.mul_sum] | |
| have hcost : maskCost h p M hd hn (l+1) ΞΈ β€ f.average Ο ΞΈ z := f.infAverage_le Ο ΞΈ z | |
| have htpos : (0:β) < t := by exact_mod_cast (show 0 < t by have := ht (l+1); omega) | |
| have hcard : (Fintype.card (MaskTag h p (l+1)) : β) = t := by rw [card_maskTag]; exact_mod_cast (length_maskTags h p (l+1)).symm | |
| rw [PhaseCost.average, hcard, le_div_iffβ htpos] at hcost | |
| dsimp only [Ο] | |
| calc | |
| _ = ((1/((2:β)^l*4))*(L:β)) * ((maskCost h p M hd hn (l+1) ΞΈ)*t) := by ring | |
| _ β€ _ := mul_le_mul_of_nonneg_left hcost (by positivity) | |
| have hfinal := hr hrows | |
| rw [length_maskWord] at hfinal | |
| dsimp only [Ο] at hfinal | |
| calc | |
| _ = ((1/((2:β)^l*4))*maskCost h p M hd hn (l+1) ΞΈ)/2 * maskLength h p R M (l+1) := by rw [pow_succ]; ring | |
| _ β€ _ := hfinal | |
| end FiniteCircle | |
| end OAI | |