|
| 1 | +#[warnings="-deprecated-from-Coq"] |
| 2 | +From Coq Require Init.Tactics. (* TODO: Can remove this line and previous once Rocq 9.0 is our minimum. *) |
| 3 | +From HoTT Require Import Basics.Overture Basics.Tactics. |
| 4 | +From HoTT.WildCat Require Import Core NatTrans Equiv SetoidRewrite. |
| 5 | + |
| 6 | +(** * Examples and tests of setoid rewriting *) |
| 7 | + |
| 8 | +(** ** Examples of setoid rewriting *) |
| 9 | + |
| 10 | +(** See theories/WildCat/HomologicalAlgebra.v for many more examples of setoid rewriting. *) |
| 11 | + |
| 12 | +(** Rewriting works in hypotheses. *) |
| 13 | +Proposition epic_sectionof {A} `{Is1Cat A} |
| 14 | + {a b : A} (f : a $-> b) : |
| 15 | + SectionOf f -> Epic f. |
| 16 | +Proof. |
| 17 | + intros [right_inverse is_section] c g h eq_gf_hf. |
| 18 | + apply cat_prewhisker with (h:=right_inverse) in eq_gf_hf. |
| 19 | + rewrite 2 cat_assoc, is_section, 2 cat_idr in eq_gf_hf. |
| 20 | + exact eq_gf_hf. |
| 21 | +Defined. |
| 22 | + |
| 23 | +(** A different approach, working in the goal. *) |
| 24 | +Proposition monic_retractionof {A} `{Is1Cat A} |
| 25 | + {b c : A} (f : b $-> c) : |
| 26 | + RetractionOf f -> Monic f. |
| 27 | +Proof. |
| 28 | + intros [left_inverse is_retraction] a g h eq_fg_fh. |
| 29 | + rewrite <- (cat_idl g), <- (cat_idl h). |
| 30 | + rewrite <- is_retraction. |
| 31 | + rewrite 2 cat_assoc. |
| 32 | + exact (_ $@L eq_fg_fh). |
| 33 | +Defined. |
| 34 | + |
| 35 | +Proposition faithful_nat_equiv_faithful {A B : Type} |
| 36 | + {F G : A -> B} `{Is1Functor _ _ F} |
| 37 | + `{!Is0Functor G, !Is1Functor G} |
| 38 | + `{!HasEquivs B} (tau : NatEquiv F G) |
| 39 | + : Faithful F -> Faithful G. |
| 40 | +Proof. |
| 41 | + intros faithful_F x y f g eq_Gf_Gg. |
| 42 | + apply faithful_F. |
| 43 | + apply (cate_monic_equiv (tau y)). |
| 44 | + rewrite 2 (isnat tau). |
| 45 | + by apply cat_prewhisker. |
| 46 | +Defined. |
| 47 | + |
| 48 | +(** ** Tests of setoid rewriting *) |
| 49 | + |
| 50 | +Section SetoidRewriteTests. |
| 51 | + |
| 52 | + Goal forall (A : Type) `(H : Is0Gpd A) (a b c : A), |
| 53 | + a $== b -> b $== c -> a $== c. |
| 54 | + Proof. |
| 55 | + intros A ? ? ? a b c eq_ab eq_bc. |
| 56 | + by rewrite eq_ab, <- eq_bc. |
| 57 | + Defined. |
| 58 | + |
| 59 | + Goal forall (A : Type) `(H : Is0Gpd A) (a b c : A), |
| 60 | + a $== b -> b $== c -> a $== c. |
| 61 | + Proof. |
| 62 | + intros A ? ? ? a b c eq_ab eq_bc. |
| 63 | + symmetry. |
| 64 | + rewrite eq_ab, <- eq_bc. |
| 65 | + rewrite eq_bc. |
| 66 | + by rewrite <- eq_bc. |
| 67 | + Defined. |
| 68 | + |
| 69 | + Goal forall (A B : Type) (F : A -> B) `{Is1Functor _ _ F} (a b : A) (f g : a $-> b), f $== g -> fmap F f $== fmap F g. |
| 70 | + Proof. |
| 71 | + do 17 intro. |
| 72 | + intro eq_fg. |
| 73 | + by rewrite eq_fg. |
| 74 | + Defined. |
| 75 | + |
| 76 | + Goal forall (A : Type) `{Is1Cat A} (a b c : A) (f1 f2 : a $-> b) (g : b $-> c), f1 $== f2 -> g $o f1 $== g $o f2. |
| 77 | + Proof. |
| 78 | + do 11 intro. |
| 79 | + intro eq. |
| 80 | + rewrite <- eq. |
| 81 | + by rewrite eq. |
| 82 | + Defined. |
| 83 | + |
| 84 | + Goal forall (A : Type) `{Is1Cat A} (a b c : A) (f : a $-> b) (g1 g2 : b $-> c), g1 $== g2 -> g1 $o f $== g2 $o f. |
| 85 | + Proof. |
| 86 | + do 11 intro. |
| 87 | + intro eq. |
| 88 | + rewrite <- eq. |
| 89 | + rewrite eq. |
| 90 | + by rewrite <- eq. |
| 91 | + Defined. |
| 92 | + |
| 93 | + Goal forall (A : Type) `{Is1Cat A} (a b c : A) (f1 f2 : a $-> b) (g1 g2 : b $-> c), g1 $== g2 -> f1 $== f2 -> g1 $o f1 $== g2 $o f2. |
| 94 | + Proof. |
| 95 | + do 12 intro. |
| 96 | + intros eq_g eq_f. |
| 97 | + rewrite eq_g. |
| 98 | + rewrite <- eq_f. |
| 99 | + rewrite eq_f. |
| 100 | + by rewrite <- eq_g. |
| 101 | + Defined. |
| 102 | + |
| 103 | +End SetoidRewriteTests. |
0 commit comments