Fixpoint ptree_cmp {T : Type} (p1 p2: Maps.PTree.tree T)
         (e : T -> T -> bool) :=
match p1, p2 with
| Maps.PTree.Leaf, Maps.PTree.Leaf => true
| Maps.PTree.Node l1 i1 r1, Maps.PTree.Node l2 i2 r2 =>
  match i1, i2 with
    | Some v1, Some v2 => andb (e v1 v2)
                               (andb (ptree_cmp l1 l2 e)
                                     (ptree_cmp r1 r2 e))
    | None, None => (andb (ptree_cmp l1 l2 e)
                          (ptree_cmp r1 r2 e))
    | _, _ => false
  end
| _, _ => false
end.

(* Specifications: *)
Lemma ptree_cmp_sound : forall T p1 p2 e, (forall (i1 i2 : T), e i1 i2 = true -> i1 = i2) -> ptree_cmp p1 p2 e = true -> p1 = p2.