Documentation

Cslib.Computability.URM.StraightLine

Straight-Line Programs #

This file defines straight-line programs (those without jumps) and proves they always halt exactly at their length.

Main definitions #

Main results #

Straight-Line Programs #

A program is "straight-line" if it contains no jump instructions.

Equations
Instances For

    Append preserves straight-line property.

    theorem Cslib.URM.Program.IsStraightLine.cons {instr : Instr} {p : Program} (hinstr : ¬instr.IsJump) (hp : p.IsStraightLine) :
    IsStraightLine (instr :: p)

    Cons of non-jumping instruction preserves straight-line.

    Singleton non-jumping instruction is straight-line.

    Straight-Line Program Execution #

    theorem Cslib.URM.Step.of_nonJump {p : Program} {s : State} (hlt : s.pc < List.length p) (hnonjump : ¬p[s.pc].IsJump) :
    ∃ (s' : State), Step p s s' s'.pc = s.pc + 1

    A non-jumping instruction produces a step that increments PC by 1.

    theorem Cslib.URM.straight_line_halts_from_regs {p : Program} (hsl : p.IsStraightLine) (r : Regs) :
    ∃ (s : State), Steps p { pc := 0, regs := r } s s.isHalted p s.pc = List.length p

    Straight-line programs halt from any starting registers, not just State.init. Useful for chaining: after running one program, we can run the next straight-line segment from whatever registers we're in.

    theorem Cslib.URM.straight_line_halts {p : Program} (hsl : p.IsStraightLine) (inputs : List ) :
    Halts p inputs

    A straight-line program halts on any input.

    noncomputable def Cslib.URM.straightLine_finalState {p : Program} (hsl : p.IsStraightLine) (r : Regs) :

    The halting state for a straight-line program starting from registers r. Wraps Classical.choose to hide it from the API.

    Equations
    Instances For
      theorem Cslib.URM.straightLine_finalState_spec {p : Program} (hsl : p.IsStraightLine) (r : Regs) :
      have s := straightLine_finalState hsl r; Steps p { pc := 0, regs := r } s s.isHalted p s.pc = List.length p

      Specification: the state from straightLine_finalState satisfies Steps, isHalted, and has pc = p.length.

      noncomputable def Cslib.URM.straightLine_finalRegs {p : Program} (hsl : p.IsStraightLine) (r : Regs) :

      The final registers after running a straight-line program from given starting registers.

      Equations
      Instances For
        theorem Cslib.URM.straightLine_finalRegs_eq_of_halted {p : Program} (hsl : p.IsStraightLine) (r : Regs) (s : State) (hsteps : Steps p { pc := 0, regs := r } s) (hhalted : s.isHalted p) :

        For a straight-line program, s.regs equals straightLine_finalRegs if halted from r.

        theorem Cslib.URM.straight_line_state_at_pc {p : Program} (hsl : p.IsStraightLine) (r : Regs) (targetPc : ) (htarget : targetPc List.length p) :
        ∃ (s : State), Steps p { pc := 0, regs := r } s s.pc = targetPc

        In a straight-line program, we can characterize the state at any intermediate pc. This gives us the state after executing instructions 0..pc-1.