(** * Semi-lattice over maps *)
Set Implicit Arguments.
(** Given a semi-lattice (without top) [L], the following functor implements a semi-lattice structure over finite maps from positive numbers to [L.t]. The default value for these maps is [L.bot].  Bottom elements are not smashed. *)
Module LPMap1(L: SEMILATTICE) <: SEMILATTICE.
Definition t := PTree.t L.t.
Definition get (p: positive) (x: t) : L.t :=
match x!p with None => L.bot | Some x => x end.
Definition set (p: positive) (v: L.t) (x: t) : t :=
if L.beq v L.bot
then PTree.remove p x
else PTree.set p v x.

(* Specifications: *)
Lemma gsspec:
forall p v x q,
L.eq (get q (set p v x)) (if peq q p then v else get q x).