Simulation theorem for sandboxed RAM subprogram calls
ProvedWilliamsonShmoys.sandbox_simulationLet be a RAM subprogram and let a host program contain its sandboxed translation at offset (SandboxedAt p q base o T O exit), with scratch cell and offset cell satisfying and .
Suppose , run from a state , sits at a halt instruction after operations. Let be a host state whose cells mirror the cells of , whose cell holds , and whose program counter is . Then there is such that the host state satisfies:
- ;
- the cells of mirror the final state of the subprogram;
- every host cell is unchanged, except the scratch cell among the natural cells.
This is the subroutine-call theorem: an arbitrary RAM program can be run inside a host program, with at most a factor- (plus one) slowdown, without touching the host's working memory below . In the mission it allows the Baker shifting program to call the exact tree-width solver times while keeping its own data.
Formalization Note. The memory correspondence is SandboxRel o O; cells not of the form with are exactly the cells below .
import Mathlib import Definitions.Def_WilliamsonShmoys_RAMSandbox set_option autoImplicit false open WilliamsonShmoys
theorem WilliamsonShmoys.sandbox_simulation (p q : List PlanarRAMInstruction) (base o T O exit : ℕ)
(hT : T < o) (hO : O < o) (hTO : T ≠ O)
(hp : SandboxedAt p q base o T O exit) :
∀ (t : ℕ) (s s' : PlanarRAMState),
q[(planarRAMRun q s t).pc]? = some PlanarRAMInstruction.halt →
SandboxRel o O s s' → s'.pc = base + 2 * s.pc →
∃ τ, τ ≤ 2 * t + 1 ∧
(planarRAMRun p s' τ).pc = exit ∧
SandboxRel o O (planarRAMRun q s t) (planarRAMRun p s' τ) ∧
(∀ a, a < o → a ≠ T → (planarRAMRun p s' τ).natMem a = s'.natMem a) ∧
(∀ a, a < o → (planarRAMRun p s' τ).realMem a = s'.realMem a) := by sorry