1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* Typeclass-based setoids. Definitions on [Equivalence].
11
Author: Matthieu Sozeau
12
Institution: LRI, CNRS UMR 8623 - Universit�copyright Paris Sud
13
91405 Orsay, France *)
15
(* $Id: Equivalence.v 12187 2009-06-13 19:36:59Z msozeau $ *)
17
Require Import Coq.Program.Basics.
18
Require Import Coq.Program.Tactics.
20
Require Import Coq.Classes.Init.
21
Require Import Relation_Definitions.
22
Require Export Coq.Classes.RelationClasses.
23
Require Import Coq.Classes.Morphisms.
25
Set Implicit Arguments.
26
Unset Strict Implicit.
28
Open Local Scope signature_scope.
30
Definition equiv `{Equivalence A R} : relation A := R.
32
(** Overloaded notations for setoid equivalence and inequivalence. Not to be confused with [eq] and [=]. *)
34
Notation " x === y " := (equiv x y) (at level 70, no associativity) : equiv_scope.
36
Notation " x =/= y " := (complement equiv x y) (at level 70, no associativity) : equiv_scope.
38
Open Local Scope equiv_scope.
40
(** Overloading for [PER]. *)
42
Definition pequiv `{PER A R} : relation A := R.
44
(** Overloaded notation for partial equivalence. *)
46
Infix "=~=" := pequiv (at level 70, no associativity) : equiv_scope.
48
(** Shortcuts to make proof search easier. *)
50
Program Instance equiv_reflexive `(sa : Equivalence A) : Reflexive equiv.
52
Program Instance equiv_symmetric `(sa : Equivalence A) : Symmetric equiv.
54
Program Instance equiv_transitive `(sa : Equivalence A) : Transitive equiv.
58
transitivity y ; auto.
61
(** Use the [substitute] command which substitutes an equivalence in every hypothesis. *)
63
Ltac setoid_subst H :=
65
?x === ?y => substitute H ; clear H x
68
Ltac setoid_subst_nofail :=
70
| [ H : ?x === ?y |- _ ] => setoid_subst H ; setoid_subst_nofail
74
(** [subst*] will try its best at substituting every equality in the goal. *)
76
Tactic Notation "subst" "*" := subst_no_fail ; setoid_subst_nofail.
78
(** Simplify the goal w.r.t. equivalence. *)
80
Ltac equiv_simplify_one :=
82
| [ H : ?x === ?x |- _ ] => clear H
83
| [ H : ?x === ?y |- _ ] => setoid_subst H
84
| [ |- ?x =/= ?y ] => let name:=fresh "Hneq" in intro name
85
| [ |- ~ ?x === ?y ] => let name:=fresh "Hneq" in intro name
88
Ltac equiv_simplify := repeat equiv_simplify_one.
90
(** "reify" relations which are equivalences to applications of the overloaded [equiv] method
91
for easy recognition in tactics. *)
95
| [ s : Equivalence ?A ?R, H : ?R ?x ?y |- _ ] => change R with (@equiv A R s) in H
96
| [ s : Equivalence ?A ?R |- context C [ ?R ?x ?y ] ] => change (R x y) with (@equiv A R s x y)
99
Ltac equivify := repeat equivify_tac.
103
(** Here we build an equivalence instance for functions which relates respectful ones only,
104
we do not export it. *)
106
Definition respecting `(eqa : Equivalence A (R : relation A), eqb : Equivalence B (R' : relation B)) : Type :=
107
{ morph : A -> B | respectful R R' morph morph }.
109
Program Instance respecting_equiv `(eqa : Equivalence A R, eqb : Equivalence B R') :
110
Equivalence (fun (f g : respecting eqa eqb) => forall (x y : A), R x y -> R' (proj1_sig f x) (proj1_sig g y)).
112
Solve Obligations using unfold respecting in * ; simpl_relation ; program_simpl.
116
unfold respecting in *. program_simpl. transitivity (y y0); auto. apply H0. reflexivity.
121
(** The default equivalence on function spaces, with higher-priority than [eq]. *)
123
Program Instance pointwise_equivalence {A} `(eqb : Equivalence B eqB) :
124
Equivalence (pointwise_relation A eqB) | 9.
128
transitivity (y a) ; auto.