Documentation

Complexity.Computability.Ram.Execution.Unbounded

Executable runs without a prescribed step limit #

Ram.runUntil repeatedly uses the existing machine transition until halt, fault or an invalid program counter. It retains the same exact transition count and stopping reasons as Ram.run, without requesting an operational budget.

The implementation uses Lean's partial_fixpoint: it is executable and has proved unfolding equations. A divergent execution keeps running; the logical value none represents the least fixed point, not a runtime report detecting divergence. Every returned some is related to a finite bounded run below. Correctness proofs can instead supply a terminating Ram.Exec directly.

@[irreducible]
def Ram.Runner.loopUntil {σ : Type} (next : σ → Option σ) (status : σ → Status) (count : Nat) (s : σ) :

Tail-recursive execution using the existing successor and status functions. count records transitions already performed. No step limit is selected.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def Ram.Runner.runUntilWith {σ : Type} (next : σ → Option σ) (status : σ → Status) (s : σ) :

    A backend-independent executable runner without an operational step limit.

    Equations
    Instances For
      theorem Ram.Runner.loopUntil_of_loop {σ : Type} (next : σ → Option σ) (status : σ → Status) (fuel count : Nat) (s : σ) (stop : (loop next status fuel count s).reason ≠ StopReason.outOfFuel) :
      loopUntil next status count s = some (loop next status fuel count s)

      Any bounded run that actually stops is the result of the unbounded runner.

      theorem Ram.Runner.runUntilWith_of_runWith {σ : Type} (next : σ → Option σ) (status : σ → Status) (fuel : Nat) (s : σ) (stop : (runWith next status fuel s).reason ≠ StopReason.outOfFuel) :
      runUntilWith next status s = some (runWith next status fuel s)
      theorem Ram.Runner.loopUntil_has_finite_run {σ : Type} (next : σ → Option σ) (status : σ → Status) (count : Nat) (s : σ) (result : RunResult σ) (h : loopUntil next status count s = some result) :
      ∃ (fuel : Nat), loop next status fuel count s = result ∧ result.reason ≠ StopReason.outOfFuel

      A returned result has a finite execution witness. This direction uses the least-fixed-point induction principle, not an assumed termination argument.

      theorem Ram.Runner.loopUntil_eq_some_iff {σ : Type} (next : σ → Option σ) (status : σ → Status) (count : Nat) (s : σ) (result : RunResult σ) :
      loopUntil next status count s = some result ↔ ∃ (fuel : Nat), loop next status fuel count s = result ∧ result.reason ≠ StopReason.outOfFuel
      theorem Ram.Runner.runUntilWith_eq_some_iff {σ : Type} (next : σ → Option σ) (status : σ → Status) (s : σ) (result : RunResult σ) :
      runUntilWith next status s = some result ↔ ∃ (fuel : Nat), runWith next status fuel s = result ∧ result.reason ≠ StopReason.outOfFuel

      The unbounded and bounded drivers agree on all finite outcomes, including faults and invalid program counters. Neither reports divergence as a fault.

      def Ram.runUntil {w : Nat} (code : Code) (s : State w) :

      Execute actual machine transitions until the machine stops. Divergent programs keep running; the logical none is not a computable divergence test.

      Equations
      Instances For
        theorem Ram.runUntil_of_run {w : Nat} {code : Code} {fuel : Nat} {s : State w} (stop : (run code fuel s).reason ≠ StopReason.outOfFuel) :
        runUntil code s = some (run code fuel s)

        A finite outcome of the existing bounded runner is unchanged without its limit.

        theorem Ram.runUntil_of_exec {w : Nat} {code : Code} {n : Nat} {s t : State w} (execution : Exec code n s t) (halted : t.status = Status.halted) :
        runUntil code s = some { state := t, steps := n, reason := StopReason.halted }

        A terminating execution gives the executable result and exact count, without requiring the user to propose an instruction budget.

        theorem Ram.runUntil_eq_some_iff {w : Nat} {code : Code} {s : State w} {result : RunResult (State w)} :
        runUntil code s = some result ↔ ∃ (fuel : Nat), run code fuel s = result ∧ result.reason ≠ StopReason.outOfFuel

        All returned outcomes have a finite bounded-run witness.

        theorem Ram.runUntil_sound {w : Nat} {code : Code} {s : State w} {result : RunResult (State w)} (h : runUntil code s = some result) :
        Exec code result.steps s result.state ∧ result.reason ≠ StopReason.outOfFuel ∧ Runner.Outcome (step code) State.status result.steps result

        Returned outcomes have an actual transition trace and the reported terminal condition; the unbounded runner cannot return outOfFuel.

        theorem Ram.runUntil_halted_iff {w : Nat} {code : Code} {n : Nat} {s t : State w} :
        runUntil code s = some { state := t, steps := n, reason := StopReason.halted } ↔ Exec code n s t ∧ t.status = Status.halted

        A successful unbounded run is exactly a finite halted machine execution, with the same final state and exact transition count in both directions.