import OAI.Computability.FourierTransform.ToeplitzUpdates namespace OAI namespace PowerSaving.Slant open Reel Stroke Zone Spectral Finset noncomputable section def strand (a : ℕ → Reel) : ℕ → Reel | 0 => wait 0 | i+1 => (strand a i).stack (a i) lemma beat_strand {a : ℕ→Reel} (n d : ℕ) (h : ∀ i simp [strand,wait] | succ n ih => change (strand a n).beats+(a n).beats=_ rw [ih (by intro i hi; exact h i (by omega)),h n (by omega),add_mul,one_mul] lemma sound_strand {a : ℕ→Reel} (n m : ℕ) (h : ∀ i exact sound_wait 0 m | succ n ih => exact (ih (fun i hi => h i (by omega))).stack (h n (by omega)) def summary (n : ℕ) (f : ℕ → Line → Line) (x : Line) : Line := fun i => ∑ j ∈ range n, f j x i lemma reads_summary {a b : ℕ} (n : ℕ) (f : ℕ → Line→Line) (h : ∀ i sum_congr rfl fun j hj => h j (mem_range.mp hj) x y hx i hi lemma spill_strand {a : ℕ→Reel} (n : ℕ) (u v : Zone) (f : ℕ→Line→Line) (h : ∀ i constructor · intro x i hi; simp [strand,summary] · intro x i hi; simp [strand] | succ n ih => have hp := ih (fun i hi => h i (by omega)) (fun i hi => hr i (by omega)) have hh := h n (by omega) constructor · intro x i hi rw [strand,go_stack,hh.adds _ i hi, hr n (by omega) _ _ (hp.preserves hs x) i hi, hp.adds x i hi] simp [summary,sum_range_succ,add_assoc] · intro x i hi rw [strand,go_stack,hh.keeps _ i hi,hp.keeps _ i hi] /-- geometry, p = count*b. -/ def quay (b j : ℕ) : Zone := ⟨j*b,b⟩ def coast (p w : ℕ) : Zone := ⟨p,w⟩ def jetty (p w b s : ℕ) : Zone := ⟨p+s*b,min b (w-s*b)⟩ lemma quay_fits (l b j w : ℕ) (hj : j (jetty_has p w b s i hi).2 lemma body_sep (p w : ℕ) : (initial p).Sep (coast p w) := sep_of _ _ (by change 0+p ≤ p; omega) lemma quay_sep (l w b s j : ℕ) (hj : j f ((quay b j).peek x)) := by constructor · intro x i hi; rw [h.adds x i hi,quay_peek] · exact h.keeps lemma reads_quay {l b j p : ℕ} {f : Line→Line} (hj : j f ((quay b j).peek x)) := by intro x y hx apply h intro i hi apply hx exact (by simpa [initial] using quay_fits l b j 0 hj _ ((quay b j).inside hi)) -- extend a jetty effect f (given with whole target indexing) def jet_effect (p w b s : ℕ) (f : Line→Line) (x : Line) : Line := fun i => if (jetty p w b s).has (p+i) then f x i else 0 lemma spill_jet {u : Reel} {v : Zone} {p w b s : ℕ} {f : Line→Line} (h : Spill u v (jetty p w b s) (fun x i => f x (s*b+i))) : Spill u v (coast p w) (jet_effect p w b s f) := by let M := jetty p w b s constructor · intro x i hi change u.go x (p+i) = _ + if M.has (p+i) then _ else _ by_cases H : M.has (p+i) · simp only [ite_eq_left H] have hh := h.adds x (p+i-M.lo) (M.enter H) change u.go x (M.lo+(p+i-M.lo)) = x (M.lo+(p+i-M.lo))+_ at hh rw [M.identify H] at hh have hh' : s*b+(p+i-M.lo)=i := by have := M.identify H change p+s*b+(_-(p+s*b))=_ at this change s*b+(_-(p+s*b))=_ omega rw [hh'] at hh exact hh · simp only [ite_eq_right H,add_zero] exact h.keeps x (p+i) H · intro x i hi exact h.keeps x i fun H => hi (jetty_has _ _ _ _ i H) lemma reads_jet {p w b s n : ℕ} {f : Line→Line} (h : Reads n w f) : Reads n w (jet_effect p w b s f) := by intro x y H i hi simp only [jet_effect,h x y H i hi] lemma sum_mult (f : ℕ→ℂ) (l b : ℕ) : ∑ j ∈ range (l*b), f j = ∑ j ∈ range l, ∑ k ∈ range b, f (j*b+k) := by induction l with | zero => simp | succ l ih => rw [add_mul,one_mul,sum_range_add,ih,sum_range_succ] lemma summary_jet (l p w b : ℕ) (hb : 0 jet_effect p w b s f) x i = f x i := by intro x i hi let j := i/b have hl : j stencil p h (stencil p g x) (p+i) lemma wave_reads (p b s c j v : ℕ) (h g : Line) : Reads b v (wave p b s c j h g) := (reads_spout b (j*b) (c*b) b g).chain (reads_spout b (c*b) (p+s*b) v h) lemma surf_reads (p w : ℕ) (h g : Line) : Reads p w (surf p h g) := by intro x y hx i hi unfold surf; rw [stencil_congr _ g hx] lemma wave_sum (l b s : ℕ) (h g x : Line) (i : ℕ) : (∑ c ∈ range l, ∑ j ∈ range l, wave (l*b) b s c j h g ((quay b j).peek x) i) = surf (l*b) h g x (s*b+i) := by simp only [wave, surf, Function.comp_apply, spout,stencil] -- expand RHS over corresponding chunks rw [sum_mult _ l b] have hp (k : ℕ) : ∑ j ∈ range (l*b), rise g k j*x j = ∑ j ∈ range l, ∑ a ∈ range b, rise g k (j*b+a) * x (j*b+a) := sum_mult .. simp only [hp,mul_sum] refine sum_congr rfl ?_ intro c hc rw [sum_comm] simp only [add_assoc,quay,Zone.peek,drift] def riprap (a : ℕ → ℕ → ℕ → Reel) (l : ℕ) : Reel := strand (fun s => strand (fun c => strand (fun j => a s c j) l) l) l lemma beats_riprap (a : ℕ → ℕ → ℕ → Reel) (l n : ℕ) (h : ∀ s beat_strand _ _ fun c hc => beat_strand _ _ (h s hs c hc) lemma sound_riprap (a : ℕ → ℕ → ℕ → Reel) (l n : ℕ) (h : ∀ s sound_strand _ _ fun c hc => sound_strand _ _ (h s hs c hc) lemma spill_riprap (a : ℕ → ℕ → ℕ → Reel) (l b w : ℕ) (h g : Line) (hb : 0 strand (fun j => a s c j) l) l let T s c j (x : Line) := wave p b s c j h g ((quay b j).peek x) have hu (s : ℕ) (hs : s f x (s*b+i)) := by have hS : (initial p).Sep (W s) := fun i hi hg => body_sep p w _ hi (jetty_has _ _ _ _ i hg) have ht (c j : ℕ) (hj : j strand (fun j => a s c j) l) l (initial p) (W s) (fun c => summary l (T s c)) (fun c hc => spill_strand l _ _ (T s c) (fun j hj => spill_quay (H s hs c hc j hj)) hS (ht c)) hS (fun c _ => reads_summary l (T s c) (ht c)) exact G.congr (fun x i _ => wave_sum l b s h g x i) have hh := spill_strand l (initial p) (coast p w) (fun s => jet_effect p w b s f) (a:=q) (fun s hs => spill_jet (hu s hs)) (body_sep p w) (fun _ _ => reads_jet (surf_reads p w h g)) exact hh.congr (summary_jet l p w b hb hw f) end end PowerSaving.Slant end OAI