1- (* Typeclass instances to allow rewriting in categories. Examples are given later in the file. *)
1+ (** * Typeclass instances to allow rewriting in categories *)
22
3- (* Init.Tactics contains the definition of the Coq stdlib typeclass_inferences database. It must be imported before Basics.Overture . *)
3+ (** The file using the setoid rewriting machinery from the Coq standard library to allow rewriting in wild-categories. Examples are given later in the file . *)
44
5- (** Warning: This imports Coq.Setoids.Setoid from the standard library. Currently the setoid rewriting machinery requires this to work, it depends on this file explicitly. This imports the whole standard library into the namespace.
6-
7- All files that import WildCat/SetoidRewrite.v will also recursively import the entire Coq.Init standard library. *)
8-
9- (** Because of this, this file needs to be the *first* file Require'd in any file that uses it. Otherwise, the typeclasses hintdb is cleared, breaking typeclass inference. Moreover, if Foo Requires this file, then Foo must also be the first file Require'd in any file that Requires Foo, and so on. In the long term it would be good if this could be avoided. *)
5+ (** Init.Tactics contains the definition of the Coq stdlib typeclass_inferences database. It must be imported before Basics.Overture. Otherwise, the typeclasses hintdb is cleared, breaking typeclass inference. Because of this, this file also needs to be the first file Require'd in any file that uses it. Moreover, if Foo Requires this file, then Foo must also be the first file Require'd in any file that Requires Foo, and so on. In the long term it would be good if this could be avoided. *)
106
117#[warnings="-deprecated-from-Coq"]
128From Coq Require Init.Tactics.
@@ -18,36 +14,43 @@ Import CMorphisms.ProperNotations.
1814From HoTT Require Import WildCat.Core
1915 WildCat.NatTrans WildCat.Equiv.
2016
17+ (** ** Setoid rewriting *)
18+
2119#[export] Instance reflexive_proper_proxy {A : Type }
2220 {R : Relation A} `(Reflexive A R) (x : A)
2321 : CMorphisms.ProperProxy R x := reflexivity x.
2422
25- (* forall (x y : A), x $== y -> forall (a b : A), a $== b -> y $== b -> x $==a *)
23+ (** forall (x y : A), x $== y -> forall (a b : A), a $== b -> y $== b -> x $==a *)
2624#[export] Instance IsProper_GpdHom_from {A : Type } `{Is0Gpd A}
2725 : CMorphisms.Proper
2826 (GpdHom ==>
2927 GpdHom ==>
3028 CRelationClasses.flip CRelationClasses.arrow) GpdHom.
3129Proof .
30+ (* Add the next line to the start of any proof to see what it means: *)
31+ unfold "==>", CMorphisms.Proper, CRelationClasses.arrow, CRelationClasses.flip in *.
3232 intros x y eq_xy a b eq_ab eq_yb.
3333 exact (transitivity eq_xy (transitivity eq_yb
3434 (symmetry _ _ eq_ab))).
35+ (* We could also just write:
36+ exact (eq_xy $@ eq_yb $@ eq_ab^$).
37+ The advantage of the above proof is that it works for other transitive and symmetric relations. *)
3538Defined .
3639
37- (* forall (x y : A), x $== y -> forall (a b : A), a $== b -> x $== a -> y $== b *)
40+ (** forall (x y : A), x $== y -> forall (a b : A), a $== b -> x $== a -> y $== b *)
3841#[export] Instance IsProper_GpdHom_to {A : Type } `{Is0Gpd A}
3942 : CMorphisms.Proper
4043 (GpdHom ==>
4144 GpdHom ==>
4245 CRelationClasses.arrow) GpdHom.
4346Proof .
44- intros x y eq_xy a b eq_ab eq_yb .
45- unshelve refine (transitivity _ eq_ab).
46- unshelve refine (transitivity _ eq_yb ).
47+ intros x y eq_xy a b eq_ab eq_xa .
48+ refine (transitivity _ eq_ab).
49+ refine (transitivity _ eq_xa ).
4750 exact (symmetry _ _ eq_xy).
4851Defined .
4952
50- (* forall a : A, x $== y -> a $== x -> a $== y *)
53+ (** forall a x y : A, x $== y -> a $== x -> a $== y *)
5154#[export] Instance IsProper_GpdHom_to_a {A : Type } `{Is0Gpd A}
5255 {a : A}
5356 : CMorphisms.Proper
5861 by transitivity x.
5962Defined .
6063
61- (* forall a : A, x $== y -> a $== y -> a $== x *)
64+ (** forall a x y : A, x $== y -> a $== y -> a $== x *)
6265#[export] Instance IsProper_GpdHom_from_a {A : Type } `{Is0Gpd A}
6366 {a : A}
6467 : CMorphisms.Proper
@@ -71,15 +74,17 @@ Defined.
7174
7275Open Scope signatureT_scope.
7376
77+ (** If [R] is symmetric and [R x y -> R' (f x) (f y)], then [R y x -> R' (f x) (f y)]. *)
7478#[export] Instance symmetry_flip {A B : Type } {f : A -> B}
7579 {R : Relation A} {R' : Relation B} `{Symmetric _ R}
7680 (H0 : CMorphisms.Proper (R ++> R') f)
7781 : CMorphisms.Proper (R --> R') f.
7882Proof .
79- intros a b Rab .
80- apply H0. unfold CRelationClasses.flip. symmetry. exact Rab .
83+ intros a b Rba; unfold CRelationClasses.flip in Rba .
84+ apply H0. symmetry. exact Rba .
8185Defined .
8286
87+ (** If [R'] is symmetric and [R x y -> R' x' y' -> R'' (f x x') (f y y')], then [R x y -> R' y' x' -> R'' (f x x') (f y y')]. *)
8388#[export] Instance symmetric_flip_snd {A B C : Type } {R : Relation A}
8489 {R' : Relation B} {R'' : Relation C} `{Symmetric _ R'}
8590 (f : A -> B -> C) (H1 : CMorphisms.Proper (R ++> R' ++> R'') f)
@@ -88,40 +93,36 @@ Proof.
8893 intros a b Rab x y R'yx. apply H1; [ assumption | symmetry; assumption ].
8994Defined .
9095
91- #[export] Instance IsProper_fmap {A B : Type } `{Is1Cat A}
92- `{Is1Cat A} (F : A -> B) `{Is1Functor _ _ F} (a b : A)
93- : CMorphisms.Proper (GpdHom ==> GpdHom) (@fmap _ _ _ _ F _ a b) := fun _ _ eq => fmap2 F eq.
96+ #[export] Instance IsProper_fmap {A B : Type }
97+ (F : A -> B) `{Is1Functor _ _ F} (a b : A)
98+ : CMorphisms.Proper (GpdHom ==> GpdHom) (@fmap _ _ _ _ F _ a b)
99+ := fun _ _ => fmap2 F.
94100
95101#[export] Instance IsProper_catcomp_g {A : Type } `{Is1Cat A}
96102 {a b c : A} (g : b $-> c)
97- : CMorphisms.Proper (GpdHom ==> GpdHom) (@cat_comp _ _ _ a b c g).
98- Proof .
99- intros f1 f2.
100- apply (is0functor_postcomp a b c g ).
101- Defined .
103+ : CMorphisms.Proper (GpdHom ==> GpdHom) (@cat_comp _ _ _ a b c g)
104+ := fun _ _ => cat_postwhisker g.
102105
103106#[export] Instance IsProper_catcomp {A : Type } `{Is1Cat A}
104107 {a b c : A}
105108 : CMorphisms.Proper (GpdHom ==> GpdHom ==> GpdHom)
106109 (@cat_comp _ _ _ a b c).
107110Proof .
108111 intros g1 g2 eq_g f1 f2 eq_f.
109- rewrite eq_f.
110- apply (is0functor_precomp a b c f2).
111- exact eq_g.
112+ exact (cat_comp2 eq_f eq_g).
112113Defined .
113114
114115#[export] Instance gpd_hom_to_hom_proper {A B : Type } `{Is0Gpd A}
115116 {R : Relation B} (F : A -> B)
116- `{ CMorphisms.Proper _ (GpdHom ==> R) F}
117+ {H2 : CMorphisms.Proper (GpdHom ==> R) F}
117118 : CMorphisms.Proper (Hom ==> R) F.
118119Proof .
119120 intros a b eq_ab; apply H2; exact eq_ab.
120121Defined .
121122
122- #[export] Instance gpd_hom_is_proper1 {A : Type } `{Is0Gpd A}
123- : CMorphisms.Proper
124- (Hom ==> Hom ==> CRelationClasses.arrow) Hom.
123+ #[export] Instance IsProper_Hom {A : Type } `{Is0Gpd A}
124+ : CMorphisms.Proper
125+ (Hom ==> Hom ==> CRelationClasses.arrow) Hom.
125126Proof .
126127 intros x y eq_xy a b eq_ab f.
127128 refine (transitivity _ eq_ab).
@@ -130,35 +131,33 @@ Proof.
130131Defined .
131132
132133#[export] Instance transitive_hom {A : Type } `{Is01Cat A} {x : A}
133- : CMorphisms.Proper
134- (Hom ==> CRelationClasses.arrow) (Hom x).
135- Proof .
136- intros y z g f.
137- exact (g $o f).
138- Defined .
134+ : CMorphisms.Proper
135+ (Hom ==> CRelationClasses.arrow) (Hom x)
136+ := fun y z => cat_comp.
137+
138+ (** ** Examples of setoid rewriting *)
139139
140+ (** Rewriting works in hypotheses. *)
140141Proposition IsEpic_HasSection {A} `{Is1Cat A}
141142 {a b : A} (f : a $-> b) :
142143 SectionOf f -> Epic f.
143144Proof .
144- intros section c g h eq_gf_hf.
145- destruct section as [right_inverse is_section].
146- apply (is0functor_precomp _ _ _ right_inverse) in eq_gf_hf;
147- unfold cat_precomp in eq_gf_hf.
145+ intros [right_inverse is_section] c g h eq_gf_hf.
146+ apply cat_prewhisker with (h:=right_inverse) in eq_gf_hf.
148147 rewrite 2 cat_assoc, is_section, 2 cat_idr in eq_gf_hf.
149148 exact eq_gf_hf.
150149Defined .
151150
151+ (** A different approach, working in the goal. *)
152152Proposition IsMonic_HasRetraction {A} `{Is1Cat A}
153153 {b c : A} (f : b $-> c) :
154154 RetractionOf f -> Monic f.
155155Proof .
156- intros retraction a g h eq_fg_fh.
157- destruct retraction as [left_inverse is_retraction].
158- apply (is0functor_postcomp _ _ _ left_inverse) in eq_fg_fh;
159- unfold cat_postcomp in eq_fg_fh.
160- rewrite <- 2 cat_assoc, is_retraction, 2 cat_idl in eq_fg_fh.
161- assumption.
156+ intros [left_inverse is_retraction] a g h eq_fg_fh.
157+ rewrite <- (cat_idl g), <- (cat_idl h).
158+ rewrite <- is_retraction.
159+ rewrite 2 cat_assoc.
160+ exact (_ $@L eq_fg_fh).
162161Defined .
163162
164163Proposition nat_equiv_faithful {A B : Type }
@@ -168,19 +167,10 @@ Proposition nat_equiv_faithful {A B : Type}
168167 : Faithful F -> Faithful G.
169168Proof .
170169 intros faithful_F x y f g eq_Gf_Gg.
171- apply (@fmap _ _ _ _ _ (is0functor_precomp _
172- _ _ (cat_equiv_natequiv tau x))) in eq_Gf_Gg.
173- cbn in eq_Gf_Gg.
174- unfold cat_precomp in eq_Gf_Gg.
175- rewrite <- 2 (isnat tau) in eq_Gf_Gg.
176170 apply faithful_F.
177- assert (X : RetractionOf (tau y)). {
178- unshelve eapply Build_RetractionOf.
179- - exact ((tau y)^-1$).
180- - exact (cate_issect _ ).
181- }
182- apply IsMonic_HasRetraction in X.
183- apply X in eq_Gf_Gg. assumption.
171+ apply (cate_monic_equiv (tau y)).
172+ rewrite 2 (isnat tau).
173+ by apply cat_prewhisker.
184174Defined .
185175
186176Section SetoidRewriteTests.
0 commit comments