import Mathlib import OAI.Computability.DeterministicSum.MatrixUp namespace OAI /-! Charged scalar leaves and exact source bilinear product assembly. -/ namespace DeterministicThreeSum.Structured.MatrixLeaves open Command def body : Command := straight [ .binary 6 .add (.register 0) (.register 3), .load 7 (.register 6), .binary 6 .add (.register 1) (.register 3), .load 8 (.register 6), .binary 7 .mul (.register 7) (.register 8), .binary 7 .rem (.register 7) (.register 5), .binary 6 .add (.register 2) (.register 3), .store (.register 6) (.register 7)] theorem body_correct {w T A B P n i : ℕ} (s : Data) (x y : ℕ → ℕ) (hi : i(x i*y i)%T) n := by let s0:=put s 3 0 have e0 : Eval w (.atom (.assign 3 (.literal 0))) s 1 s0 := by simpa [operand_literal] using eval_assign (w:=w) s 3 (.literal 0) obtain ⟨cost,t,he,hc,hr,hi,ht⟩ := indexedLoop_correct (w:=w) (n:=n) (index:=3) (bound:=4) (base:=P) (K:=8) (by omega) (by decide) body s s0 (fun i=>(x i*y i)%T) (fun r=>r≤2 ∨ r=4 ∨ r=5 ∨ 9≤r) (by omega) (by omega) (by simpa [s0,put] using h4) (by simp [s0,put]) rfl (by intro i u h_i hu hindex hmem have hmx : u.memory (A+i)=some (x i) := by rw [hmem,written_outside (by omega : A+i

hv r (by omega),hvm⟩) refine ⟨1+cost,t,Eval.seq e0 he,by omega,?_,ht⟩ intro r h rw [hr r h] simp only [s0,put,Function.update_of_ne (by omega : r≠3)] lemma value_modular (T a b : ℕ) : (((a*b)%T:ℕ):ZMod T)=(a:ZMod T)*(b:ZMod T) := by simp end DeterministicThreeSum.Structured.MatrixLeaves namespace DeterministicThreeSum.Structured.Indexed.MatrixUp open Command DeterministicThreeSum.Rectangular Axis MatrixLayout MatrixDown noncomputable section lemma value_succ_last (T Q k r : ℕ) (co : ℕ → ℕ) (d B : ℕ) (x : ℕ → ℕ) : value T Q k r co (d+1) B x = mapValue T r (k*Q) (B*Q^d) (value T Q k r co d B x) co := by induction d generalizing B x with | zero => simp [value] | succ d ih => change value T Q k r co (d+1) (B*Q) (mapValue T r (k*Q) B x co) = mapValue T r (k*Q) (B*Q^(d+1)) (value T Q k r co d (B*Q) (mapValue T r (k*Q) B x co)) co rw [ih] congr 1 rw [pow_succ] ring theorem value_multiplyBatch {T a b k r d t : ℕ} (ha : 0 have hu : u=0 := Subsingleton.elim _ _ have hv : v=0 := Subsingleton.elim _ _ subst u; subst v simpa only [value,multiplyBatch,leftLeaves,rightLeaves,pairCode,pow_zero, Nat.mul_one,Nat.add_zero] using hdata e | succ d ih => rw [value_succ_last] simp only [Nat.one_mul] apply combine_level_value ha hk f (multiplyBatch f hk d (batchCount t k*r) (childLeft f x) (childRight f y)) (value T (a*a) k r co d 1 data) co _ hc e u v intro z u' v' exact ih (childLeft f x) (childRight f y) (by intro z' exact hdata z') z u' v' theorem value_product {T a b k r d t : ℕ} (ha : 0