Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

RAM fragment for halving with remainder

Proved
WilliamsonShmoys.ram_halve_fragment

by もち · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

program-logicram-model

Let a program ppp contain, at position base\mathrm{base}base, the 5-instruction loop that sets cell 9 to 000 and then, while cell 10 ≤\le≤ cell 8, subtracts cell 10 from cell 8 and adds cell 11 to cell 9. Started at base\mathrm{base}base with xxx in cell 8, 222 in cell 10 and 111 in cell 11, after exactly 4⌊x/2⌋+24\lfloor x/2\rfloor+24⌊x/2⌋+2 operations the program counter is base+5\mathrm{base}+5base+5 and

cell 8=x mod 2,cell 9=⌊x/2⌋,\text{cell }8=x\bmod 2,\qquad \text{cell }9=\lfloor x/2\rfloor,cell 8=xmod2,cell 9=⌊x/2⌋,

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 sorry
Source
RAM implementation of Williamson–Shmoys, The Design of Approximation Algorithms, Theorem 10.11 (mission formalization)

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me