Section MemoizingServer.
Variable l : Label.
Variable f : input -> option nat.
Variable prec : input -> bool.
Hypothesis prec_valid :
forall i, prec i -> exists v, f i = Some v.
Variables (cs cls : seq nid).
Notation nodes := (cs ++ cls).
Hypothesis Huniq : uniq nodes.
Notation cal := (CalculatorProtocol f prec cs cls l).
Notation sts := (snd_trans cal).
Notation rts := (rcv_trans cal).
Notation W := (mkWorld cal).
Variable sv : nid.
Hypothesis  Hs : sv \in cs.
Notation loc i := (getLocal sv (getStatelet i l)).
(* Server-specific infrastructure *)
Notation Sstate := (seq ((seq nat) * nat)).
Definition state_wf (s : Sstate) :=
forall e, e \in s -> f e.1 = Some e.2.
Definition state0 : Sstate := [::].
(* Lookup tables *)
Definition update_mem_table (s : Sstate) args v :=
(args, v) :: s.
Fixpoint lookup_mem_table (s : Sstate) args : option nat :=
match s with
| x :: xs => if x.1 == args
then Some x.2
else lookup_mem_table xs args
| [::] => None
end.

Lemma lookup_valid' s args :
state_wf s ->
forall v, lookup_mem_table s args = Some v ->
f args = Some v.