-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivisibility.thy
More file actions
2981 lines (2571 loc) · 112 KB
/
Divisibility.thy
File metadata and controls
2981 lines (2571 loc) · 112 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/Divisibility.thy
Author: Clemens Ballarin
Author: Stephan Hohe
*)
section \<open>Divisibility in monoids and rings\<close>
theory Divisibility
imports "HOL-Library.Permutation" Coset Group
begin
section \<open>Factorial Monoids\<close>
subsection \<open>Monoids with Cancellation Law\<close>
locale monoid_cancel = monoid +
assumes l_cancel: "\<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b"
and r_cancel: "\<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b"
lemma (in monoid) monoid_cancelI:
assumes l_cancel: "\<And>a b c. \<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b"
and r_cancel: "\<And>a b c. \<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b"
shows "monoid_cancel G"
by standard fact+
lemma (in monoid_cancel) is_monoid_cancel: "monoid_cancel G" ..
sublocale group \<subseteq> monoid_cancel
by standard simp_all
locale comm_monoid_cancel = monoid_cancel + comm_monoid
lemma comm_monoid_cancelI:
fixes G (structure)
assumes "comm_monoid G"
assumes cancel: "\<And>a b c. \<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b"
shows "comm_monoid_cancel G"
proof -
interpret comm_monoid G by fact
show "comm_monoid_cancel G"
by unfold_locales (metis assms(2) m_ac(2))+
qed
lemma (in comm_monoid_cancel) is_comm_monoid_cancel: "comm_monoid_cancel G"
by intro_locales
sublocale comm_group \<subseteq> comm_monoid_cancel ..
subsection \<open>Products of Units in Monoids\<close>
lemma (in monoid) prod_unit_l:
assumes abunit[simp]: "a \<otimes> b \<in> Units G"
and aunit[simp]: "a \<in> Units G"
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G"
shows "b \<in> Units G"
proof -
have c: "inv (a \<otimes> b) \<otimes> a \<in> carrier G" by simp
have "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = inv (a \<otimes> b) \<otimes> (a \<otimes> b)"
by (simp add: m_assoc)
also have "\<dots> = \<one>" by simp
finally have li: "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = \<one>" .
have "\<one> = inv a \<otimes> a" by (simp add: Units_l_inv[symmetric])
also have "\<dots> = inv a \<otimes> \<one> \<otimes> a" by simp
also have "\<dots> = inv a \<otimes> ((a \<otimes> b) \<otimes> inv (a \<otimes> b)) \<otimes> a"
by (simp add: Units_r_inv[OF abunit, symmetric] del: Units_r_inv)
also have "\<dots> = ((inv a \<otimes> a) \<otimes> b) \<otimes> inv (a \<otimes> b) \<otimes> a"
by (simp add: m_assoc del: Units_l_inv)
also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp
also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> a)" by (simp add: m_assoc)
finally have ri: "b \<otimes> (inv (a \<otimes> b) \<otimes> a) = \<one> " by simp
from c li ri show "b \<in> Units G" by (auto simp: Units_def)
qed
lemma (in monoid) prod_unit_r:
assumes abunit[simp]: "a \<otimes> b \<in> Units G"
and bunit[simp]: "b \<in> Units G"
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G"
shows "a \<in> Units G"
proof -
have c: "b \<otimes> inv (a \<otimes> b) \<in> carrier G" by simp
have "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = (a \<otimes> b) \<otimes> inv (a \<otimes> b)"
by (simp add: m_assoc del: Units_r_inv)
also have "\<dots> = \<one>" by simp
finally have li: "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = \<one>" .
have "\<one> = b \<otimes> inv b" by (simp add: Units_r_inv[symmetric])
also have "\<dots> = b \<otimes> \<one> \<otimes> inv b" by simp
also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> (a \<otimes> b)) \<otimes> inv b"
by (simp add: Units_l_inv[OF abunit, symmetric] del: Units_l_inv)
also have "\<dots> = (b \<otimes> inv (a \<otimes> b) \<otimes> a) \<otimes> (b \<otimes> inv b)"
by (simp add: m_assoc del: Units_l_inv)
also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp
finally have ri: "(b \<otimes> inv (a \<otimes> b)) \<otimes> a = \<one> " by simp
from c li ri show "a \<in> Units G" by (auto simp: Units_def)
qed
lemma (in comm_monoid) unit_factor:
assumes "a \<otimes> b \<in> Units G"
and "a \<in> carrier G" "b \<in> carrier G"
shows "a \<in> Units G"
using assms(1)[simplified Units_def]
proof clarsimp
fix i assume i: "i \<in> carrier G" "i \<otimes> (a \<otimes> b) = \<one>" "(a \<otimes> b) \<otimes> i = \<one>"
hence "(i \<otimes> b) \<otimes> a = \<one>" and "a \<otimes> (i \<otimes> b) = \<one>"
using assms m_comm m_lcomm m_assoc by auto
thus "a \<in> Units G"
using i(1) assms unfolding Units_def by auto
qed
subsection \<open>Divisibility and Association\<close>
subsubsection \<open>Function definitions\<close>
definition factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65)
where "a divides\<^bsub>G\<^esub> b \<longleftrightarrow> (\<exists>c\<in>carrier G. b = a \<otimes>\<^bsub>G\<^esub> c)"
definition associated :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "\<sim>\<index>" 55)
where "a \<sim>\<^bsub>G\<^esub> b \<longleftrightarrow> a divides\<^bsub>G\<^esub> b \<and> b divides\<^bsub>G\<^esub> a"
abbreviation "division_rel G \<equiv> \<lparr> carrier = carrier G, eq = (\<sim>\<^bsub>G\<^esub>), le = (divides\<^bsub>G\<^esub>) \<rparr>"
definition properfactor :: "[_, 'a, 'a] \<Rightarrow> bool"
where "properfactor G a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> b \<and> \<not>(b divides\<^bsub>G\<^esub> a)"
definition irreducible :: "[_, 'a] \<Rightarrow> bool"
where "irreducible G a \<longleftrightarrow> a \<notin> Units G \<and> (\<forall>b\<in>carrier G. properfactor G b a \<longrightarrow> b \<in> Units G)"
definition prime :: "[_, 'a] \<Rightarrow> bool"
where "prime G p \<longleftrightarrow>
p \<notin> Units G \<and>
(\<forall>a\<in>carrier G. \<forall>b\<in>carrier G. p divides\<^bsub>G\<^esub> (a \<otimes>\<^bsub>G\<^esub> b) \<longrightarrow> p divides\<^bsub>G\<^esub> a \<or> p divides\<^bsub>G\<^esub> b)"
subsubsection \<open>Divisibility\<close>
lemma dividesI:
fixes G (structure)
assumes carr: "c \<in> carrier G"
and p: "b = a \<otimes> c"
shows "a divides b"
unfolding factor_def using assms by fast
lemma dividesI' [intro]:
fixes G (structure)
assumes p: "b = a \<otimes> c"
and carr: "c \<in> carrier G"
shows "a divides b"
using assms by (fast intro: dividesI)
lemma dividesD:
fixes G (structure)
assumes "a divides b"
shows "\<exists>c\<in>carrier G. b = a \<otimes> c"
using assms unfolding factor_def by fast
lemma dividesE [elim]:
fixes G (structure)
assumes d: "a divides b"
and elim: "\<And>c. \<lbrakk>b = a \<otimes> c; c \<in> carrier G\<rbrakk> \<Longrightarrow> P"
shows "P"
proof -
from dividesD[OF d] obtain c where "c \<in> carrier G" and "b = a \<otimes> c" by auto
then show P by (elim elim)
qed
lemma (in monoid) divides_refl[simp, intro!]:
assumes carr: "a \<in> carrier G"
shows "a divides a"
by (intro dividesI[of "\<one>"]) (simp_all add: carr)
lemma (in monoid) divides_trans [trans]:
assumes dvds: "a divides b" "b divides c"
and acarr: "a \<in> carrier G"
shows "a divides c"
using dvds[THEN dividesD] by (blast intro: dividesI m_assoc acarr)
lemma (in monoid) divides_mult_lI [intro]:
assumes "a divides b" "a \<in> carrier G" "c \<in> carrier G"
shows "(c \<otimes> a) divides (c \<otimes> b)"
by (metis assms factor_def m_assoc)
lemma (in monoid_cancel) divides_mult_l [simp]:
assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G"
shows "(c \<otimes> a) divides (c \<otimes> b) = a divides b"
proof
show "c \<otimes> a divides c \<otimes> b \<Longrightarrow> a divides b"
using carr monoid.m_assoc monoid_axioms monoid_cancel.l_cancel monoid_cancel_axioms by fastforce
show "a divides b \<Longrightarrow> c \<otimes> a divides c \<otimes> b"
using carr(1) carr(3) by blast
qed
lemma (in comm_monoid) divides_mult_rI [intro]:
assumes ab: "a divides b"
and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G"
shows "(a \<otimes> c) divides (b \<otimes> c)"
using carr ab by (metis divides_mult_lI m_comm)
lemma (in comm_monoid_cancel) divides_mult_r [simp]:
assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G"
shows "(a \<otimes> c) divides (b \<otimes> c) = a divides b"
using carr by (simp add: m_comm[of a c] m_comm[of b c])
lemma (in monoid) divides_prod_r:
assumes ab: "a divides b"
and carr: "a \<in> carrier G" "c \<in> carrier G"
shows "a divides (b \<otimes> c)"
using ab carr by (fast intro: m_assoc)
lemma (in comm_monoid) divides_prod_l:
assumes "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" "a divides b"
shows "a divides (c \<otimes> b)"
using assms by (simp add: divides_prod_r m_comm)
lemma (in monoid) unit_divides:
assumes uunit: "u \<in> Units G"
and acarr: "a \<in> carrier G"
shows "u divides a"
proof (intro dividesI[of "(inv u) \<otimes> a"], fast intro: uunit acarr)
from uunit acarr have xcarr: "inv u \<otimes> a \<in> carrier G" by fast
from uunit acarr have "u \<otimes> (inv u \<otimes> a) = (u \<otimes> inv u) \<otimes> a"
by (fast intro: m_assoc[symmetric])
also have "\<dots> = \<one> \<otimes> a" by (simp add: Units_r_inv[OF uunit])
also from acarr have "\<dots> = a" by simp
finally show "a = u \<otimes> (inv u \<otimes> a)" ..
qed
lemma (in comm_monoid) divides_unit:
assumes udvd: "a divides u"
and carr: "a \<in> carrier G" "u \<in> Units G"
shows "a \<in> Units G"
using udvd carr by (blast intro: unit_factor)
lemma (in comm_monoid) Unit_eq_dividesone:
assumes ucarr: "u \<in> carrier G"
shows "u \<in> Units G = u divides \<one>"
using ucarr by (fast dest: divides_unit intro: unit_divides)
subsubsection \<open>Association\<close>
lemma associatedI:
fixes G (structure)
assumes "a divides b" "b divides a"
shows "a \<sim> b"
using assms by (simp add: associated_def)
lemma (in monoid) associatedI2:
assumes uunit[simp]: "u \<in> Units G"
and a: "a = b \<otimes> u"
and bcarr: "b \<in> carrier G"
shows "a \<sim> b"
using uunit bcarr
unfolding a
apply (intro associatedI)
apply (metis Units_closed divides_mult_lI one_closed r_one unit_divides)
by blast
lemma (in monoid) associatedI2':
assumes "a = b \<otimes> u"
and "u \<in> Units G"
and "b \<in> carrier G"
shows "a \<sim> b"
using assms by (intro associatedI2)
lemma associatedD:
fixes G (structure)
assumes "a \<sim> b"
shows "a divides b"
using assms by (simp add: associated_def)
lemma (in monoid_cancel) associatedD2:
assumes assoc: "a \<sim> b"
and carr: "a \<in> carrier G" "b \<in> carrier G"
shows "\<exists>u\<in>Units G. a = b \<otimes> u"
using assoc
unfolding associated_def
proof clarify
assume "b divides a"
then obtain u where ucarr: "u \<in> carrier G" and a: "a = b \<otimes> u"
by (rule dividesE)
assume "a divides b"
then obtain u' where u'carr: "u' \<in> carrier G" and b: "b = a \<otimes> u'"
by (rule dividesE)
note carr = carr ucarr u'carr
from carr have "a \<otimes> \<one> = a" by simp
also have "\<dots> = b \<otimes> u" by (simp add: a)
also have "\<dots> = a \<otimes> u' \<otimes> u" by (simp add: b)
also from carr have "\<dots> = a \<otimes> (u' \<otimes> u)" by (simp add: m_assoc)
finally have "a \<otimes> \<one> = a \<otimes> (u' \<otimes> u)" .
with carr have u1: "\<one> = u' \<otimes> u" by (fast dest: l_cancel)
from carr have "b \<otimes> \<one> = b" by simp
also have "\<dots> = a \<otimes> u'" by (simp add: b)
also have "\<dots> = b \<otimes> u \<otimes> u'" by (simp add: a)
also from carr have "\<dots> = b \<otimes> (u \<otimes> u')" by (simp add: m_assoc)
finally have "b \<otimes> \<one> = b \<otimes> (u \<otimes> u')" .
with carr have u2: "\<one> = u \<otimes> u'" by (fast dest: l_cancel)
from u'carr u1[symmetric] u2[symmetric] have "\<exists>u'\<in>carrier G. u' \<otimes> u = \<one> \<and> u \<otimes> u' = \<one>"
by fast
then have "u \<in> Units G"
by (simp add: Units_def ucarr)
with ucarr a show "\<exists>u\<in>Units G. a = b \<otimes> u" by fast
qed
lemma associatedE:
fixes G (structure)
assumes assoc: "a \<sim> b"
and e: "\<lbrakk>a divides b; b divides a\<rbrakk> \<Longrightarrow> P"
shows "P"
proof -
from assoc have "a divides b" "b divides a"
by (simp_all add: associated_def)
then show P by (elim e)
qed
lemma (in monoid_cancel) associatedE2:
assumes assoc: "a \<sim> b"
and e: "\<And>u. \<lbrakk>a = b \<otimes> u; u \<in> Units G\<rbrakk> \<Longrightarrow> P"
and carr: "a \<in> carrier G" "b \<in> carrier G"
shows "P"
proof -
from assoc and carr have "\<exists>u\<in>Units G. a = b \<otimes> u"
by (rule associatedD2)
then obtain u where "u \<in> Units G" "a = b \<otimes> u"
by auto
then show P by (elim e)
qed
lemma (in monoid) associated_refl [simp, intro!]:
assumes "a \<in> carrier G"
shows "a \<sim> a"
using assms by (fast intro: associatedI)
lemma (in monoid) associated_sym [sym]:
assumes "a \<sim> b"
shows "b \<sim> a"
using assms by (iprover intro: associatedI elim: associatedE)
lemma (in monoid) associated_trans [trans]:
assumes "a \<sim> b" "b \<sim> c"
and "a \<in> carrier G" "c \<in> carrier G"
shows "a \<sim> c"
using assms by (iprover intro: associatedI divides_trans elim: associatedE)
lemma (in monoid) division_equiv [intro, simp]: "equivalence (division_rel G)"
apply unfold_locales
apply simp_all
apply (metis associated_def)
apply (iprover intro: associated_trans)
done
subsubsection \<open>Division and associativity\<close>
lemmas divides_antisym = associatedI
lemma (in monoid) divides_cong_l [trans]:
assumes "x \<sim> x'" "x' divides y" "x \<in> carrier G"
shows "x divides y"
by (meson assms associatedD divides_trans)
lemma (in monoid) divides_cong_r [trans]:
assumes "x divides y" "y \<sim> y'" "x \<in> carrier G"
shows "x divides y'"
by (meson assms associatedD divides_trans)
lemma (in monoid) division_weak_partial_order [simp, intro!]:
"weak_partial_order (division_rel G)"
apply unfold_locales
apply (simp_all add: associated_sym divides_antisym)
apply (metis associated_trans)
apply (metis divides_trans)
by (meson associated_def divides_trans)
subsubsection \<open>Multiplication and associativity\<close>
lemma (in monoid_cancel) mult_cong_r:
assumes "b \<sim> b'" "a \<in> carrier G" "b \<in> carrier G" "b' \<in> carrier G"
shows "a \<otimes> b \<sim> a \<otimes> b'"
by (meson assms associated_def divides_mult_lI)
lemma (in comm_monoid_cancel) mult_cong_l:
assumes "a \<sim> a'" "a \<in> carrier G" "a' \<in> carrier G" "b \<in> carrier G"
shows "a \<otimes> b \<sim> a' \<otimes> b"
using assms m_comm mult_cong_r by auto
lemma (in monoid_cancel) assoc_l_cancel:
assumes "a \<in> carrier G" "b \<in> carrier G" "b' \<in> carrier G" "a \<otimes> b \<sim> a \<otimes> b'"
shows "b \<sim> b'"
by (meson assms associated_def divides_mult_l)
lemma (in comm_monoid_cancel) assoc_r_cancel:
assumes "a \<otimes> b \<sim> a' \<otimes> b" "a \<in> carrier G" "a' \<in> carrier G" "b \<in> carrier G"
shows "a \<sim> a'"
using assms assoc_l_cancel m_comm by presburger
subsubsection \<open>Units\<close>
lemma (in monoid_cancel) assoc_unit_l [trans]:
assumes "a \<sim> b"
and "b \<in> Units G"
and "a \<in> carrier G"
shows "a \<in> Units G"
using assms by (fast elim: associatedE2)
lemma (in monoid_cancel) assoc_unit_r [trans]:
assumes aunit: "a \<in> Units G"
and asc: "a \<sim> b"
and bcarr: "b \<in> carrier G"
shows "b \<in> Units G"
using aunit bcarr associated_sym[OF asc] by (blast intro: assoc_unit_l)
lemma (in comm_monoid) Units_cong:
assumes aunit: "a \<in> Units G" and asc: "a \<sim> b"
and bcarr: "b \<in> carrier G"
shows "b \<in> Units G"
using assms by (blast intro: divides_unit elim: associatedE)
lemma (in monoid) Units_assoc:
assumes units: "a \<in> Units G" "b \<in> Units G"
shows "a \<sim> b"
using units by (fast intro: associatedI unit_divides)
lemma (in monoid) Units_are_ones: "Units G {.=}\<^bsub>(division_rel G)\<^esub> {\<one>}"
proof -
have "a .\<in>\<^bsub>division_rel G\<^esub> {\<one>}" if "a \<in> Units G" for a
proof -
have "a \<sim> \<one>"
by (rule associatedI) (simp_all add: Units_closed that unit_divides)
then show ?thesis
by (simp add: elem_def)
qed
moreover have "\<one> .\<in>\<^bsub>division_rel G\<^esub> Units G"
by (simp add: equivalence.mem_imp_elem)
ultimately show ?thesis
by (auto simp: set_eq_def)
qed
lemma (in comm_monoid) Units_Lower: "Units G = Lower (division_rel G) (carrier G)"
apply (auto simp add: Units_def Lower_def)
apply (metis Units_one_closed unit_divides unit_factor)
apply (metis Unit_eq_dividesone Units_r_inv_ex m_ac(2) one_closed)
done
(* NEW ====================================================================== *)
lemma (in monoid_cancel) associated_iff:
assumes "a \<in> carrier G" "b \<in> carrier G"
shows "a \<sim> b \<longleftrightarrow> (\<exists>c \<in> Units G. a = b \<otimes> c)"
using assms associatedI2' associatedD2 by auto
(* ========================================================================== *)
subsubsection \<open>Proper factors\<close>
lemma properfactorI:
fixes G (structure)
assumes "a divides b"
and "\<not>(b divides a)"
shows "properfactor G a b"
using assms unfolding properfactor_def by simp
lemma properfactorI2:
fixes G (structure)
assumes advdb: "a divides b"
and neq: "\<not>(a \<sim> b)"
shows "properfactor G a b"
proof (rule properfactorI, rule advdb, rule notI)
assume "b divides a"
with advdb have "a \<sim> b" by (rule associatedI)
with neq show "False" by fast
qed
lemma (in comm_monoid_cancel) properfactorI3:
assumes p: "p = a \<otimes> b"
and nunit: "b \<notin> Units G"
and carr: "a \<in> carrier G" "b \<in> carrier G"
shows "properfactor G a p"
unfolding p
using carr
apply (intro properfactorI, fast)
proof (clarsimp, elim dividesE)
fix c
assume ccarr: "c \<in> carrier G"
note [simp] = carr ccarr
have "a \<otimes> \<one> = a" by simp
also assume "a = a \<otimes> b \<otimes> c"
also have "\<dots> = a \<otimes> (b \<otimes> c)" by (simp add: m_assoc)
finally have "a \<otimes> \<one> = a \<otimes> (b \<otimes> c)" .
then have rinv: "\<one> = b \<otimes> c" by (intro l_cancel[of "a" "\<one>" "b \<otimes> c"], simp+)
also have "\<dots> = c \<otimes> b" by (simp add: m_comm)
finally have linv: "\<one> = c \<otimes> b" .
from ccarr linv[symmetric] rinv[symmetric] have "b \<in> Units G"
unfolding Units_def by fastforce
with nunit show False ..
qed
lemma properfactorE:
fixes G (structure)
assumes pf: "properfactor G a b"
and r: "\<lbrakk>a divides b; \<not>(b divides a)\<rbrakk> \<Longrightarrow> P"
shows "P"
using pf unfolding properfactor_def by (fast intro: r)
lemma properfactorE2:
fixes G (structure)
assumes pf: "properfactor G a b"
and elim: "\<lbrakk>a divides b; \<not>(a \<sim> b)\<rbrakk> \<Longrightarrow> P"
shows "P"
using pf unfolding properfactor_def by (fast elim: elim associatedE)
lemma (in monoid) properfactor_unitE:
assumes uunit: "u \<in> Units G"
and pf: "properfactor G a u"
and acarr: "a \<in> carrier G"
shows "P"
using pf unit_divides[OF uunit acarr] by (fast elim: properfactorE)
lemma (in monoid) properfactor_divides:
assumes pf: "properfactor G a b"
shows "a divides b"
using pf by (elim properfactorE)
lemma (in monoid) properfactor_trans1 [trans]:
assumes dvds: "a divides b" "properfactor G b c"
and carr: "a \<in> carrier G" "c \<in> carrier G"
shows "properfactor G a c"
using dvds carr
apply (elim properfactorE, intro properfactorI)
apply (iprover intro: divides_trans)+
done
lemma (in monoid) properfactor_trans2 [trans]:
assumes dvds: "properfactor G a b" "b divides c"
and carr: "a \<in> carrier G" "b \<in> carrier G"
shows "properfactor G a c"
using dvds carr
apply (elim properfactorE, intro properfactorI)
apply (iprover intro: divides_trans)+
done
lemma properfactor_lless:
fixes G (structure)
shows "properfactor G = lless (division_rel G)"
by (force simp: lless_def properfactor_def associated_def)
lemma (in monoid) properfactor_cong_l [trans]:
assumes x'x: "x' \<sim> x"
and pf: "properfactor G x y"
and carr: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G"
shows "properfactor G x' y"
using pf
unfolding properfactor_lless
proof -
interpret weak_partial_order "division_rel G" ..
from x'x have "x' .=\<^bsub>division_rel G\<^esub> x" by simp
also assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y"
finally show "x' \<sqsubset>\<^bsub>division_rel G\<^esub> y" by (simp add: carr)
qed
lemma (in monoid) properfactor_cong_r [trans]:
assumes pf: "properfactor G x y"
and yy': "y \<sim> y'"
and carr: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G"
shows "properfactor G x y'"
using pf
unfolding properfactor_lless
proof -
interpret weak_partial_order "division_rel G" ..
assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y"
also from yy'
have "y .=\<^bsub>division_rel G\<^esub> y'" by simp
finally show "x \<sqsubset>\<^bsub>division_rel G\<^esub> y'" by (simp add: carr)
qed
lemma (in monoid_cancel) properfactor_mult_lI [intro]:
assumes ab: "properfactor G a b"
and carr: "a \<in> carrier G" "c \<in> carrier G"
shows "properfactor G (c \<otimes> a) (c \<otimes> b)"
using ab carr by (fastforce elim: properfactorE intro: properfactorI)
lemma (in monoid_cancel) properfactor_mult_l [simp]:
assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G"
shows "properfactor G (c \<otimes> a) (c \<otimes> b) = properfactor G a b"
using carr by (fastforce elim: properfactorE intro: properfactorI)
lemma (in comm_monoid_cancel) properfactor_mult_rI [intro]:
assumes ab: "properfactor G a b"
and carr: "a \<in> carrier G" "c \<in> carrier G"
shows "properfactor G (a \<otimes> c) (b \<otimes> c)"
using ab carr by (fastforce elim: properfactorE intro: properfactorI)
lemma (in comm_monoid_cancel) properfactor_mult_r [simp]:
assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G"
shows "properfactor G (a \<otimes> c) (b \<otimes> c) = properfactor G a b"
using carr by (fastforce elim: properfactorE intro: properfactorI)
lemma (in monoid) properfactor_prod_r:
assumes ab: "properfactor G a b"
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G"
shows "properfactor G a (b \<otimes> c)"
by (intro properfactor_trans2[OF ab] divides_prod_r) simp_all
lemma (in comm_monoid) properfactor_prod_l:
assumes ab: "properfactor G a b"
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G"
shows "properfactor G a (c \<otimes> b)"
by (intro properfactor_trans2[OF ab] divides_prod_l) simp_all
subsection \<open>Irreducible Elements and Primes\<close>
subsubsection \<open>Irreducible elements\<close>
lemma irreducibleI:
fixes G (structure)
assumes "a \<notin> Units G"
and "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b a\<rbrakk> \<Longrightarrow> b \<in> Units G"
shows "irreducible G a"
using assms unfolding irreducible_def by blast
lemma irreducibleE:
fixes G (structure)
assumes irr: "irreducible G a"
and elim: "\<lbrakk>a \<notin> Units G; \<forall>b. b \<in> carrier G \<and> properfactor G b a \<longrightarrow> b \<in> Units G\<rbrakk> \<Longrightarrow> P"
shows "P"
using assms unfolding irreducible_def by blast
lemma irreducibleD:
fixes G (structure)
assumes irr: "irreducible G a"
and pf: "properfactor G b a"
and bcarr: "b \<in> carrier G"
shows "b \<in> Units G"
using assms by (fast elim: irreducibleE)
lemma (in monoid_cancel) irreducible_cong [trans]:
assumes irred: "irreducible G a"
and aa': "a \<sim> a'" "a \<in> carrier G" "a' \<in> carrier G"
shows "irreducible G a'"
using assms
apply (auto simp: irreducible_def assoc_unit_l)
apply (metis aa' associated_sym properfactor_cong_r)
done
lemma (in monoid) irreducible_prod_rI:
assumes airr: "irreducible G a"
and bunit: "b \<in> Units G"
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G"
shows "irreducible G (a \<otimes> b)"
using airr carr bunit
apply (elim irreducibleE, intro irreducibleI)
using prod_unit_r apply blast
using associatedI2' properfactor_cong_r by auto
lemma (in comm_monoid) irreducible_prod_lI:
assumes birr: "irreducible G b"
and aunit: "a \<in> Units G"
and carr [simp]: "a \<in> carrier G" "b \<in> carrier G"
shows "irreducible G (a \<otimes> b)"
by (metis aunit birr carr irreducible_prod_rI m_comm)
lemma (in comm_monoid_cancel) irreducible_prodE [elim]:
assumes irr: "irreducible G (a \<otimes> b)"
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G"
and e1: "\<lbrakk>irreducible G a; b \<in> Units G\<rbrakk> \<Longrightarrow> P"
and e2: "\<lbrakk>a \<in> Units G; irreducible G b\<rbrakk> \<Longrightarrow> P"
shows P
using irr
proof (elim irreducibleE)
assume abnunit: "a \<otimes> b \<notin> Units G"
and isunit[rule_format]: "\<forall>ba. ba \<in> carrier G \<and> properfactor G ba (a \<otimes> b) \<longrightarrow> ba \<in> Units G"
show P
proof (cases "a \<in> Units G")
case aunit: True
have "irreducible G b"
proof (rule irreducibleI, rule notI)
assume "b \<in> Units G"
with aunit have "(a \<otimes> b) \<in> Units G" by fast
with abnunit show "False" ..
next
fix c
assume ccarr: "c \<in> carrier G"
and "properfactor G c b"
then have "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_l[of c b a])
with ccarr show "c \<in> Units G" by (fast intro: isunit)
qed
with aunit show "P" by (rule e2)
next
case anunit: False
with carr have "properfactor G b (b \<otimes> a)" by (fast intro: properfactorI3)
then have bf: "properfactor G b (a \<otimes> b)" by (subst m_comm[of a b], simp+)
then have bunit: "b \<in> Units G" by (intro isunit, simp)
have "irreducible G a"
proof (rule irreducibleI, rule notI)
assume "a \<in> Units G"
with bunit have "(a \<otimes> b) \<in> Units G" by fast
with abnunit show "False" ..
next
fix c
assume ccarr: "c \<in> carrier G"
and "properfactor G c a"
then have "properfactor G c (a \<otimes> b)"
by (simp add: properfactor_prod_r[of c a b])
with ccarr show "c \<in> Units G" by (fast intro: isunit)
qed
from this bunit show "P" by (rule e1)
qed
qed
subsubsection \<open>Prime elements\<close>
lemma primeI:
fixes G (structure)
assumes "p \<notin> Units G"
and "\<And>a b. \<lbrakk>a \<in> carrier G; b \<in> carrier G; p divides (a \<otimes> b)\<rbrakk> \<Longrightarrow> p divides a \<or> p divides b"
shows "prime G p"
using assms unfolding prime_def by blast
lemma primeE:
fixes G (structure)
assumes pprime: "prime G p"
and e: "\<lbrakk>p \<notin> Units G; \<forall>a\<in>carrier G. \<forall>b\<in>carrier G.
p divides a \<otimes> b \<longrightarrow> p divides a \<or> p divides b\<rbrakk> \<Longrightarrow> P"
shows "P"
using pprime unfolding prime_def by (blast dest: e)
lemma (in comm_monoid_cancel) prime_divides:
assumes carr: "a \<in> carrier G" "b \<in> carrier G"
and pprime: "prime G p"
and pdvd: "p divides a \<otimes> b"
shows "p divides a \<or> p divides b"
using assms by (blast elim: primeE)
lemma (in monoid_cancel) prime_cong [trans]:
assumes "prime G p"
and pp': "p \<sim> p'" "p \<in> carrier G" "p' \<in> carrier G"
shows "prime G p'"
using assms
apply (auto simp: prime_def assoc_unit_l)
apply (metis pp' associated_sym divides_cong_l)
done
(*by Paulo Emílio de Vilhena*)
lemma (in comm_monoid_cancel) prime_irreducible:
assumes "prime G p"
shows "irreducible G p"
proof (rule irreducibleI)
show "p \<notin> Units G"
using assms unfolding prime_def by simp
next
fix b assume A: "b \<in> carrier G" "properfactor G b p"
then obtain c where c: "c \<in> carrier G" "p = b \<otimes> c"
unfolding properfactor_def factor_def by auto
hence "p divides c"
using A assms unfolding prime_def properfactor_def by auto
then obtain b' where b': "b' \<in> carrier G" "c = p \<otimes> b'"
unfolding factor_def by auto
hence "\<one> = b \<otimes> b'"
by (metis A(1) l_cancel m_closed m_lcomm one_closed r_one c)
thus "b \<in> Units G"
using A(1) Units_one_closed b'(1) unit_factor by presburger
qed
subsection \<open>Factorization and Factorial Monoids\<close>
subsubsection \<open>Function definitions\<close>
definition factors :: "[_, 'a list, 'a] \<Rightarrow> bool"
where "factors G fs a \<longleftrightarrow> (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (\<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> = a"
definition wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool"
where "wfactors G fs a \<longleftrightarrow> (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (\<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> \<sim>\<^bsub>G\<^esub> a"
abbreviation list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44)
where "list_assoc G \<equiv> list_all2 (\<sim>\<^bsub>G\<^esub>)"
definition essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool"
where "essentially_equal G fs1 fs2 \<longleftrightarrow> (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>]\<^bsub>G\<^esub> fs2)"
locale factorial_monoid = comm_monoid_cancel +
assumes factors_exist: "\<lbrakk>a \<in> carrier G; a \<notin> Units G\<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a"
and factors_unique:
"\<lbrakk>factors G fs a; factors G fs' a; a \<in> carrier G; a \<notin> Units G;
set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'"
subsubsection \<open>Comparing lists of elements\<close>
text \<open>Association on lists\<close>
lemma (in monoid) listassoc_refl [simp, intro]:
assumes "set as \<subseteq> carrier G"
shows "as [\<sim>] as"
using assms by (induct as) simp_all
lemma (in monoid) listassoc_sym [sym]:
assumes "as [\<sim>] bs"
and "set as \<subseteq> carrier G"
and "set bs \<subseteq> carrier G"
shows "bs [\<sim>] as"
using assms
proof (induction as arbitrary: bs)
case Cons
then show ?case
by (induction bs) (use associated_sym in auto)
qed auto
lemma (in monoid) listassoc_trans [trans]:
assumes "as [\<sim>] bs" and "bs [\<sim>] cs"
and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" and "set cs \<subseteq> carrier G"
shows "as [\<sim>] cs"
using assms
apply (simp add: list_all2_conv_all_nth set_conv_nth, safe)
by (metis (mono_tags, lifting) associated_trans nth_mem subsetCE)
lemma (in monoid_cancel) irrlist_listassoc_cong:
assumes "\<forall>a\<in>set as. irreducible G a"
and "as [\<sim>] bs"
and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
shows "\<forall>a\<in>set bs. irreducible G a"
using assms
apply (clarsimp simp add: list_all2_conv_all_nth set_conv_nth)
apply (blast intro: irreducible_cong)
done
text \<open>Permutations\<close>
lemma perm_map [intro]:
assumes p: "a <~~> b"
shows "map f a <~~> map f b"
using p by induct auto
lemma perm_map_switch:
assumes m: "map f a = map f b" and p: "b <~~> c"
shows "\<exists>d. a <~~> d \<and> map f d = map f c"
using p m by (induct arbitrary: a) (simp, force, force, blast)
lemma (in monoid) perm_assoc_switch:
assumes a:"as [\<sim>] bs" and p: "bs <~~> cs"
shows "\<exists>bs'. as <~~> bs' \<and> bs' [\<sim>] cs"
using p a
proof (induction bs cs arbitrary: as)
case (swap y x l)
then show ?case
by (metis (no_types, hide_lams) list_all2_Cons2 perm.swap)
next
case (Cons xs ys z)
then show ?case
by (metis list_all2_Cons2 perm.Cons)
next
case (trans xs ys zs)
then show ?case
by (meson perm.trans)
qed auto
lemma (in monoid) perm_assoc_switch_r:
assumes p: "as <~~> bs" and a:"bs [\<sim>] cs"
shows "\<exists>bs'. as [\<sim>] bs' \<and> bs' <~~> cs"
using p a
proof (induction as bs arbitrary: cs)
case Nil
then show ?case
by auto
next
case (swap y x l)
then show ?case
by (metis (no_types, hide_lams) list_all2_Cons1 perm.swap)
next
case (Cons xs ys z)
then show ?case
by (metis list_all2_Cons1 perm.Cons)
next
case (trans xs ys zs)
then show ?case
by (blast intro: elim: )
qed
declare perm_sym [sym]
lemma perm_setP:
assumes perm: "as <~~> bs"
and as: "P (set as)"
shows "P (set bs)"
proof -
from perm have "mset as = mset bs"
by (simp add: mset_eq_perm)
then have "set as = set bs"
by (rule mset_eq_setD)
with as show "P (set bs)"
by simp
qed
lemmas (in monoid) perm_closed = perm_setP[of _ _ "\<lambda>as. as \<subseteq> carrier G"]
lemmas (in monoid) irrlist_perm_cong = perm_setP[of _ _ "\<lambda>as. \<forall>a\<in>as. irreducible G a"]
text \<open>Essentially equal factorizations\<close>
lemma (in monoid) essentially_equalI:
assumes ex: "fs1 <~~> fs1'" "fs1' [\<sim>] fs2"
shows "essentially_equal G fs1 fs2"
using ex unfolding essentially_equal_def by fast
lemma (in monoid) essentially_equalE:
assumes ee: "essentially_equal G fs1 fs2"
and e: "\<And>fs1'. \<lbrakk>fs1 <~~> fs1'; fs1' [\<sim>] fs2\<rbrakk> \<Longrightarrow> P"
shows "P"
using ee unfolding essentially_equal_def by (fast intro: e)
lemma (in monoid) ee_refl [simp,intro]:
assumes carr: "set as \<subseteq> carrier G"
shows "essentially_equal G as as"
using carr by (fast intro: essentially_equalI)
lemma (in monoid) ee_sym [sym]:
assumes ee: "essentially_equal G as bs"
and carr: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G"
shows "essentially_equal G bs as"
using ee
proof (elim essentially_equalE)
fix fs
assume "as <~~> fs" "fs [\<sim>] bs"
from perm_assoc_switch_r [OF this] obtain fs' where a: "as [\<sim>] fs'" and p: "fs' <~~> bs"
by blast
from p have "bs <~~> fs'" by (rule perm_sym)
with a[symmetric] carr show ?thesis
by (iprover intro: essentially_equalI perm_closed)
qed
lemma (in monoid) ee_trans [trans]:
assumes ab: "essentially_equal G as bs" and bc: "essentially_equal G bs cs"
and ascarr: "set as \<subseteq> carrier G"
and bscarr: "set bs \<subseteq> carrier G"
and cscarr: "set cs \<subseteq> carrier G"
shows "essentially_equal G as cs"
using ab bc
proof (elim essentially_equalE)
fix abs bcs
assume "abs [\<sim>] bs" and pb: "bs <~~> bcs"
from perm_assoc_switch [OF this] obtain bs' where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs"
by blast
assume "as <~~> abs"
with p have pp: "as <~~> bs'" by fast
from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed)
from pb bscarr have c2: "set bcs \<subseteq> carrier G" by (rule perm_closed)
assume "bcs [\<sim>] cs"
then have "bs' [\<sim>] cs"
using a c1 c2 cscarr listassoc_trans by blast
with pp show ?thesis
by (rule essentially_equalI)
qed
subsubsection \<open>Properties of lists of elements\<close>
text \<open>Multiplication of factors in a list\<close>
lemma (in monoid) multlist_closed [simp, intro]:
assumes ascarr: "set fs \<subseteq> carrier G"
shows "foldr (\<otimes>) fs \<one> \<in> carrier G"
using ascarr by (induct fs) simp_all
lemma (in comm_monoid) multlist_dividesI:
assumes "f \<in> set fs" and "set fs \<subseteq> carrier G"
shows "f divides (foldr (\<otimes>) fs \<one>)"
using assms
proof (induction fs)
case (Cons a fs)
then have f: "f \<in> carrier G"
by blast
show ?case
proof (cases "f = a")
case True
then show ?thesis
using Cons.prems by auto
next
case False
with Cons show ?thesis