Hint Extern 0 (RIntro _ ⊤ _ _) =>
eapply rel_top_rintro : typeclass_instances.
Global Instance rel_top_equiv {A}:
@Equivalence A ⊤.
(** ** Relation equivalence *)
Definition eqrel {A B}: rel (rel A B) (rel A B) :=
(subrel /\ flip subrel)%rel.
Arguments eqrel {_ _} RA%rel RB%rel.
Global Instance eqrel_equivalence A B:
Equivalence (@eqrel A B).
Global Instance eqrel_subrel A B:
Related (@eqrel A B) (@subrel A B) subrel.
(** ** Relation composition *)
Definition rel_compose {A B C} (RAB: rel A B) (RBC: rel B C): rel A C :=
fun x z => exists y, RAB x y /\ RBC y z.
Hint Unfold rel_compose.
Global Instance rel_compose_subrel {A B C}:
Monotonic (@rel_compose A B C) (subrel ++> subrel ++> subrel).
Global Instance rel_compose_eqrel {A B C}:
Monotonic (@rel_compose A B C) (eqrel ==> eqrel ==> eqrel).
Global Instance rel_compose_params:
Params (@rel_compose) 4.

(* Specifications: *)
Lemma rel_compose_id_left {A B} (R: rel A B):
eqrel (rel_compose R eq) R.
Lemma rel_compose_id_right {A B} (R: rel A B):
eqrel (rel_compose eq R) R.
Lemma rel_compose_assoc {A B C D} (RAB: rel A B) (RBC: rel B C) (RCD: rel C D):
eqrel
(rel_compose (rel_compose RAB RBC) RCD)
(rel_compose RAB (rel_compose RBC RCD)).