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.
Total natural-number contents of every named machine array.
Allocated capacity of each named machine array.
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
Update one point of a function.
Instances For
Assign values to a list of locals, left to right.
Equations
- OrderMaintenance.Machine.State.setLocs f (x_2 :: xs) (v :: vs) = OrderMaintenance.Machine.State.setLocs (OrderMaintenance.Machine.State.upd f x_2 v) xs vs
- OrderMaintenance.Machine.State.setLocs f x✝¹ x✝ = f
Instances For
The callee's frame: parameters bound to the argument values, every other local 0.
Equations
- s.enter params vs = { mem := s.mem, cap := s.cap, loc := OrderMaintenance.Machine.State.setLocs (fun (x : OrderMaintenance.Machine.Reg) => 0) params vs, peak := s.peak }
Instances For
Evaluate a binary natural-number primitive, rejecting invalid arithmetic.
Equations
- OrderMaintenance.Machine.BinOp.add.eval x✝¹ x✝ = some (x✝¹ + x✝)
- OrderMaintenance.Machine.BinOp.sub.eval x✝¹ x✝ = if x✝ ≤ x✝¹ then some (x✝¹ - x✝) else none
- OrderMaintenance.Machine.BinOp.mul.eval x✝¹ x✝ = some (x✝¹ * x✝)
- OrderMaintenance.Machine.BinOp.div.eval x✝¹ x✝ = some (x✝¹ / x✝)
- OrderMaintenance.Machine.BinOp.mod.eval x✝¹ x✝ = some (x✝¹ % x✝)
- OrderMaintenance.Machine.BinOp.shl.eval x✝¹ x✝ = some (x✝¹ * 2 ^ x✝)
- OrderMaintenance.Machine.BinOp.shr.eval x✝¹ x✝ = some (x✝¹ / 2 ^ x✝)
- OrderMaintenance.Machine.BinOp.lt.eval x✝¹ x✝ = some (if x✝¹ < x✝ then 1 else 0)
- OrderMaintenance.Machine.BinOp.le.eval x✝¹ x✝ = some (if x✝¹ ≤ x✝ then 1 else 0)
- OrderMaintenance.Machine.BinOp.eq.eval x✝¹ x✝ = some (if x✝¹ = x✝ then 1 else 0)
- OrderMaintenance.Machine.BinOp.and.eval x✝¹ x✝ = some (if x✝¹ ≠ 0 ∧ x✝ ≠ 0 then 1 else 0)
- OrderMaintenance.Machine.BinOp.or.eval x✝¹ x✝ = some (if x✝¹ ≠ 0 ∨ x✝ ≠ 0 then 1 else 0)
Instances For
Evaluate a RAM expression, rejecting out-of-bounds reads and invalid arithmetic.
Equations
- One or more equations did not get rendered due to their size.
- OrderMaintenance.Machine.Expr.eval s (OrderMaintenance.Machine.Expr.lit n) = some n
- OrderMaintenance.Machine.Expr.eval s (OrderMaintenance.Machine.Expr.var x_1) = some (s.loc x_1)
- OrderMaintenance.Machine.Expr.eval s a[[i]] = (OrderMaintenance.Machine.Expr.eval s i).bind fun (j : Nat) => if j < s.cap a then some (s.mem a j) else none
- OrderMaintenance.Machine.Expr.eval s (OrderMaintenance.Machine.Expr.un op e) = Option.map op.eval (OrderMaintenance.Machine.Expr.eval s e)
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
- One or more equations did not get rendered due to their size.
- OrderMaintenance.Machine.Expr.maxv s (OrderMaintenance.Machine.Expr.lit n) = n
- OrderMaintenance.Machine.Expr.maxv s (OrderMaintenance.Machine.Expr.var x_1) = s.loc x_1
- OrderMaintenance.Machine.Expr.maxv s a[[i]] = max (OrderMaintenance.Machine.Expr.maxv s i) ((OrderMaintenance.Machine.Expr.eval s a[[i]]).getD 0)
Instances For
Evaluate all argument expressions, failing if any expression is invalid.
Equations
- OrderMaintenance.Machine.evalList s es = List.mapM (fun (x : OrderMaintenance.Machine.Expr) => OrderMaintenance.Machine.Expr.eval s x) es
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
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Sequential composition of outcomes: costs add; abnormal termination propagates.
Equations
Instances For
Iterations k, k+1, …, k+n-1 of a loop with counter x and body f; each costs
one step plus the body.
Equations
- One or more equations did not get rendered due to their size.
- OrderMaintenance.Machine.runFor f x x✝¹ 0 x✝ = { st := x✝, cost := 0, status := OrderMaintenance.Machine.Status.ok }
Instances For
Execute the RAM statement with explicit costs and guarded memory access.
Equations
- One or more equations did not get rendered due to their size.
- OrderMaintenance.Machine.exec OrderMaintenance.Machine.Stmt.skip x✝ = { st := x✝, cost := 1, status := OrderMaintenance.Machine.Status.ok }
- OrderMaintenance.Machine.exec (c;; d) x✝ = (OrderMaintenance.Machine.exec c x✝).bind (OrderMaintenance.Machine.exec d)
- OrderMaintenance.Machine.exec OrderMaintenance.Machine.Stmt.fail x✝ = { st := x✝, cost := 1, status := OrderMaintenance.Machine.Status.fail }