Definition setd {T} (f : M.elt -> T) (g : T -> T -> T) (b : T) (s : M.t) :=
  listd f g b (M.elements s).

(* Specifications: *)
Lemma setd_add_In_refl : M.In x (M.add x s).
Lemma setd_add_In_refl_elems : In x (M.elements (M.add x s)).
Lemma setd_add_In : x = y \/ M.In y s -> M.In y (M.add x s).
Lemma setd_add_In_inv : M.In y (M.add x s) -> x = y \/ M.In y s.
Lemma elements_In {s0} : In y (M.elements s0) = M.In y s0.
Lemma empty_set_elems : M.elements M.empty = nil.
Lemma setd_add_In_inv_elems : In y (M.elements (M.add x s)) -> x = y \/ M.In y s.
Lemma setd_rem_In_inv : M.In y (M.remove x s) -> M.In y s.
Lemma setd_rem_In_inv_elems : In y (M.elements (M.remove x s)) -> In y (M.elements s).
Lemma setd_fold_left cls0 l s : listd f inter b l s -> setd f inter b cls0 s -> setd f inter b (fold_left h l cls0) s.
Lemma setd_fold cls0 l s : setd f inter b l s -> setd f inter b cls0 s -> setd f inter b (M.fold (Basics.flip h) cls0 l) s.
Lemma setd_un cls1 cls2 s : setd f inter TT cls1 s -> setd f inter TT cls2 s -> setd f inter TT (M.union cls1 cls2) s.
Lemma setd_base_separate: forall {A} f (b: pred A) cls, setd f inter b cls = andp b (setd f inter (@TT A) cls).
Lemma setd_add c cls s : setd f inter b cls s -> f c s -> setd f inter b (M.add c cls) s.
Lemma setd_remove c cls s : setd f inter TT cls s -> setd f inter TT (M.remove c cls) s.
Lemma setd_empty_set s : setd f inter TT M.empty s.
Lemma setd_filter bf cls s : setd f inter TT cls s -> setd f inter TT (M.filter bf cls) s.
Lemma listd_fold_left cls0 l s (H : forall c cls, listd f inter b cls s -> f c s -> listd f inter b (h cls c) s) : listd f inter b l s -> listd f inter b cls0 s -> listd f inter b (fold_left h l cls0) s.
Lemma listd_fold_left_wk cls0 l s : listd (fun c => forall s, f c s) and True l -> listd f inter b cls0 s -> listd f inter b (fold_left h l cls0) s.
Lemma listd_inter_map: forall {A B C} (l:list A) (f:B -> C -> Prop) h s, (forall x, In x l -> f (h x) s) -> inter (listd f inter TT (map h l)) TT s.
Lemma listd_inter_rev: forall {A B} (f: A -> B -> Prop) l, listd f inter TT (rev l) = listd f inter TT l.
Lemma orp_FF {A} (p : pred A) : orp p FF = p.
Lemma listd_un_rev: forall {A B} (f: A -> B -> Prop) l, listd f un FF (rev l) = listd f un FF l.