Documentation

Complexitylib.Models.RandomAccessMachine.Structured.Defs

Structured logarithmic-cost RAM programs — definitions #

This file defines a minimal first-order imperative language over RAM register stores. Atomic commands are the data-manipulating RAM instructions; sequencing, conditionals, and loops are structured syntax rather than program-counter arithmetic. The source semantics is independent of compilation and records the same operand-sensitive logarithmic cost and finite-support space measure as the target RAM.

Cmd.compileAt erases structured control flow into absolute jz/jmp targets. The compiler appends no hidden data operations: source and target executions therefore have equal register effects, logarithmic cost, and peak register space.

@[reducible, inline]

A source store maps register indices to natural-number contents.

Equations
Instances For
    noncomputable def Complexity.RAM.Structured.Store.space (store : Store) :

    Logarithmic space occupied by a source store. This deliberately matches RAM.Cfg.space, but does not mention a target program counter.

    Equations
    Instances For

      Natural-number representation of one input bit.

      Equations
      Instances For
        def Complexity.RAM.Structured.Input.bitStore (lengthReg inputBase : ) (bits : List Bool) :

        Store a bit string above a reserved register prefix, with its length in a distinguished register.

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

          Data-manipulating instructions of the structured source language. Control flow is represented by Cmd, so arbitrary jumps and halt are not source atoms.

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

                Execute one source-level basic instruction on a register store.

                Equations
                Instances For

                  Operand-sensitive source cost of one basic instruction.

                  Equations
                  Instances For

                    Execute a straight-line list of basic instructions.

                    Equations
                    Instances For

                      Minimal structured imperative syntax over RAM stores.

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

                            Number of RAM instructions emitted for a structured command.

                            Equations
                            Instances For

                              Compile a command whose first instruction will be placed at start. All generated branch destinations are absolute RAM program counters.

                              Equations
                              Instances For

                                Compile a closed source command and halt immediately after it finishes.

                                Equations
                                Instances For

                                  Embed a straight-line list of basic instructions as one structured command.

                                  Equations
                                  Instances For
                                    inductive Complexity.RAM.Structured.Exec :
                                    CmdStoreStoreProp

                                    Independent big-step semantics for structured commands. Besides the final store, the relation records target instruction steps, exact logarithmic cost, and peak source-store space. Branch and loop-control costs are explicit.

                                    • skip (store : Store) : Exec Cmd.skip store store 0 0 store.space
                                    • basic (op : Basic) (store : Store) : Exec (Cmd.basic op) store (op.exec store) 1 (op.logCost store) (max store.space (op.exec store).space)
                                    • seq {first second : Cmd} {store middle final : Store} {firstSteps secondSteps firstCost secondCost firstSpace secondSpace : } (hfirst : Exec first store middle firstSteps firstCost firstSpace) (hsecond : Exec second middle final secondSteps secondCost secondSpace) : Exec (first.seq second) store final (firstSteps + secondSteps) (firstCost + secondCost) (max firstSpace secondSpace)
                                    • ifZero {test : } {onZero onNonzero : Cmd} {store final : Store} {steps cost space : } (htest : store test = 0) (hbranch : Exec onZero store final steps cost space) : Exec (Cmd.ifZero test onZero onNonzero) store final (steps + 1) (bitlen (store test) + 1 + cost) (max store.space space)
                                    • ifNonzero {test : } {onZero onNonzero : Cmd} {store final : Store} {steps cost space : } (htest : store test 0) (hbranch : Exec onNonzero store final steps cost space) : Exec (Cmd.ifZero test onZero onNonzero) store final (steps + 2) (bitlen (store test) + 1 + cost + 1) (max store.space space)
                                    • whileZero {test : } {body : Cmd} {store : Store} (htest : store test = 0) : Exec (Cmd.whileNonzero test body) store store 1 (bitlen (store test) + 1) store.space
                                    • whileNonzero {test : } {body : Cmd} {store middle final : Store} {bodySteps loopSteps bodyCost loopCost bodySpace loopSpace : } (htest : store test 0) (hbody : Exec body store middle bodySteps bodyCost bodySpace) (hloop : Exec (Cmd.whileNonzero test body) middle final loopSteps loopCost loopSpace) : Exec (Cmd.whileNonzero test body) store final (bodySteps + loopSteps + 2) (bitlen (store test) + 1 + bodyCost + 1 + loopCost) (max bodySpace loopSpace)
                                    Instances For