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".
intros E; try assumption.
cut (reflexive (Equal (s:=E))); auto with algebra.
Qed.
intros E; try assumption.
cut (symmetric (Equal (s:=E))); auto with algebra.
Qed.
intros E; try assumption.
cut (transitive (Equal (s:=E))); auto with algebra.
Qed.
Hint Resolve Refl: algebra.
Hint Immediate Sym: algebra.
Comments
"Every type in Coq can be seen as a set, with the Leibnitz equality:".
Let eqT_equiv : forall A : Type, equivalence (eq (A:=A)).
intros A; try assumption.
red in |- *.
split; [ try assumption | idtac ].
red in |- *.
unfold app_rel in |- *; auto with algebra.
red in |- *.
split; [ try assumption | idtac ].
red in |- *.
unfold app_rel in |- *; auto with algebra.
intros x y z H' H'0; try assumption.
rewrite H'; auto with algebra.
red in |- *.
unfold app_rel in |- *; auto with algebra.
Qed.
Definition Leibnitz_set (A : Type) : Setoid := Build_Setoid (eqT_equiv A).

Lemma Leibnitz_set_prop :
forall (A : Type) (x y : Leibnitz_set A), Equal x y -> x = y.