import Mathlib import OAI.Computability.DeterministicSum.Structured namespace OAI /-! Signed word encoding, no-wrap bounds and modular arithmetic commands. -/ namespace DeterministicThreeSum lemma wordModulus_pos (w : ℕ) : 0 .skip | a::as => .seq (.atom a) (straight as) def execStraight (w : ℕ) : List Atom → Data → Option Data | [],s => some s | a::as,s => (a.eval w s).bind (execStraight w as) lemma straight_correct {w : ℕ} {as : List Atom} {s t : Data} (he : execStraight w as s=some t) : Eval w (straight as) s as.length t := by induction as generalizing s with | nil => simp only [execStraight,Option.some.injEq] at he; subst t; exact Eval.skip s | cons a as ih => obtain ⟨u,ha,hu⟩ := Option.bind_eq_some_iff.mp he simpa only [straight,List.length_cons,Nat.add_comm] using Eval.seq (Eval.atom ha) (ih hu) lemma straight_writes (as : List Atom) : (straight as).writes=as.foldr (fun a S => a.writes∪S) ∅ := by induction as with | nil => rfl | cons a as ih => simp only [straight,Command.writes,List.foldr_cons,ih] lemma eval_add {w r a b : ℕ} (s : Data) (_ha : a