Item-language compiler correctness with cost preservation
ProvedNLogN.compile_correctLet iprog be an item-language program with procedures over item stacks, and let prog be a stack-machine program over stacks whose procedures are the compilations of those of iprog ( for all ). Suppose the item statement executes (big-step semantics IExec, with input word ) from item state to with cost . Then
- the compiled statement runs on the encoded states within the same cost:
- if moreover , then and the inner loop of its compilation runs from (the encoding of with the loop flag for the test on stack pushed on the scratch stack ) to with a flag pushed on , within cost .
Part 2 is the strengthened induction hypothesis needed for loops. The item-level costs (e.g. for a conditional, per loop test) are chosen to dominate the compiled code, so all cost bounds proved in the item language transfer verbatim to the stack machine and hence, via multipliesAt_of_exec, to the Turing machine.
Formalization Note. Item states IState S have item stacks G, input pointer ip and output out; encI s writes each item stack as the concatenation of item encodings on stack and leaves the four extra scratch stacks ( = indices ) empty. Runs asserts an exact final state and an upper bound on the cost; IExec carries the exact item-level cost.
-- Schönhage–Strassen multitape-TM development (NLogN), generated by skeleton subtraction.
import Definitions.Def_IntMul_SS_Defs2
set_option autoImplicit false
set_option relaxedAutoImplicit false
set_option maxHeartbeats 1000000
open NLogN
open IntMul
variable {S P : ℕ}
variable {I : List Sym} {prog : Fin P → Stmt (S + 4) P}
theorem NLogN.compile_correct {iprog : Fin P → IStmt S P} (hprog : ∀ j, prog j = compile (iprog j))
{p : IStmt S P} {s s' : IState S} {c : ℕ} (h : IExec I iprog p s s' c) :
Runs I prog (compile p) (encI s) (encI s') c ∧
∀ i f b, p = .loop i f b →
Runs I prog (inner i f b) (encF i f s) ((encI s').push (s3 S) 0) (c - 24) ∧ 24 ≤ c := by sorry