Documentation

LeanPool.PlanarSeparator.WordRAM.Spec

A random-access machine with a cost model #

A unit-cost random-access machine with natural-number words, for algorithms on integer data:

Everything else is unchanged: natural registers and memory, exact real registers and memory, a program counter, unit cost per executed instruction (RunsWithin charges one step per instruction and one for the final halt), and a bound W on every natural word along the run (WordsBounded), which a cost theorem states explicitly.

structure WordRAM.Input :

The input of a run: a list of words and a random tape.

  • data : List ℕ

    The input words.

  • tape : ℕ → ℕ

    The random tape.

Instances For
    inductive WordRAM.Instr :

    The instruction set. r, a, b name registers; k is a literal natural; z a literal integer; l a literal instruction address.

    Instances For
      @[reducible, inline]

      A program is a finite list of instructions; instruction addresses are list positions.

      Equations
      Instances For
        structure WordRAM.Config :

        A machine configuration.

        • pc : ℕ

          The program counter.

        • nreg : ℕ → ℕ

          Natural registers.

        • rreg : ℕ → ℝ

          Real registers.

        • nmem : ℕ → ℕ

          Natural memory.

        • rmem : ℕ → ℝ

          Real memory.

        • output : List ℕ

          The words output so far, in order.

        Instances For

          The initial configuration: program counter 0, all registers and memory cells zero, nothing output.

          Equations
          Instances For
            def WordRAM.upd {α : Type} (f : ℕ → α) (i : ℕ) (v : α) :
            ℕ → α

            Update one entry of a register file or memory.

            Equations
            Instances For
              noncomputable def WordRAM.step (prog : Program) (P : Input) (c : Config) :

              Execute one instruction of prog on input P from configuration c. Returns none on a fault (program counter out of range, or real division by zero) or when the current instruction is halt; otherwise the next configuration.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                noncomputable def WordRAM.run (prog : Program) (P : Input) :

                Run k instructions, faulting if any step faults.

                Equations
                Instances For
                  def WordRAM.AtHalt (prog : Program) (c : Config) :

                  The configuration is at a halt instruction.

                  Equations
                  Instances For

                    Every natural register and every natural memory cell of c is at most W.

                    Equations
                    Instances For
                      def WordRAM.RunsWithin (prog : Program) (P : Input) (W steps : ℕ) (out : List ℕ) :

                      prog, started on input P in the initial configuration, executes exactly k instructions without faulting and then sits at halt, every configuration along the way (including the final one) has its natural words bounded by W, and the output at the end is out. The run is charged k + 1 steps: one for each executed instruction and one for the final halt.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For