Documentation

Complexity.Computability.Ram.Source.State

Parameter binding and returned local frames #

Function arguments use ordinary list indexing. Return discards callee locals, restores caller locals except the destinations, and retains the actual shared memory and I/O effects. The frame rule below simplifies a pure call to a register update only after all three shared-state equalities are proved.

These are equations about the existing source state, not a new calling convention, evaluator, or cost model.

@[simp]
theorem Ram.Source.State.enter_regs {w : Nat} (s : State w) (args : List (Word w)) (r : Reg) :
(s.enter args).regs r = args[r]?.getD 0
theorem Ram.Source.State.enter_regs_getElem {w : Nat} (s : State w) (args : List (Word w)) (r : Reg) (h : r < args.length) :
(s.enter args).regs r = args[r]

A parameter within the argument list has its ordinary list value.

theorem Ram.Source.State.enter_regs_of_length_le {w : Nat} (s : State w) (args : List (Word w)) (r : Reg) (h : args.length ≤ r) :
(s.enter args).regs r = 0

Non-parameter locals start at zero, rather than inheriting caller values.

@[simp]
theorem Ram.Source.State.setReg_setReg {w : Nat} (s : State w) (r : Reg) (a b : Word w) :
(s.setReg r a).setReg r b = s.setReg r b
theorem Ram.Source.State.setRegs_regs {w : Nat} (s : State w) (dsts : List Reg) (values : List (Word w)) :
(s.setRegs dsts values).regs = List.foldl (fun (regs : Reg → Word w) (field : Reg × Word w) (r : Reg) => if r = field.fst then field.snd else regs r) s.regs (dsts.zip values)

The register projection of ordered assignment is the corresponding ordinary list fold; shared state is not part of the assignment.

theorem Ram.Source.State.setRegs_getElem {w : Nat} (s : State w) (dsts : List Reg) (values : List (Word w)) (distinct : dsts.Nodup) (hlength : dsts.length = values.length) (i : Nat) (hi : i < dsts.length) :
(s.setRegs dsts values).regs dsts[i] = values[i]

Distinct destinations expose each field separately. Equal lengths prevent truncation, while ordinary assignment itself also permits repeated destinations.

@[simp]
theorem Ram.Source.State.leave_nil {w : Nat} (caller callee : State w) (results : List Expr) :
caller.leave callee [] results = { regs := caller.regs, mem := callee.mem, input := callee.input, outputRev := callee.outputRev }
@[simp]
theorem Ram.Source.State.leave_singleton {w : Nat} (caller callee : State w) (dst : Reg) (result : Expr) :
caller.leave callee [dst] [result] = { regs := caller.regs, mem := callee.mem, input := callee.input, outputRev := callee.outputRev }.setReg dst (callee.eval result)
theorem Ram.Source.State.leave_getElem {w : Nat} (caller callee : State w) (dsts : List Reg) (results : List Expr) (distinct : dsts.Nodup) (hlength : dsts.length = results.length) (i : Nat) (hi : i < dsts.length) :
(caller.leave callee dsts results).regs dsts[i] = callee.eval results[i]

Return fields are all observed in the original callee state, even when an earlier caller destination has the same index as a later result expression.

theorem Ram.Source.State.leave_eq_setRegs_of_frame {w : Nat} (caller callee : State w) (dsts : List Reg) (results : List Expr) (memory : callee.mem = caller.mem) (input : callee.input = caller.input) (output : callee.outputRev = caller.outputRev) :
caller.leave callee dsts results = caller.setRegs dsts (List.map callee.eval results)

A call with unchanged shared memory and I/O is an ordered local assignment of its actual returned fields. No callee-local preservation is required.

theorem Ram.Source.State.leave_eq_setReg_of_frame {w : Nat} (caller callee : State w) (dst : Reg) (result : Expr) (memory : callee.mem = caller.mem) (input : callee.input = caller.input) (output : callee.outputRev = caller.outputRev) :
caller.leave callee [dst] [result] = caller.setReg dst (callee.eval result)

A call with proved unchanged shared memory and I/O is precisely a local assignment of its actual return value. Callee registers need not be preserved.

@[simp]
theorem Ram.Source.State.leave_enter_setReg {w : Nat} (s : State w) (args : List (Word w)) (calleeReg dst : Reg) (value : Word w) :
s.leave ((s.enter args).setReg calleeReg value) [dst] [Expr.var calleeReg] = s.setReg dst value

The callee's return register and the caller's destination can be different. No other caller local or shared component changes for this endpoint.