Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Instruction semantics and code placement for the planar RAM

Definition
WilliamsonShmoys_RAMExec

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

program-logicram-model

Explicit single-instruction semantics and code placement for the unit-cost RAM of this mission.

execInstr ins s is the state obtained by executing instruction ins on state sss. It does exactly what planarRAMStep does once it has looked up ins at the program counter: arithmetic and memory instructions update one cell and advance the counter by 111, branches and jumps set the counter, and halt leaves the state unchanged.

CodeAt p base code says that the list code occupies positions base,base+1,…\mathrm{base},\mathrm{base}+1,\dotsbase,base+1,… of the program ppp. Code fragments can then be specified and verified in isolation and placed anywhere in a larger program.

Definition code
import Definitions.Def_WilliamsonShmoys_PlanarIndependentSetRAM

set_option autoImplicit false

namespace WilliamsonShmoys

open PlanarRAMInstruction

/-- The effect of one instruction on a state, exactly as in `planarRAMStep`
(the step function looks up the instruction at the program counter and applies this). -/
noncomputable def execInstr : PlanarRAMInstruction → PlanarRAMState → PlanarRAMState
  | natConst dst value, s => { s with pc := s.pc + 1, natMem := Function.update s.natMem dst value }
  | natAdd dst l r, s => { s with pc := s.pc + 1, natMem := Function.update s.natMem dst (s.natMem l + s.natMem r) }
  | natSub dst l r, s => { s with pc := s.pc + 1, natMem := Function.update s.natMem dst (s.natMem l - s.natMem r) }
  | natLoad dst a, s => { s with pc := s.pc + 1, natMem := Function.update s.natMem dst (s.natMem (s.natMem a)) }
  | natStore a src, s => { s with pc := s.pc + 1, natMem := Function.update s.natMem (s.natMem a) (s.natMem src) }
  | realZero dst, s => { s with pc := s.pc + 1, realMem := Function.update s.realMem dst 0 }
  | realAdd dst l r, s => { s with pc := s.pc + 1, realMem := Function.update s.realMem dst (s.realMem l + s.realMem r) }
  | realSub dst l r, s => { s with pc := s.pc + 1, realMem := Function.update s.realMem dst (s.realMem l - s.realMem r) }
  | realLoad dst a, s => { s with pc := s.pc + 1, realMem := Function.update s.realMem dst (s.realMem (s.natMem a)) }
  | realStore a src, s => { s with pc := s.pc + 1, realMem := Function.update s.realMem (s.natMem a) (s.realMem src) }
  | natBranch l r y n, s => { s with pc := if s.natMem l ≤ s.natMem r then y else n }
  | realBranch l r y n, s => { s with pc := if s.realMem l ≤ s.realMem r then y else n }
  | jump j, s => { s with pc := j }
  | halt, s => s

/-- The code fragment `code` occupies positions `base, base+1, …` of the program `p`. -/
def CodeAt (p : List PlanarRAMInstruction) (base : ℕ) (code : List PlanarRAMInstruction) : Prop :=
  ∀ i, i < code.length → p[base + i]? = code[i]?

end WilliamsonShmoys
Source
Program-logic infrastructure for the RAM model 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