math / data /lean /OAI /Combinatorics /EditDistance /FourierCharacters.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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