Compiled arithmetic expressions evaluate correctly
ProvedNLogN.Ex.code_runsFor every arithmetic expression over the 64 registers (built from register tops, literals, , negation, selection on sign, multiplication, shifts, floor division, …) that does not mention the eight scratch stacks (e.Clean) and is defined in state (e.ok s), the compiled code e.code zX runs from to the state obtained by pushing the value e.eval s on stack , within cost e.cost s.
Formalization Note. IRuns I iprog p s s' c is the item-language big-step semantics with cost bound ; zX is the record of scratch stacks used by the expression compiler. The machine layer: IState HS is a state with stacks of items (Item = integer or mark), an input position and an output; RM programs (straight-line register code RS, loops rep, conditionals, calls of the multiplication procedure through a MulSpec giving its domain and cost) have a functional semantics p.run s, a definedness predicate p.ok M s and a cost p.cost M s; Spec M p s s' c abbreviates p.ok M s ∧ p.run s = s' ∧ p.cost M s ≤ c. ints L / gints U push an integer list / a list of pairs as items (head = top); zsz z is the bit length of . MulBnd M m Φ says the multiplication procedure accepts all pairs of integers of bit length at cost . Register names (GU, CR, KB, XN, …) are fixed stack indices.
-- Harvey–van der Hoeven multitape-TM development (NLogN), generated by skeleton subtraction.
import Definitions.Def_IntMul_HvdH_M_Defs4
set_option autoImplicit false
set_option relaxedAutoImplicit false
set_option maxHeartbeats 1000000
set_option linter.unusedSimpArgs false
open NLogN
open IntMul
variable {P : ℕ} {I : List Sym} {iprog : Fin P → IStmt HS P}
open NLogN.Ex
theorem NLogN.Ex.code_runs : ∀ (e : Ex HS) (s : IState HS), e.Clean → e.ok s →
IRuns I iprog (e.code zX) s (s.upd 56 (.int (e.eval s) :: s.G 56)) (e.cost s) := by sorry