Cslib.URM.Step.preserves_register
theoremverifiedformalizationimported Lean
A single step preserves registers not written to by the current instruction. This is a fundamental property of URM execution: each instruction modifies at most one register (Z, S, T write to one register; J writes to none).
Statement
set_option autoImplicit true in set_option relaxedAutoImplicit true in variable (p : Program) in variable {p : Program} in theorem Cslib.URM.Step.preserves_register {s s' : State} {r : ℕ} (hstep : Step p s s') (hr : ∀ instr, p[s.pc]? = some instr → instr.writesTo ≠ some r) : s'.regs.read r = s.regs.read r
- Formalizes
- CSLib, `Cslib.URM.Step.preserves_register`
- Lean proof
- By Jesse Alama, from github.com/leanprover/cslib at
3951377e5a3f(Copyright (c) 2026 Jesse Alama. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.33.0.Cslib.URM.Step.preserves_register← Cslib.URM.Step.preserves_register (Cslib/Computability/URM/Execution.lean:97): verbatim
- Verified
- 08 Oct 2026
- Axioms
propext- Built on 10
- Cslib.URM.State.instDecidableIsHaltedCslib.URM.State.instDecidableIsHalted
- Cslib.URM.InstrURM instructions. -
Z n: Set register n to zero -S n: Increment register n by one -T m n: Transfer (copy) the contents of register… - Cslib.URM.Regs.writeWrite value v to register n.
- Cslib.URM.Instr.writesToThe register written to by an instruction, if any.
- Cslib.URM.State.instInhabitedCslib.URM.State.instInhabited
- Cslib.URM.Regs.readRead the contents of register n.
- Cslib.URM.State.instReprCslib.URM.State.instRepr
- Cslib.URM.StepSingle-step execution relation for URMs. Each constructor corresponds to one of the four instruction types: -
zero: ExecuteZ n(set… - Cslib.URM.StateMachine state: program counter (0-indexed) and register contents.
- Cslib.URM.ProgramA URM program is a list of instructions.
- Used by 1
- Cslib.URM.Steps.preserves_registerMulti-step execution preserves registers not written by any executed instruction.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
set_option autoImplicit true inset_option relaxedAutoImplicit true invariable (p : Program) invariable {p : Program} in/-- A single step preserves registers not written to by the current instruction. This is a fundamental property of URM execution: each instruction modifies at most one register (Z, S, T write to one register; J writes to none). -/theorem Cslib.URM.Step.preserves_register {s s' : State} {r : ℕ} (hstep : Step p s s') (hr : ∀ instr, p[s.pc]? = some instr → instr.writesTo ≠ some r) : s'.regs.read r = s.regs.read r := by cases hstep with | zero hinstr | succ hinstr | transfer hinstr => have := hr _ hinstr simp only [Instr.writesTo, ne_eq, Option.some.injEq] at this exact Function.update_of_ne (Ne.symm this) _ _ | jump_eq _ _ | jump_ne _ _ => rfl