Cslib.URM.Step.toStandardForm
theoremverifiedformalizationimported Lean
Forward step correspondence: if p steps from s to s', then either: (1) p.toStandardForm steps from s to s' (same step), or (2) s' is halted in p, and p.toStandardForm steps to a state that is also halted with the same registers (this only happens for jumps with unbounded targets).
Statement
set_option autoImplicit true in set_option relaxedAutoImplicit true in theorem Cslib.URM.Step.toStandardForm {p : Program} {s s' : State} (hstep : Step p s s') : Step p.toStandardForm s s' ∨ (s'.isHalted p ∧ ∃ s₂, Step p.toStandardForm s s₂ ∧ s₂.isHalted p.toStandardForm ∧ s'.regs = s₂.regs)
- Formalizes
- CSLib, `Cslib.URM.Step.toStandardForm`
- 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.toStandardForm← Cslib.URM.Step.toStandardForm (Cslib/Computability/URM/StandardForm.lean:96): verbatim
- Verified
- 08 Oct 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 33
- Cslib.URM.ProgramA URM program is a list of instructions.
- Cslib.URM.StateMachine state: program counter (0-indexed) and register contents.
- Cslib.URM.StepSingle-step execution relation for URMs. Each constructor corresponds to one of the four instruction types: -
zero: ExecuteZ n(set… - Cslib.URM.Program.toStandardFormConvert a program to standard form by capping all jump targets at the program length.
- Cslib.URM.State.isHaltedA state is halted if the program counter is at or beyond the program length.
- Cslib.URM.RegsRegister contents: maps register indices to natural number contents. Uses the functional representation
ℕ → ℕfor efficiency with… - 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.capJumpCap a jump target to be at most
len. Non-jump instructions are unchanged. - Cslib.URM.Program.getElem?_toStandardFormAccessing an instruction in toStandardForm gives the capJump'd instruction.
- Cslib.URM.Regs.readRead the contents of register n.
- Cslib.URM.Program.toStandardForm_lengthtoStandardForm preserves program length.
- Cslib.URM.Regs.write_read_selfCslib.URM.Regs.write_read_self
- Cslib.URM.Regs.write_read_of_neCslib.URM.Regs.write_read_of_ne
- Cslib.URM.State.isHalted_iffCslib.URM.State.isHalted_iff
- Cslib.URM.Instr.Z_nonJumpZ instruction is not a jump.
- Cslib.URM.Instr.S_nonJumpS instruction is not a jump.
- Cslib.URM.Instr.T_nonJumpT instruction is not a jump.
- Cslib.URM.Instr.J_IsJumpJ instruction is a jump.
- Cslib.URM.Instr.capJump_ZCslib.URM.Instr.capJump_Z
- Cslib.URM.Instr.capJump_SCslib.URM.Instr.capJump_S
- Cslib.URM.Instr.capJump_TCslib.URM.Instr.capJump_T
- Cslib.URM.Instr.capJump_JCslib.URM.Instr.capJump_J
- Cslib.URM.Instr.capJump_idempotentcapJump is idempotent: capping twice is the same as capping once.
- Cslib.URM.Program.toStandardForm_idempotenttoStandardForm is idempotent: applying it twice equals applying it once.
- Cslib.URM.State.instDecidableIsHaltedCslib.URM.State.instDecidableIsHalted
- Cslib.URM.State.instInhabitedCslib.URM.State.instInhabited
- Cslib.URM.State.instReprCslib.URM.State.instRepr
- Cslib.URM.Instr.instDecidableIsJumpCslib.URM.Instr.instDecidableIsJump
- Cslib.URM.Instr.instDecidableJumpsBoundedByCslib.URM.Instr.instDecidableJumpsBoundedBy
- Cslib.URM.instSetoidProgramSetoid instance for programs, enabling the ≈ notation.
- Cslib.URM.instDecidableIsStraightLineCslib.URM.instDecidableIsStraightLine
- Cslib.URM.Program.instDecidableIsStandardFormCslib.URM.Program.instDecidableIsStandardForm
- Used by 2
- urm_halts_toStandardFormFor any URM program p and input list inputs, p halts on inputs if and only if its standard form p.toStandardForm halts on inputs.
- urm_halts_toStandardForm_of_haltsIf a URM program p halts on inputs, then its standard form p.toStandardForm halts on inputs.
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 in/-- Forward step correspondence: if p steps from s to s', then either: (1) p.toStandardForm steps from s to s' (same step), or (2) s' is halted in p, and p.toStandardForm steps to a state that is also halted with the same registers (this only happens for jumps with unbounded targets). -/theorem Cslib.URM.Step.toStandardForm {p : Program} {s s' : State} (hstep : Step p s s') : Step p.toStandardForm s s' ∨ (s'.isHalted p ∧ ∃ s₂, Step p.toStandardForm s s₂ ∧ s₂.isHalted p.toStandardForm ∧ s'.regs = s₂.regs) := by cases hstep with | zero hinstr => left exact Step.zero (by simp [Program.getElem?_toStandardForm, hinstr]) | succ hinstr => left exact Step.succ (by simp [Program.getElem?_toStandardForm, hinstr]) | transfer hinstr => left exact Step.transfer (by simp [Program.getElem?_toStandardForm, hinstr]) | @jump_ne m n q hinstr hne => left have hcap : p.toStandardForm[s.pc]? = some (Instr.J m n (min q p.length)) := by simp [Program.getElem?_toStandardForm, hinstr] exact Step.jump_ne hcap hne | @jump_eq m n q hinstr heq => have (x : ℕ) (h : min q p.length = x) : p.toStandardForm[s.pc]? = some (Instr.J m n x) := by grind [Program.getElem?_toStandardForm, Instr.capJump] by_cases q ≤ p.length · grind [Step.jump_eq] · right split_ands · grind [State.isHalted] · use ⟨p.length, s.regs⟩ grind [State.isHalted, Program.toStandardForm_length]