Download data/lean/OAI/NumberTheory/GaussianMoat/DifferenceSampling.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/NumberTheory/GaussianMoat/DifferenceSampling.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/NumberTheory/GaussianMoat/DifferenceSampling.lean
-
curl -L -o DifferenceSampling.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/NumberTheory/GaussianMoat/DifferenceSampling.lean
11.4 kB
| import OAI.NumberTheory.GaussianMoat.WalkGeometry | |
| namespace OAI | |
| namespace GaussianMoat | |
| noncomputable def walkSegment (z : β β GaussianInt) (n : β) : Finset GaussianInt := | |
| (Finset.range (n+1)).image z | |
| noncomputable def differences (E : Finset GaussianInt) : Finset GaussianInt := | |
| (E ΓΛ’ E).image (fun p => p.1-p.2) | |
| @[simp] theorem mem_walkSegment (z : β β GaussianInt) (n : β) (w : GaussianInt) : | |
| w β walkSegment z n β β i β€ n, z i = w := by | |
| simp [walkSegment,Finset.mem_image] | |
| @[simp] theorem mem_differences (E : Finset GaussianInt) (w : GaussianInt) : | |
| w β differences E β β a β E, β b β E, a-b = w := by | |
| simp [differences,Finset.mem_image,Prod.exists,and_assoc] | |
| theorem card_le_card_differences {E : Finset GaussianInt} (hE : E.Nonempty) : | |
| E.card β€ (differences E).card := by | |
| classical | |
| obtain β¨a,haβ© := hE | |
| have hs : E.image (fun b => b-a) β differences E := by | |
| intro w hw | |
| obtain β¨b,hb,rflβ© := Finset.mem_image.mp hw | |
| exact mem_differences E (b-a) |>.mpr β¨b,hb,a,ha,rflβ© | |
| have hi : Function.Injective (fun b : GaussianInt => b-a) := sub_left_injective | |
| rw [β Finset.card_image_of_injective E hi] | |
| exact Finset.card_le_card hs | |
| theorem walkSegment_dist_le (z : β β GaussianInt) {n : β} {D : β} (hD : 0 β€ D) | |
| (hz : β i < n, dist (z i:β) (z (i+1):β) β€ D) {i j : β} (hi : i β€ n) (hj : j β€ n) : | |
| dist (z i:β) (z j:β) β€ D*n := by | |
| wlog hij : i β€ j generalizing i j | |
| Β· rw [dist_comm] | |
| exact this hj hi (by omega) | |
| have h := dist_le_Ico_sum_of_dist_le (f := fun k => (z k:β)) hij | |
| (d := fun _ => D) (fun {k} _ hk => hz k (lt_of_lt_of_le hk hj)) | |
| simp only [Finset.sum_const,Nat.card_Ico,nsmul_eq_mul] at h | |
| calc | |
| dist (z i:β) (z j:β) β€ (j-i:β)*D := h | |
| _ β€ (n:β)*D := mul_le_mul_of_nonneg_right (by exact_mod_cast (show j-i β€ n by omega)) hD | |
| _ = D*n := mul_comm _ _ | |
| def joinedPath (z : β β GaussianInt) (t : β) (i : β) : GaussianInt := | |
| z (Nat.dist t i)-z t | |
| @[simp] theorem joinedPath_zero (z : β β GaussianInt) (t : β) : joinedPath z t 0 = 0 := by | |
| simp [joinedPath,Nat.dist] | |
| @[simp] theorem joinedPath_end (z : β β GaussianInt) (t s : β) : | |
| joinedPath z t (t+s) = z s-z t := by simp [joinedPath,Nat.dist] | |
| theorem joinedPath_step (z : β β GaussianInt) {n t s : β} (ht : t β€ n) (hs : s β€ n) | |
| {D : β} (hz : β i < n, dist (z i:β) (z (i+1):β) β€ D) : | |
| β i < t+s, dist (joinedPath z t i:β) (joinedPath z t (i+1):β) β€ D := by | |
| intro i hi | |
| simp only [joinedPath,map_sub,dist_sub_right] | |
| by_cases hit : i < t | |
| Β· have he : Nat.dist t i = Nat.dist t (i+1)+1 := by simp only [Nat.dist]; omega | |
| rw [he,dist_comm] | |
| exact hz _ (by simp only [Nat.dist]; omega) | |
| Β· have he : Nat.dist t (i+1) = Nat.dist t i+1 := by simp only [Nat.dist]; omega | |
| rw [he] | |
| exact hz _ (by simp only [Nat.dist]; omega) | |
| theorem differences_card_of_triangle (z : β β GaussianInt) {n t s u : β} | |
| (ht : t β€ n) (hs : s β€ n) (hu : u β€ n) {D : β} (hD : 0 β€ D) | |
| (hz : β i < n, dist (z i:β) (z (i+1):β) β€ D) | |
| (hab : (z s-z t).re*(z u-z t).im-(z s-z t).im*(z u-z t).re β 0) : | |
| ((z s-z t).re*(z u-z t).im-(z s-z t).im*(z u-z t).re).natAbs β€ | |
| (differences (walkSegment z n)).card * (latticeBall (4*D)).card := by | |
| have hts : 0 < t+s := by | |
| by_contra hh | |
| have ht0 : t=0 := by omega | |
| have hs0 : s=0 := by omega | |
| simp [ht0,hs0] at hab | |
| have htu : 0 < t+u := by | |
| by_contra hh | |
| have ht0 : t=0 := by omega | |
| have hu0 : u=0 := by omega | |
| simp [ht0,hu0] at hab | |
| apply lattice_path_difference_card (joinedPath z t) (joinedPath z t) hts htu | |
| (z s-z t) (z u-z t) (joinedPath_zero z t) (joinedPath_zero z t) | |
| (joinedPath_end z t s) (joinedPath_end z t u) hab hD | |
| (joinedPath_step z ht hs hz) (joinedPath_step z ht hu hz) | |
| intro i hi j hj | |
| apply (mem_differences _ _).mpr | |
| refine β¨z (Nat.dist t i),(mem_walkSegment _ _ _).mpr β¨_,?_,rflβ©, | |
| z (Nat.dist t j),(mem_walkSegment _ _ _).mpr β¨_,?_,rflβ©,?_β© | |
| Β· simp only [Nat.dist]; omega | |
| Β· simp only [Nat.dist]; omega | |
| Β· simp only [joinedPath]; ring | |
| noncomputable def diameterRotation (a : β) : β := star a / (βaβ:β) | |
| theorem diameterRotation_norm {a : β} (ha : a β 0) : βdiameterRotation aβ = 1 := by | |
| simp [diameterRotation,Complex.norm_real,norm_ne_zero_iff.mpr ha] | |
| theorem diameterRotation_mul (a : β) : diameterRotation a*a = (βaβ:β) := by | |
| by_cases ha : a=0 | |
| Β· simp [ha,diameterRotation] | |
| have hn : (βaβ:β) β 0 := by exact_mod_cast norm_ne_zero_iff.mpr ha | |
| have hm : star a*a = (βaβ:β)^2 := Complex.conj_mul' a | |
| rw [diameterRotation,div_mul_eq_mul_div,hm] | |
| field_simp | |
| theorem diameter_rectangle {a v : β} (ha : a β 0) (hv : βvβ β€ βaβ) | |
| (hva : βv-aβ β€ βaβ) : | |
| 0 β€ (diameterRotation a*v).re β§ (diameterRotation a*v).re β€ βaβ β§ | |
| |(diameterRotation a*v).im| β€ βaβ := by | |
| let u := diameterRotation a*v | |
| have hn : βuβ β€ βaβ := by simpa [u,norm_mul,diameterRotation_norm ha] using hv | |
| have hna : βu-(βaβ:β)β β€ βaβ := by | |
| rw [β diameterRotation_mul a,β mul_sub] | |
| simpa [norm_mul,diameterRotation_norm ha] using hva | |
| have hr := Complex.abs_re_le_norm u | |
| have hi := Complex.abs_im_le_norm u | |
| have hra := Complex.abs_re_le_norm (u-(βaβ:β)) | |
| simp only [Complex.sub_re,Complex.ofReal_re] at hra | |
| have hl := (abs_le.mp (hra.trans hna)).1 | |
| exact β¨by dsimp [u] at *; linarith, (le_abs_self u.re).trans (hr.trans hn), hi.trans hnβ© | |
| theorem diameter_height (a b : GaussianInt) : | |
| |((a.re*b.im-a.im*b.re:β€):β)| = | |
| β(a:β)β*|(diameterRotation (a:β)*(b:β)).im| := by | |
| by_cases ha : a=0 | |
| Β· simp [ha,diameterRotation] | |
| have hna : β(a:β)β β 0 := norm_ne_zero_iff.mpr (by simpa using ha) | |
| have he : (diameterRotation (a:β)*(b:β)).im = | |
| ((a.re:β)*(b.im:β)-(a.im:β)*(b.re:β))/β(a:β)β := by | |
| simp only [diameterRotation,div_mul_eq_mul_div,Complex.div_ofReal_im, | |
| Complex.mul_im,Complex.star_def,Complex.conj_re,Complex.conj_im, | |
| β GaussianInt.intCast_re,β GaussianInt.intCast_im] | |
| ring | |
| rw [he,abs_div,abs_of_nonneg (norm_nonneg (a:β))] | |
| push_cast | |
| field_simp | |
| theorem walk_many_differences (z : β β GaussianInt) {n : β} (hn : 1 β€ n) | |
| (hinj : Function.Injective z) {D : β} (hD : 1 β€ D) | |
| (hz : β i < n, dist (z i:β) (z (i+1):β) β€ D) : | |
| β (R W : β) (e c : β), 1 β€ W β§ W β€ R β§ βeβ = 1 β§ | |
| (β p β walkSegment z n, 0 β€ (e*((p:β)-c)).re β§ | |
| (e*((p:β)-c)).re β€ R β§ |(e*((p:β)-c)).im| β€ W) β§ | |
| (n:β) β€ 18*(R*W) β§ R*W β€ D^2*(n:β)^2 β§ | |
| R*W β€ max D ((latticeBall (4*D)).card:β)*(differences (walkSegment z n)).card := by | |
| classical | |
| let I := Finset.range (n+1) | |
| have hI : I.Nonempty := β¨0,by simp [I]β© | |
| obtain β¨β¨t,sβ©,hts,hmaxβ© := Finset.exists_max_image (I ΓΛ’ I) | |
| (fun q => dist (z q.1:β) (z q.2:β)) (hI.product hI) | |
| have ht : t β€ n := by simpa [I] using (Finset.mem_product.mp hts).1 | |
| have hs : s β€ n := by simpa [I] using (Finset.mem_product.mp hts).2 | |
| let a := z s-z t | |
| let R := β(a:β)β | |
| have hdiam : β i β€ n, β j β€ n, dist (z i:β) (z j:β) β€ R := by | |
| intro i hi j hj | |
| have h := hmax (i,j) (by simp [I,hi,hj]) | |
| simpa [R,a,map_sub,β dist_eq_norm,dist_comm] using h | |
| have hR : 1 β€ R := (lattice_dist_ge_one (hinj.ne (by omega : 0 β 1))).trans (hdiam 0 (by omega) 1 hn) | |
| have ha : a β 0 := by intro hh; simp [R,hh] at hR; linarith | |
| have hac : (a:β) β 0 := by simpa using ha | |
| let e := diameterRotation (a:β) | |
| let c := (z t:β) | |
| have he : βeβ = 1 := diameterRotation_norm hac | |
| have hr : β i β€ n, 0 β€ (e*((z i:β)-c)).re β§ | |
| (e*((z i:β)-c)).re β€ R β§ |(e*((z i:β)-c)).im| β€ R := by | |
| intro i hi | |
| have hv : β(z i:β)-cβ β€ β(a:β)β := by simpa only [β dist_eq_norm] using hdiam i hi t ht | |
| have hva : β((z i:β)-c)-(a:β)β β€ β(a:β)β := by | |
| have hh : ((z i:β)-c)-(a:β) = (z i:β)-(z s:β) := by simp [a,c] | |
| rw [hh,β dist_eq_norm] | |
| exact hdiam i hi s hs | |
| exact diameter_rectangle hac hv hva | |
| obtain β¨u,hu,humaxβ© := Finset.exists_max_image I | |
| (fun i => |(e*((z i:β)-c)).im|) hI | |
| have hu' : u β€ n := by simpa [I] using hu | |
| let W := max 1 |(e*((z u:β)-c)).im| | |
| have hW : 1 β€ W := le_max_left _ _ | |
| have hWR : W β€ R := max_le hR (hr u hu').2.2 | |
| have hrect : β p β walkSegment z n, 0 β€ (e*((p:β)-c)).re β§ | |
| (e*((p:β)-c)).re β€ R β§ |(e*((p:β)-c)).im| β€ W := by | |
| intro p hp | |
| obtain β¨i,hi,rflβ© := (mem_walkSegment _ _ _).mp hp | |
| exact β¨(hr i hi).1,(hr i hi).2.1,(humax i (by simpa [I] using hi)).trans (le_max_right _ _)β© | |
| have hcard : (walkSegment z n).card = n+1 := by | |
| rw [walkSegment,Finset.card_image_of_injective _ hinj,Finset.card_range] | |
| have hcount : (n:β)+1 β€ 18*R*W := by | |
| have h := lattice_rectangle_card (walkSegment z n) he hR hW hrect | |
| simpa only [hcard,Nat.cast_add,Nat.cast_one] using h | |
| have hRD : R β€ D*n := by | |
| simpa only [R,a,map_sub,β dist_eq_norm] using walkSegment_dist_le z (by linarith) hz hs ht | |
| have hAupper : R*W β€ D^2*(n:β)^2 := by | |
| have hn0 : (0:β) β€ n := Nat.cast_nonneg _ | |
| have hm := mul_le_mul hRD hRD (by linarith : 0 β€ R) (by positivity : 0 β€ D*n) | |
| have hw := mul_le_mul_of_nonneg_left hWR (by linarith : 0 β€ R) | |
| nlinarith | |
| refine β¨R,W,e,c,hW,hWR,he,hrect,by nlinarith,hAupper,?_β© | |
| have hdif := card_le_card_differences (E := walkSegment z n) | |
| β¨z 0,(mem_walkSegment _ _ _).mpr β¨0,by omega,rflβ©β© | |
| have hcountdif : (n:β)+1 β€ ((differences (walkSegment z n)).card:β) := by | |
| rw [hcard] at hdif | |
| exact_mod_cast hdif | |
| by_cases hthin : |(e*((z u:β)-c)).im| β€ 1 | |
| Β· have hWeq : W = 1 := max_eq_left hthin | |
| rw [hWeq,mul_one] | |
| have hdn : D*(n:β) β€ D*((differences (walkSegment z n)).card:β) := | |
| mul_le_mul_of_nonneg_left (by linarith) (by linarith) | |
| exact (hRD.trans hdn).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) (by positivity)) | |
| Β· have hWeq : W = |(e*((z u:β)-c)).im| := max_eq_right (by linarith) | |
| let b := z u-z t | |
| have hdet : |((a.re*b.im-a.im*b.re:β€):β)| = R*W := by | |
| rw [diameter_height,hWeq] | |
| simp only [R,e,b,map_sub,c] | |
| have hab : a.re*b.im-a.im*b.re β 0 := by | |
| intro hh | |
| rw [hh,Int.cast_zero,abs_zero] at hdet | |
| have : 0 < R*W := mul_pos (by linarith) (by linarith) | |
| linarith | |
| have hcd := differences_card_of_triangle z ht hs hu' (by linarith) hz hab | |
| have hcd' : |((a.re*b.im-a.im*b.re:β€):β)| β€ | |
| ((differences (walkSegment z n)).card:β)*((latticeBall (4*D)).card:β) := by | |
| have hh : ((a.re*b.im-a.im*b.re).natAbs:β) β€ | |
| ((differences (walkSegment z n)).card:β)*((latticeBall (4*D)).card:β) := by | |
| exact_mod_cast hcd | |
| simpa only [Nat.cast_natAbs,Int.cast_abs] using hh | |
| rw [hdet] at hcd' | |
| calc | |
| R*W β€ ((differences (walkSegment z n)).card:β)*((latticeBall (4*D)).card:β) := hcd' | |
| _ = ((latticeBall (4*D)).card:β)*((differences (walkSegment z n)).card:β) := mul_comm _ _ | |
| _ β€ _ := mul_le_mul_of_nonneg_right (le_max_right _ _) (by positivity) | |
| end GaussianMoat | |
| end OAI | |