Module ME := OrderedTypeFacts E.
Definition empty : t := let (s, _) := empty in s.
Definition is_empty (s : t) : bool :=
if is_empty s then true else false.
Definition mem (x : elt) (s : t) : bool :=
if mem x s then true else false.
Definition eq_dec := equal.
Definition equal (s s' : t) : bool :=
if equal s s' then true else false.
Definition subset (s s' : t) : bool :=
if subset s s' then true else false.
Definition choose (s : t) : option elt :=
match choose s with
| inleft (exist _ x _) => Some x
| inright _ => None
end.
Definition elements (s : t) : list elt := let (l, _) := elements s in l.
Hint Resolve elements_3 : core.
Definition max_elt (s : t) : option elt :=
match max_elt s with
| inleft (exist _ x _) => Some x
| inright _ => None
end.
Definition add (x : elt) (s : t) : t := let (s', _) := add x s in s'.
Definition remove (x : elt) (s : t) : t := let (s', _) := remove x s in s'.
Definition singleton (x : elt) : t := let (s, _) := singleton x in s.
Definition union (s s' : t) : t := let (s'', _) := union s s' in s''.
Definition inter (s s' : t) : t := let (s'', _) := inter s s' in s''.
Definition diff (s s' : t) : t := let (s'', _) := diff s s' in s''.
Definition cardinal (s : t) : nat := let (f, _) := cardinal s in f.
Definition fold (B : Type) (f : elt -> B -> B) (i : t)
(s : B) : B := let (fold, _) := fold f i s in fold.
Definition f_dec :
forall (f : elt -> bool) (x : elt), {f x = true} + {f x <> true}.
Hint Resolve compat_P_aux : core.
Definition filter (f : elt -> bool) (s : t) : t :=
let (s', _) := filter (P:=fun x => f x = true) (f_dec f) s in s'.
Definition for_all (f : elt -> bool) (s : t) : bool :=
if for_all (P:=fun x => f x = true) (f_dec f) s
then true
else false.
Definition exists_ (f : elt -> bool) (s : t) : bool :=
if exists_ (P:=fun x => f x = true) (f_dec f) s
then true
else false.
Definition partition (f : elt -> bool) (s : t) :
t * t :=
let (p, _) := partition (P:=fun x => f x = true) (f_dec f) s in p.

Lemma partition_1 :
forall (s : t) (f : elt -> bool),
compat_bool E.eq f -> Equal (fst (partition f s)) (filter f s).