(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
Global Set Automatic Coercions Import.
Global Set Asymmetric Patterns.
Set Implicit Arguments.
Unset Strict Implicit.
(** Title "Sets, relations, maps" *)
Section Sets1.
Comments
"Basically, algebraic structures are sets, in which we talk about elements, belonging, equality,"
"applications, equivalence relations, quotient sets, etc".
Comments
"Types in Coq are not well-suited to represent sets, because they cannot be quotiented".
Comments "We will define sets in Coq as types with an equivalence relation".
Comments "First, we need some definitions on binary relations on types:".
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:".

Lemma equiv_refl : forall R : relation E, equivalence R -> reflexive R.
compute in |- *. tauto.