Global Instance : forall T, Equivalence (@set_eq T).Definition set_incl {A} (m1 m2 : set A) :=
  forall (a : A), m1 a -> m2 a.Definition set0 {T} := [set _ : T | False].Definition setT {T} := [set _ : T | True].Implicit Types (a x : T) (A B : set T).Definition set1 a := eq a.Definition setU A B := [set x | x \in A \/ x \in B].Definition setI A B := [set x | x \in A /\ x \in B].Definition codom (f : T -> U) := [set y | exists x, f x = y].Definition bigcup A (F : T -> set U) := [set x | exists i, i \in A /\ x \in F i].Definition bigcap (A : set T) (F : T -> set U) :=
  [set x | forall (i : T), i \in A -> x \in F i].Definition imset {T U} (f : T -> U) A := bigcup A (fun x => set1 (f x)).Definition imset2 T U V (f : T -> U -> V) A1 A2 :=
  imset (prod_curry f) (setX A1 A2).Definition codom2 T U V (f : T -> U -> V) := codom (prod_curry f).Definition lift {T} (S : set T) : set (option T) :=
  Some @: S :|: [set None].

(* Specifications: *)
Lemma subset_eqP T (A B : set T) : (A <--> B) <-> (A \subset B /\ B \subset A).
Lemma subset_trans T (A1 A2 A3 : set T) : A1 \subset A2 -> A2 \subset A3 -> A1 \subset A3.
Lemma subset_refl T (A : set T) : A \subset A.
Lemma subset_singl : forall {T} (x y : T), [set x] \subset [set y] <-> y = x.
Lemma subset_respects_set_eq_l : forall (T : Type) (s1 s2 s3 : set T), s1 <--> s3 -> s3 \subset s2 -> s1 \subset s2.
Lemma subset_respects_set_eq_r : forall (T : Type) (s1 s2 s3 : set T), s3 <--> s2 -> s1 \subset s2 -> s1 \subset s3.
Lemma subset_respects_set_eq : forall {T : Type} {s1 s2 s1' s2' : set T}, s1 <--> s1' -> s2 <--> s2' -> s1' \subset s2' -> s1 \subset s2.
Lemma imsetT T U (f : T -> U) : f @: setT <--> codom f.
Lemma imset_id T (A : set T) : id @: A <--> A.
Lemma imset_incl {T U} (A B : set T) (f : T -> U): A \subset B -> f @: A \subset f @: B.
Lemma imset_eq {T U} (A B : set T) (f : T -> U): A <--> B -> f @: A <--> f @: B.
Lemma imset_in a b x (f : a -> b) (A : set a) : x \in A -> f x \in (f @: A).
Lemma imset_id_ext T (A : set T) f : (forall x, f x = x) -> f @: A <--> A.
Lemma imset_eq_ext a b (f g : a -> b) (A : set a) : (forall x, f x = g x) -> f @: A <--> g @: A.
Lemma coverE T (A : set T) : \bigcup_(x in A) [set x] <--> A.
Lemma setXT T U : setX [set: T] [set: U] <--> [set: T * U].
Lemma sub0set T (A : set T) : set0 \subset A.
Lemma bigcup_set0 T U (F : T -> set U) : \bigcup_(x in set0) F x <--> set0.
Lemma imset0 T U (f : T -> U) : f @: set0 <--> set0.
Lemma bigcup_set1 T U (F : T -> set U) y : \bigcup_(x in [set y]) F x <--> F y.
Lemma bigcup_setU_l: forall (U T : Type) (s1 s2 : set U) (f : U -> set T), \bigcup_(i in (s1 :|: s2)) f i <--> \bigcup_(i in s1) f i :|: \bigcup_(i in s2) f i.
Lemma bigcup_const A B (P : set B) : inhabited A -> (\bigcup_(_ : A) P) <--> P.
Lemma bigcup_const_2 A (x :A) B (P : set B) : (\bigcup_(_ in [set x]) P) <--> P.
Lemma bigcupC T U V A B (F : T -> U -> set V) : \bigcup_(i in A) \bigcup_(j in B) F i j <--> \bigcup_(j in B) \bigcup_(i in A) F i j.
Lemma incl_bigcupr T U A (F : T -> set U) G : (forall x, F x \subset G x) -> \bigcup_(x in A) F x \subset \bigcup_(x in A) G x.
Lemma eq_bigcupr T U A (F : T -> set U) G : (forall x, F x <--> G x) -> \bigcup_(x in A) F x <--> \bigcup_(x in A) G x.
Lemma incl_bigcupl T U A B (F : T -> set U) : A \subset B -> \bigcup_(x in A) F x \subset \bigcup_(x in B) F x.
Lemma eq_bigcupl T U A B (F : T -> set U) : A <--> B -> \bigcup_(x in A) F x <--> \bigcup_(x in B) F x.
Lemma incl_bigcup a b (x:a) (A : set a) (f:a->set b) : x \in A -> f x \subset \bigcup_(x in A) f x.
Lemma bigcup_flatten T U V A (F : T -> set U) (G : U -> set V) : \bigcup_(x in \bigcup_(y in A) F y) G x <--> \bigcup_(y in A) \bigcup_(x in F y) G x.
Lemma codom_apply {A B : Type} {f : A -> B} {x : A} : f x \in codom f.
Lemma codomE T U (f : T -> U) : codom f <--> \bigcup_x [set f x].
Lemma codom_id T : codom id <--> [set: T].
Lemma codom_const A B (x : B) : inhabited A -> codom (fun _ : A => x) <--> [set x].
Lemma curry_codom2l T U V (f : T -> U -> V) : codom (prod_curry f) <--> \bigcup_x1 codom (f x1).
Lemma imset_bigcup T U V (f : U -> V) A (F : T -> set U) : (f @: \bigcup_(x in A) (F x)) <--> \bigcup_(x in A) f @: F x.
Lemma bigcup_imset T U V (f : T -> U) A (F : U -> set V) : \bigcup_(y in f @: A) (F y) <--> \bigcup_(x in A) F (f x).
Lemma bigcup_codom T U V (f : T -> U) (F : U -> set V) : \bigcup_(y in codom f) (F y) <--> \bigcup_x F (f x).