Debian Codegraph @

src/Algebra/Group.v

raw
1 From Coq Require Import Morphisms.
2 Require Import Crypto.Util.Relations (*Crypto.Util.Tactics*).
3 Require Import Crypto.Algebra.Hierarchy Crypto.Algebra.Monoid.
4
5 Section BasicProperties.
6 Context {T eq op id inv} `{@group T eq op id inv}.
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_left : forall z x y, z*x = z*y <-> x = y.
14 Proof using Type*. epose Monoid.cancel_left; epose left_inverse; eauto. Qed.
15 Lemma cancel_right : forall z x y, x*z = y*z <-> x = y.
16 Proof using Type*. epose Monoid.cancel_right; epose right_inverse; eauto. Qed.
17 Lemma inv_inv x : inv(inv(x)) = x.
18 Proof using Type*. epose Monoid.inv_inv; epose left_inverse; eauto. Qed.
19 Lemma inv_op_ext x y : (inv y*inv x)*(x*y) =id.
20 Proof using Type*. epose Monoid.inv_op; epose left_inverse; eauto. Qed.
21
22 Lemma inv_unique x ix : ix * x = id -> ix = inv x.
23 Proof using Type*.
24 intro Hix.
25 cut (ix*x*inv x = inv x).
26 - rewrite <-associative, right_inverse, right_identity; trivial.
27 - rewrite Hix, left_identity; reflexivity.
28 Qed.
29
30 Lemma inv_bijective x y : inv x = inv y <-> x = y.
31 Proof using Type*.
32 split; intro Hi; rewrite ?Hi; try reflexivity.
33 assert (Hii:inv (inv x) = inv (inv y)) by (rewrite Hi; reflexivity).
34 rewrite 2inv_inv in Hii; exact Hii.
35 Qed.
36
37 Lemma inv_op x y : inv (x*y) = inv y*inv x.
38 Proof using Type*.
39 symmetry. etransitivity.
40 2:eapply inv_unique.
41 2:eapply inv_op_ext.
42 reflexivity.
43 Qed.
44
45 Lemma inv_id : inv id = id.
46 Proof using Type*. symmetry. eapply inv_unique, left_identity. Qed.
47
48 Lemma inv_id_iff x : inv x = id <-> x = id.
49 Proof using Type*.
50 split; intro Hi; rewrite ?Hi, ?inv_id; try reflexivity.
51 rewrite <-inv_id, inv_bijective in Hi; exact Hi.
52 Qed.
53
54 Lemma inv_nonzero_nonzero x : x <> id <-> inv x <> id.
55 Proof using Type*. setoid_rewrite inv_id_iff; reflexivity. Qed.
56
57 Lemma eq_r_opp_r_inv a b c : a = op c (inv b) <-> op a b = c.
58 Proof using Type*.
59 split; intro Hx; rewrite Hx || rewrite <-Hx;
60 rewrite <-!associative, ?left_inverse, ?right_inverse, right_identity;
61 reflexivity.
62 Qed.
63
64 Section ZeroNeqOne.
65 Context {one} `{is_zero_neq_one T eq id one}.
66 Lemma opp_one_neq_zero : inv one <> id.
67 Proof using Type*. setoid_rewrite inv_id_iff. exact one_neq_zero. Qed.
68 Lemma zero_neq_opp_one : id <> inv one.
69 Proof using Type*. intro Hx. symmetry in Hx. eauto using opp_one_neq_zero. Qed.
70 End ZeroNeqOne.
71 End BasicProperties.
72
73 Section Homomorphism.
74 Context {G EQ OP ID INV} {groupG:@group G EQ OP ID INV}.
75 Context {H eq op id inv} {groupH:@group H eq op id inv}.
76 Context {phi:G->H}`{homom:@Monoid.is_homomorphism G EQ OP H eq op phi}.
77 Local Infix "=" := eq. Local Infix "=" := eq : type_scope.
78
79 Lemma homomorphism_id : phi ID = id.
80 Proof using Type*.
81 assert (Hii: op (phi ID) (phi ID) = op (phi ID) id) by
82 (rewrite <- Monoid.homomorphism, left_identity, right_identity; reflexivity).
83 rewrite cancel_left in Hii; exact Hii.
84 Qed.
85
86 Lemma homomorphism_inv x : phi (INV x) = inv (phi x).
87 Proof using Type*.
88 apply inv_unique.
89 rewrite <- Monoid.homomorphism, left_inverse, homomorphism_id; reflexivity.
90 Qed.
91
92 Lemma compose_homomorphism
93 {H2 eq2 op2 id2 inv2} {groupH2:@group H2 eq2 op2 id2 inv2}
94 {phi2:H->H2}`{homom2:@Monoid.is_homomorphism H eq op H2 eq2 op2 phi2}
95 : @Monoid.is_homomorphism G EQ OP H2 eq2 op2 (fun x => phi2 (phi x)).
96 Proof.
97 split; repeat intro.
98 { do 2 rewrite homomorphism. f_equiv. }
99 { f_equiv. f_equiv. trivial. }
100 Qed.
101 End Homomorphism.
102
103 Section GroupByIsomorphism.
104 Context {G} {EQ:G->G->Prop} {OP:G->G->G} {ID:G} {INV:G->G}.
105 Context {H} {eq : H -> H -> Prop} {op : H -> H -> H} {id : H} {inv : H -> H}.
106 Context {phi:G->H} {phi':H->G}.
107 Local Infix "=" := EQ. Local Infix "=" := EQ : type_scope.
108
109 Class isomorphic_groups :=
110 {
111 #[global] isomorphic_groups_group_G :: @group G EQ OP ID INV;
112 #[global] isomorphic_groups_group_H :: @group H eq op id inv;
113 #[global] isomorphic_groups_hom_GH :: @Monoid.is_homomorphism G EQ OP H eq op phi;
114 #[global] isomorphic_groups_hom_HG :: @Monoid.is_homomorphism H eq op G EQ OP phi';
115 }.
116
117 Lemma group_by_isomorphism
118 (groupG:@group G EQ OP ID INV)
119 (phi'_phi_id : forall A, phi' (phi A) = A)
120 (phi'_eq : forall a b, EQ (phi' a) (phi' b) <-> eq a b)
121 (phi'_op : forall a b, phi' (op a b) = OP (phi' a) (phi' b))
122 (phi'_inv : forall a, phi' (inv a) = INV (phi' a))
123 (phi'_id : phi' id = ID)
124 : isomorphic_groups.
125 Proof using Type*.
126 repeat match goal with
127 | [ H : _/\_ |- _ ] => destruct H; try clear H
128 | [ H : commutative_group |- _ ] => destruct H; try clear H
129 | [ H : group |- _ ] => destruct H; try clear H
130 | [ H : monoid |- _ ] => destruct H; try clear H
131 | [ H : is_commutative |- _ ] => destruct H; try clear H
132 | [ H : is_associative |- _ ] => destruct H; try clear H
133 | [ H : is_left_identity |- _ ] => destruct H; try clear H
134 | [ H : is_right_identity |- _ ] => destruct H; try clear H
135 | [ H : Equivalence _ |- _ ] => destruct H; try clear H
136 | [ H : is_left_inverse |- _ ] => destruct H; try clear H
137 | [ H : is_right_inverse |- _ ] => destruct H; try clear H
138 | _ => intro
139 | _ => split
140 | [ H : eq _ _ |- _ ] => apply phi'_eq in H
141 | [ |- eq _ _ ] => apply phi'_eq
142 | [ H : EQ _ _ |- _ ] => rewrite H
143 | _ => progress erewrite ?phi'_op, ?phi'_inv, ?phi'_id, ?phi'_phi_id by reflexivity
144 | [ H : _ |- _ ] => progress erewrite ?phi'_op, ?phi'_inv, ?phi'_id in H by reflexivity
145 | _ => solve [ eauto ]
146 end.
147 Qed.
148 End GroupByIsomorphism.
149
150 Section CommutativeGroupByIsomorphism.
151 Context {G} {EQ:G->G->Prop} {OP:G->G->G} {ID:G} {INV:G->G}.
152 Context {H} {eq : H -> H -> Prop} {op : H -> H -> H} {id : H} {inv : H -> H}.
153 Context {phi:G->H} {phi':H->G}.
154 Local Infix "=" := EQ. Local Infix "=" := EQ : type_scope.
155
156 Class isomorphic_commutative_groups :=
157 {
158 #[global] isomorphic_commutative_groups_group_G :: @commutative_group G EQ OP ID INV;
159 #[global] isomorphic_commutative_groups_group_H :: @commutative_group H eq op id inv;
160 #[global] isomorphic_commutative_groups_hom_GH :: @Monoid.is_homomorphism G EQ OP H eq op phi;
161 #[global] isomorphic_commutative_groups_hom_HG :: @Monoid.is_homomorphism H eq op G EQ OP phi';
162 }.
163
164 Lemma commutative_group_by_isomorphism
165 (groupG:@commutative_group G EQ OP ID INV)
166 (phi'_phi_id : forall A, phi' (phi A) = A)
167 (phi'_eq : forall a b, EQ (phi' a) (phi' b) <-> eq a b)
168 (phi'_op : forall a b, phi' (op a b) = OP (phi' a) (phi' b))
169 (phi'_inv : forall a, phi' (inv a) = INV (phi' a))
170 (phi'_id : phi' id = ID)
171 : isomorphic_commutative_groups.
172 Proof using Type*.
173 repeat match goal with
174 | [ H : _/\_ |- _ ] => destruct H; try clear H
175 | [ H : commutative_group |- _ ] => destruct H; try clear H
176 | [ H : group |- _ ] => destruct H; try clear H
177 | [ H : monoid |- _ ] => destruct H; try clear H
178 | [ H : is_commutative |- _ ] => destruct H; try clear H
179 | [ H : is_associative |- _ ] => destruct H; try clear H
180 | [ H : is_left_identity |- _ ] => destruct H; try clear H
181 | [ H : is_right_identity |- _ ] => destruct H; try clear H
182 | [ H : Equivalence _ |- _ ] => destruct H; try clear H
183 | [ H : is_left_inverse |- _ ] => destruct H; try clear H
184 | [ H : is_right_inverse |- _ ] => destruct H; try clear H
185 | _ => intro
186 | _ => split
187 | [ H : eq _ _ |- _ ] => apply phi'_eq in H
188 | [ |- eq _ _ ] => apply phi'_eq
189 | [ H : EQ _ _ |- _ ] => rewrite H
190 | _ => progress erewrite ?phi'_op, ?phi'_inv, ?phi'_id, ?phi'_phi_id by reflexivity
191 | [ H : _ |- _ ] => progress erewrite ?phi'_op, ?phi'_inv, ?phi'_id in H by reflexivity
192 | _ => solve [ eauto ]
193 end.
194 Qed.
195 End CommutativeGroupByIsomorphism.