| 1 |
From Coq Require Import Morphisms. |
| 2 |
Require Import Crypto.Util.Tactics.RewriteHyp. |
| 3 |
Require Import Crypto.Algebra.Hierarchy. |
| 4 |
|
| 5 |
Section Monoid. |
| 6 |
Context {T eq op id} {monoid:@monoid T eq op id}. |
| 7 |
Local Infix "=" := eq : type_scope. Local Notation "a <> b" := (not (a = b)) : type_scope. |
| 8 |
Local Infix "*" := op. |
| 9 |
Declare Scope eq_scope. |
| 10 |
Local Infix "=" := eq : eq_scope. |
| 11 |
Local Open Scope eq_scope. |
| 12 |
|
| 13 |
Lemma cancel_right z iz (Hinv:op z iz = id) : |
| 14 |
forall x y, x * z = y * z <-> x = y. |
| 15 |
Proof using Type*. |
| 16 |
intros x y; split; intro. |
| 17 |
{ assert (op (op x z) iz = op (op y z) iz) as Hcut by (rewrite_hyp ->!*; reflexivity). |
| 18 |
rewrite <-associative in Hcut. |
| 19 |
rewrite <-!associative, !Hinv, !right_identity in Hcut; exact Hcut. } |
| 20 |
{ rewrite_hyp ->!*. reflexivity. } |
| 21 |
Qed. |
| 22 |
|
| 23 |
Lemma cancel_left z iz (Hinv:op iz z = id) : |
| 24 |
forall x y, z * x = z * y <-> x = y. |
| 25 |
Proof using Type*. |
| 26 |
intros x y; split; intros. |
| 27 |
{ assert (op iz (op z x) = op iz (op z y)) as Hcut by (rewrite_hyp ->!*; reflexivity). |
| 28 |
rewrite !associative, !Hinv, !left_identity in Hcut; exact Hcut. } |
| 29 |
{ rewrite_hyp ->!*; reflexivity. } |
| 30 |
Qed. |
| 31 |
|
| 32 |
Lemma inv_inv x ix iix : ix*x = id -> iix*ix = id -> iix = x. |
| 33 |
Proof using Type*. |
| 34 |
intros Hi Hii. |
| 35 |
assert (H:op iix id = op iix (op ix x)) by (rewrite Hi; reflexivity). |
| 36 |
rewrite associative, Hii, left_identity, right_identity in H; exact H. |
| 37 |
Qed. |
| 38 |
|
| 39 |
Lemma inv_op x y ix iy : ix*x = id -> iy*y = id -> (iy*ix)*(x*y) =id. |
| 40 |
Proof using Type*. |
| 41 |
intros Hx Hy. |
| 42 |
cut (iy * (ix*x) * y = id); try intro H. |
| 43 |
{ rewrite <-!associative; rewrite <-!associative in H; exact H. } |
| 44 |
rewrite Hx, right_identity, Hy. reflexivity. |
| 45 |
Qed. |
| 46 |
|
| 47 |
End Monoid. |
| 48 |
|
| 49 |
Section Homomorphism. |
| 50 |
Context {T EQ OP ID} {monoidT: @monoid T EQ OP ID }. |
| 51 |
Context {T' eq op id} {monoidT': @monoid T' eq op id }. |
| 52 |
Context {phi:T->T'}. |
| 53 |
Local Infix "=" := eq. Local Infix "=" := eq : type_scope. |
| 54 |
Class is_homomorphism := |
| 55 |
{ |
| 56 |
homomorphism : forall a b, phi (OP a b) = op (phi a) (phi b); |
| 57 |
|
| 58 |
is_homomorphism_phi_proper : Proper (respectful EQ eq) phi |
| 59 |
}. |
| 60 |
Global Existing Instance is_homomorphism_phi_proper. |
| 61 |
End Homomorphism. |
| 62 |
|
| 63 |
Section HomomorphismComposition. |
| 64 |
Context {G EQ OP ID} {monoidG:@monoid G EQ OP ID}. |
| 65 |
Context {H eq op id} {monoidH:@monoid H eq op id}. |
| 66 |
Context {K eqK opK idK} {monoidK:@monoid K eqK opK idK}. |
| 67 |
Context {phi:G->H} {phi':H->K} |
| 68 |
{Hphi:@is_homomorphism G EQ OP H eq op phi} |
| 69 |
{Hphi':@is_homomorphism H eq op K eqK opK phi'}. |
| 70 |
Lemma is_homomorphism_compose |
| 71 |
{phi'':G->K} |
| 72 |
(Hphi'' : forall x, eqK (phi' (phi x)) (phi'' x)) |
| 73 |
: @is_homomorphism G EQ OP K eqK opK phi''. |
| 74 |
Proof using Hphi Hphi' monoidK. |
| 75 |
split; repeat intro; rewrite <- !Hphi''. |
| 76 |
{ rewrite !homomorphism; reflexivity. } |
| 77 |
{ apply Hphi', Hphi; assumption. } |
| 78 |
Qed. |
| 79 |
|
| 80 |
Global Instance is_homomorphism_compose_refl |
| 81 |
: @is_homomorphism G EQ OP K eqK opK (fun x => phi' (phi x)) |
| 82 |
:= is_homomorphism_compose (fun x => reflexivity _). |
| 83 |
End HomomorphismComposition. |