Documentation

LeanPool.OrderMaintenance.Machine.Exec

Cost semantics #

exec c s runs statement c from state s. It returns the final state, the number of steps taken, and a status. The cost is part of the semantics: every expression node, assignment, array access, allocation, branch, loop iteration, call, returned value and handler entry costs one step. No other computation is available to a program.

Two kinds of abnormal termination:

Array memory, capacities, local registers and the ghost peak value of the RAM.

  • mem : Arr → Nat → Nat

    Total natural-number contents of every named machine array.

  • cap : Arr → Nat

    Allocated capacity of each named machine array.

  • loc : Reg → Nat

    Natural-number value of each local register.

  • peak : Nat

    The largest value computed so far (ghost; read only by the word-size theorem).

Instances For

    The zero-filled initial RAM with zero capacities and zero locals.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      def OrderMaintenance.Machine.State.upd {α : Type} [DecidableEq α] (f : α → Nat) (a : α) (v : Nat) :
      α → Nat

      Update one point of a function.

      Equations
      Instances For

        Write one local register without changing array memory.

        Equations
        Instances For

          Write one array cell without changing capacities or locals.

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

            Reset one named array to zero and assign its capacity.

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

              Record a computed value in the ghost peak bound.

              Equations
              Instances For

                Assign values to a list of locals, left to right.

                Equations
                Instances For

                  The callee's frame: parameters bound to the argument values, every other local 0.

                  Equations
                  Instances For
                    def OrderMaintenance.Machine.State.leave (s : State) (caller : Reg → Nat) (rets dsts : List Reg) :

                    Return to the caller's frame caller, copying the callee's locals rets to dsts.

                    Equations
                    Instances For

                      Evaluate a binary natural-number primitive, rejecting invalid arithmetic.

                      Equations
                      Instances For

                        Evaluate Boolean negation or the most-significant-bit index.

                        Equations
                        Instances For

                          Evaluate a RAM expression, rejecting out-of-bounds reads and invalid arithmetic.

                          Equations
                          Instances For

                            The cost of evaluating an expression depends only on its syntax.

                            Equations
                            Instances For

                              The largest value among the expression and all its subexpressions.

                              Equations
                              Instances For

                                Evaluate all argument expressions, failing if any expression is invalid.

                                Equations
                                Instances For

                                  Sum the static instruction costs of the argument expressions.

                                  Equations
                                  Instances For

                                    Largest intermediate value produced by evaluating the argument expressions.

                                    Equations
                                    Instances For

                                      Normal termination, recoverable failure or an internal machine error.

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

                                          A RAM execution outcome with its reached state and charged instruction cost.

                                          • st : State

                                            Machine state reached on normal or abnormal termination.

                                          • cost : Nat

                                            Total number of charged machine instructions.

                                          • status : Status

                                            Normal, recoverable-failure or internal-error termination status.

                                          Instances For

                                            Sequential composition of outcomes: costs add; abnormal termination propagates.

                                            Equations
                                            Instances For
                                              def OrderMaintenance.Machine.runFor (f : State → Out) (x : Reg) :
                                              Nat → Nat → State → Out

                                              Iterations k, k+1, …, k+n-1 of a loop with counter x and body f; each costs one step plus the body.

                                              Equations
                                              Instances For

                                                Execute the RAM statement with explicit costs and guarded memory access.

                                                Equations
                                                Instances For