Section Relations.
Variable E : Type.
Definition relation (E : Type) := E -> E -> Prop.
Definition app_rel (R : relation E) (x y : E) := R x y.
Definition reflexive (R : relation E) : Prop := forall x : E, app_rel R x x.
Definition symmetric (R : relation E) : Prop :=
forall x y : E, app_rel R x y -> app_rel R y x.
Definition transitive (R : relation E) : Prop :=
forall x y z : E, app_rel R x y -> app_rel R y z -> app_rel R x z.
Comments "A partial equivalence on" E
" is a relation which is transitive and symmetric:".
Definition partial_equivalence (R : relation E) : Prop :=
transitive R /\ symmetric R.
Comments "An equivalence relation is reflexive, symmetric and transitive:".
Definition equivalence (R : relation E) : Prop :=
reflexive R /\ partial_equivalence R.
Comments "Some immediate properties:".
compute in |- *. tauto.
Qed.
compute in |- *; tauto.
Qed.
compute in |- *; tauto.
Qed.
End Relations.
Hint Unfold reflexive transitive symmetric partial_equivalence equivalence:
algebra.
Hint Resolve equiv_refl equiv_sym equiv_trans: algebra.
Comments "Then we define a dedicated structure to represent sets:".
Record Setoid : Type :=
{Carrier :> Type; Equal : relation Carrier; Prf_equiv :> equivalence Equal}.
Hint Resolve Prf_equiv: algebra.
Comments
"A set is then given by a type (for its elements), a binary relation"
"and a proof that this relation is an equivalence relation".
Comments "We will write" (Equal x y)
"for the equality of two elements of a set".

Lemma Refl : forall (E : Setoid) (x : E), Equal x x.