RAM fragment for halving with remainder
ProvedWilliamsonShmoys.ram_halve_fragmentprogram-logicram-model
Let a program contain, at position , the 5-instruction loop that sets cell 9 to and then, while cell 10 cell 8, subtracts cell 10 from cell 8 and adds cell 11 to cell 9. Started at with in cell 8, in cell 10 and in cell 11, after exactly operations the program counter is and
with all other cells unchanged. The instruction set has no division, so this is the basic decoding step for numbers built by repeated doubling.
Formalization Note. Code placement is CodeAt from Def_WilliamsonShmoys_RAMExec.
Preamble
import Mathlib import Definitions.Def_WilliamsonShmoys_RAMExec set_option autoImplicit false open WilliamsonShmoys PlanarRAMInstruction
Formal statement
theorem WilliamsonShmoys.ram_halve_fragment (p : List PlanarRAMInstruction) (base : ℕ)
(hcode : CodeAt p base
[natConst 9 0, natBranch 10 8 (base + 2) (base + 5), natSub 8 8 10, natAdd 9 9 11, jump (base + 1)]) (s : PlanarRAMState) (hpc : s.pc = base) (h10 : s.natMem 10 = 2)
(h11 : s.natMem 11 = 1) :
let x := s.natMem 8
let s' := planarRAMRun p s (4 * (x / 2) + 2)
s'.pc = base + 5 ∧ s'.natMem 8 = x % 2 ∧ s'.natMem 9 = x / 2 ∧
(∀ a, a ≠ 8 → a ≠ 9 → s'.natMem a = s.natMem a) ∧ s'.realMem = s.realMem := by sorrySource
RAM implementation of Williamson–Shmoys, The Design of Approximation Algorithms, Theorem 10.11 (mission formalization)