-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroup.thy
More file actions
1483 lines (1254 loc) · 60.3 KB
/
Group.thy
File metadata and controls
1483 lines (1254 loc) · 60.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* Title: HOL/Algebra/Group.thy
Author: Clemens Ballarin, started 4 February 2003
Based on work by Florian Kammueller, L C Paulson and Markus Wenzel.
With additional contributions from Martin Baillon and Paulo Emílio de Vilhena.
*)
theory Group
imports Complete_Lattice "HOL-Library.FuncSet"
begin
section \<open>Monoids and Groups\<close>
subsection \<open>Definitions\<close>
text \<open>
Definitions follow @{cite "Jacobson:1985"}.
\<close>
record 'a monoid = "'a partial_object" +
mult :: "['a, 'a] \<Rightarrow> 'a" (infixl "\<otimes>\<index>" 70)
one :: 'a ("\<one>\<index>")
definition
m_inv :: "('a, 'b) monoid_scheme => 'a => 'a" ("inv\<index> _" [81] 80)
where "inv\<^bsub>G\<^esub> x = (THE y. y \<in> carrier G \<and> x \<otimes>\<^bsub>G\<^esub> y = \<one>\<^bsub>G\<^esub> \<and> y \<otimes>\<^bsub>G\<^esub> x = \<one>\<^bsub>G\<^esub>)"
definition
Units :: "_ => 'a set"
\<comment> \<open>The set of invertible elements\<close>
where "Units G = {y. y \<in> carrier G \<and> (\<exists>x \<in> carrier G. x \<otimes>\<^bsub>G\<^esub> y = \<one>\<^bsub>G\<^esub> \<and> y \<otimes>\<^bsub>G\<^esub> x = \<one>\<^bsub>G\<^esub>)}"
consts
pow :: "[('a, 'm) monoid_scheme, 'a, 'b::semiring_1] => 'a" (infixr "[^]\<index>" 75)
overloading nat_pow == "pow :: [_, 'a, nat] => 'a"
begin
definition "nat_pow G a n = rec_nat \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a) n"
end
overloading int_pow == "pow :: [_, 'a, int] => 'a"
begin
definition "int_pow G a z =
(let p = rec_nat \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a)
in if z < 0 then inv\<^bsub>G\<^esub> (p (nat (-z))) else p (nat z))"
end
lemma int_pow_int: "x [^]\<^bsub>G\<^esub> (int n) = x [^]\<^bsub>G\<^esub> n"
by(simp add: int_pow_def nat_pow_def)
locale monoid =
fixes G (structure)
assumes m_closed [intro, simp]:
"\<lbrakk>x \<in> carrier G; y \<in> carrier G\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> carrier G"
and m_assoc:
"\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk>
\<Longrightarrow> (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
and one_closed [intro, simp]: "\<one> \<in> carrier G"
and l_one [simp]: "x \<in> carrier G \<Longrightarrow> \<one> \<otimes> x = x"
and r_one [simp]: "x \<in> carrier G \<Longrightarrow> x \<otimes> \<one> = x"
lemma monoidI:
fixes G (structure)
assumes m_closed:
"!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
and one_closed: "\<one> \<in> carrier G"
and m_assoc:
"!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
(x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
and r_one: "!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
shows "monoid G"
by (fast intro!: monoid.intro intro: assms)
lemma (in monoid) Units_closed [dest]:
"x \<in> Units G ==> x \<in> carrier G"
by (unfold Units_def) fast
lemma (in monoid) one_unique:
assumes "u \<in> carrier G"
and "\<And>x. x \<in> carrier G \<Longrightarrow> u \<otimes> x = x"
shows "u = \<one>"
using assms(2)[OF one_closed] r_one[OF assms(1)] by simp
lemma (in monoid) inv_unique:
assumes eq: "y \<otimes> x = \<one>" "x \<otimes> y' = \<one>"
and G: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G"
shows "y = y'"
proof -
from G eq have "y = y \<otimes> (x \<otimes> y')" by simp
also from G have "... = (y \<otimes> x) \<otimes> y'" by (simp add: m_assoc)
also from G eq have "... = y'" by simp
finally show ?thesis .
qed
lemma (in monoid) Units_m_closed [simp, intro]:
assumes x: "x \<in> Units G" and y: "y \<in> Units G"
shows "x \<otimes> y \<in> Units G"
proof -
from x obtain x' where x: "x \<in> carrier G" "x' \<in> carrier G" and xinv: "x \<otimes> x' = \<one>" "x' \<otimes> x = \<one>"
unfolding Units_def by fast
from y obtain y' where y: "y \<in> carrier G" "y' \<in> carrier G" and yinv: "y \<otimes> y' = \<one>" "y' \<otimes> y = \<one>"
unfolding Units_def by fast
from x y xinv yinv have "y' \<otimes> (x' \<otimes> x) \<otimes> y = \<one>" by simp
moreover from x y xinv yinv have "x \<otimes> (y \<otimes> y') \<otimes> x' = \<one>" by simp
moreover note x y
ultimately show ?thesis unfolding Units_def
by simp (metis m_assoc m_closed)
qed
lemma (in monoid) Units_one_closed [intro, simp]:
"\<one> \<in> Units G"
by (unfold Units_def) auto
lemma (in monoid) Units_inv_closed [intro, simp]:
"x \<in> Units G ==> inv x \<in> carrier G"
apply (unfold Units_def m_inv_def, auto)
apply (rule theI2, fast)
apply (fast intro: inv_unique, fast)
done
lemma (in monoid) Units_l_inv_ex:
"x \<in> Units G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
by (unfold Units_def) auto
lemma (in monoid) Units_r_inv_ex:
"x \<in> Units G ==> \<exists>y \<in> carrier G. x \<otimes> y = \<one>"
by (unfold Units_def) auto
lemma (in monoid) Units_l_inv [simp]:
"x \<in> Units G ==> inv x \<otimes> x = \<one>"
apply (unfold Units_def m_inv_def, auto)
apply (rule theI2, fast)
apply (fast intro: inv_unique, fast)
done
lemma (in monoid) Units_r_inv [simp]:
"x \<in> Units G ==> x \<otimes> inv x = \<one>"
by (metis (full_types) Units_closed Units_inv_closed Units_l_inv Units_r_inv_ex inv_unique)
lemma (in monoid) inv_one [simp]:
"inv \<one> = \<one>"
by (metis Units_one_closed Units_r_inv l_one monoid.Units_inv_closed monoid_axioms)
lemma (in monoid) Units_inv_Units [intro, simp]:
"x \<in> Units G ==> inv x \<in> Units G"
proof -
assume x: "x \<in> Units G"
show "inv x \<in> Units G"
by (auto simp add: Units_def
intro: Units_l_inv Units_r_inv x Units_closed [OF x])
qed
lemma (in monoid) Units_l_cancel [simp]:
"[| x \<in> Units G; y \<in> carrier G; z \<in> carrier G |] ==>
(x \<otimes> y = x \<otimes> z) = (y = z)"
proof
assume eq: "x \<otimes> y = x \<otimes> z"
and G: "x \<in> Units G" "y \<in> carrier G" "z \<in> carrier G"
then have "(inv x \<otimes> x) \<otimes> y = (inv x \<otimes> x) \<otimes> z"
by (simp add: m_assoc Units_closed del: Units_l_inv)
with G show "y = z" by simp
next
assume eq: "y = z"
and G: "x \<in> Units G" "y \<in> carrier G" "z \<in> carrier G"
then show "x \<otimes> y = x \<otimes> z" by simp
qed
lemma (in monoid) Units_inv_inv [simp]:
"x \<in> Units G ==> inv (inv x) = x"
proof -
assume x: "x \<in> Units G"
then have "inv x \<otimes> inv (inv x) = inv x \<otimes> x" by simp
with x show ?thesis by (simp add: Units_closed del: Units_l_inv Units_r_inv)
qed
lemma (in monoid) inv_inj_on_Units:
"inj_on (m_inv G) (Units G)"
proof (rule inj_onI)
fix x y
assume G: "x \<in> Units G" "y \<in> Units G" and eq: "inv x = inv y"
then have "inv (inv x) = inv (inv y)" by simp
with G show "x = y" by simp
qed
lemma (in monoid) Units_inv_comm:
assumes inv: "x \<otimes> y = \<one>"
and G: "x \<in> Units G" "y \<in> Units G"
shows "y \<otimes> x = \<one>"
proof -
from G have "x \<otimes> y \<otimes> x = x \<otimes> \<one>" by (auto simp add: inv Units_closed)
with G show ?thesis by (simp del: r_one add: m_assoc Units_closed)
qed
lemma (in monoid) carrier_not_empty: "carrier G \<noteq> {}"
by auto
text \<open>Power\<close>
lemma (in monoid) nat_pow_closed [intro, simp]:
"x \<in> carrier G ==> x [^] (n::nat) \<in> carrier G"
by (induct n) (simp_all add: nat_pow_def)
lemma (in monoid) nat_pow_0 [simp]:
"x [^] (0::nat) = \<one>"
by (simp add: nat_pow_def)
lemma (in monoid) nat_pow_Suc [simp]:
"x [^] (Suc n) = x [^] n \<otimes> x"
by (simp add: nat_pow_def)
lemma (in monoid) nat_pow_one [simp]:
"\<one> [^] (n::nat) = \<one>"
by (induct n) simp_all
lemma (in monoid) nat_pow_mult:
"x \<in> carrier G ==> x [^] (n::nat) \<otimes> x [^] m = x [^] (n + m)"
by (induct m) (simp_all add: m_assoc [THEN sym])
lemma (in monoid) nat_pow_comm:
"x \<in> carrier G \<Longrightarrow> (x [^] (n::nat)) \<otimes> (x [^] (m :: nat)) = (x [^] m) \<otimes> (x [^] n)"
using nat_pow_mult[of x n m] nat_pow_mult[of x m n] by (simp add: add.commute)
lemma (in monoid) nat_pow_Suc2:
"x \<in> carrier G \<Longrightarrow> x [^] (Suc n) = x \<otimes> (x [^] n)"
using nat_pow_mult[of x 1 n] Suc_eq_plus1[of n]
by (metis One_nat_def Suc_eq_plus1_left l_one nat.rec(1) nat_pow_Suc nat_pow_def)
lemma (in monoid) nat_pow_pow:
"x \<in> carrier G ==> (x [^] n) [^] m = x [^] (n * m::nat)"
by (induct m) (simp, simp add: nat_pow_mult add.commute)
lemma (in monoid) nat_pow_consistent:
"x [^] (n :: nat) = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
unfolding nat_pow_def by simp
(* Jacobson defines submonoid here. *)
(* Jacobson defines the order of a monoid here. *)
subsection \<open>Groups\<close>
text \<open>
A group is a monoid all of whose elements are invertible.
\<close>
locale group = monoid +
assumes Units: "carrier G <= Units G"
lemma (in group) is_group: "group G" by (rule group_axioms)
theorem groupI:
fixes G (structure)
assumes m_closed [simp]:
"!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
and one_closed [simp]: "\<one> \<in> carrier G"
and m_assoc:
"!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
(x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
and l_one [simp]: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
and l_inv_ex: "!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
shows "group G"
proof -
have l_cancel [simp]:
"!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
(x \<otimes> y = x \<otimes> z) = (y = z)"
proof
fix x y z
assume eq: "x \<otimes> y = x \<otimes> z"
and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
and l_inv: "x_inv \<otimes> x = \<one>" by fast
from G eq xG have "(x_inv \<otimes> x) \<otimes> y = (x_inv \<otimes> x) \<otimes> z"
by (simp add: m_assoc)
with G show "y = z" by (simp add: l_inv)
next
fix x y z
assume eq: "y = z"
and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
then show "x \<otimes> y = x \<otimes> z" by simp
qed
have r_one:
"!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
proof -
fix x
assume x: "x \<in> carrier G"
with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
and l_inv: "x_inv \<otimes> x = \<one>" by fast
from x xG have "x_inv \<otimes> (x \<otimes> \<one>) = x_inv \<otimes> x"
by (simp add: m_assoc [symmetric] l_inv)
with x xG show "x \<otimes> \<one> = x" by simp
qed
have inv_ex:
"\<And>x. x \<in> carrier G \<Longrightarrow> \<exists>y \<in> carrier G. y \<otimes> x = \<one> \<and> x \<otimes> y = \<one>"
proof -
fix x
assume x: "x \<in> carrier G"
with l_inv_ex obtain y where y: "y \<in> carrier G"
and l_inv: "y \<otimes> x = \<one>" by fast
from x y have "y \<otimes> (x \<otimes> y) = y \<otimes> \<one>"
by (simp add: m_assoc [symmetric] l_inv r_one)
with x y have r_inv: "x \<otimes> y = \<one>"
by simp
from x y show "\<exists>y \<in> carrier G. y \<otimes> x = \<one> \<and> x \<otimes> y = \<one>"
by (fast intro: l_inv r_inv)
qed
then have carrier_subset_Units: "carrier G \<subseteq> Units G"
by (unfold Units_def) fast
show ?thesis
by standard (auto simp: r_one m_assoc carrier_subset_Units)
qed
lemma (in monoid) group_l_invI:
assumes l_inv_ex:
"!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
shows "group G"
by (rule groupI) (auto intro: m_assoc l_inv_ex)
lemma (in group) Units_eq [simp]:
"Units G = carrier G"
proof
show "Units G \<subseteq> carrier G" by fast
next
show "carrier G \<subseteq> Units G" by (rule Units)
qed
lemma (in group) inv_closed [intro, simp]:
"x \<in> carrier G ==> inv x \<in> carrier G"
using Units_inv_closed by simp
lemma (in group) l_inv_ex [simp]:
"x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
using Units_l_inv_ex by simp
lemma (in group) r_inv_ex [simp]:
"x \<in> carrier G ==> \<exists>y \<in> carrier G. x \<otimes> y = \<one>"
using Units_r_inv_ex by simp
lemma (in group) l_inv [simp]:
"x \<in> carrier G ==> inv x \<otimes> x = \<one>"
by simp
subsection \<open>Cancellation Laws and Basic Properties\<close>
lemma (in group) r_inv [simp]:
"x \<in> carrier G ==> x \<otimes> inv x = \<one>"
by simp
lemma (in group) right_cancel [simp]:
"[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
(y \<otimes> x = z \<otimes> x) = (y = z)"
by (metis inv_closed m_assoc r_inv r_one)
lemma (in group) inv_inv [simp]:
"x \<in> carrier G ==> inv (inv x) = x"
using Units_inv_inv by simp
lemma (in group) inv_inj:
"inj_on (m_inv G) (carrier G)"
using inv_inj_on_Units by simp
lemma (in group) inv_mult_group:
"[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv y \<otimes> inv x"
proof -
assume G: "x \<in> carrier G" "y \<in> carrier G"
then have "inv (x \<otimes> y) \<otimes> (x \<otimes> y) = (inv y \<otimes> inv x) \<otimes> (x \<otimes> y)"
by (simp add: m_assoc) (simp add: m_assoc [symmetric])
with G show ?thesis by (simp del: l_inv Units_l_inv)
qed
lemma (in group) inv_comm:
"[| x \<otimes> y = \<one>; x \<in> carrier G; y \<in> carrier G |] ==> y \<otimes> x = \<one>"
by (rule Units_inv_comm) auto
lemma (in group) inv_equality:
"[|y \<otimes> x = \<one>; x \<in> carrier G; y \<in> carrier G|] ==> inv x = y"
using inv_unique r_inv by blast
(* Contributed by Joachim Breitner *)
lemma (in group) inv_solve_left:
"\<lbrakk> a \<in> carrier G; b \<in> carrier G; c \<in> carrier G \<rbrakk> \<Longrightarrow> a = inv b \<otimes> c \<longleftrightarrow> c = b \<otimes> a"
by (metis inv_equality l_inv_ex l_one m_assoc r_inv)
lemma (in group) inv_solve_right:
"\<lbrakk> a \<in> carrier G; b \<in> carrier G; c \<in> carrier G \<rbrakk> \<Longrightarrow> a = b \<otimes> inv c \<longleftrightarrow> b = a \<otimes> c"
by (metis inv_equality l_inv_ex l_one m_assoc r_inv)
text \<open>Power\<close>
lemma (in group) int_pow_def2:
"a [^] (z::int) = (if z < 0 then inv (a [^] (nat (-z))) else a [^] (nat z))"
by (simp add: int_pow_def nat_pow_def Let_def)
lemma (in group) int_pow_0 [simp]:
"x [^] (0::int) = \<one>"
by (simp add: int_pow_def2)
lemma (in group) int_pow_one [simp]:
"\<one> [^] (z::int) = \<one>"
by (simp add: int_pow_def2)
(* The following are contributed by Joachim Breitner *)
lemma (in group) int_pow_closed [intro, simp]:
"x \<in> carrier G ==> x [^] (i::int) \<in> carrier G"
by (simp add: int_pow_def2)
lemma (in group) int_pow_1 [simp]:
"x \<in> carrier G \<Longrightarrow> x [^] (1::int) = x"
by (simp add: int_pow_def2)
lemma (in group) int_pow_neg:
"x \<in> carrier G \<Longrightarrow> x [^] (-i::int) = inv (x [^] i)"
by (simp add: int_pow_def2)
lemma (in group) int_pow_mult:
"x \<in> carrier G \<Longrightarrow> x [^] (i + j::int) = x [^] i \<otimes> x [^] j"
proof -
have [simp]: "-i - j = -j - i" by simp
assume "x \<in> carrier G" then
show ?thesis
by (auto simp add: int_pow_def2 inv_solve_left inv_solve_right nat_add_distrib [symmetric] nat_pow_mult )
qed
lemma (in group) nat_pow_inv:
"x \<in> carrier G \<Longrightarrow> (inv x) [^] (i :: nat) = inv (x [^] i)"
proof (induction i)
case 0 thus ?case by simp
next
case (Suc i)
have "(inv x) [^] Suc i = ((inv x) [^] i) \<otimes> inv x"
by simp
also have " ... = (inv (x [^] i)) \<otimes> inv x"
by (simp add: Suc.IH Suc.prems)
also have " ... = inv (x \<otimes> (x [^] i))"
using inv_mult_group[OF Suc.prems nat_pow_closed[OF Suc.prems, of i]] by simp
also have " ... = inv (x [^] (Suc i))"
using Suc.prems nat_pow_Suc2 by auto
finally show ?case .
qed
lemma (in group) int_pow_inv:
"x \<in> carrier G \<Longrightarrow> (inv x) [^] (i :: int) = inv (x [^] i)"
by (simp add: nat_pow_inv int_pow_def2)
lemma (in group) int_pow_pow:
assumes "x \<in> carrier G"
shows "(x [^] (n :: int)) [^] (m :: int) = x [^] (n * m :: int)"
proof (cases)
assume n_ge: "n \<ge> 0" thus ?thesis
proof (cases)
assume m_ge: "m \<ge> 0" thus ?thesis
using n_ge nat_pow_pow[OF assms, of "nat n" "nat m"] int_pow_def2
by (simp add: mult_less_0_iff nat_mult_distrib)
next
assume m_lt: "\<not> m \<ge> 0" thus ?thesis
using n_ge int_pow_def2 nat_pow_pow[OF assms, of "nat n" "nat (- m)"]
by (smt assms group.int_pow_neg is_group mult_minus_right nat_mult_distrib split_mult_neg_le)
qed
next
assume n_lt: "\<not> n \<ge> 0" thus ?thesis
proof (cases)
assume m_ge: "m \<ge> 0" thus ?thesis
using n_lt nat_pow_pow[OF assms, of "nat (- n)" "nat m"]
nat_pow_inv[of "x [^] nat (- n)" "nat m"] int_pow_def2
by (smt assms group.int_pow_closed group.int_pow_neg is_group mult_minus_right
mult_nonpos_nonpos nat_mult_distrib_neg)
next
assume m_lt: "\<not> m \<ge> 0" thus ?thesis
using n_lt nat_pow_pow[OF assms, of "nat (- n)" "nat (- m)"]
nat_pow_inv[of "x [^] nat (- n)" "nat (- m)"] int_pow_def2
by (smt assms inv_inv mult_nonpos_nonpos nat_mult_distrib_neg nat_pow_closed)
qed
qed
lemma (in group) int_pow_diff:
"x \<in> carrier G \<Longrightarrow> x [^] (n - m :: int) = x [^] n \<otimes> inv (x [^] m)"
by(simp only: diff_conv_add_uminus int_pow_mult int_pow_neg)
lemma (in group) inj_on_multc: "c \<in> carrier G \<Longrightarrow> inj_on (\<lambda>x. x \<otimes> c) (carrier G)"
by(simp add: inj_on_def)
lemma (in group) inj_on_cmult: "c \<in> carrier G \<Longrightarrow> inj_on (\<lambda>x. c \<otimes> x) (carrier G)"
by(simp add: inj_on_def)
(*Following subsection contributed by Martin Baillon*)
subsection \<open>Submonoids\<close>
locale submonoid =
fixes H and G (structure)
assumes subset: "H \<subseteq> carrier G"
and m_closed [intro, simp]: "\<lbrakk>x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> H"
and one_closed [simp]: "\<one> \<in> H"
lemma (in submonoid) is_submonoid:
"submonoid H G" by (rule submonoid_axioms)
lemma (in submonoid) mem_carrier [simp]:
"x \<in> H \<Longrightarrow> x \<in> carrier G"
using subset by blast
lemma (in submonoid) submonoid_is_monoid [intro]:
assumes "monoid G"
shows "monoid (G\<lparr>carrier := H\<rparr>)"
proof -
interpret monoid G by fact
show ?thesis
by (simp add: monoid_def m_assoc)
qed
lemma submonoid_nonempty:
"~ submonoid {} G"
by (blast dest: submonoid.one_closed)
lemma (in submonoid) finite_monoid_imp_card_positive:
"finite (carrier G) ==> 0 < card H"
proof (rule classical)
assume "finite (carrier G)" and a: "~ 0 < card H"
then have "finite H" by (blast intro: finite_subset [OF subset])
with is_submonoid a have "submonoid {} G" by simp
with submonoid_nonempty show ?thesis by contradiction
qed
lemma (in monoid) monoid_incl_imp_submonoid :
assumes "H \<subseteq> carrier G"
and "monoid (G\<lparr>carrier := H\<rparr>)"
shows "submonoid H G"
proof (intro submonoid.intro[OF assms(1)])
have ab_eq : "\<And> a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> b = a \<otimes> b" using assms by simp
have "\<And>a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes> b \<in> carrier (G\<lparr>carrier := H\<rparr>) "
using assms ab_eq unfolding group_def using monoid.m_closed by fastforce
thus "\<And>a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes> b \<in> H" by simp
show "\<one> \<in> H " using monoid.one_closed[OF assms(2)] assms by simp
qed
lemma (in monoid) inv_unique':
assumes "x \<in> carrier G" "y \<in> carrier G"
shows "\<lbrakk> x \<otimes> y = \<one>; y \<otimes> x = \<one> \<rbrakk> \<Longrightarrow> y = inv x"
proof -
assume "x \<otimes> y = \<one>" and l_inv: "y \<otimes> x = \<one>"
hence unit: "x \<in> Units G"
using assms unfolding Units_def by auto
show "y = inv x"
using inv_unique[OF l_inv Units_r_inv[OF unit] assms Units_inv_closed[OF unit]] .
qed
lemma (in monoid) m_inv_monoid_consistent: (* contributed by Paulo *)
assumes "x \<in> Units (G \<lparr> carrier := H \<rparr>)" and "submonoid H G"
shows "inv\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> x = inv x"
proof -
have monoid: "monoid (G \<lparr> carrier := H \<rparr>)"
using submonoid.submonoid_is_monoid[OF assms(2) monoid_axioms] .
obtain y where y: "y \<in> H" "x \<otimes> y = \<one>" "y \<otimes> x = \<one>"
using assms(1) unfolding Units_def by auto
have x: "x \<in> H" and in_carrier: "x \<in> carrier G" "y \<in> carrier G"
using y(1) submonoid.subset[OF assms(2)] assms(1) unfolding Units_def by auto
show ?thesis
using monoid.inv_unique'[OF monoid, of x y] x y
using inv_unique'[OF in_carrier y(2-3)] by auto
qed
subsection \<open>Subgroups\<close>
locale subgroup =
fixes H and G (structure)
assumes subset: "H \<subseteq> carrier G"
and m_closed [intro, simp]: "\<lbrakk>x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> H"
and one_closed [simp]: "\<one> \<in> H"
and m_inv_closed [intro,simp]: "x \<in> H \<Longrightarrow> inv x \<in> H"
lemma (in subgroup) is_subgroup:
"subgroup H G" by (rule subgroup_axioms)
declare (in subgroup) group.intro [intro]
lemma (in subgroup) mem_carrier [simp]:
"x \<in> H \<Longrightarrow> x \<in> carrier G"
using subset by blast
lemma (in subgroup) subgroup_is_group [intro]:
assumes "group G"
shows "group (G\<lparr>carrier := H\<rparr>)"
proof -
interpret group G by fact
have "Group.monoid (G\<lparr>carrier := H\<rparr>)"
by (simp add: monoid_axioms submonoid.intro submonoid.submonoid_is_monoid subset)
then show ?thesis
by (rule monoid.group_l_invI) (auto intro: l_inv mem_carrier)
qed
lemma subgroup_is_submonoid:
assumes "subgroup H G" shows "submonoid H G"
using assms by (auto intro: submonoid.intro simp add: subgroup_def)
lemma (in group) subgroup_Units:
assumes "subgroup H G" shows "H \<subseteq> Units (G \<lparr> carrier := H \<rparr>)"
using group.Units[OF subgroup.subgroup_is_group[OF assms group_axioms]] by simp
lemma (in group) m_inv_consistent:
assumes "subgroup H G" "x \<in> H"
shows "inv\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> x = inv x"
using assms m_inv_monoid_consistent[OF _ subgroup_is_submonoid] subgroup_Units[of H] by auto
lemma (in group) int_pow_consistent: (* by Paulo *)
assumes "subgroup H G" "x \<in> H"
shows "x [^] (n :: int) = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
proof (cases)
assume ge: "n \<ge> 0"
hence "x [^] n = x [^] (nat n)"
using int_pow_def2 by auto
also have " ... = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (nat n)"
using nat_pow_consistent by simp
also have " ... = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
using group.int_pow_def2[OF subgroup.subgroup_is_group[OF assms(1) is_group]] ge by auto
finally show ?thesis .
next
assume "\<not> n \<ge> 0" hence lt: "n < 0" by simp
hence "x [^] n = inv (x [^] (nat (- n)))"
using int_pow_def2 by auto
also have " ... = (inv x) [^] (nat (- n))"
by (metis assms nat_pow_inv subgroup.mem_carrier)
also have " ... = (inv\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> x) [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (nat (- n))"
using m_inv_consistent[OF assms] nat_pow_consistent by auto
also have " ... = inv\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (nat (- n)))"
using group.nat_pow_inv[OF subgroup.subgroup_is_group[OF assms(1) is_group]] assms(2) by auto
also have " ... = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
using group.int_pow_def2[OF subgroup.subgroup_is_group[OF assms(1) is_group]] lt by auto
finally show ?thesis .
qed
text \<open>
Since @{term H} is nonempty, it contains some element @{term x}. Since
it is closed under inverse, it contains \<open>inv x\<close>. Since
it is closed under product, it contains \<open>x \<otimes> inv x = \<one>\<close>.
\<close>
lemma (in group) one_in_subset:
"[| H \<subseteq> carrier G; H \<noteq> {}; \<forall>a \<in> H. inv a \<in> H; \<forall>a\<in>H. \<forall>b\<in>H. a \<otimes> b \<in> H |]
==> \<one> \<in> H"
by force
text \<open>A characterization of subgroups: closed, non-empty subset.\<close>
lemma (in group) subgroupI:
assumes subset: "H \<subseteq> carrier G" and non_empty: "H \<noteq> {}"
and inv: "!!a. a \<in> H \<Longrightarrow> inv a \<in> H"
and mult: "!!a b. \<lbrakk>a \<in> H; b \<in> H\<rbrakk> \<Longrightarrow> a \<otimes> b \<in> H"
shows "subgroup H G"
proof (simp add: subgroup_def assms)
show "\<one> \<in> H" by (rule one_in_subset) (auto simp only: assms)
qed
lemma (in group) subgroupE:
assumes "subgroup H G"
shows "H \<subseteq> carrier G"
and "H \<noteq> {}"
and "\<And>a. a \<in> H \<Longrightarrow> inv a \<in> H"
and "\<And>a b. \<lbrakk> a \<in> H; b \<in> H \<rbrakk> \<Longrightarrow> a \<otimes> b \<in> H"
using assms unfolding subgroup_def[of H G] by auto
declare monoid.one_closed [iff] group.inv_closed [simp]
monoid.l_one [simp] monoid.r_one [simp] group.inv_inv [simp]
lemma subgroup_nonempty:
"\<not> subgroup {} G"
by (blast dest: subgroup.one_closed)
lemma (in subgroup) finite_imp_card_positive: "finite (carrier G) \<Longrightarrow> 0 < card H"
using subset one_closed card_gt_0_iff finite_subset by blast
(*Following 3 lemmas contributed by Martin Baillon*)
lemma (in subgroup) subgroup_is_submonoid :
"submonoid H G"
by (simp add: submonoid.intro subset)
lemma (in group) submonoid_subgroupI :
assumes "submonoid H G"
and "\<And>a. a \<in> H \<Longrightarrow> inv a \<in> H"
shows "subgroup H G"
by (metis assms subgroup_def submonoid_def)
lemma (in group) group_incl_imp_subgroup:
assumes "H \<subseteq> carrier G"
and "group (G\<lparr>carrier := H\<rparr>)"
shows "subgroup H G"
proof (intro submonoid_subgroupI[OF monoid_incl_imp_submonoid[OF assms(1)]])
show "monoid (G\<lparr>carrier := H\<rparr>)" using group_def assms by blast
have ab_eq : "\<And> a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> b = a \<otimes> b" using assms by simp
fix a assume aH : "a \<in> H"
have " inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a \<in> carrier G"
using assms aH group.inv_closed[OF assms(2)] by auto
moreover have "\<one>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> = \<one>" using assms monoid.one_closed ab_eq one_def by simp
hence "a \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a= \<one>"
using assms ab_eq aH group.r_inv[OF assms(2)] by simp
hence "a \<otimes> inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a= \<one>"
using aH assms group.inv_closed[OF assms(2)] ab_eq by simp
ultimately have "inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a = inv a"
by (smt aH assms(1) contra_subsetD group.inv_inv is_group local.inv_equality)
moreover have "inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a \<in> H" using aH group.inv_closed[OF assms(2)] by auto
ultimately show "inv a \<in> H" by auto
qed
subsection \<open>Direct Products\<close>
definition
DirProd :: "_ \<Rightarrow> _ \<Rightarrow> ('a \<times> 'b) monoid" (infixr "\<times>\<times>" 80) where
"G \<times>\<times> H =
\<lparr>carrier = carrier G \<times> carrier H,
mult = (\<lambda>(g, h) (g', h'). (g \<otimes>\<^bsub>G\<^esub> g', h \<otimes>\<^bsub>H\<^esub> h')),
one = (\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>)\<rparr>"
lemma DirProd_monoid:
assumes "monoid G" and "monoid H"
shows "monoid (G \<times>\<times> H)"
proof -
interpret G: monoid G by fact
interpret H: monoid H by fact
from assms
show ?thesis by (unfold monoid_def DirProd_def, auto)
qed
text\<open>Does not use the previous result because it's easier just to use auto.\<close>
lemma DirProd_group:
assumes "group G" and "group H"
shows "group (G \<times>\<times> H)"
proof -
interpret G: group G by fact
interpret H: group H by fact
show ?thesis by (rule groupI)
(auto intro: G.m_assoc H.m_assoc G.l_inv H.l_inv
simp add: DirProd_def)
qed
lemma carrier_DirProd [simp]:
"carrier (G \<times>\<times> H) = carrier G \<times> carrier H"
by (simp add: DirProd_def)
lemma one_DirProd [simp]:
"\<one>\<^bsub>G \<times>\<times> H\<^esub> = (\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>)"
by (simp add: DirProd_def)
lemma mult_DirProd [simp]:
"(g, h) \<otimes>\<^bsub>(G \<times>\<times> H)\<^esub> (g', h') = (g \<otimes>\<^bsub>G\<^esub> g', h \<otimes>\<^bsub>H\<^esub> h')"
by (simp add: DirProd_def)
lemma DirProd_assoc :
"(G \<times>\<times> H \<times>\<times> I) = (G \<times>\<times> (H \<times>\<times> I))"
by auto
lemma inv_DirProd [simp]:
assumes "group G" and "group H"
assumes g: "g \<in> carrier G"
and h: "h \<in> carrier H"
shows "m_inv (G \<times>\<times> H) (g, h) = (inv\<^bsub>G\<^esub> g, inv\<^bsub>H\<^esub> h)"
proof -
interpret G: group G by fact
interpret H: group H by fact
interpret Prod: group "G \<times>\<times> H"
by (auto intro: DirProd_group group.intro group.axioms assms)
show ?thesis by (simp add: Prod.inv_equality g h)
qed
lemma DirProd_subgroups :
assumes "group G"
and "subgroup H G"
and "group K"
and "subgroup I K"
shows "subgroup (H \<times> I) (G \<times>\<times> K)"
proof (intro group.group_incl_imp_subgroup[OF DirProd_group[OF assms(1)assms(3)]])
have "H \<subseteq> carrier G" "I \<subseteq> carrier K" using subgroup.subset assms apply blast+.
thus "(H \<times> I) \<subseteq> carrier (G \<times>\<times> K)" unfolding DirProd_def by auto
have "Group.group ((G\<lparr>carrier := H\<rparr>) \<times>\<times> (K\<lparr>carrier := I\<rparr>))"
using DirProd_group[OF subgroup.subgroup_is_group[OF assms(2)assms(1)]
subgroup.subgroup_is_group[OF assms(4)assms(3)]].
moreover have "((G\<lparr>carrier := H\<rparr>) \<times>\<times> (K\<lparr>carrier := I\<rparr>)) = ((G \<times>\<times> K)\<lparr>carrier := H \<times> I\<rparr>)"
unfolding DirProd_def using assms apply simp.
ultimately show "Group.group ((G \<times>\<times> K)\<lparr>carrier := H \<times> I\<rparr>)" by simp
qed
subsection \<open>Homomorphisms and Isomorphisms\<close>
definition
hom :: "_ => _ => ('a => 'b) set" where
"hom G H =
{h. h \<in> carrier G \<rightarrow> carrier H \<and>
(\<forall>x \<in> carrier G. \<forall>y \<in> carrier G. h (x \<otimes>\<^bsub>G\<^esub> y) = h x \<otimes>\<^bsub>H\<^esub> h y)}"
(* NEW ========================================================================== *)
lemma hom_trans:
"\<lbrakk> f \<in> hom G H; g \<in> hom H I \<rbrakk> \<Longrightarrow> g \<circ> f \<in> hom G I"
unfolding hom_def by (auto simp add: Pi_iff)
(* ============================================================================== *)
(* NEW ============================================================================ *)
lemma (in group) hom_restrict:
assumes "h \<in> hom G H" and "\<And>g. g \<in> carrier G \<Longrightarrow> h g = t g" shows "t \<in> hom G H"
using assms unfolding hom_def by (auto simp add: Pi_iff)
(* ============================================================================== *)
lemma (in group) hom_compose:
"[|h \<in> hom G H; i \<in> hom H I|] ==> compose (carrier G) i h \<in> hom G I"
by (fastforce simp add: hom_def compose_def)
definition
iso :: "_ => _ => ('a => 'b) set"
where "iso G H = {h. h \<in> hom G H \<and> bij_betw h (carrier G) (carrier H)}"
definition
is_iso :: "_ \<Rightarrow> _ \<Rightarrow> bool" (infixr "\<cong>" 60)
where "G \<cong> H = (iso G H \<noteq> {})"
lemma iso_set_refl: "(\<lambda>x. x) \<in> iso G G"
by (simp add: iso_def hom_def inj_on_def bij_betw_def Pi_def)
corollary iso_refl : "G \<cong> G"
using iso_set_refl unfolding is_iso_def by auto
lemma (in group) iso_set_sym:
assumes "h \<in> iso G H"
shows "inv_into (carrier G) h \<in> iso H G"
proof -
have h: "h \<in> hom G H" "bij_betw h (carrier G) (carrier H)"
using assms by (auto simp add: iso_def bij_betw_inv_into)
then have HG: "bij_betw (inv_into (carrier G) h) (carrier H) (carrier G)"
by (simp add: bij_betw_inv_into)
have "inv_into (carrier G) h \<in> hom H G"
unfolding hom_def
proof safe
show *: "\<And>x. x \<in> carrier H \<Longrightarrow> inv_into (carrier G) h x \<in> carrier G"
by (meson HG bij_betwE)
show "inv_into (carrier G) h (x \<otimes>\<^bsub>H\<^esub> y) = inv_into (carrier G) h x \<otimes> inv_into (carrier G) h y"
if "x \<in> carrier H" "y \<in> carrier H" for x y
proof (rule inv_into_f_eq)
show "inj_on h (carrier G)"
using bij_betw_def h(2) by blast
show "inv_into (carrier G) h x \<otimes> inv_into (carrier G) h y \<in> carrier G"
by (simp add: * that)
show "h (inv_into (carrier G) h x \<otimes> inv_into (carrier G) h y) = x \<otimes>\<^bsub>H\<^esub> y"
using h bij_betw_inv_into_right [of h] unfolding hom_def by (simp add: "*" that)
qed
qed
then show ?thesis
by (simp add: Group.iso_def bij_betw_inv_into h)
qed
corollary (in group) iso_sym: "G \<cong> H \<Longrightarrow> H \<cong> G"
using iso_set_sym unfolding is_iso_def by auto
lemma (in group) iso_set_trans:
"[|h \<in> iso G H; i \<in> iso H I|] ==> (compose (carrier G) i h) \<in> iso G I"
by (auto simp add: iso_def hom_compose bij_betw_compose)
corollary (in group) iso_trans: "\<lbrakk>G \<cong> H ; H \<cong> I\<rbrakk> \<Longrightarrow> G \<cong> I"
using iso_set_trans unfolding is_iso_def by blast
(* NEW ====================================================================== *)
lemma iso_same_card: "G \<cong> H \<Longrightarrow> card (carrier G) = card (carrier H)"
using bij_betw_same_card unfolding is_iso_def iso_def by auto
(* ========================================================================== *)
(* Next four lemmas contributed by Paulo. *)
lemma (in monoid) hom_imp_img_monoid:
assumes "h \<in> hom G H"
shows "monoid (H \<lparr> carrier := h ` (carrier G), one := h \<one>\<^bsub>G\<^esub> \<rparr>)" (is "monoid ?h_img")
proof (rule monoidI)
show "\<one>\<^bsub>?h_img\<^esub> \<in> carrier ?h_img"
by auto
next
fix x y z assume "x \<in> carrier ?h_img" "y \<in> carrier ?h_img" "z \<in> carrier ?h_img"
then obtain g1 g2 g3
where g1: "g1 \<in> carrier G" "x = h g1"
and g2: "g2 \<in> carrier G" "y = h g2"
and g3: "g3 \<in> carrier G" "z = h g3"
using image_iff[where ?f = h and ?A = "carrier G"] by auto
have aux_lemma:
"\<And>a b. \<lbrakk> a \<in> carrier G; b \<in> carrier G \<rbrakk> \<Longrightarrow> h a \<otimes>\<^bsub>(?h_img)\<^esub> h b = h (a \<otimes> b)"
using assms unfolding hom_def by auto
show "x \<otimes>\<^bsub>(?h_img)\<^esub> \<one>\<^bsub>(?h_img)\<^esub> = x"
using aux_lemma[OF g1(1) one_closed] g1(2) r_one[OF g1(1)] by simp
show "\<one>\<^bsub>(?h_img)\<^esub> \<otimes>\<^bsub>(?h_img)\<^esub> x = x"
using aux_lemma[OF one_closed g1(1)] g1(2) l_one[OF g1(1)] by simp
have "x \<otimes>\<^bsub>(?h_img)\<^esub> y = h (g1 \<otimes> g2)"
using aux_lemma g1 g2 by auto
thus "x \<otimes>\<^bsub>(?h_img)\<^esub> y \<in> carrier ?h_img"
using g1(1) g2(1) by simp
have "(x \<otimes>\<^bsub>(?h_img)\<^esub> y) \<otimes>\<^bsub>(?h_img)\<^esub> z = h ((g1 \<otimes> g2) \<otimes> g3)"
using aux_lemma g1 g2 g3 by auto
also have " ... = h (g1 \<otimes> (g2 \<otimes> g3))"
using m_assoc[OF g1(1) g2(1) g3(1)] by simp
also have " ... = x \<otimes>\<^bsub>(?h_img)\<^esub> (y \<otimes>\<^bsub>(?h_img)\<^esub> z)"
using aux_lemma g1 g2 g3 by auto
finally show "(x \<otimes>\<^bsub>(?h_img)\<^esub> y) \<otimes>\<^bsub>(?h_img)\<^esub> z = x \<otimes>\<^bsub>(?h_img)\<^esub> (y \<otimes>\<^bsub>(?h_img)\<^esub> z)" .
qed
lemma (in group) hom_imp_img_group:
assumes "h \<in> hom G H"
shows "group (H \<lparr> carrier := h ` (carrier G), one := h \<one>\<^bsub>G\<^esub> \<rparr>)" (is "group ?h_img")
proof -
interpret monoid ?h_img
using hom_imp_img_monoid[OF assms] .
show ?thesis
proof (unfold_locales)
show "carrier ?h_img \<subseteq> Units ?h_img"
proof (auto simp add: Units_def)
have aux_lemma:
"\<And>g1 g2. \<lbrakk> g1 \<in> carrier G; g2 \<in> carrier G \<rbrakk> \<Longrightarrow> h g1 \<otimes>\<^bsub>H\<^esub> h g2 = h (g1 \<otimes> g2)"
using assms unfolding hom_def by auto
fix g1 assume g1: "g1 \<in> carrier G"
thus "\<exists>g2 \<in> carrier G. (h g2) \<otimes>\<^bsub>H\<^esub> (h g1) = h \<one> \<and> (h g1) \<otimes>\<^bsub>H\<^esub> (h g2) = h \<one>"
using aux_lemma[OF g1 inv_closed[OF g1]]
aux_lemma[OF inv_closed[OF g1] g1]
inv_closed by auto
qed
qed
qed
lemma (in group) iso_imp_group:
assumes "G \<cong> H" and "monoid H"
shows "group H"
proof -
obtain \<phi> where phi: "\<phi> \<in> iso G H" "inv_into (carrier G) \<phi> \<in> iso H G"
using iso_set_sym assms unfolding is_iso_def by blast
define \<psi> where psi_def: "\<psi> = inv_into (carrier G) \<phi>"
from phi
have surj: "\<phi> ` (carrier G) = (carrier H)" "\<psi> ` (carrier H) = (carrier G)"
and inj: "inj_on \<phi> (carrier G)" "inj_on \<psi> (carrier H)"
and phi_hom: "\<And>g1 g2. \<lbrakk> g1 \<in> carrier G; g2 \<in> carrier G \<rbrakk> \<Longrightarrow> \<phi> (g1 \<otimes> g2) = (\<phi> g1) \<otimes>\<^bsub>H\<^esub> (\<phi> g2)"
and psi_hom: "\<And>h1 h2. \<lbrakk> h1 \<in> carrier H; h2 \<in> carrier H \<rbrakk> \<Longrightarrow> \<psi> (h1 \<otimes>\<^bsub>H\<^esub> h2) = (\<psi> h1) \<otimes> (\<psi> h2)"
using psi_def unfolding iso_def bij_betw_def hom_def by auto
have phi_one: "\<phi> \<one> = \<one>\<^bsub>H\<^esub>"
proof -
have "(\<phi> \<one>) \<otimes>\<^bsub>H\<^esub> \<one>\<^bsub>H\<^esub> = (\<phi> \<one>) \<otimes>\<^bsub>H\<^esub> (\<phi> \<one>)"
by (metis assms(2) image_eqI monoid.r_one one_closed phi_hom r_one surj(1))
thus ?thesis
by (metis (no_types, hide_lams) Units_eq Units_one_closed assms(2) f_inv_into_f imageI
monoid.l_one monoid.one_closed phi_hom psi_def r_one surj)
qed
have "carrier H \<subseteq> Units H"
proof
fix h assume h: "h \<in> carrier H"
let ?inv_h = "\<phi> (inv (\<psi> h))"
have "h \<otimes>\<^bsub>H\<^esub> ?inv_h = \<phi> (\<psi> h) \<otimes>\<^bsub>H\<^esub> ?inv_h"
by (simp add: f_inv_into_f h psi_def surj(1))
also have " ... = \<phi> ((\<psi> h) \<otimes> inv (\<psi> h))"
by (metis h imageI inv_closed phi_hom surj(2))
also have " ... = \<phi> \<one>"
by (simp add: h inv_into_into psi_def surj(1))
finally have 1: "h \<otimes>\<^bsub>H\<^esub> ?inv_h = \<one>\<^bsub>H\<^esub>"
using phi_one by simp
have "?inv_h \<otimes>\<^bsub>H\<^esub> h = ?inv_h \<otimes>\<^bsub>H\<^esub> \<phi> (\<psi> h)"
by (simp add: f_inv_into_f h psi_def surj(1))
also have " ... = \<phi> (inv (\<psi> h) \<otimes> (\<psi> h))"
by (metis h imageI inv_closed phi_hom surj(2))
also have " ... = \<phi> \<one>"
by (simp add: h inv_into_into psi_def surj(1))
finally have 2: "?inv_h \<otimes>\<^bsub>H\<^esub> h = \<one>\<^bsub>H\<^esub>"
using phi_one by simp
thus "h \<in> Units H" unfolding Units_def using 1 2 h surj by fastforce
qed
thus ?thesis unfolding group_def group_axioms_def using assms(2) by simp
qed
corollary (in group) iso_imp_img_group:
assumes "h \<in> iso G H"
shows "group (H \<lparr> one := h \<one> \<rparr>)"
proof -
let ?h_img = "H \<lparr> carrier := h ` (carrier G), one := h \<one> \<rparr>"
have "h \<in> iso G ?h_img"
using assms unfolding iso_def hom_def bij_betw_def by auto
hence "G \<cong> ?h_img"
unfolding is_iso_def by auto
hence "group ?h_img"
using iso_imp_group[of ?h_img] hom_imp_img_monoid[of h H] assms unfolding iso_def by simp
moreover have "carrier H = carrier ?h_img"
using assms unfolding iso_def bij_betw_def by simp
hence "H \<lparr> one := h \<one> \<rparr> = ?h_img"
by simp
ultimately show ?thesis by simp
qed