End ListMaps.
Section Logs.
(* A log is a map from Z, and a finite log has a latest element. *)
Context {B : Type}.
Definition log_latest s (v1 : Z) (v2 : B) := s v1 = Some v2 /\ forall v', v1 < v' -> s v' = None.

(* Specifications: *)
Lemma log_latest_singleton : forall v1 v2, log_latest (singleton v1 v2) v1 v2.
Lemma log_incl_latest : forall k1 k2 v1 v2 log1 log2 (Hincl : map_incl log1 log2)
(Hv1 : log1 k1 = Some v1) (Hlatest : log_latest log2 k2 v2), k1 <= k2.
Lemma log_latest_upd : forall log v1 v2 v1' v2', log_latest log v1 v2 -> v1 < v1' ->
map_incl log (map_upd log v1' v2') /\ log_latest (map_upd log v1' v2') v1' v2'.
Lemma log_latest_inj : forall log v1 v2 v1' v2' (H1 : log_latest log v1 v2) (H1' : log_latest log v1' v2'),
v1 = v1' /\ v2 = v2'.
Lemma log_latest_add : forall m1 m2 k1 k2 (v1 v2 : B)
(Hlatest1 : log_latest m1 k1 v1) (Hlatest2 : log_latest m2 k2 v2),
log_latest (map_add m1 m2) (Z.max k1 k2) (if zlt k1 k2 then v2 else v1).
Lemma log_latest_upd_list : forall l (m : Z -> option B) k v k' v' (Hm : log_latest m k v)
(Hlast : last l (k, v) = (k', v')) (Hlt : k <= k') (Hordered : Forall (fun '(k, v) => k <= k') l),
log_latest (map_upd_list m l) k' v'.