Documentation

Cslib.Computability.URM.Basic

URM Basic Lemmas #

This file contains basic lemmas and helper operations for URM types.

Main definitions #

Main results #

Register Lemmas #

@[simp]
theorem Cslib.URM.Regs.write_read_self (σ : Regs) (n v : ā„•) :
(σ.write n v).read n = v
@[simp]
theorem Cslib.URM.Regs.write_read_of_ne (σ : Regs) (m n v : ā„•) (h : m ≠ n) :
(σ.write n v).read m = σ.read m

State Lemmas #

@[simp]
theorem Cslib.URM.State.isHalted_iff (s : State) (p : Program) :
s.isHalted p ↔ List.length p ≤ s.pc
theorem Cslib.URM.State.ext {s₁ sā‚‚ : State} (hpc : s₁.pc = sā‚‚.pc) (hregs : s₁.regs = sā‚‚.regs) :
s₁ = sā‚‚

Extensionality for State: two states are equal iff their components are equal.

theorem Cslib.URM.State.ext_iff {s₁ sā‚‚ : State} :
s₁ = sā‚‚ ↔ s₁.pc = sā‚‚.pc ∧ s₁.regs = sā‚‚.regs

Instruction Lemmas #

Jump Instructions #

An instruction is a jump instruction.

Equations
Instances For
    @[implicit_reducible]
    instance Cslib.URM.Instr.instDecidableIsJump (instr : Instr) :
    Decidable instr.IsJump
    Equations
    • One or more equations did not get rendered due to their size.
    @[simp]
    theorem Cslib.URM.Instr.Z_nonJump (n : ā„•) :
    ¬(Z n).IsJump

    Z instruction is not a jump.

    @[simp]
    theorem Cslib.URM.Instr.S_nonJump (n : ā„•) :
    ¬(S n).IsJump

    S instruction is not a jump.

    @[simp]
    theorem Cslib.URM.Instr.T_nonJump (m n : ā„•) :
    ¬(T m n).IsJump

    T instruction is not a jump.

    @[simp]
    theorem Cslib.URM.Instr.J_IsJump (m n q : ā„•) :
    (J m n q).IsJump

    J instruction is a jump.

    theorem Cslib.URM.Instr.shiftJumps_of_nonJump {instr : Instr} (h : ¬instr.IsJump) (offset : ā„•) :
    shiftJumps offset instr = instr

    shiftJumps is identity for non-jumping instructions.

    Bounded Jump Targets #

    def Cslib.URM.Instr.JumpsBoundedBy (len : ā„•) :
    Instr → Prop

    An instruction's jump target is bounded by a given length. Non-jump instructions trivially satisfy this.

    Equations
    Instances For
      @[implicit_reducible]
      instance Cslib.URM.Instr.instDecidableJumpsBoundedBy (len : ā„•) (instr : Instr) :
      Decidable (JumpsBoundedBy len instr)
      Equations
      • One or more equations did not get rendered due to their size.
      theorem Cslib.URM.Instr.jumpsBoundedBy_of_nonJump {instr : Instr} (h : ¬instr.IsJump) (len : ā„•) :
      JumpsBoundedBy len instr

      Non-jumping instructions have bounded jumps for any length.

      theorem Cslib.URM.Instr.JumpsBoundedBy.mono {instr : Instr} {len1 len2 : ā„•} (h : JumpsBoundedBy len1 instr) (hle : len1 ≤ len2) :
      JumpsBoundedBy len2 instr

      JumpsBoundedBy is monotonic: if bounded for len1, then bounded for any len2 ≄ len1.

      theorem Cslib.URM.Instr.JumpsBoundedBy.shiftJumps {instr : Instr} {len offset : ā„•} (h : JumpsBoundedBy len instr) :
      JumpsBoundedBy (offset + len) (Instr.shiftJumps offset instr)

      shiftJumps preserves bounded jumps with adjusted bound.

      Jump Target Capping #

      def Cslib.URM.Instr.capJump (len : ā„•) :
      Instr → Instr

      Cap a jump target to be at most len. Non-jump instructions are unchanged.

      Equations
      Instances For
        @[simp]
        theorem Cslib.URM.Instr.capJump_Z (len n : ā„•) :
        capJump len (Z n) = Z n
        @[simp]
        theorem Cslib.URM.Instr.capJump_S (len n : ā„•) :
        capJump len (S n) = S n
        @[simp]
        theorem Cslib.URM.Instr.capJump_T (len m n : ā„•) :
        capJump len (T m n) = T m n
        @[simp]
        theorem Cslib.URM.Instr.capJump_J (len m n q : ā„•) :
        capJump len (J m n q) = J m n (min q len)
        theorem Cslib.URM.Instr.JumpsBoundedBy.capJump (len : ā„•) (instr : Instr) :

        capJump always produces an instruction with bounded jump.

        @[simp]
        theorem Cslib.URM.Instr.capJump_idempotent (len : ā„•) (instr : Instr) :
        capJump len (capJump len instr) = capJump len instr

        capJump is idempotent: capping twice is the same as capping once.

        theorem Cslib.URM.Program.mem_maxRegister {p : Program} {instr : Instr} (h : instr ∈ p) :
        instr.maxRegister ≤ p.maxRegister

        Any instruction in a program has maxRegister at most the program's maxRegister.