End EMap.
(** * A partial implementation of trees over any type that injects into type [positive] *)
Module ITree(X: INDEXED_TYPE).
Definition elt := X.t.
Definition elt_eq := X.eq.
Definition t : Type -> Type := PTree.t.
Definition empty (A: Type): t A := PTree.empty A.
Definition get (A: Type) (k: elt) (m: t A): option A := PTree.get (X.index k) m.
Definition set (A: Type) (k: elt) (v: A) (m: t A): t A := PTree.set (X.index k) v m.
Definition remove (A: Type) (k: elt) (m: t A): t A := PTree.remove (X.index k) m.

(* Specifications: *)
Theorem gempty:
forall (A: Type) (i: elt), get i (empty A) = None.
Theorem gss:
forall (A: Type) (i: elt) (x: A) (m: t A), get i (set i x m) = Some x.
Theorem gso:
forall (A: Type) (i j: elt) (x: A) (m: t A),
i <> j -> get i (set j x m) = get i m.
Theorem gsspec:
forall (A: Type) (i j: elt) (x: A) (m: t A),
get i (set j x m) = if elt_eq i j then Some x else get i m.
Theorem grs:
forall (A: Type) (i: elt) (m: t A), get i (remove i m) = None.
Theorem gro:
forall (A: Type) (i j: elt) (m: t A),
i <> j -> get i (remove j m) = get i m.
Theorem grspec:
forall (A: Type) (i j: elt) (m: t A),
get i (remove j m) = if elt_eq i j then None else get i m.
Theorem gempty:
forall (A: Type) (i: elt), get i (empty A) = None.
Theorem gss:
forall (A: Type) (i: elt) (x: A) (m: t A), get i (set i x m) = Some x.
Theorem gso:
forall (A: Type) (i j: elt) (x: A) (m: t A),
i <> j -> get i (set j x m) = get i m.
Theorem gsspec:
forall (A: Type) (i j: elt) (x: A) (m: t A),
get i (set j x m) = if elt_eq i j then Some x else get i m.
Theorem grs:
forall (A: Type) (i: elt) (m: t A), get i (remove i m) = None.
Theorem gro:
forall (A: Type) (i j: elt) (m: t A),
i <> j -> get i (remove j m) = get i m.
Theorem grspec:
forall (A: Type) (i j: elt) (m: t A),
get i (remove j m) = if elt_eq i j then None else get i m.