Download data/lean/OAI/Combinatorics/EditDistance/FourierCharacters.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.66 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/FourierCharacters.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditDistance/FourierCharacters.lean
-
curl -L -o FourierCharacters.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/FourierCharacters.lean
7.66 kB
| import Mathlib | |
| namespace OAI | |
| /-! | |
| # Finite Fourier inversion, Parseval, and character displacement | |
| -/ | |
| namespace EditFourier | |
| open scoped BigOperators | |
| open Finset | |
| section FiniteRing | |
| variable {R : Type*} [CommRing R] [Fintype R] [DecidableEq R] | |
| noncomputable def transform (Ο : AddChar R β) (F : R β β) (k : R) : β := | |
| β t : R, Ο (-(t * k)) * F t | |
| theorem transform_twice (Ο : AddChar R β) (hΟ : Ο.IsPrimitive) (F : R β β) : | |
| transform Ο (transform Ο F) = fun j => (Fintype.card R : β) * F (-j) := by | |
| funext j | |
| simp only [transform, mul_sum, β mul_assoc, β AddChar.map_add_eq_mul, β neg_add, | |
| mul_comm _ j, β add_mul] | |
| rw [sum_comm] | |
| simp only [β sum_mul, β neg_mul] | |
| have h1 (t : R) : β i, Ο (t * i) = if t = 0 then (Fintype.card R : β) else 0 := by | |
| simpa only [mul_comm, Nat.cast_ite, Nat.cast_zero] using AddChar.sum_mulShift t hΟ | |
| have h2 (x j : R) : -(j + x) = 0 β x = -j := by | |
| rw [neg_add, add_comm, add_eq_zero_iff_neg_eq, neg_neg] | |
| simp only [h1, h2, ite_mul, zero_mul, sum_ite_eq', mem_univ, ite_true] | |
| omit [DecidableEq R] in | |
| theorem transform_sub (Ο : AddChar R β) (F G : R β β) : | |
| transform Ο (F - G) = transform Ο F - transform Ο G := by | |
| funext k | |
| simp only [transform, Pi.sub_apply, mul_sub, sum_sub_distrib] | |
| omit [DecidableEq R] in | |
| theorem transform_shift (Ο : AddChar R β) (F : R β β) (l k : R) : | |
| transform Ο (fun t => F (t + l)) k = Ο (l * k) * transform Ο F k := by | |
| classical | |
| calc | |
| _ = β t : R, Ο (-((t - l) * k)) * F t := by | |
| apply Fintype.sum_equiv (Equiv.addRight l) | |
| intro t | |
| simp | |
| _ = Ο (l * k) * transform Ο F k := by | |
| rw [transform, mul_sum] | |
| apply sum_congr rfl | |
| intro t _ | |
| rw [sub_mul, neg_sub, sub_eq_add_neg, AddChar.map_add_eq_mul] | |
| ring | |
| omit [DecidableEq R] in | |
| theorem transform_pairing (Ο : AddChar R β) (F G : R β β) : | |
| β k, transform Ο F k * G k = β t, F t * transform Ο G t := by | |
| simp only [transform, sum_mul, mul_sum] | |
| rw [sum_comm] | |
| apply sum_congr rfl | |
| intro t _ | |
| apply sum_congr rfl | |
| intro k _ | |
| rw [mul_comm k t] | |
| ring | |
| omit [DecidableEq R] in | |
| theorem transform_conj (Ο : AddChar R β) (F : R β β) (k : R) : | |
| transform Ο (fun t => (starRingEnd β) (F t)) k = | |
| (starRingEnd β) (transform Ο F (-k)) := by | |
| simp only [transform, map_sum, map_mul] | |
| apply sum_congr rfl | |
| intro t _ | |
| rw [β AddChar.map_neg_eq_conj] | |
| congr 2 | |
| ring | |
| theorem parseval (Ο : AddChar R β) (hΟ : Ο.IsPrimitive) (F : R β β) : | |
| β k, βtransform Ο F kβ ^ 2 = (Fintype.card R : β) * β t, βF tβ ^ 2 := by | |
| simp only [β Complex.normSq_eq_norm_sq] | |
| apply Complex.ofReal_injective | |
| push_cast | |
| simp only [β Complex.mul_conj] | |
| rw [transform_pairing] | |
| simp only [transform_conj, transform_twice Ο hΟ F, neg_neg, map_mul, | |
| map_natCast, Finset.mul_sum] | |
| apply sum_congr rfl | |
| intro t _ | |
| ring | |
| theorem displacement (Ο : AddChar R β) (hΟ : Ο.IsPrimitive) (F : R β β) (l : R) : | |
| (Fintype.card R : β) * β t, βF (t + l) - F tβ ^ 2 = | |
| β k, βtransform Ο F kβ ^ 2 * βΟ (l * k) - 1β ^ 2 := by | |
| rw [β parseval Ο hΟ (fun t => F (t + l) - F t)] | |
| have ht : transform Ο (fun t => F (t + l) - F t) = | |
| fun k => (Ο (l * k) - 1) * transform Ο F k := by | |
| rw [show (fun t => F (t + l) - F t) = (fun t => F (t + l)) - F from rfl, | |
| transform_sub] | |
| funext k | |
| simp only [Pi.sub_apply, transform_shift] | |
| ring | |
| rw [ht] | |
| apply sum_congr rfl | |
| intro k _ | |
| rw [norm_mul, mul_pow, mul_comm] | |
| noncomputable def fourier (Ο : AddChar R β) (F : R β β) (k : R) : β := | |
| transform Ο F k / (Fintype.card R : β) | |
| theorem displacement_normalized (Ο : AddChar R β) (hΟ : Ο.IsPrimitive) | |
| (F : R β β) (l : R) : | |
| (β t, βF (t + l) - F tβ ^ 2) / (Fintype.card R : β) = | |
| β k, βfourier Ο F kβ ^ 2 * βΟ (l * k) - 1β ^ 2 := by | |
| have hn : (Fintype.card R : β) β 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero | |
| simp only [fourier, norm_div, Complex.norm_natCast, div_pow, div_mul_eq_mul_div, | |
| β sum_div] | |
| apply (eq_div_iff (pow_ne_zero 2 hn)).mpr | |
| rw [β displacement Ο hΟ F l] | |
| field_simp | |
| end FiniteRing | |
| section ProductCharacter | |
| variable {J : Type*} [Fintype J] [DecidableEq J] | |
| variable {A : J β Type*} [β j, CommRing (A j)] | |
| noncomputable def productCharacter (Ο : β j, AddChar (A j) β) : | |
| AddChar (β j, A j) β where | |
| toFun x := β j, Ο j (x j) | |
| map_zero_eq_one' := by simp | |
| map_add_eq_mul' x y := by simp [AddChar.map_add_eq_mul, prod_mul_distrib] | |
| theorem productCharacter_single (Ο : β j, AddChar (A j) β) | |
| (a : β j, A j) (j : J) (x : A j) : | |
| (productCharacter Ο) (a * Pi.single j x) = Ο j (a j * x) := by | |
| change β i, Ο i (a i * Pi.single j x i) = _ | |
| rw [prod_eq_single j] | |
| Β· simp | |
| Β· intro i _ hi | |
| simp [Pi.single_eq_of_ne hi] | |
| Β· simp | |
| theorem productCharacter_primitive (Ο : β j, AddChar (A j) β) | |
| (hΟ : β j, (Ο j).IsPrimitive) : (productCharacter Ο).IsPrimitive := by | |
| intro a ha h | |
| apply ha | |
| funext j | |
| by_contra hj | |
| apply hΟ j hj | |
| ext x | |
| have hx := DFunLike.congr_fun h (Pi.single j x) | |
| simpa only [AddChar.mulShift_apply, productCharacter_single, AddChar.one_apply] using hx | |
| noncomputable def torusCharacter (p : J β β) [β j, NeZero (p j)] : | |
| AddChar (β j, ZMod (p j)) β := | |
| productCharacter (fun j => ZMod.stdAddChar (N := p j)) | |
| theorem torusCharacter_primitive (p : J β β) [β j, NeZero (p j)] : | |
| (torusCharacter p).IsPrimitive := | |
| productCharacter_primitive _ (fun j => ZMod.isPrimitive_stdAddChar (p j)) | |
| end ProductCharacter | |
| end EditFourier | |
| namespace EditFourier | |
| open scoped BigOperators | |
| open Finset | |
| theorem norm_pow_sub_one_le (z : β) (hz : βzβ = 1) (n : β) : | |
| βz ^ n - 1β β€ (n : β) * βz - 1β := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => | |
| calc | |
| βz ^ (n + 1) - 1β = βz * (z ^ n - 1) + (z - 1)β := by | |
| congr 1 | |
| rw [pow_succ'] | |
| ring | |
| _ β€ βz * (z ^ n - 1)β + βz - 1β := norm_add_le _ _ | |
| _ = βz ^ n - 1β + βz - 1β := by rw [norm_mul, hz, one_mul] | |
| _ β€ (n : β) * βz - 1β + βz - 1β := add_le_add ih le_rfl | |
| _ = ((n + 1 : β) : β) * βz - 1β := by push_cast; ring | |
| theorem root_separation (z : β) (hz : βzβ = 1) (hne : z β 1) | |
| (q : β) (hq : 0 < q) (hpow : z ^ q = 1) : | |
| 2 β€ (q : β) * βz - 1β := by | |
| have hs : β i β range q, z ^ i = 0 := by | |
| apply eq_zero_of_ne_zero_of_mul_left_eq_zero (sub_ne_zero.mpr hne.symm) | |
| rw [mul_neg_geom_sum, hpow, sub_self] | |
| have heq : (q : β) = ββ i β range q, (1 - z ^ i)β := by | |
| simp [sum_sub_distrib, hs] | |
| have hbound : (q : β) β€ (β i β range q, (i : β)) * βz - 1β := by | |
| rw [heq] | |
| calc | |
| _ β€ β i β range q, β1 - z ^ iβ := norm_sum_le _ _ | |
| _ β€ β i β range q, (i : β) * βz - 1β := by | |
| apply sum_le_sum | |
| intro i _ | |
| rw [norm_sub_rev] | |
| exact norm_pow_sub_one_le z hz i | |
| _ = _ := by rw [sum_mul] | |
| have hid : (β i β range q, (i : β)) * 2 = (q : β) * ((q : β) - 1) := by | |
| have ht := congrArg (fun a : β => (a : β)) (sum_range_id_mul_two q) | |
| push_cast [Nat.cast_sub (Nat.succ_le_of_lt hq)] at ht | |
| exact ht | |
| have hnn := norm_nonneg (z - 1) | |
| have hm := congrArg (fun x : β => x * βz - 1β) hid | |
| have hp : (0 : β) < q := Nat.cast_pos.mpr hq | |
| have hh : (q : β) * 2 β€ (q : β) * ((q : β) * βz - 1β) := by | |
| nlinarith | |
| exact (mul_le_mul_iff_rightβ hp).mp hh | |
| end EditFourier | |
| end OAI | |