Documentation

LeanPool.PlanarSeparator.WordRAM.Machine.Relocate

Relocation and linking #

Shift every jump/branch target by off; other instructions are unchanged.

Equations
Instances For
    @[simp]
    theorem WordRAM.Instr.relocate_jump (off l : ℕ) :
    relocate off (jump l) = jump (l + off)
    @[simp]
    theorem WordRAM.Instr.relocate_brLtN (off a b l : ℕ) :
    relocate off (brLtN a b l) = brLtN a b (l + off)
    @[simp]
    theorem WordRAM.Instr.relocate_brLtR (off a b l : ℕ) :
    relocate off (brLtR a b l) = brLtR a b (l + off)
    @[simp]
    theorem WordRAM.Instr.relocate_zero (ins : Instr) :
    relocate 0 ins = ins
    theorem WordRAM.Instr.relocate_relocate (ins : Instr) (a b : ℕ) :
    relocate b (relocate a ins) = relocate (a + b) ins
    @[simp]
    theorem WordRAM.Instr.relocate_of_isStraight {ins : Instr} (h : ins.IsStraight) (off : ℕ) :
    relocate off ins = ins

    Relocation does not touch straight-line instructions.

    @[simp]

    Relocate every instruction of a program.

    Equations
    Instances For
      @[simp]
      @[simp]
      @[simp]
      theorem WordRAM.Program.relocate_cons (off : ℕ) (ins : Instr) (p : Program) :
      relocate off (ins :: p) = Instr.relocate off ins :: relocate off p
      @[simp]
      theorem WordRAM.Program.relocate_append (off : ℕ) (p₁ p₂ : Program) :
      relocate off (p₁ ++ p₂) = relocate off p₁ ++ relocate off p₂

      Placement of a program inside a larger one #

      def WordRAM.Machine.SubAt (p q : Program) (base : ℕ) :

      The program p sits verbatim at address base inside q.

      Equations
      Instances For
        theorem WordRAM.Machine.SubAt.lookup {p q : Program} {base : ℕ} (h : SubAt p q base) {i : ℕ} (hi : i < List.length p) :
        q[base + i]? = p[i]?

        Lookup through a placement.

        theorem WordRAM.Machine.subAt_iff {p q : Program} {base : ℕ} :
        SubAt p q base ↔ ∀ i < List.length p, q[base + i]? = p[i]?
        theorem WordRAM.Machine.SubAt.length_le {p q : Program} {base : ℕ} (h : SubAt p q base) (hp : 0 < List.length p) :

        A nonempty placed program fits inside the host.

        @[simp]
        theorem WordRAM.Machine.SubAt.nil (q : Program) (base : ℕ) :
        SubAt [] q base
        theorem WordRAM.Machine.SubAt.cons_iff {ins : Instr} {p q : Program} {base : ℕ} :
        SubAt (ins :: p) q base ↔ q[base]? = some ins ∧ SubAt p q (base + 1)
        theorem WordRAM.Machine.SubAt.head {ins : Instr} {p q : Program} {base : ℕ} (h : SubAt (ins :: p) q base) :
        q[base]? = some ins
        theorem WordRAM.Machine.SubAt.tail {ins : Instr} {p q : Program} {base : ℕ} (h : SubAt (ins :: p) q base) :
        SubAt p q (base + 1)
        theorem WordRAM.Machine.SubAt.singleton_iff {ins : Instr} {q : Program} {base : ℕ} :
        SubAt [ins] q base ↔ q[base]? = some ins
        theorem WordRAM.Machine.SubAt.append_iff {p₁ p₂ q : Program} {base : ℕ} :
        SubAt (p₁ ++ p₂) q base ↔ SubAt p₁ q base ∧ SubAt p₂ q (base + List.length p₁)
        theorem WordRAM.Machine.SubAt.of_append_left {p₁ p₂ q : Program} {base : ℕ} (h : SubAt (p₁ ++ p₂) q base) :
        SubAt p₁ q base
        theorem WordRAM.Machine.SubAt.of_append_right {p₁ p₂ q : Program} {base : ℕ} (h : SubAt (p₁ ++ p₂) q base) :
        SubAt p₂ q (base + List.length p₁)
        theorem WordRAM.Machine.getElem?_append_length_add (p₁ p₂ : Program) (i : ℕ) :
        (p₁ ++ p₂)[List.length p₁ + i]? = p₂[i]?

        The lookup lemma for concatenation.

        theorem WordRAM.Machine.SubAt.append_left (p₁ p₂ : Program) :
        SubAt p₁ (p₁ ++ p₂) 0

        The first half of a concatenation sits at address 0.

        theorem WordRAM.Machine.SubAt.append_right (p₁ p₂ : Program) :
        SubAt p₂ (p₁ ++ p₂) (List.length p₁)

        The second half of a concatenation sits at address p₁.length.

        theorem WordRAM.Machine.SubAt.trans {p q r : Program} {a b : ℕ} (h₁ : SubAt p q a) (h₂ : SubAt q r b) :
        SubAt p r (b + a)
        theorem WordRAM.Machine.SubAt.append_right_of {p q r : Program} {base : ℕ} (h : SubAt p q base) :
        SubAt p (q ++ r) base

        Placement inside a longer program obtained by appending on the right.

        theorem WordRAM.Machine.SubAt.append_left_of {p q r : Program} {base : ℕ} (h : SubAt p q base) :
        SubAt p (r ++ q) (List.length r + base)

        Placement inside a longer program obtained by prepending on the left.

        Shifting the program counter #

        The configuration c with its program counter shifted by off.

        Equations
        Instances For
          @[simp]
          theorem WordRAM.Machine.shiftPc_pc (off : ℕ) (c : Config) :
          (shiftPc off c).pc = c.pc + off
          @[simp]
          theorem WordRAM.Machine.shiftPc_nreg (off : ℕ) (c : Config) :
          (shiftPc off c).nreg = c.nreg
          @[simp]
          theorem WordRAM.Machine.shiftPc_rreg (off : ℕ) (c : Config) :
          (shiftPc off c).rreg = c.rreg
          @[simp]
          theorem WordRAM.Machine.shiftPc_nmem (off : ℕ) (c : Config) :
          (shiftPc off c).nmem = c.nmem
          @[simp]
          theorem WordRAM.Machine.shiftPc_rmem (off : ℕ) (c : Config) :
          (shiftPc off c).rmem = c.rmem
          @[simp]
          @[simp]
          theorem WordRAM.Machine.shiftPc_setPc (off : ℕ) (c : Config) (p : ℕ) :
          shiftPc off { pc := p, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output } = { pc := p + off, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }

          The relocation theorem #

          theorem WordRAM.Machine.step_relocate {p q : Program} {off : ℕ} {P : Input} {c : Config} {ins : Instr} (hp : p[c.pc]? = some ins) (hq : q[c.pc + off]? = some (Instr.relocate off ins)) :
          step q P (shiftPc off c) = Option.map (shiftPc off) (step p P c)

          One step of p at c is simulated by one step of q at shiftPc off c, provided the relocated instruction sits at the shifted address. Faults are reproduced.

          theorem WordRAM.Machine.SubAt.relocate_lookup {p q : Program} {off : ℕ} (h : SubAt (Program.relocate off p) q off) {i : ℕ} {ins : Instr} (hi : p[i]? = some ins) :
          q[i + off]? = some (Instr.relocate off ins)

          Placing p.relocate off at address off of q is the "relocation placement".

          theorem WordRAM.Machine.run_relocate {p q : Program} {off : ℕ} {P : Input} {k : ℕ} {c : Config} (hq : SubAt (Program.relocate off p) q off) (hpc : ∀ i < k, ∀ (c' : Config), run p P i c = some c' → c'.pc < List.length p) :
          run q P k (shiftPc off c) = Option.map (shiftPc off) (run p P k c)

          Relocation. If p.relocate off sits at off inside q and the k-step run of p from c never leaves p's code (the program counter of every configuration at which a step is taken is < p.length), then the run of q from the shifted configuration is the shifted run of p, faults included.

          theorem WordRAM.Machine.run_relocate_of_run {p q : Program} {off : ℕ} {P : Input} {k : ℕ} {c c' : Config} (hq : SubAt (Program.relocate off p) q off) (hpc : ∀ i < k, ∀ (c'' : Config), run p P i c = some c'' → c''.pc < List.length p) (h : run p P k c = some c') :
          run q P k (shiftPc off c) = some (shiftPc off c')

          Relocation of a successful run.

          theorem WordRAM.Machine.RunsTo.relocate {p q : Program} {off : ℕ} {P : Input} {W k : ℕ} {c c' : Config} (hq : SubAt (Program.relocate off p) q off) (hpc : ∀ i < k, ∀ (c'' : Config), run p P i c = some c'' → c''.pc < List.length p) (h : RunsTo p P W k c c') :
          RunsTo q P W k (shiftPc off c) (shiftPc off c')

          Relocation of a bounded run (RunsTo).

          theorem WordRAM.Machine.AtHalt.relocate {p q : Program} {off : ℕ} {c : Config} (hq : SubAt (Program.relocate off p) q off) (h : AtHalt p c) :
          AtHalt q (shiftPc off c)

          A halt of p at c is a halt of q at the shifted configuration.

          A program placed at 0 with no relocation.