Documentation

CslibFrontier.Computability.WordRAM.SymbolicExec.MemFrame

Memory facts across calls #

A proof about a word-RAM program carries memory invariants and cell values across calls: each subprogram specification gives a result state y together with either a whole-memory equation y.mem = x.mem, a frame ∀ a, P₁ a → … → y.mem a = x.mem a, a Set.EqOn y.mem x.mem R, a Modifies writes x.mem y.mem, or a store-free execution Exec w c x y n / ExecWithin w c x y T. Writing frame chains by hand repeats arithmetic disjointness proofs (by wram_omega) and manual .trans pipelines across intermediate states.

This file provides Code.StoreFree (kernel-decidable store-freeness giving Exec.mem_eq and ExecWithin.mem_eq) and mem_frame, the memory-framing twin of regs_frame (CslibFrontier/Computability/WordRAM/SymbolicExec/Frame.lean).

Main definitions #

Main results #

Store-free programs #

def Cslib.WordRAM.Op.StoreFree {B : Basis} {r : ℕ} :
Op B r → Prop

Whether a data instruction does not write to memory (is not Op.store).

Instances For
    @[instance_reducible]

    Decidability of whether a data instruction is store-free.

    @[simp]
    theorem Cslib.WordRAM.Op.storeFree_bin {r : ℕ} (f : BinOp) (d i j : Fin r) :
    (bin f d i j).StoreFree

    A binary operation instruction is store-free.

    @[simp]

    Reading the word width is store-free.

    @[simp]
    theorem Cslib.WordRAM.Op.storeFree_exactBin {r : ℕ} (f : BinOp) (d i j : Fin r) :

    An exact binary operation instruction is store-free.

    @[simp]

    Reading the word width over Basis.exact is store-free.

    @[simp]
    theorem Cslib.WordRAM.Op.storeFree_rename {B : Basis} {r r' : ℕ} (f : Fin r → Fin r') (o : Op B r) :

    Register renaming preserves store-freeness of a data instruction.

    A structured program is store-free when no instruction inside it is Op.store.

    Instances For
      @[instance_reducible]

      Decidability of whether a structured program is store-free.

      @[simp]
      theorem Cslib.WordRAM.Code.storeFree_rename {B : Basis} {r r' : ℕ} (f : Fin r → Fin r') (c : Code B r) :

      Register renaming preserves store-freeness of a structured program.

      theorem Cslib.WordRAM.Code.StoreFree.rename {B : Basis} {r r' : ℕ} {f : Fin r → Fin r'} {c : Code B r} (h : c.StoreFree) :

      A renamed store-free program is store-free.

      theorem Cslib.WordRAM.Exec.mem_eq {B : Basis} {r w : ℕ} {c : Code B r} {x y : Data r} {n : ℕ} (h : Exec w c x y n) (hc : c.StoreFree) :
      y.mem = x.mem

      Memory preservation. A store-free structured program leaves memory unchanged.

      theorem Cslib.WordRAM.ExecWithin.mem_eq {B : Basis} {r w T : ℕ} {c : Code B r} {x y : Data r} (h : ExecWithin w c x y T) (hc : c.StoreFree) :
      y.mem = x.mem

      Any store-free structured program leaves memory unchanged across a bounded execution.

      Decompose a goal through And, Prop-valued structures, and user-selected unfoldDefs Prop definitions, plus Modifies / Set.EqOn / universal quantifiers.

      Try to close a single atomic subgoal g. Returns none on success or some (orig, left) plus stuck entries for diagnostics.

      Attempt to close g with mem_frame, restoring the state and returning false on failure.

      mem_frame proves a fact about memory after a sequence of stores or calls from the frames among the hypotheses:

      • an exact memory equality z.mem = x.mem (or y.mem = m);
      • a single cell read z.mem a = v, z.mem a = x.mem a, or z.mem a = ?v (inferring ?v);
      • a quantified frame ∀ a, P₁ a → … → z.mem a = x.mem a, Set.EqOn z.mem x.mem R, or Modifies F x.mem z.mem;
      • an indexed slice equality ∀ i, P i → z.mem (base + i) = f i;
      • a conjunction or Prop-valued structure of any of the above (splitting fields recursively).

      Optional hints mem_frame [h₁, h₂, DefName] supply either extra fact terms / polymorphic frame lemmas (such as insertMem_of_outside) or def names to unfold when splitting goals and hypotheses (such as TableRep or restoreAfterHashInitData).

      It follows each memory map or read back through:

      • whole-memory equations h : y.mem = x.mem and state equations h : y = x;
      • store-free execution hypotheses he : Exec w c x y n / ExecWithin w c x y T (or any J with a J.mem_eq lemma), deciding Code.StoreFree c in the kernel when c is closed and structurally when c contains parameters;
      • pointwise frames ∀ a, P a → y.mem a = x.mem a, Set.EqOn, and Modifies;
      • Data.set, Data.comap, Data.extend, Data.havoc, Data.write, Function.update, and let-bound states;
      • concrete cell values h : x.mem a = v and indexed slice equations ∀ i, P i → x.mem (base + i) = f i.

      Frame premises (a ≠ b, a < base ∨ base + n ≤ a, a ∉ b.footprint, a ∉ Finset.Ico l u, a ∈ Set.Ico l u, …) are discharged by closed evaluation, hypotheses, omega, and silent @[wram_arith] unfolding without triggering linter.unnecessaryWramOmega.