Module LPMap(L: SEMILATTICE_WITH_TOP) <: SEMILATTICE_WITH_TOP.
Inductive t' : Type :=
| Bot: t'
| Top_except: PTree.t L.t -> t'.
Definition t: Type := t'.
Definition get (p: positive) (x: t) : L.t :=
match x with
| Bot => L.bot
| Top_except m => match m!p with None => L.top | Some x => x end
end.
Definition set (p: positive) (v: L.t) (x: t) : t :=
match x with
| Bot => Bot
| Top_except m =>
if L.beq v L.bot
then Bot
else Top_except (if L.beq v L.top then PTree.remove p m else PTree.set p v m)
end.
Definition eq (x y: t) : Prop :=
forall p, L.eq (get p x) (get p y).
Definition beq (x y: t) : bool :=
match x, y with
| Bot, Bot => true
| Top_except m, Top_except n => PTree.beq L.beq m n
| _, _ => false
end.
Definition ge (x y: t) : Prop :=
forall p, L.ge (get p x) (get p y).
Definition bot := Bot.
Definition top := Top_except (PTree.empty L.t).

Lemma get_top: forall p, get p top = L.top.