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).

Lemma eq_trans: forall x y z, eq x y -> eq y z -> eq x z.