Download data/lean/OAI/Combinatorics/EditDistance/PrimeCharacters.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.99 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/PrimeCharacters.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditDistance/PrimeCharacters.lean
-
curl -L -o PrimeCharacters.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/PrimeCharacters.lean
6.99 kB
| import OAI.Combinatorics.EditDistance.FourierCharacters | |
| namespace OAI | |
| /-! | |
| # Coprime roots and prime-product Fourier multipliers | |
| -/ | |
| namespace EditFourier | |
| open scoped BigOperators | |
| open Finset | |
| section CoprimeRoots | |
| variable {J : Type*} [DecidableEq J] | |
| omit [DecidableEq J] in | |
| theorem prod_roots_pow (s : Finset J) (p : J β β) (z : J β β) | |
| (hz : β j β s, z j ^ p j = 1) (q : β) (hq : β j β s, p j β£ q) : | |
| (β j β s, z j) ^ q = 1 := by | |
| rw [β prod_pow] | |
| apply prod_eq_one | |
| intro j hj | |
| obtain β¨m, hmβ© := hq j hj | |
| rw [hm, pow_mul, hz j hj, one_pow] | |
| theorem coprime_roots_nontrivial (s : Finset J) (p : J β β) (z : J β β) | |
| (hcop : (s : Set J).Pairwise (fun i j => (p i).Coprime (p j))) | |
| (hz : β j β s, z j ^ p j = 1) (i : J) (hi : i β s) (hne : z i β 1) : | |
| (β j β s, z j) β 1 := by | |
| intro h | |
| let q := β j β s.erase i, p j | |
| have hq : β j β s.erase i, p j β£ q := fun j hj => dvd_prod_of_mem p hj | |
| have hpow := prod_roots_pow (s.erase i) p z | |
| (fun j hj => hz j (mem_of_mem_erase hj)) q hq | |
| have hp : z i ^ q = 1 := by | |
| have hh := congrArg (fun a : β => a ^ q) h | |
| rw [β mul_prod_erase s z hi, mul_pow, hpow, mul_one, one_pow] at hh | |
| exact hh | |
| have hc : (p i).Coprime q := Nat.Coprime.prod_right fun j hj => | |
| hcop hi (mem_of_mem_erase hj) (ne_of_mem_erase hj).symm | |
| exact hne ((pow_eq_one_iff_of_coprime hc).mp β¨hz i hi, hpβ©) | |
| theorem coprime_root_separation (s : Finset J) (p : J β β) (z : J β β) | |
| (hpos : β j β s, 0 < p j) | |
| (hcop : (s : Set J).Pairwise (fun i j => (p i).Coprime (p j))) | |
| (hz : β j β s, z j ^ p j = 1) (hnorm : β j β s, βz jβ = 1) | |
| (i : J) (hi : i β s) (hne : z i β 1) : | |
| 2 β€ ((β j β s, p j : β) : β) * β(β j β s, z j) - 1β := by | |
| apply root_separation | |
| Β· rw [norm_prod] | |
| exact prod_eq_one hnorm | |
| Β· exact coprime_roots_nontrivial s p z hcop hz i hi hne | |
| Β· exact prod_pos hpos | |
| Β· apply prod_roots_pow s p z hz | |
| exact fun j hj => dvd_prod_of_mem p hj | |
| end CoprimeRoots | |
| end EditFourier | |
| namespace EditFourier | |
| open scoped BigOperators | |
| open Finset | |
| lemma norm_sub_one_sq_of_norm_one (z : β) (hz : βzβ = 1) : | |
| βz - 1β ^ 2 = 2 - 2 * z.re := by | |
| have hh : z.re * z.re + z.im * z.im = 1 := by | |
| have h := congrArg (fun x : β => x ^ 2) hz | |
| rw [β Complex.normSq_eq_norm_sq, Complex.normSq_apply] at h | |
| simpa only [one_pow] using h | |
| simp only [β Complex.normSq_eq_norm_sq, Complex.normSq_apply, | |
| Complex.sub_re, Complex.one_re, Complex.sub_im, Complex.one_im, sub_zero] | |
| nlinarith | |
| lemma character_multiplier_four {R : Type*} [AddCommGroup R] [Finite R] | |
| (Ο : AddChar R β) (a : R) : βΟ a - 1β ^ 2 β€ 4 := by | |
| have hb : βΟ a - 1β β€ 2 := by | |
| calc | |
| _ β€ βΟ aβ + β(1 : β)β := norm_sub_le _ _ | |
| _ = 2 := by rw [Ο.norm_apply, norm_one]; norm_num | |
| nlinarith [norm_nonneg (Ο a - 1)] | |
| lemma average_character_multiplier {R : Type*} [CommRing R] [Fintype R] [DecidableEq R] | |
| (Ο : AddChar R β) (hΟ : Ο.IsPrimitive) (a : R) : | |
| (β x : R, βΟ (a * x) - 1β ^ 2) / (Fintype.card R : β) = | |
| if a = 0 then 0 else 2 := by | |
| by_cases ha : a = 0 | |
| Β· simp [ha] | |
| have hs : β x : R, Ο (a * x) = 0 := by | |
| simpa only [ha, ite_false, Nat.cast_zero, mul_comm] using AddChar.sum_mulShift a hΟ | |
| have hr : β x : R, (Ο (a * x)).re = 0 := by rw [β Complex.re_sum, hs]; rfl | |
| simp_rw [norm_sub_one_sq_of_norm_one _ (Ο.norm_apply _)] | |
| rw [sum_sub_distrib, β mul_sum, hr, mul_zero, sub_zero] | |
| simp only [sum_const, card_univ, nsmul_eq_mul, ha, ite_false] | |
| field_simp | |
| lemma std_character_pow (p : β) [NeZero p] (a : ZMod p) : | |
| (ZMod.stdAddChar a) ^ p = 1 := by | |
| rw [β AddChar.map_nsmul_eq_pow, nsmul_eq_mul] | |
| simp | |
| end EditFourier | |
| namespace EditFourier | |
| open scoped BigOperators | |
| open Finset | |
| section PrimeProduct | |
| variable {J : Type*} [Fintype J] [DecidableEq J] | |
| variable (p : J β β) [β j, NeZero (p j)] | |
| theorem multiplier_comparison | |
| (hcop : Pairwise (fun i j => (p i).Coprime (p j))) | |
| (B : β) (hB : 1 β€ B) (hpB : β j, (p j : β) β€ B) | |
| (h : β) (hh : 0 < h) (lam : β j, ZMod (p j)) (i : J) (u : ZMod (p i)) : | |
| βZMod.stdAddChar (lam i * u) - 1β ^ 2 β€ | |
| B ^ (2 * h) * βtorusCharacter p lam - 1β ^ 2 + | |
| (2 / (h : β)) * β j, (if lam j = 0 then (0 : β) else 2) := by | |
| have hSim : 0 β€ B ^ (2 * h) * βtorusCharacter p lam - 1β ^ 2 := by positivity | |
| have hCoord : 0 β€ (2 / (h : β)) * β j, (if lam j = 0 then (0 : β) else 2) := by | |
| apply mul_nonneg (by positivity) | |
| apply sum_nonneg | |
| intro j _ | |
| split_ifs <;> norm_num | |
| by_cases hi : lam i = 0 | |
| Β· simpa only [hi, zero_mul, AddChar.map_zero_eq_one, sub_self, norm_zero, zero_pow | |
| (by omega : 2 β 0)] using add_nonneg hSim hCoord | |
| have hleft := character_multiplier_four (ZMod.stdAddChar (N := p i)) (lam i * u) | |
| let s : Finset J := univ.filter (fun j => lam j β 0) | |
| have his : i β s := by simp [s, hi] | |
| by_cases hs : s.card < h | |
| Β· have hroot := coprime_root_separation s p (fun j => ZMod.stdAddChar (lam j)) | |
| (fun j _ => NeZero.pos (p j)) | |
| (fun _ _ _ _ hij => hcop hij) | |
| (fun j _ => std_character_pow (p j) (lam j)) | |
| (fun j _ => (ZMod.stdAddChar (N := p j)).norm_apply (lam j)) i his | |
| (by | |
| intro heq | |
| apply hi | |
| exact ZMod.injective_stdAddChar (heq.trans (AddChar.map_zero_eq_one _).symm)) | |
| have heq : (β j β s, ZMod.stdAddChar (lam j)) = torusCharacter p lam := by | |
| change (β j β s, ZMod.stdAddChar (lam j)) = β j, ZMod.stdAddChar (lam j) | |
| apply prod_subset (filter_subset _ _) | |
| intro j _ hj | |
| have hjz : lam j = 0 := by simpa [s] using hj | |
| simp [hjz] | |
| rw [heq] at hroot | |
| have hprod : ((β j β s, p j : β) : β) β€ B ^ h := by | |
| calc | |
| _ = β j β s, (p j : β) := by norm_cast | |
| _ β€ β _j β s, B := prod_le_prodβ (fun _ _ => Nat.cast_nonneg _) (fun j _ => hpB j) | |
| _ = B ^ s.card := by rw [prod_const] | |
| _ β€ B ^ h := pow_le_pow_rightβ hB hs.le | |
| have htwo : 2 β€ B ^ h * βtorusCharacter p lam - 1β := | |
| hroot.trans (mul_le_mul_of_nonneg_right hprod (norm_nonneg _)) | |
| have hfour : 4 β€ B ^ (2 * h) * βtorusCharacter p lam - 1β ^ 2 := by | |
| have hsq : 4 β€ (B ^ h * βtorusCharacter p lam - 1β) ^ 2 := by nlinarith | |
| simpa only [mul_pow, β pow_mul, Nat.mul_comm h 2] using hsq | |
| linarith | |
| Β· have hcard : (h : β) β€ s.card := by exact_mod_cast Nat.le_of_not_gt hs | |
| have hsum : (β j, (if lam j = 0 then (0 : β) else 2)) = (s.card : β) * 2 := by | |
| calc | |
| _ = β _j β s, (2 : β) := by simp only [s, sum_filter, ite_not] | |
| _ = _ := by simp | |
| rw [hsum] | |
| have hfour : 4 β€ 2 / (h : β) * ((s.card : β) * 2) := by | |
| rw [div_mul_eq_mul_div, le_div_iffβ (Nat.cast_pos.mpr hh)] | |
| linarith | |
| linarith | |
| end PrimeProduct | |
| end EditFourier | |
| end OAI | |