Download data/lean/OAI/Computability/FourierTransform/ChirpConvolution.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.27 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FourierTransform/ChirpConvolution.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/FourierTransform/ChirpConvolution.lean
-
curl -L -o ChirpConvolution.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/FourierTransform/ChirpConvolution.lean
6.27 kB
| import OAI.Computability.FourierTransform.FourierIdentities | |
| namespace OAI | |
| /- Positive/negative chirps and consequence for linear convolution. -/ | |
| namespace PowerSaving | |
| open Finset Complex Matrix | |
| noncomputable section | |
| namespace Spectral | |
| -- ret true for inverse signs | |
| def pr : Boolββββ | |
| | false => root | |
| | true => fun n => (root n)β»ΒΉ | |
| lemma primitive_pr (n : β) (hn : 0<n) (r : Bool) : | |
| IsPrimitiveRoot (pr r n) n := by | |
| cases r | |
| Β· exact root_primitive n hn | |
| Β· exact (root_primitive n hn).inv | |
| lemma twice_pr (n : β) (hn : 0<n) (r : Bool) : | |
| (pr r (2*n))^2 = pr r n := by | |
| cases r with | |
| | false => exact root_mul_pow 2 n (by norm_num) hn | |
| | true => simp [pr,inv_pow,root_mul_pow 2 n (by norm_num) hn] | |
| lemma cyc_formula {u : β} {n : β} (hu : IsPrimitiveRoot u n) (x h : Line) {i} (hi : i<n) : | |
| (n:β)β»ΒΉ * freq n uβ»ΒΉ (fun j => freq n u h j * freq n u x j) i = | |
| cyclic n h x i := by | |
| simp_rw [β freq_cyclic hu.pow_eq_one] | |
| exact freq_inv hu (cyclic n h x) i hi | |
| lemma range_pad (n N : β) (h : n β€ N) (x : Line) : | |
| β i β range N, (if i < n then x i else 0) = β i β range n,x i := by | |
| induction N, h using Nat.le_induction with | |
| | base => | |
| exact sum_congr rfl fun i hi => ite_eq_left (mem_range.mp hi) | |
| | succ m hm ih => rw [sum_range_succ,ih,ite_eq_right (not_lt.mpr hm),add_zero] | |
| def epschirp (z : β) : Line := fun i => z ^ (i*i) | |
| lemma eps_eq_sq (z : β) (h : zβ 0) (i j k : β) | |
| (hk : i=j+k β¨ j=i+k) : | |
| epschirp z i * (epschirp z k)β»ΒΉ * epschirp z j = (z^2)^(i*j) := by | |
| have hh : i*i+j*j=2*(i*j)+k*k := by rcases hk with rfl|rfl <;> ring | |
| unfold epschirp | |
| rw [show z^(i*i) * (z^(k*k))β»ΒΉ * z^(j*j)=z^(i*i+j*j)*(z^(k*k))β»ΒΉ by | |
| rw [pow_add]; ring, hh,pow_add,mul_assoc,mul_inv_cancelβ (pow_ne_zero _ h),mul_one, | |
| pow_mul] | |
| def chirp_seed (n : β) (z : β) (x : Line) : Line := | |
| fun i => if i<n then epschirp z i * x i else 0 | |
| def legdist (n N : β) (i : β) := if i < n then i else N-i | |
| def fall (n N : β) (z : β) : Line := | |
| fun i => (epschirp z (legdist n N i))β»ΒΉ | |
| lemma chirp (z : β) (h : zβ 0) (x : Line) {n N : β} (hn : 2*nβ€N) (i : β) (hi : i<n) : | |
| epschirp z i * (cyclic N (fall n N z) (chirp_seed n z x) i) = | |
| freq n (z^2) x i := by | |
| have hh (j : β) (hj : j<n) : | |
| epschirp z i * (fall n N z (predAt N i j) * (epschirp z j * x j)) = | |
| (z^2)^(i*j)*x j := by | |
| unfold fall; rw [β mul_assoc,β mul_assoc] | |
| rw [eps_eq_sq z h i j _ ?_] | |
| unfold legdist predAt; split_ifs <;> omega | |
| simp only [cyclic,chirp_seed,mul_sum,mul_ite,mul_zero,freq] | |
| rw [range_pad n N (by omega)] | |
| exact sum_congr rfl fun j hj => hh j (mem_range.mp hj) | |
| def pointC (n : β) (u : β) (h x : Line) : Line := | |
| fun i => freq n u h i * freq n u x i | |
| def fetchC (n : β) (u : β) (h x : Line) : Line := | |
| freq n uβ»ΒΉ (pointC n u h x) | |
| lemma chirps (n N : β) (hn : 0<n) (hh : 2*n β€ N) (ret : Bool) (x : Line) | |
| (i : β) (hi : i<n) : | |
| let z := pr ret (2*n) | |
| epschirp z i * ((N:β)β»ΒΉ * fetchC N (pr false N) (fall n N z) (chirp_seed n z x) i) | |
| = freq n (pr ret n) x i := by | |
| have hk := primitive_pr N (by omega) false | |
| have ht := (primitive_pr (2*n) (by omega) ret).ne_zero (by omega) | |
| dsimp only [fetchC,pointC] | |
| unfold pointC | |
| rw [cyc_formula hk _ _ (by omega),chirp _ ht _ hh _ hi,twice_pr _ hn ret] | |
| def padline (n : β) (x : Line) : Line := fun i => if i<n then x i else 0 | |
| lemma conv_pad_row (n : β) (x y : Line) {i : β} (hi : i < 2*n-1) (r : β) (hr : r<n) : | |
| padline n y (predAt (2*n-1) i r) * x r = | |
| β j β range n, if r+j=i then x r*y j else 0 := by | |
| unfold padline predAt | |
| by_cases h : r β€ i β§ i-r<n | |
| Β· obtain β¨h,gβ© := h | |
| rw [ite_eq_left h,ite_eq_left g] | |
| rw [sum_eq_single (i-r)] | |
| Β· rw [ite_eq_left (by omega),mul_comm] | |
| Β· intro b _ h; rw [ite_eq_right (by omega)] | |
| Β· intro k; have := k (mem_range.mpr g); contradiction | |
| Β· have hh (j : β) (hj : j β range n) : r+jβ i := by have := mem_range.mp hj; omega | |
| rw [sum_eq_zero (fun j hj => ite_eq_right (hh j hj))] | |
| split_ifs <;> first | rw [zero_mul] | omega | |
| lemma cyclic_pad (n : β) (x y : Line) (i : β) (hi : i < 2*n-1) : | |
| cyclic (2*n-1) (padline n y) (padline n x) i = | |
| β r β range n, β j β range n, if r+j=i then x r*y j else 0 := by | |
| unfold cyclic padline | |
| simp_rw [mul_ite,mul_zero] | |
| rw [range_pad n (2*n-1) (by omega)] | |
| exact sum_congr rfl fun j hj => conv_pad_row n x y hi j (mem_range.mp hj) | |
| lemma cyclic_pad_front (n : β) (x y : Line) : | |
| front (2*n-1) (cyclic (2*n-1) (padline n y) (padline n x)) = | |
| conv n (front n x) (front n y) := by | |
| funext i | |
| simp only [front,cyclic_pad n x y _ i.isLt,conv] | |
| have hh (r : β) : β j : Fin n,(if r+j.val=i.val then x r*y j.val else 0) = | |
| β j β range n, if r+j=i.val then x r*y j else 0 := | |
| Fin.sum_univ_eq_sum_range (fun j => if r+j=i.val then x r*y j else 0) n | |
| simp_rw [hh] | |
| exact (Fin.sum_univ_eq_sum_range (fun r => β j β range n, if r+j=i.val then x r*y j else 0) n).symm | |
| lemma freq_pad_row (n : β) (x y : Line) (i : β) (hi : i < 2*n-1) : | |
| let N := 2*n-1 | |
| (N:β)β»ΒΉ*freq N (pr true N) | |
| (pointC N (pr false N) (padline n x) (padline n y)) i | |
| = cyclic N (padline n y) (padline n x) i := by | |
| let N := 2*n-1 | |
| have H := cyc_formula (primitive_pr N (by dsimp [N]; omega) false) | |
| (padline n x) (padline n y) hi | |
| have h (j : β) : pointC N (pr false N) (padline n x) (padline n y) j = | |
| freq N (pr false N) (padline n y) j * freq N (pr false N) (padline n x) j := | |
| mul_comm _ _ | |
| change (N:β)β»ΒΉ* freq N (pr false N)β»ΒΉ (pointC _ _ _ _) i = _ | |
| rw [show pointC N (pr false N) (padline n x) (padline n y) = | |
| (fun j => freq N (pr false N) (padline n y) j * freq N (pr false N) (padline n x) j) from | |
| funext h]; exact H | |
| lemma dft_front (n : β) (x : Line) : | |
| dft n (front n x) = front n (freq n (pr false n) x) := | |
| funext fun i => Fin.sum_univ_eq_sum_range (fun j => (root n)^(i.val*j)*x j) n | |
| def extendLine {n : β} (x : Vec n) : Line := fun i => if h : i<n then x β¨i,hβ© else 0 | |
| lemma front_exact {n : β} (x : Vec n) : front n (extendLine x) = x := by | |
| funext i; simp [front,extendLine,i.isLt] | |
| end Spectral | |
| end | |
| end PowerSaving | |
| end OAI | |