Cslib.URM.Halts.toHaltsWithResult
theoremverifiedformalizationimported Lean
If a program halts, it halts with the output of the final state.
Statement
set_option autoImplicit true in set_option relaxedAutoImplicit true in open Cslib Cslib.URM in variable (p : Program) in variable {p : Program} in theorem Cslib.URM.Halts.toHaltsWithResult {inputs : List ℕ} (h : p ↓ inputs) : p ↓ inputs ≫ ((evalState p inputs).get h).regs.output
- Formalizes
- CSLib, `Cslib.URM.Halts.toHaltsWithResult`
- 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.Halts.toHaltsWithResult← Cslib.URM.Halts.toHaltsWithResult (Cslib/Computability/URM/Execution.lean:224): verbatim
- Verified
- 08 Oct 2026
- Axioms
Classical.choicepropext- Built on 13
- Cslib.URM.evalState_specSpecification: the state from evalState satisfies Steps and isHalted.
- Cslib.URM.ProgramA URM program is a list of instructions.
- Cslib.URM.HaltsA program halts on given inputs if execution reaches a halted state. This is equivalent to
(Step p).Normalizable (State.init inputs)—… - Cslib.URM.HaltsWithResultA program halts on given inputs with a specific result in R[0].
- Cslib.URM.Regs.outputExtract output from register 0.
- Cslib.URM.StateMachine state: program counter (0-indexed) and register contents.
- Cslib.URM.evalStateEvaluation returning the full halting state.
- Cslib.URM.StepsMulti-step execution: the reflexive-transitive closure of
Step. - Cslib.URM.State.initInitial state for a program with given inputs. The program counter starts at 0, and inputs are loaded into registers 0, 1, ....
- Cslib.URM.State.isHaltedA state is halted if the program counter is at or beyond the program length.
- Cslib.URM.State.instDecidableIsHaltedCslib.URM.State.instDecidableIsHalted
- Cslib.URM.State.instInhabitedCslib.URM.State.instInhabited
- Cslib.URM.State.instReprCslib.URM.State.instRepr
Lean source view module on GitHub
set_option quotPrecheck false open Cslib Cslib.URM local notation:50 p " ↓ " inputs:51 => Halts p inputs local notation:50 p " ↑ " inputs:51 => Diverges p inputs local notation:50 p " ↓ " inputs:51 " ≫ " result:51 => HaltsWithResult p inputs result set_option autoImplicit true in set_option relaxedAutoImplicit true in open Cslib Cslib.URM in variable (p : Program) in variable {p : Program} in /-- If a program halts, it halts with the output of the final state. -/ theorem Cslib.URM.Halts.toHaltsWithResult {inputs : List ℕ} (h : p ↓ inputs) : p ↓ inputs ≫ ((evalState p inputs).get h).regs.output := let s := (evalState p inputs).get h let ⟨hsteps, hhalted⟩ := evalState_spec p h ⟨s, hsteps, hhalted, rfl⟩