src/HOL/Algebra/Divisibility.thy
author wenzelm
Sun, 12 Aug 2018 14:28:28 +0200
changeset 68743 91162dd89571
parent 68664 bd0df72c16d5
child 68684 9a42b84f8838
permissions -rw-r--r--
proper session dirs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 41413
diff changeset
     1
(*  Title:      HOL/Algebra/Divisibility.thy
b460124855b8 tuned headers;
wenzelm
parents: 41413
diff changeset
     2
    Author:     Clemens Ballarin
b460124855b8 tuned headers;
wenzelm
parents: 41413
diff changeset
     3
    Author:     Stephan Hohe
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
     4
*)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
     5
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
     6
section \<open>Divisibility in monoids and rings\<close>
41959
b460124855b8 tuned headers;
wenzelm
parents: 41413
diff changeset
     7
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
     8
theory Divisibility
66579
2db3fe23fdaf Revert 5a42eddc11c1.
ballarin
parents: 66501
diff changeset
     9
  imports "HOL-Library.Permutation" Coset Group
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    10
begin
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    11
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    12
section \<open>Factorial Monoids\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    13
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    14
subsection \<open>Monoids with Cancellation Law\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    15
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    16
locale monoid_cancel = monoid +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    17
  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"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    18
    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"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    19
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    20
lemma (in monoid) monoid_cancelI:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    21
  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"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    22
    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"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    23
  shows "monoid_cancel G"
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60515
diff changeset
    24
    by standard fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    25
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    26
lemma (in monoid_cancel) is_monoid_cancel: "monoid_cancel G" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    27
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
    28
sublocale group \<subseteq> monoid_cancel
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60515
diff changeset
    29
  by standard simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    30
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    31
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    32
locale comm_monoid_cancel = monoid_cancel + comm_monoid
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    33
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    34
lemma comm_monoid_cancelI:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    35
  fixes G (structure)
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    36
  assumes "comm_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    37
  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"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    38
  shows "comm_monoid_cancel G"
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    39
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
    40
  interpret comm_monoid G by fact
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    41
  show "comm_monoid_cancel G"
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
    42
    by unfold_locales (metis assms(2) m_ac(2))+
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    43
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    44
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    45
lemma (in comm_monoid_cancel) is_comm_monoid_cancel: "comm_monoid_cancel G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
    46
  by intro_locales
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    47
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    48
sublocale comm_group \<subseteq> comm_monoid_cancel ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    49
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    50
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
    51
subsection \<open>Products of Units in Monoids\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    52
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    53
lemma (in monoid) prod_unit_l:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    54
  assumes abunit[simp]: "a \<otimes> b \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    55
    and aunit[simp]: "a \<in> Units G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    56
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    57
  shows "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    58
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    59
  have c: "inv (a \<otimes> b) \<otimes> a \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    60
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    61
  have "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = inv (a \<otimes> b) \<otimes> (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    62
    by (simp add: m_assoc)
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
    63
  also have "\<dots> = \<one>" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    64
  finally have li: "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    65
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    66
  have "\<one> = inv a \<otimes> a" by (simp add: Units_l_inv[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    67
  also have "\<dots> = inv a \<otimes> \<one> \<otimes> a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    68
  also have "\<dots> = inv a \<otimes> ((a \<otimes> b) \<otimes> inv (a \<otimes> b)) \<otimes> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    69
    by (simp add: Units_r_inv[OF abunit, symmetric] del: Units_r_inv)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    70
  also have "\<dots> = ((inv a \<otimes> a) \<otimes> b) \<otimes> inv (a \<otimes> b) \<otimes> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    71
    by (simp add: m_assoc del: Units_l_inv)
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
    72
  also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    73
  also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> a)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    74
  finally have ri: "b \<otimes> (inv (a \<otimes> b) \<otimes> a) = \<one> " by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    75
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    76
  from c li ri show "b \<in> Units G" by (auto simp: Units_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    77
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    78
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    79
lemma (in monoid) prod_unit_r:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    80
  assumes abunit[simp]: "a \<otimes> b \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    81
    and bunit[simp]: "b \<in> Units G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    82
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    83
  shows "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    84
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    85
  have c: "b \<otimes> inv (a \<otimes> b) \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    86
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    87
  have "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = (a \<otimes> b) \<otimes> inv (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    88
    by (simp add: m_assoc del: Units_r_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    89
  also have "\<dots> = \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    90
  finally have li: "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    91
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    92
  have "\<one> = b \<otimes> inv b" by (simp add: Units_r_inv[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    93
  also have "\<dots> = b \<otimes> \<one> \<otimes> inv b" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    94
  also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> (a \<otimes> b)) \<otimes> inv b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
    95
    by (simp add: Units_l_inv[OF abunit, symmetric] del: Units_l_inv)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    96
  also have "\<dots> = (b \<otimes> inv (a \<otimes> b) \<otimes> a) \<otimes> (b \<otimes> inv b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    97
    by (simp add: m_assoc del: Units_l_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    98
  also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    99
  finally have ri: "(b \<otimes> inv (a \<otimes> b)) \<otimes> a = \<one> " by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   100
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   101
  from c li ri show "a \<in> Units G" by (auto simp: Units_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   102
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   103
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   104
lemma (in comm_monoid) unit_factor:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   105
  assumes abunit: "a \<otimes> b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   106
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   107
  shows "a \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   108
  using abunit[simplified Units_def]
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   109
proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   110
  fix i
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   111
  assume [simp]: "i \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   112
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   113
  have carr': "b \<otimes> i \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   114
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   115
  have "(b \<otimes> i) \<otimes> a = (i \<otimes> b) \<otimes> a" by (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   116
  also have "\<dots> = i \<otimes> (b \<otimes> a)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   117
  also have "\<dots> = i \<otimes> (a \<otimes> b)" by (simp add: m_comm)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   118
  also assume "i \<otimes> (a \<otimes> b) = \<one>"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   119
  finally have li': "(b \<otimes> i) \<otimes> a = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   120
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   121
  have "a \<otimes> (b \<otimes> i) = a \<otimes> b \<otimes> i" by (simp add: m_assoc)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   122
  also assume "a \<otimes> b \<otimes> i = \<one>"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   123
  finally have ri': "a \<otimes> (b \<otimes> i) = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   124
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   125
  from carr' li' ri'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   126
  show "a \<in> Units G" by (simp add: Units_def, fast)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   127
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   128
35849
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
   129
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   130
subsection \<open>Divisibility and Association\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   131
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   132
subsubsection \<open>Function definitions\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   133
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   134
definition factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65)
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   135
  where "a divides\<^bsub>G\<^esub> b \<longleftrightarrow> (\<exists>c\<in>carrier G. b = a \<otimes>\<^bsub>G\<^esub> c)"
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   136
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   137
definition associated :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "\<sim>\<index>" 55)
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   138
  where "a \<sim>\<^bsub>G\<^esub> b \<longleftrightarrow> a divides\<^bsub>G\<^esub> b \<and> b divides\<^bsub>G\<^esub> a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   139
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
   140
abbreviation "division_rel G \<equiv> \<lparr>carrier = carrier G, eq = (\<sim>\<^bsub>G\<^esub>), le = (divides\<^bsub>G\<^esub>)\<rparr>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   141
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   142
definition properfactor :: "[_, 'a, 'a] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   143
  where "properfactor G a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> b \<and> \<not>(b divides\<^bsub>G\<^esub> a)"
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   144
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   145
definition irreducible :: "[_, 'a] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   146
  where "irreducible G a \<longleftrightarrow> a \<notin> Units G \<and> (\<forall>b\<in>carrier G. properfactor G b a \<longrightarrow> b \<in> Units G)"
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   147
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   148
definition prime :: "[_, 'a] \<Rightarrow> bool"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   149
  where "prime G p \<longleftrightarrow>
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   150
    p \<notin> Units G \<and>
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   151
    (\<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)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   152
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   153
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   154
subsubsection \<open>Divisibility\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   155
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   156
lemma dividesI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   157
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   158
  assumes carr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   159
    and p: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   160
  shows "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   161
  unfolding factor_def using assms by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   162
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   163
lemma dividesI' [intro]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   164
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   165
  assumes p: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   166
    and carr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   167
  shows "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   168
  using assms by (fast intro: dividesI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   169
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   170
lemma dividesD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   171
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   172
  assumes "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   173
  shows "\<exists>c\<in>carrier G. b = a \<otimes> c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   174
  using assms unfolding factor_def by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   175
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   176
lemma dividesE [elim]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   177
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   178
  assumes d: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   179
    and elim: "\<And>c. \<lbrakk>b = a \<otimes> c; c \<in> carrier G\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   180
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   181
proof -
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
   182
  from dividesD[OF d] obtain c where "c \<in> carrier G" and "b = a \<otimes> c" by auto
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   183
  then show P by (elim elim)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   184
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   185
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   186
lemma (in monoid) divides_refl[simp, intro!]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   187
  assumes carr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   188
  shows "a divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   189
  by (intro dividesI[of "\<one>"]) (simp_all add: carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   190
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   191
lemma (in monoid) divides_trans [trans]:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   192
  assumes dvds: "a divides b" "b divides c"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   193
    and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   194
  shows "a divides c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   195
  using dvds[THEN dividesD] by (blast intro: dividesI m_assoc acarr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   196
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   197
lemma (in monoid) divides_mult_lI [intro]:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   198
  assumes  "a divides b" "a \<in> carrier G" "c \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   199
  shows "(c \<otimes> a) divides (c \<otimes> b)"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   200
  by (metis assms factor_def m_assoc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   201
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   202
lemma (in monoid_cancel) divides_mult_l [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   203
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   204
  shows "(c \<otimes> a) divides (c \<otimes> b) = a divides b"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   205
proof
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   206
  show "c \<otimes> a divides c \<otimes> b \<Longrightarrow> a divides b"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   207
    using carr monoid.m_assoc monoid_axioms monoid_cancel.l_cancel monoid_cancel_axioms by fastforce
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   208
  show "a divides b \<Longrightarrow> c \<otimes> a divides c \<otimes> b"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   209
  using carr(1) carr(3) by blast
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   210
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   211
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   212
lemma (in comm_monoid) divides_mult_rI [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   213
  assumes ab: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   214
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   215
  shows "(a \<otimes> c) divides (b \<otimes> c)"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   216
  using carr ab by (metis divides_mult_lI m_comm)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   217
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   218
lemma (in comm_monoid_cancel) divides_mult_r [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   219
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   220
  shows "(a \<otimes> c) divides (b \<otimes> c) = a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   221
  using carr by (simp add: m_comm[of a c] m_comm[of b c])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   222
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   223
lemma (in monoid) divides_prod_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   224
  assumes ab: "a divides b"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   225
    and carr: "a \<in> carrier G" "c \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   226
  shows "a divides (b \<otimes> c)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   227
  using ab carr by (fast intro: m_assoc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   228
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   229
lemma (in comm_monoid) divides_prod_l:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   230
  assumes "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" "a divides b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   231
  shows "a divides (c \<otimes> b)"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   232
  using assms  by (simp add: divides_prod_r m_comm)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   233
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   234
lemma (in monoid) unit_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   235
  assumes uunit: "u \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   236
    and acarr: "a \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   237
  shows "u divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   238
proof (intro dividesI[of "(inv u) \<otimes> a"], fast intro: uunit acarr)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   239
  from uunit acarr have xcarr: "inv u \<otimes> a \<in> carrier G" by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   240
  from uunit acarr have "u \<otimes> (inv u \<otimes> a) = (u \<otimes> inv u) \<otimes> a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   241
    by (fast intro: m_assoc[symmetric])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   242
  also have "\<dots> = \<one> \<otimes> a" by (simp add: Units_r_inv[OF uunit])
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   243
  also from acarr have "\<dots> = a" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   244
  finally show "a = u \<otimes> (inv u \<otimes> a)" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   245
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   246
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   247
lemma (in comm_monoid) divides_unit:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   248
  assumes udvd: "a divides u"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   249
    and  carr: "a \<in> carrier G"  "u \<in> Units G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   250
  shows "a \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   251
  using udvd carr by (blast intro: unit_factor)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   252
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   253
lemma (in comm_monoid) Unit_eq_dividesone:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   254
  assumes ucarr: "u \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   255
  shows "u \<in> Units G = u divides \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   256
  using ucarr by (fast dest: divides_unit intro: unit_divides)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   257
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   258
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   259
subsubsection \<open>Association\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   260
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   261
lemma associatedI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   262
  fixes G (structure)
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   263
  assumes "a divides b" "b divides a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   264
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   265
  using assms by (simp add: associated_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   266
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   267
lemma (in monoid) associatedI2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   268
  assumes uunit[simp]: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   269
    and a: "a = b \<otimes> u"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   270
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   271
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   272
  using uunit bcarr
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   273
  unfolding a
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   274
  apply (intro associatedI)
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   275
  apply (metis Units_closed divides_mult_lI one_closed r_one unit_divides)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   276
  by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   277
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   278
lemma (in monoid) associatedI2':
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   279
  assumes "a = b \<otimes> u"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   280
    and "u \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   281
    and "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   282
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   283
  using assms by (intro associatedI2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   284
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   285
lemma associatedD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   286
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   287
  assumes "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   288
  shows "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   289
  using assms by (simp add: associated_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   290
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   291
lemma (in monoid_cancel) associatedD2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   292
  assumes assoc: "a \<sim> b"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   293
    and carr: "a \<in> carrier G" "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   294
  shows "\<exists>u\<in>Units G. a = b \<otimes> u"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   295
  using assoc
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   296
  unfolding associated_def
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   297
proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   298
  assume "b divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   299
  then obtain u where ucarr: "u \<in> carrier G" and a: "a = b \<otimes> u"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
   300
    by (rule dividesE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   301
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   302
  assume "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   303
  then obtain u' where u'carr: "u' \<in> carrier G" and b: "b = a \<otimes> u'"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
   304
    by (rule dividesE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   305
  note carr = carr ucarr u'carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   306
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   307
  from carr have "a \<otimes> \<one> = a" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   308
  also have "\<dots> = b \<otimes> u" by (simp add: a)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   309
  also have "\<dots> = a \<otimes> u' \<otimes> u" by (simp add: b)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   310
  also from carr have "\<dots> = a \<otimes> (u' \<otimes> u)" by (simp add: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   311
  finally have "a \<otimes> \<one> = a \<otimes> (u' \<otimes> u)" .
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   312
  with carr have u1: "\<one> = u' \<otimes> u" by (fast dest: l_cancel)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   313
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   314
  from carr have "b \<otimes> \<one> = b" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   315
  also have "\<dots> = a \<otimes> u'" by (simp add: b)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   316
  also have "\<dots> = b \<otimes> u \<otimes> u'" by (simp add: a)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   317
  also from carr have "\<dots> = b \<otimes> (u \<otimes> u')" by (simp add: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   318
  finally have "b \<otimes> \<one> = b \<otimes> (u \<otimes> u')" .
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   319
  with carr have u2: "\<one> = u \<otimes> u'" by (fast dest: l_cancel)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   320
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   321
  from u'carr u1[symmetric] u2[symmetric] have "\<exists>u'\<in>carrier G. u' \<otimes> u = \<one> \<and> u \<otimes> u' = \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   322
    by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   323
  then have "u \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   324
    by (simp add: Units_def ucarr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   325
  with ucarr a show "\<exists>u\<in>Units G. a = b \<otimes> u" by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   326
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   327
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   328
lemma associatedE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   329
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   330
  assumes assoc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   331
    and e: "\<lbrakk>a divides b; b divides a\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   332
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   333
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   334
  from assoc have "a divides b" "b divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   335
    by (simp_all add: associated_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   336
  then show P by (elim e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   337
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   338
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   339
lemma (in monoid_cancel) associatedE2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   340
  assumes assoc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   341
    and e: "\<And>u. \<lbrakk>a = b \<otimes> u; u \<in> Units G\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   342
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   343
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   344
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   345
  from assoc and carr have "\<exists>u\<in>Units G. a = b \<otimes> u"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   346
    by (rule associatedD2)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   347
  then obtain u where "u \<in> Units G"  "a = b \<otimes> u"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   348
    by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   349
  then show P by (elim e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   350
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   351
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   352
lemma (in monoid) associated_refl [simp, intro!]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   353
  assumes "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   354
  shows "a \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   355
  using assms by (fast intro: associatedI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   356
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   357
lemma (in monoid) associated_sym [sym]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   358
  assumes "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   359
  shows "b \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   360
  using assms by (iprover intro: associatedI elim: associatedE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   361
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   362
lemma (in monoid) associated_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   363
  assumes "a \<sim> b"  "b \<sim> c"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   364
    and "a \<in> carrier G" "c \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   365
  shows "a \<sim> c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   366
  using assms by (iprover intro: associatedI divides_trans elim: associatedE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   367
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   368
lemma (in monoid) division_equiv [intro, simp]: "equivalence (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   369
  apply unfold_locales
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   370
    apply simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   371
   apply (metis associated_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   372
  apply (iprover intro: associated_trans)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   373
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   374
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   375
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   376
subsubsection \<open>Division and associativity\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   377
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   378
lemmas divides_antisym = associatedI
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   379
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   380
lemma (in monoid) divides_cong_l [trans]:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   381
  assumes "x \<sim> x'" "x' divides y" "x \<in> carrier G" 
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   382
  shows "x divides y"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   383
  by (meson assms associatedD divides_trans)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   384
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   385
lemma (in monoid) divides_cong_r [trans]:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   386
  assumes "x divides y" "y \<sim> y'" "x \<in> carrier G" 
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   387
  shows "x divides y'"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   388
  by (meson assms associatedD divides_trans)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   389
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   390
lemma (in monoid) division_weak_partial_order [simp, intro!]:
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   391
  "weak_partial_order (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   392
  apply unfold_locales
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   393
      apply (simp_all add: associated_sym divides_antisym)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   394
     apply (metis associated_trans)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   395
   apply (metis divides_trans)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   396
  by (meson associated_def divides_trans)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   397
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   398
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   399
subsubsection \<open>Multiplication and associativity\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   400
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   401
lemma (in monoid_cancel) mult_cong_r:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   402
  assumes "b \<sim> b'" "a \<in> carrier G"  "b \<in> carrier G"  "b' \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   403
  shows "a \<otimes> b \<sim> a \<otimes> b'"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   404
  by (meson assms associated_def divides_mult_lI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   405
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   406
lemma (in comm_monoid_cancel) mult_cong_l:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   407
  assumes "a \<sim> a'" "a \<in> carrier G"  "a' \<in> carrier G"  "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   408
  shows "a \<otimes> b \<sim> a' \<otimes> b"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   409
  using assms m_comm mult_cong_r by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   410
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   411
lemma (in monoid_cancel) assoc_l_cancel:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   412
  assumes "a \<in> carrier G"  "b \<in> carrier G"  "b' \<in> carrier G" "a \<otimes> b \<sim> a \<otimes> b'"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   413
  shows "b \<sim> b'"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   414
  by (meson assms associated_def divides_mult_l)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   415
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   416
lemma (in comm_monoid_cancel) assoc_r_cancel:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   417
  assumes "a \<otimes> b \<sim> a' \<otimes> b" "a \<in> carrier G"  "a' \<in> carrier G"  "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   418
  shows "a \<sim> a'"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   419
  using assms assoc_l_cancel m_comm by presburger
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   420
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   421
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   422
subsubsection \<open>Units\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   423
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   424
lemma (in monoid_cancel) assoc_unit_l [trans]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   425
  assumes "a \<sim> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   426
    and "b \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   427
    and "a \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   428
  shows "a \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   429
  using assms by (fast elim: associatedE2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   430
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   431
lemma (in monoid_cancel) assoc_unit_r [trans]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   432
  assumes aunit: "a \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   433
    and asc: "a \<sim> b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   434
    and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   435
  shows "b \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   436
  using aunit bcarr associated_sym[OF asc] by (blast intro: assoc_unit_l)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   437
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   438
lemma (in comm_monoid) Units_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   439
  assumes aunit: "a \<in> Units G" and asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   440
    and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   441
  shows "b \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   442
  using assms by (blast intro: divides_unit elim: associatedE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   443
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   444
lemma (in monoid) Units_assoc:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   445
  assumes units: "a \<in> Units G"  "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   446
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   447
  using units by (fast intro: associatedI unit_divides)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   448
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   449
lemma (in monoid) Units_are_ones: "Units G {.=}\<^bsub>(division_rel G)\<^esub> {\<one>}"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   450
proof -
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   451
  have "a .\<in>\<^bsub>division_rel G\<^esub> {\<one>}" if "a \<in> Units G" for a
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   452
  proof -
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   453
    have "a \<sim> \<one>"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   454
      by (rule associatedI) (simp_all add: Units_closed that unit_divides)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   455
    then show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   456
      by (simp add: elem_def)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   457
  qed
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   458
  moreover have "\<one> .\<in>\<^bsub>division_rel G\<^esub> Units G"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   459
    by (simp add: equivalence.mem_imp_elem)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   460
  ultimately show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   461
    by (auto simp: set_eq_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   462
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   463
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   464
lemma (in comm_monoid) Units_Lower: "Units G = Lower (division_rel G) (carrier G)"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   465
  apply (auto simp add: Units_def Lower_def)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   466
   apply (metis Units_one_closed unit_divides unit_factor)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   467
  apply (metis Unit_eq_dividesone Units_r_inv_ex m_ac(2) one_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   468
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   469
68664
bd0df72c16d5 updated material concerning Algebra
paulson <lp15@cam.ac.uk>
parents: 68604
diff changeset
   470
lemma (in monoid_cancel) associated_iff:
bd0df72c16d5 updated material concerning Algebra
paulson <lp15@cam.ac.uk>
parents: 68604
diff changeset
   471
  assumes "a \<in> carrier G" "b \<in> carrier G"
bd0df72c16d5 updated material concerning Algebra
paulson <lp15@cam.ac.uk>
parents: 68604
diff changeset
   472
  shows "a \<sim> b \<longleftrightarrow> (\<exists>c \<in> Units G. a = b \<otimes> c)"
bd0df72c16d5 updated material concerning Algebra
paulson <lp15@cam.ac.uk>
parents: 68604
diff changeset
   473
  using assms associatedI2' associatedD2 by auto
bd0df72c16d5 updated material concerning Algebra
paulson <lp15@cam.ac.uk>
parents: 68604
diff changeset
   474
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   475
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   476
subsubsection \<open>Proper factors\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   477
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   478
lemma properfactorI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   479
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   480
  assumes "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   481
    and "\<not>(b divides a)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   482
  shows "properfactor G a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   483
  using assms unfolding properfactor_def by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   484
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   485
lemma properfactorI2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   486
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   487
  assumes advdb: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   488
    and neq: "\<not>(a \<sim> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   489
  shows "properfactor G a b"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
   490
proof (rule properfactorI, rule advdb, rule notI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   491
  assume "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   492
  with advdb have "a \<sim> b" by (rule associatedI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   493
  with neq show "False" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   494
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   495
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   496
lemma (in comm_monoid_cancel) properfactorI3:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   497
  assumes p: "p = a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   498
    and nunit: "b \<notin> Units G"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   499
    and carr: "a \<in> carrier G"  "b \<in> carrier G" 
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   500
  shows "properfactor G a p"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   501
  unfolding p
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   502
  using carr
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   503
  apply (intro properfactorI, fast)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   504
proof (clarsimp, elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   505
  fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   506
  assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   507
  note [simp] = carr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   508
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   509
  have "a \<otimes> \<one> = a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   510
  also assume "a = a \<otimes> b \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   511
  also have "\<dots> = a \<otimes> (b \<otimes> c)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   512
  finally have "a \<otimes> \<one> = a \<otimes> (b \<otimes> c)" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   513
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   514
  then have rinv: "\<one> = b \<otimes> c" by (intro l_cancel[of "a" "\<one>" "b \<otimes> c"], simp+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   515
  also have "\<dots> = c \<otimes> b" by (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   516
  finally have linv: "\<one> = c \<otimes> b" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   517
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   518
  from ccarr linv[symmetric] rinv[symmetric] have "b \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   519
    unfolding Units_def by fastforce
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   520
  with nunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   521
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   522
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   523
lemma properfactorE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   524
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   525
  assumes pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   526
    and r: "\<lbrakk>a divides b; \<not>(b divides a)\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   527
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   528
  using pf unfolding properfactor_def by (fast intro: r)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   529
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   530
lemma properfactorE2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   531
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   532
  assumes pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   533
    and elim: "\<lbrakk>a divides b; \<not>(a \<sim> b)\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   534
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   535
  using pf unfolding properfactor_def by (fast elim: elim associatedE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   536
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   537
lemma (in monoid) properfactor_unitE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   538
  assumes uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   539
    and pf: "properfactor G a u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   540
    and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   541
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   542
  using pf unit_divides[OF uunit acarr] by (fast elim: properfactorE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   543
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   544
lemma (in monoid) properfactor_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   545
  assumes pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   546
  shows "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   547
  using pf by (elim properfactorE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   548
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   549
lemma (in monoid) properfactor_trans1 [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   550
  assumes dvds: "a divides b"  "properfactor G b c"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   551
    and carr: "a \<in> carrier G"  "c \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   552
  shows "properfactor G a c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   553
  using dvds carr
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   554
  apply (elim properfactorE, intro properfactorI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   555
   apply (iprover intro: divides_trans)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   556
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   557
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   558
lemma (in monoid) properfactor_trans2 [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   559
  assumes dvds: "properfactor G a b"  "b divides c"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   560
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   561
  shows "properfactor G a c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   562
  using dvds carr
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   563
  apply (elim properfactorE, intro properfactorI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   564
   apply (iprover intro: divides_trans)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   565
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   566
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   567
lemma properfactor_lless:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   568
  fixes G (structure)
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   569
  shows "properfactor G = lless (division_rel G)"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   570
  by (force simp: lless_def properfactor_def associated_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   571
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   572
lemma (in monoid) properfactor_cong_l [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   573
  assumes x'x: "x' \<sim> x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   574
    and pf: "properfactor G x y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   575
    and carr: "x \<in> carrier G"  "x' \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   576
  shows "properfactor G x' y"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   577
  using pf
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   578
  unfolding properfactor_lless
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   579
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
   580
  interpret weak_partial_order "division_rel G" ..
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   581
  from x'x have "x' .=\<^bsub>division_rel G\<^esub> x" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   582
  also assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   583
  finally show "x' \<sqsubset>\<^bsub>division_rel G\<^esub> y" by (simp add: carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   584
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   585
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   586
lemma (in monoid) properfactor_cong_r [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   587
  assumes pf: "properfactor G x y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   588
    and yy': "y \<sim> y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   589
    and carr: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   590
  shows "properfactor G x y'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   591
  using pf
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   592
  unfolding properfactor_lless
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   593
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
   594
  interpret weak_partial_order "division_rel G" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   595
  assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   596
  also from yy'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   597
  have "y .=\<^bsub>division_rel G\<^esub> y'" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   598
  finally show "x \<sqsubset>\<^bsub>division_rel G\<^esub> y'" by (simp add: carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   599
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   600
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   601
lemma (in monoid_cancel) properfactor_mult_lI [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   602
  assumes ab: "properfactor G a b"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   603
    and carr: "a \<in> carrier G" "c \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   604
  shows "properfactor G (c \<otimes> a) (c \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   605
  using ab carr by (fastforce elim: properfactorE intro: properfactorI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   606
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   607
lemma (in monoid_cancel) properfactor_mult_l [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   608
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   609
  shows "properfactor G (c \<otimes> a) (c \<otimes> b) = properfactor G a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   610
  using carr by (fastforce elim: properfactorE intro: properfactorI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   611
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   612
lemma (in comm_monoid_cancel) properfactor_mult_rI [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   613
  assumes ab: "properfactor G a b"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   614
    and carr: "a \<in> carrier G" "c \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   615
  shows "properfactor G (a \<otimes> c) (b \<otimes> c)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   616
  using ab carr by (fastforce elim: properfactorE intro: properfactorI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   617
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   618
lemma (in comm_monoid_cancel) properfactor_mult_r [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   619
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   620
  shows "properfactor G (a \<otimes> c) (b \<otimes> c) = properfactor G a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   621
  using carr by (fastforce elim: properfactorE intro: properfactorI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   622
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   623
lemma (in monoid) properfactor_prod_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   624
  assumes ab: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   625
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   626
  shows "properfactor G a (b \<otimes> c)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   627
  by (intro properfactor_trans2[OF ab] divides_prod_r) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   628
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   629
lemma (in comm_monoid) properfactor_prod_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   630
  assumes ab: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   631
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   632
  shows "properfactor G a (c \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   633
  by (intro properfactor_trans2[OF ab] divides_prod_l) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   634
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   635
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   636
subsection \<open>Irreducible Elements and Primes\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   637
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   638
subsubsection \<open>Irreducible elements\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   639
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   640
lemma irreducibleI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   641
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   642
  assumes "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   643
    and "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b a\<rbrakk> \<Longrightarrow> b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   644
  shows "irreducible G a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   645
  using assms unfolding irreducible_def by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   646
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   647
lemma irreducibleE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   648
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   649
  assumes irr: "irreducible G a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   650
    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"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   651
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   652
  using assms unfolding irreducible_def by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   653
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   654
lemma irreducibleD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   655
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   656
  assumes irr: "irreducible G a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   657
    and pf: "properfactor G b a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   658
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   659
  shows "b \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   660
  using assms by (fast elim: irreducibleE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   661
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   662
lemma (in monoid_cancel) irreducible_cong [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   663
  assumes irred: "irreducible G a"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   664
    and aa': "a \<sim> a'" "a \<in> carrier G"  "a' \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   665
  shows "irreducible G a'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   666
  using assms
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
   667
  apply (auto simp: irreducible_def assoc_unit_l)
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   668
  apply (metis aa' associated_sym properfactor_cong_r)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   669
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   670
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   671
lemma (in monoid) irreducible_prod_rI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   672
  assumes airr: "irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   673
    and bunit: "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   674
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   675
  shows "irreducible G (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   676
  using airr carr bunit
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   677
  apply (elim irreducibleE, intro irreducibleI)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   678
  using prod_unit_r apply blast
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   679
  using associatedI2' properfactor_cong_r by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   680
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   681
lemma (in comm_monoid) irreducible_prod_lI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   682
  assumes birr: "irreducible G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   683
    and aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   684
    and carr [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   685
  shows "irreducible G (a \<otimes> b)"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   686
  by (metis aunit birr carr irreducible_prod_rI m_comm)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   687
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   688
lemma (in comm_monoid_cancel) irreducible_prodE [elim]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   689
  assumes irr: "irreducible G (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   690
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   691
    and e1: "\<lbrakk>irreducible G a; b \<in> Units G\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   692
    and e2: "\<lbrakk>a \<in> Units G; irreducible G b\<rbrakk> \<Longrightarrow> P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   693
  shows P
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   694
  using irr
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   695
proof (elim irreducibleE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   696
  assume abnunit: "a \<otimes> b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   697
    and isunit[rule_format]: "\<forall>ba. ba \<in> carrier G \<and> properfactor G ba (a \<otimes> b) \<longrightarrow> ba \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   698
  show P
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   699
  proof (cases "a \<in> Units G")
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   700
    case aunit: True
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   701
    have "irreducible G b"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
   702
    proof (rule irreducibleI, rule notI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   703
      assume "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   704
      with aunit have "(a \<otimes> b) \<in> Units G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   705
      with abnunit show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   706
    next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   707
      fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   708
      assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   709
        and "properfactor G c b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   710
      then have "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_l[of c b a])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   711
      with ccarr show "c \<in> Units G" by (fast intro: isunit)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   712
    qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   713
    with aunit show "P" by (rule e2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   714
  next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   715
    case anunit: False
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   716
    with carr have "properfactor G b (b \<otimes> a)" by (fast intro: properfactorI3)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   717
    then have bf: "properfactor G b (a \<otimes> b)" by (subst m_comm[of a b], simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   718
    then have bunit: "b \<in> Units G" by (intro isunit, simp)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   719
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   720
    have "irreducible G a"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
   721
    proof (rule irreducibleI, rule notI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   722
      assume "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   723
      with bunit have "(a \<otimes> b) \<in> Units G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   724
      with abnunit show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   725
    next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   726
      fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   727
      assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   728
        and "properfactor G c a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   729
      then have "properfactor G c (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   730
        by (simp add: properfactor_prod_r[of c a b])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   731
      with ccarr show "c \<in> Units G" by (fast intro: isunit)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   732
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   733
    from this bunit show "P" by (rule e1)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   734
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   735
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   736
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   737
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   738
subsubsection \<open>Prime elements\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   739
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   740
lemma primeI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   741
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   742
  assumes "p \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   743
    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"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   744
  shows "prime G p"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   745
  using assms unfolding prime_def by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   746
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   747
lemma primeE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   748
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   749
  assumes pprime: "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   750
    and e: "\<lbrakk>p \<notin> Units G; \<forall>a\<in>carrier G. \<forall>b\<in>carrier G.
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   751
      p divides a \<otimes> b \<longrightarrow> p divides a \<or> p divides b\<rbrakk> \<Longrightarrow> P"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   752
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   753
  using pprime unfolding prime_def by (blast dest: e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   754
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   755
lemma (in comm_monoid_cancel) prime_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   756
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   757
    and pprime: "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   758
    and pdvd: "p divides a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   759
  shows "p divides a \<or> p divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   760
  using assms by (blast elim: primeE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   761
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   762
lemma (in monoid_cancel) prime_cong [trans]:
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
   763
  assumes "prime G p"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   764
    and pp': "p \<sim> p'" "p \<in> carrier G"  "p' \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   765
  shows "prime G p'"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
   766
  using assms
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
   767
  apply (auto simp: prime_def assoc_unit_l)
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   768
  apply (metis pp' associated_sym divides_cong_l)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   769
  done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   770
68551
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   771
(*by Paulo Emílio de Vilhena*)
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   772
lemma (in comm_monoid_cancel) prime_irreducible:
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   773
  assumes "prime G p"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   774
  shows "irreducible G p"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   775
proof (rule irreducibleI)
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   776
  show "p \<notin> Units G"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   777
    using assms unfolding prime_def by simp
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   778
next
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   779
  fix b assume A: "b \<in> carrier G" "properfactor G b p"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   780
  then obtain c where c: "c \<in> carrier G" "p = b \<otimes> c"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   781
    unfolding properfactor_def factor_def by auto
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   782
  hence "p divides c"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   783
    using A assms unfolding prime_def properfactor_def by auto
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   784
  then obtain b' where b': "b' \<in> carrier G" "c = p \<otimes> b'"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   785
    unfolding factor_def by auto
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   786
  hence "\<one> = b \<otimes> b'"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   787
    by (metis A(1) l_cancel m_closed m_lcomm one_closed r_one c)
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   788
  thus "b \<in> Units G"
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   789
    using A(1) Units_one_closed b'(1) unit_factor by presburger
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   790
qed
b680e74eb6f2 More on Algebra by Paulo and Martin
paulson <lp15@cam.ac.uk>
parents: 68488
diff changeset
   791
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   792
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   793
subsection \<open>Factorization and Factorial Monoids\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   794
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   795
subsubsection \<open>Function definitions\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   796
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   797
definition factors :: "[_, 'a list, 'a] \<Rightarrow> bool"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
   798
  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"
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   799
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   800
definition wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
   801
  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"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   802
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   803
abbreviation list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
   804
  where "list_assoc G \<equiv> list_all2 (\<sim>\<^bsub>G\<^esub>)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   805
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   806
definition essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   807
  where "essentially_equal G fs1 fs2 \<longleftrightarrow> (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>]\<^bsub>G\<^esub> fs2)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   808
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   809
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   810
locale factorial_monoid = comm_monoid_cancel +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   811
  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"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   812
    and factors_unique:
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   813
      "\<lbrakk>factors G fs a; factors G fs' a; a \<in> carrier G; a \<notin> Units G;
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   814
        set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   815
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   816
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   817
subsubsection \<open>Comparing lists of elements\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   818
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   819
text \<open>Association on lists\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   820
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   821
lemma (in monoid) listassoc_refl [simp, intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   822
  assumes "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   823
  shows "as [\<sim>] as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   824
  using assms by (induct as) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   825
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   826
lemma (in monoid) listassoc_sym [sym]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   827
  assumes "as [\<sim>] bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   828
    and "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   829
    and "set bs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   830
  shows "bs [\<sim>] as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   831
  using assms
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   832
proof (induction as arbitrary: bs)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   833
  case Cons
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   834
  then show ?case
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   835
    by (induction bs) (use associated_sym in auto)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   836
qed auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   837
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   838
lemma (in monoid) listassoc_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   839
  assumes "as [\<sim>] bs" and "bs [\<sim>] cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   840
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" and "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   841
  shows "as [\<sim>] cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   842
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   843
  apply (simp add: list_all2_conv_all_nth set_conv_nth, safe)
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   844
  by (metis (mono_tags, lifting) associated_trans nth_mem subsetCE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   845
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   846
lemma (in monoid_cancel) irrlist_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   847
  assumes "\<forall>a\<in>set as. irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   848
    and "as [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   849
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   850
  shows "\<forall>a\<in>set bs. irreducible G a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   851
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   852
  apply (clarsimp simp add: list_all2_conv_all_nth set_conv_nth)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   853
  apply (blast intro: irreducible_cong)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   854
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   855
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   856
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   857
text \<open>Permutations\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   858
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   859
lemma perm_map [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   860
  assumes p: "a <~~> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   861
  shows "map f a <~~> map f b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   862
  using p by induct auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   863
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   864
lemma perm_map_switch:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   865
  assumes m: "map f a = map f b" and p: "b <~~> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   866
  shows "\<exists>d. a <~~> d \<and> map f d = map f c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   867
  using p m by (induct arbitrary: a) (simp, force, force, blast)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   868
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   869
lemma (in monoid) perm_assoc_switch:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   870
  assumes a:"as [\<sim>] bs" and p: "bs <~~> cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   871
  shows "\<exists>bs'. as <~~> bs' \<and> bs' [\<sim>] cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   872
  using p a
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   873
proof (induction bs cs arbitrary: as)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   874
  case (swap y x l)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   875
  then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   876
    by (metis (no_types, hide_lams) list_all2_Cons2 perm.swap)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   877
next
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   878
case (Cons xs ys z)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   879
  then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   880
    by (metis list_all2_Cons2 perm.Cons)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   881
next
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   882
  case (trans xs ys zs)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   883
  then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   884
    by (meson perm.trans)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   885
qed auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   886
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   887
lemma (in monoid) perm_assoc_switch_r:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   888
  assumes p: "as <~~> bs" and a:"bs [\<sim>] cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   889
  shows "\<exists>bs'. as [\<sim>] bs' \<and> bs' <~~> cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   890
  using p a
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   891
proof (induction as bs arbitrary: cs)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   892
  case Nil
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   893
  then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   894
    by auto
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   895
next
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   896
  case (swap y x l)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   897
  then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   898
    by (metis (no_types, hide_lams) list_all2_Cons1 perm.swap)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   899
next
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   900
  case (Cons xs ys z)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   901
  then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   902
    by (metis list_all2_Cons1 perm.Cons)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   903
next
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   904
  case (trans xs ys zs)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   905
  then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   906
    by (blast intro:  elim: )
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   907
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   908
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   909
declare perm_sym [sym]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   910
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   911
lemma perm_setP:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   912
  assumes perm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   913
    and as: "P (set as)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   914
  shows "P (set bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   915
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   916
  from perm have "mset as = mset bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   917
    by (simp add: mset_eq_perm)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   918
  then have "set as = set bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   919
    by (rule mset_eq_setD)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   920
  with as show "P (set bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   921
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   922
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   923
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   924
lemmas (in monoid) perm_closed = perm_setP[of _ _ "\<lambda>as. as \<subseteq> carrier G"]
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   925
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   926
lemmas (in monoid) irrlist_perm_cong = perm_setP[of _ _ "\<lambda>as. \<forall>a\<in>as. irreducible G a"]
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   927
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   928
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   929
text \<open>Essentially equal factorizations\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   930
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   931
lemma (in monoid) essentially_equalI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   932
  assumes ex: "fs1 <~~> fs1'"  "fs1' [\<sim>] fs2"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   933
  shows "essentially_equal G fs1 fs2"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   934
  using ex unfolding essentially_equal_def by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   935
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   936
lemma (in monoid) essentially_equalE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   937
  assumes ee: "essentially_equal G fs1 fs2"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   938
    and e: "\<And>fs1'. \<lbrakk>fs1 <~~> fs1'; fs1' [\<sim>] fs2\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   939
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   940
  using ee unfolding essentially_equal_def by (fast intro: e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   941
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   942
lemma (in monoid) ee_refl [simp,intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   943
  assumes carr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   944
  shows "essentially_equal G as as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   945
  using carr by (fast intro: essentially_equalI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   946
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   947
lemma (in monoid) ee_sym [sym]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   948
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   949
    and carr: "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   950
  shows "essentially_equal G bs as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   951
  using ee
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   952
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   953
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   954
  assume "as <~~> fs"  "fs [\<sim>] bs"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
   955
  from perm_assoc_switch_r [OF this] obtain fs' where a: "as [\<sim>] fs'" and p: "fs' <~~> bs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
   956
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   957
  from p have "bs <~~> fs'" by (rule perm_sym)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   958
  with a[symmetric] carr show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   959
    by (iprover intro: essentially_equalI perm_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   960
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   961
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   962
lemma (in monoid) ee_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   963
  assumes ab: "essentially_equal G as bs" and bc: "essentially_equal G bs cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   964
    and ascarr: "set as \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   965
    and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   966
    and cscarr: "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   967
  shows "essentially_equal G as cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   968
  using ab bc
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   969
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   970
  fix abs bcs
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
   971
  assume "abs [\<sim>] bs" and pb: "bs <~~> bcs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
   972
  from perm_assoc_switch [OF this] obtain bs' where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
   973
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   974
  assume "as <~~> abs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   975
  with p have pp: "as <~~> bs'" by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   976
  from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   977
  from pb bscarr have c2: "set bcs \<subseteq> carrier G" by (rule perm_closed)
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   978
  assume "bcs [\<sim>] cs"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   979
  then have "bs' [\<sim>] cs"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   980
    using a c1 c2 cscarr listassoc_trans by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   981
  with pp show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   982
    by (rule essentially_equalI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   983
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   984
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   985
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   986
subsubsection \<open>Properties of lists of elements\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   987
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
   988
text \<open>Multiplication of factors in a list\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   989
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   990
lemma (in monoid) multlist_closed [simp, intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   991
  assumes ascarr: "set fs \<subseteq> carrier G"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
   992
  shows "foldr (\<otimes>) fs \<one> \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   993
  using ascarr by (induct fs) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   994
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   995
lemma  (in comm_monoid) multlist_dividesI:
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   996
  assumes "f \<in> set fs" and "set fs \<subseteq> carrier G"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
   997
  shows "f divides (foldr (\<otimes>) fs \<one>)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
   998
  using assms
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
   999
proof (induction fs)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1000
  case (Cons a fs)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1001
  then have f: "f \<in> carrier G"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1002
    by blast
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1003
  show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1004
  proof (cases "f = a")
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1005
    case True
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1006
    then show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1007
      using Cons.prems by auto
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1008
  next
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1009
    case False
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1010
    with Cons show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1011
      by clarsimp (metis f divides_prod_l multlist_closed)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1012
  qed
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1013
qed auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1014
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1015
lemma (in comm_monoid_cancel) multlist_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1016
  assumes "fs [\<sim>] fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1017
    and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1018
  shows "foldr (\<otimes>) fs \<one> \<sim> foldr (\<otimes>) fs' \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1019
  using assms
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1020
proof (induct fs arbitrary: fs')
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1021
  case (Cons a as fs')
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1022
  then show ?case
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1023
  proof (induction fs')
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1024
    case (Cons b bs)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1025
    then have p: "a \<otimes> foldr (\<otimes>) as \<one> \<sim> b \<otimes> foldr (\<otimes>) as \<one>"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1026
      by (simp add: mult_cong_l)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1027
    then have "foldr (\<otimes>) as \<one> \<sim> foldr (\<otimes>) bs \<one>"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1028
      using Cons by auto
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1029
    with Cons have "b \<otimes> foldr (\<otimes>) as \<one> \<sim> b \<otimes> foldr (\<otimes>) bs \<one>"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1030
      by (simp add: mult_cong_r)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1031
    then show ?case
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1032
      using Cons.prems(3) Cons.prems(4) monoid.associated_trans monoid_axioms p by force
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1033
  qed auto
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1034
qed auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1035
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1036
lemma (in comm_monoid) multlist_perm_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1037
  assumes prm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1038
    and ascarr: "set as \<subseteq> carrier G"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1039
  shows "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1040
  using prm ascarr
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1041
proof induction
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1042
  case (swap y x l) then show ?case
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1043
    by (simp add: m_lcomm)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1044
next
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1045
  case (trans xs ys zs) then show ?case
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1046
    using perm_closed by auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1047
qed auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1048
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1049
lemma (in comm_monoid_cancel) multlist_ee_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1050
  assumes "essentially_equal G fs fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1051
    and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1052
  shows "foldr (\<otimes>) fs \<one> \<sim> foldr (\<otimes>) fs' \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1053
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1054
  apply (elim essentially_equalE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1055
  apply (simp add: multlist_perm_cong multlist_listassoc_cong perm_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1056
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1057
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1058
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1059
subsubsection \<open>Factorization in irreducible elements\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1060
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1061
lemma wfactorsI:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1062
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1063
  assumes "\<forall>f\<in>set fs. irreducible G f"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1064
    and "foldr (\<otimes>) fs \<one> \<sim> a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1065
  shows "wfactors G fs a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1066
  using assms unfolding wfactors_def by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1067
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1068
lemma wfactorsE:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1069
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1070
  assumes wf: "wfactors G fs a"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1071
    and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> \<sim> a\<rbrakk> \<Longrightarrow> P"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1072
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1073
  using wf unfolding wfactors_def by (fast dest: e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1074
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1075
lemma (in monoid) factorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1076
  assumes "\<forall>f\<in>set fs. irreducible G f"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1077
    and "foldr (\<otimes>) fs \<one> = a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1078
  shows "factors G fs a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1079
  using assms unfolding factors_def by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1080
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1081
lemma factorsE:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1082
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1083
  assumes f: "factors G fs a"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1084
    and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> = a\<rbrakk> \<Longrightarrow> P"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1085
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1086
  using f unfolding factors_def by (simp add: e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1087
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1088
lemma (in monoid) factors_wfactors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1089
  assumes "factors G as a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1090
  shows "wfactors G as a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1091
  using assms by (blast elim: factorsE intro: wfactorsI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1092
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1093
lemma (in monoid) wfactors_factors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1094
  assumes "wfactors G as a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1095
  shows "\<exists>a'. factors G as a' \<and> a' \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1096
  using assms by (blast elim: wfactorsE intro: factorsI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1097
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1098
lemma (in monoid) factors_closed [dest]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1099
  assumes "factors G fs a" and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1100
  shows "a \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1101
  using assms by (elim factorsE, clarsimp)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1102
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1103
lemma (in monoid) nunit_factors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1104
  assumes anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1105
    and fs: "factors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1106
  shows "length as > 0"
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1107
proof -
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1108
  from anunit Units_one_closed have "a \<noteq> \<one>" by auto
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1109
  with fs show ?thesis by (auto elim: factorsE)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1110
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1111
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1112
lemma (in monoid) unit_wfactors [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1113
  assumes aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1114
  shows "wfactors G [] a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1115
  using aunit by (intro wfactorsI) (simp, simp add: Units_assoc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1116
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1117
lemma (in comm_monoid_cancel) unit_wfactors_empty:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1118
  assumes aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1119
    and wf: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1120
    and carr[simp]: "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1121
  shows "fs = []"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1122
proof (cases fs)
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1123
  case Nil
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1124
  then show ?thesis .
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1125
next
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1126
  case fs: (Cons f fs')
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1127
  from carr have fcarr[simp]: "f \<in> carrier G" and carr'[simp]: "set fs' \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1128
    by (simp_all add: fs)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1129
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1130
  from fs wf have "irreducible G f" by (simp add: wfactors_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1131
  then have fnunit: "f \<notin> Units G" by (fast elim: irreducibleE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1132
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1133
  from fs wf have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1134
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1135
  note aunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1136
  also from fs wf
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1137
  have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def)
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1138
  have "a \<sim> f \<otimes> foldr (\<otimes>) fs' \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1139
    by (simp add: Units_closed[OF aunit] a[symmetric])
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1140
  finally have "f \<otimes> foldr (\<otimes>) fs' \<one> \<in> Units G" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1141
  then have "f \<in> Units G" by (intro unit_factor[of f], simp+)
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1142
  with fnunit show ?thesis by contradiction
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1143
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1144
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1145
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1146
text \<open>Comparing wfactors\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1147
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1148
lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1149
  assumes fact: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1150
    and asc: "fs [\<sim>] fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1151
    and carr: "a \<in> carrier G"  "set fs \<subseteq> carrier G"  "set fs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1152
  shows "wfactors G fs' a"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1153
proof -
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1154
  { from asc[symmetric] have "foldr (\<otimes>) fs' \<one> \<sim> foldr (\<otimes>) fs \<one>"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1155
      by (simp add: multlist_listassoc_cong carr)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1156
    also assume "foldr (\<otimes>) fs \<one> \<sim> a"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1157
    finally have "foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: carr) }
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1158
  then show ?thesis
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1159
  using fact
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1160
  by (meson asc carr(2) carr(3) irrlist_listassoc_cong wfactors_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1161
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1162
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1163
lemma (in comm_monoid) wfactors_perm_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1164
  assumes "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1165
    and "fs <~~> fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1166
    and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1167
  shows "wfactors G fs' a"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1168
  using assms irrlist_perm_cong multlist_perm_cong wfactors_def by fastforce
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1169
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1170
lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1171
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1172
    and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1173
    and carr: "b \<in> carrier G"  "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1174
  shows "wfactors G as b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1175
  using ee
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1176
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1177
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1178
  assume prm: "as <~~> fs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1179
  with carr have fscarr: "set fs \<subseteq> carrier G" by (simp add: perm_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1180
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1181
  note bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1182
  also assume [symmetric]: "fs [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1183
  also (wfactors_listassoc_cong_l)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1184
  note prm[symmetric]
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1185
  finally (wfactors_perm_cong_l)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1186
  show "wfactors G as b" by (simp add: carr fscarr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1187
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1188
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1189
lemma (in monoid) wfactors_cong_r [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1190
  assumes fac: "wfactors G fs a" and aa': "a \<sim> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1191
    and carr[simp]: "a \<in> carrier G"  "a' \<in> carrier G"  "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1192
  shows "wfactors G fs a'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1193
  using fac
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1194
proof (elim wfactorsE, intro wfactorsI)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1195
  assume "foldr (\<otimes>) fs \<one> \<sim> a" also note aa'
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1196
  finally show "foldr (\<otimes>) fs \<one> \<sim> a'" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1197
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1198
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1199
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1200
subsubsection \<open>Essentially equal factorizations\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1201
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1202
lemma (in comm_monoid_cancel) unitfactor_ee:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1203
  assumes uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1204
    and carr: "set as \<subseteq> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1205
  shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1206
    (is "essentially_equal G ?as' as")
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1207
proof -
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1208
  have "as[0 := as ! 0 \<otimes> u] [\<sim>] as"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1209
  proof (cases as)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1210
    case (Cons a as')
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1211
    then show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1212
      using associatedI2 carr uunit by auto
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1213
  qed auto
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1214
  then show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1215
    using essentially_equal_def by blast
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1216
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1217
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1218
lemma (in comm_monoid_cancel) factors_cong_unit:
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1219
  assumes u: "u \<in> Units G"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1220
    and a: "a \<notin> Units G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1221
    and afs: "factors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1222
    and ascarr: "set as \<subseteq> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1223
  shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1224
    (is "factors G ?as' ?a'")
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1225
proof (cases as)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1226
  case Nil
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1227
  then show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1228
    using afs a nunit_factors by auto
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1229
next
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1230
  case (Cons b bs)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1231
  have *: "\<forall>f\<in>set as. irreducible G f" "foldr (\<otimes>) as \<one> = a"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1232
    using afs  by (auto simp: factors_def)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1233
  show ?thesis
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1234
  proof (intro factorsI)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1235
    show "foldr (\<otimes>) (as[0 := as ! 0 \<otimes> u]) \<one> = a \<otimes> u"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1236
      using Cons u ascarr * by (auto simp add: m_ac Units_closed)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1237
    show "\<forall>f\<in>set (as[0 := as ! 0 \<otimes> u]). irreducible G f"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1238
      using Cons u ascarr * by (force intro: irreducible_prod_rI)
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1239
  qed 
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1240
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1241
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1242
lemma (in comm_monoid) perm_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1243
  assumes prm: "as <~~> bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1244
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1245
    and bfs: "wfactors G bs b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1246
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1247
    and ascarr [simp]: "set as \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1248
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1249
  using afs bfs
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1250
proof (elim wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1251
  from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1252
  assume "foldr (\<otimes>) as \<one> \<sim> a"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1253
  then have "a \<sim> foldr (\<otimes>) as \<one>"
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1254
    by (simp add: associated_sym)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1255
  also from prm
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1256
  have "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>" by (rule multlist_perm_cong, simp)
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1257
  also assume "foldr (\<otimes>) bs \<one> \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1258
  finally show "a \<sim> b" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1259
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1260
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1261
lemma (in comm_monoid_cancel) listassoc_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1262
  assumes assoc: "as [\<sim>] bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1263
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1264
    and bfs: "wfactors G bs b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1265
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1266
    and [simp]: "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1267
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1268
  using afs bfs
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1269
proof (elim wfactorsE)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1270
  assume "foldr (\<otimes>) as \<one> \<sim> a"
68470
7ddcce75c3ee Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68399
diff changeset
  1271
  then have "a \<sim> foldr (\<otimes>) as \<one>" by (simp add: associated_sym)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1272
  also from assoc
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1273
  have "foldr (\<otimes>) as \<one> \<sim> foldr (\<otimes>) bs \<one>" by (rule multlist_listassoc_cong, simp+)
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  1274
  also assume "foldr (\<otimes>) bs \<one> \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1275
  finally show "a \<sim> b" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1276
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1277
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1278
lemma (in comm_monoid_cancel) ee_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1279
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1280
    and afs: "wfactors G as a" and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1281
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1282
    and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1283
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1284
  using ee
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1285
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1286
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1287
  assume prm: "as <~~> fs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1288
  then have as'carr[simp]: "set fs \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1289
    by (simp add: perm_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1290
  from afs prm have afs': "wfactors G fs a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1291
    by (rule wfactors_perm_cong_l) simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1292
  assume "fs [\<sim>] bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1293
  from this afs' bfs show "a \<sim> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1294
    by (rule listassoc_wfactorsD) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1295
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1296
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1297
lemma (in comm_monoid_cancel) ee_factorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1298
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1299
    and afs: "factors G as a" and bfs:"factors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1300
    and "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1301
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1302
  using assms by (blast intro: factors_wfactors dest: ee_wfactorsD)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1303
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1304
lemma (in factorial_monoid) ee_factorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1305
  assumes ab: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1306
    and afs: "factors G as a" and anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1307
    and bfs: "factors G bs b" and bnunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1308
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1309
  shows "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1310
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1311
  note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1312
    factors_closed[OF bfs bscarr] bscarr[THEN subsetD]
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1313
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1314
  from ab carr obtain u where uunit: "u \<in> Units G" and a: "a = b \<otimes> u"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1315
    by (elim associatedE2)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1316
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1317
  from uunit bscarr have ee: "essentially_equal G (bs[0 := (bs!0 \<otimes> u)]) bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1318
    (is "essentially_equal G ?bs' bs")
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1319
    by (rule unitfactor_ee)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1320
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1321
  from bscarr uunit have bs'carr: "set ?bs' \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1322
    by (cases bs) (simp_all add: Units_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1323
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1324
  from uunit bnunit bfs bscarr have fac: "factors G ?bs' (b \<otimes> u)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1325
    by (rule factors_cong_unit)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1326
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1327
  from afs fac[simplified a[symmetric]] ascarr bs'carr anunit
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1328
  have "essentially_equal G as ?bs'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1329
    by (blast intro: factors_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1330
  also note ee
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1331
  finally show "essentially_equal G as bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1332
    by (simp add: ascarr bscarr bs'carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1333
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1334
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1335
lemma (in factorial_monoid) ee_wfactorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1336
  assumes asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1337
    and asf: "wfactors G as a" and bsf: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1338
    and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1339
    and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1340
  shows "essentially_equal G as bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1341
  using assms
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1342
proof (cases "a \<in> Units G")
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1343
  case aunit: True
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1344
  also note asc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1345
  finally have bunit: "b \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1346
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1347
  from aunit asf ascarr have e: "as = []"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1348
    by (rule unit_wfactors_empty)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1349
  from bunit bsf bscarr have e': "bs = []"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1350
    by (rule unit_wfactors_empty)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1351
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1352
  have "essentially_equal G [] []"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1353
    by (fast intro: essentially_equalI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1354
  then show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1355
    by (simp add: e e')
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1356
next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1357
  case anunit: False
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1358
  have bnunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1359
  proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1360
    assume "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1361
    also note asc[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1362
    finally have "a \<in> Units G" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1363
    with anunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1364
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1365
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1366
  from wfactors_factors[OF asf ascarr] obtain a' where fa': "factors G as a'" and a': "a' \<sim> a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1367
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1368
  from fa' ascarr have a'carr[simp]: "a' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1369
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1370
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1371
  have a'nunit: "a' \<notin> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1372
  proof clarify
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1373
    assume "a' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1374
    also note a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1375
    finally have "a \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1376
    with anunit
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1377
    show "False" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1378
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1379
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1380
  from wfactors_factors[OF bsf bscarr] obtain b' where fb': "factors G bs b'" and b': "b' \<sim> b"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1381
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1382
  from fb' bscarr have b'carr[simp]: "b' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1383
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1384
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1385
  have b'nunit: "b' \<notin> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1386
  proof clarify
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1387
    assume "b' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1388
    also note b'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1389
    finally have "b \<in> Units G" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1390
    with bnunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1391
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1392
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1393
  note a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1394
  also note asc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1395
  also note b'[symmetric]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1396
  finally have "a' \<sim> b'" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1397
  from this fa' a'nunit fb' b'nunit ascarr bscarr show "essentially_equal G as bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1398
    by (rule ee_factorsI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1399
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1400
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1401
lemma (in factorial_monoid) ee_wfactors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1402
  assumes asf: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1403
    and bsf: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1404
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1405
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1406
  shows asc: "a \<sim> b = essentially_equal G as bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1407
  using assms by (fast intro: ee_wfactorsI ee_wfactorsD)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1408
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1409
lemma (in factorial_monoid) wfactors_exist [intro, simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1410
  assumes acarr[simp]: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1411
  shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1412
proof (cases "a \<in> Units G")
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1413
  case True
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1414
  then have "wfactors G [] a" by (rule unit_wfactors)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1415
  then show ?thesis by (intro exI) force
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1416
next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1417
  case False
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1418
  with factors_exist [OF acarr] obtain fs where fscarr: "set fs \<subseteq> carrier G" and f: "factors G fs a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1419
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1420
  from f have "wfactors G fs a" by (rule factors_wfactors) fact
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1421
  with fscarr show ?thesis by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1422
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1423
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1424
lemma (in monoid) wfactors_prod_exists [intro, simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1425
  assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1426
  shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1427
  unfolding wfactors_def using assms by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1428
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1429
lemma (in factorial_monoid) wfactors_unique:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1430
  assumes "wfactors G fs a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1431
    and "wfactors G fs' a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1432
    and "a \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1433
    and "set fs \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1434
    and "set fs' \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1435
  shows "essentially_equal G fs fs'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1436
  using assms by (fast intro: ee_wfactorsI[of a a])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1437
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1438
lemma (in monoid) factors_mult_single:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1439
  assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1440
  shows "factors G (a # fb) (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1441
  using assms unfolding factors_def by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1442
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1443
lemma (in monoid_cancel) wfactors_mult_single:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1444
  assumes f: "irreducible G a"  "wfactors G fb b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1445
    "a \<in> carrier G"  "b \<in> carrier G"  "set fb \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1446
  shows "wfactors G (a # fb) (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1447
  using assms unfolding wfactors_def by (simp add: mult_cong_r)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1448
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1449
lemma (in monoid) factors_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1450
  assumes factors: "factors G fa a"  "factors G fb b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1451
    and ascarr: "set fa \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1452
    and bscarr: "set fb \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1453
  shows "factors G (fa @ fb) (a \<otimes> b)"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1454
proof -
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1455
  have "foldr (\<otimes>) (fa @ fb) \<one> = foldr (\<otimes>) fa \<one> \<otimes> foldr (\<otimes>) fb \<one>" if "set fa \<subseteq> carrier G" 
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1456
    "Ball (set fa) (irreducible G)"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1457
    using that bscarr by (induct fa) (simp_all add: m_assoc)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1458
  then show ?thesis
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1459
    using assms unfolding factors_def by force
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1460
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1461
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1462
lemma (in comm_monoid_cancel) wfactors_mult [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1463
  assumes asf: "wfactors G as a" and bsf:"wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1464
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1465
    and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1466
  shows "wfactors G (as @ bs) (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1467
  using wfactors_factors[OF asf ascarr] and wfactors_factors[OF bsf bscarr]
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1468
proof clarsimp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1469
  fix a' b'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1470
  assume asf': "factors G as a'" and a'a: "a' \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1471
    and bsf': "factors G bs b'" and b'b: "b' \<sim> b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1472
  from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1473
  from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1474
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1475
  note carr = acarr bcarr a'carr b'carr ascarr bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1476
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1477
  from asf' bsf' have "factors G (as @ bs) (a' \<otimes> b')"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1478
    by (rule factors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1479
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1480
  with carr have abf': "wfactors G (as @ bs) (a' \<otimes> b')"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1481
    by (intro factors_wfactors) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1482
  also from b'b carr have trb: "a' \<otimes> b' \<sim> a' \<otimes> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1483
    by (intro mult_cong_r)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1484
  also from a'a carr have tra: "a' \<otimes> b \<sim> a \<otimes> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1485
    by (intro mult_cong_l)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1486
  finally show "wfactors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1487
    by (simp add: carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1488
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1489
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1490
lemma (in comm_monoid) factors_dividesI:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1491
  assumes "factors G fs a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1492
    and "f \<in> set fs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1493
    and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1494
  shows "f divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1495
  using assms by (fast elim: factorsE intro: multlist_dividesI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1496
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1497
lemma (in comm_monoid) wfactors_dividesI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1498
  assumes p: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1499
    and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1500
    and f: "f \<in> set fs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1501
  shows "f divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1502
  using wfactors_factors[OF p fscarr]
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1503
proof clarsimp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1504
  fix a'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1505
  assume fsa': "factors G fs a'" and a'a: "a' \<sim> a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1506
  with fscarr have a'carr: "a' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1507
    by (simp add: factors_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1508
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1509
  from fsa' fscarr f have "f divides a'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1510
    by (fast intro: factors_dividesI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1511
  also note a'a
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1512
  finally show "f divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1513
    by (simp add: f fscarr[THEN subsetD] acarr a'carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1514
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1515
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1516
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1517
subsubsection \<open>Factorial monoids and wfactors\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1518
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1519
lemma (in comm_monoid_cancel) factorial_monoidI:
68664
bd0df72c16d5 updated material concerning Algebra
paulson <lp15@cam.ac.uk>
parents: 68604
diff changeset
  1520
  assumes wfactors_exists: "\<And>a. \<lbrakk> a \<in> carrier G; a \<notin> Units G \<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1521
    and wfactors_unique:
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1522
      "\<And>a fs fs'. \<lbrakk>a \<in> carrier G; set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G;
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1523
        wfactors G fs a; wfactors G fs' a\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1524
  shows "factorial_monoid G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
  1525
proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1526
  fix a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1527
  assume acarr: "a \<in> carrier G" and anunit: "a \<notin> Units G"
68664
bd0df72c16d5 updated material concerning Algebra
paulson <lp15@cam.ac.uk>
parents: 68604
diff changeset
  1528
  from wfactors_exists[OF acarr anunit]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1529
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1530
    by blast
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1531
  from wfactors_factors [OF afs ascarr] obtain a' where afs': "factors G as a'" and a'a: "a' \<sim> a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1532
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1533
  from afs' ascarr have a'carr: "a' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1534
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1535
  have a'nunit: "a' \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1536
  proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1537
    assume "a' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1538
    also note a'a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1539
    finally have "a \<in> Units G" by (simp add: acarr)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1540
    with anunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1541
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1542
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1543
  from a'carr acarr a'a obtain u where uunit: "u \<in> Units G" and a': "a' = a \<otimes> u"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1544
    by (blast elim: associatedE2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1545
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1546
  note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1547
  have "a = a \<otimes> \<one>" by simp
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
  1548
  also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: uunit)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1549
  also have "\<dots> = a' \<otimes> inv u" by (simp add: m_assoc[symmetric] a'[symmetric])
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1550
  finally have a: "a = a' \<otimes> inv u" .
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1551
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1552
  from ascarr uunit have cr: "set (as[0:=(as!0 \<otimes> inv u)]) \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1553
    by (cases as) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1554
  from afs' uunit a'nunit acarr ascarr have "factors G (as[0:=(as!0 \<otimes> inv u)]) a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1555
    by (simp add: a factors_cong_unit)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1556
  with cr show "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1557
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1558
qed (blast intro: factors_wfactors wfactors_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1559
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1560
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1561
subsection \<open>Factorizations as Multisets\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1562
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1563
text \<open>Gives useful operations like intersection\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1564
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1565
(* FIXME: use class_of x instead of closure_of {x} *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1566
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1567
abbreviation "assocs G x \<equiv> eq_closure_of (division_rel G) {x}"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1568
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1569
definition "fmset G as = mset (map (\<lambda>a. assocs G a) as)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1570
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1571
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1572
text \<open>Helper lemmas\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1573
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1574
lemma (in monoid) assocs_repr_independence:
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1575
  assumes "y \<in> assocs G x" "x \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1576
  shows "assocs G x = assocs G y"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1577
  using assms
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1578
  by (simp add: eq_closure_of_def elem_def) (use associated_sym associated_trans in \<open>blast+\<close>)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1579
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1580
lemma (in monoid) assocs_self:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1581
  assumes "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1582
  shows "x \<in> assocs G x"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1583
  using assms by (fastforce intro: closure_ofI2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1584
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1585
lemma (in monoid) assocs_repr_independenceD:
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1586
  assumes repr: "assocs G x = assocs G y" and ycarr: "y \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1587
  shows "y \<in> assocs G x"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1588
  unfolding repr using ycarr by (intro assocs_self)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1589
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1590
lemma (in comm_monoid) assocs_assoc:
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1591
  assumes "a \<in> assocs G b" "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1592
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1593
  using assms by (elim closure_ofE2) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1594
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1595
lemmas (in comm_monoid) assocs_eqD = assocs_repr_independenceD[THEN assocs_assoc]
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1596
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1597
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1598
subsubsection \<open>Comparing multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1599
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1600
lemma (in monoid) fmset_perm_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1601
  assumes prm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1602
  shows "fmset G as = fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1603
  using perm_map[OF prm] unfolding mset_eq_perm fmset_def by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1604
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1605
lemma (in comm_monoid_cancel) eqc_listassoc_cong:
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1606
  assumes "as [\<sim>] bs" and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1607
  shows "map (assocs G) as = map (assocs G) bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1608
  using assms
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1609
proof (induction as arbitrary: bs)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1610
  case Nil
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1611
  then show ?case by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1612
next
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1613
  case (Cons a as)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1614
  then show ?case
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1615
  proof (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1616
    fix z zs 
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1617
    assume zzs: "a \<in> carrier G" "set as \<subseteq> carrier G" "bs = z # zs" "a \<sim> z"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1618
      "as [\<sim>] zs" "z \<in> carrier G" "set zs \<subseteq> carrier G"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1619
    then show "assocs G a = assocs G z"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1620
      apply (simp add: eq_closure_of_def elem_def)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1621
      using \<open>a \<in> carrier G\<close> \<open>z \<in> carrier G\<close> \<open>a \<sim> z\<close> associated_sym associated_trans by blast+
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1622
  qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1623
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1624
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1625
lemma (in comm_monoid_cancel) fmset_listassoc_cong:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1626
  assumes "as [\<sim>] bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1627
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1628
  shows "fmset G as = fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1629
  using assms unfolding fmset_def by (simp add: eqc_listassoc_cong)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1630
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1631
lemma (in comm_monoid_cancel) ee_fmset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1632
  assumes ee: "essentially_equal G as bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1633
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1634
  shows "fmset G as = fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1635
  using ee
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1636
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1637
  fix as'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1638
  assume prm: "as <~~> as'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1639
  from prm ascarr have as'carr: "set as' \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1640
    by (rule perm_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1641
  from prm have "fmset G as = fmset G as'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1642
    by (rule fmset_perm_cong)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1643
  also assume "as' [\<sim>] bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1644
  with as'carr bscarr have "fmset G as' = fmset G bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1645
    by (simp add: fmset_listassoc_cong)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1646
  finally show "fmset G as = fmset G bs" .
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1647
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1648
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1649
lemma (in monoid_cancel) fmset_ee_aux:
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1650
  assumes "cas <~~> cbs" "cas = map (assocs G) as" "cbs = map (assocs G) bs"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1651
  shows "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1652
  using assms
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1653
proof (induction cas cbs arbitrary: as bs rule: perm.induct)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1654
  case (Cons xs ys z)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1655
  then show ?case
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1656
    by (clarsimp simp add: map_eq_Cons_conv) blast
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1657
next
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1658
  case (trans xs ys zs)
68604
57721285d4ef elimination of some "smt"
paulson <lp15@cam.ac.uk>
parents: 68551
diff changeset
  1659
  then obtain as' where " as <~~> as' \<and> map (assocs G) as' = ys"
57721285d4ef elimination of some "smt"
paulson <lp15@cam.ac.uk>
parents: 68551
diff changeset
  1660
    by (metis (no_types, lifting) ex_map_conv mset_eq_perm set_mset_mset)
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1661
  then show ?case
68604
57721285d4ef elimination of some "smt"
paulson <lp15@cam.ac.uk>
parents: 68551
diff changeset
  1662
    using trans.IH(2) trans.prems(2) by blast
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1663
qed auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1664
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1665
lemma (in comm_monoid_cancel) fmset_ee:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1666
  assumes mset: "fmset G as = fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1667
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1668
  shows "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1669
proof -
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1670
  from mset have "map (assocs G) as <~~> map (assocs G) bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1671
    by (simp add: fmset_def mset_eq_perm del: mset_map)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1672
  then obtain as' where tp: "as <~~> as'" and tm: "map (assocs G) as' = map (assocs G) bs"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1673
    using fmset_ee_aux by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1674
  with ascarr have as'carr: "set as' \<subseteq> carrier G"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1675
    using perm_closed by blast
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1676
  from tm as'carr[THEN subsetD] bscarr[THEN subsetD] have "as' [\<sim>] bs"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44655
diff changeset
  1677
    by (induct as' arbitrary: bs) (simp, fastforce dest: assocs_eqD[THEN associated_sym])
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1678
  with tp show "essentially_equal G as bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1679
    by (fast intro: essentially_equalI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1680
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1681
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1682
lemma (in comm_monoid_cancel) ee_is_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1683
  assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1684
  shows "essentially_equal G as bs = (fmset G as = fmset G bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1685
  using assms by (fast intro: ee_fmset fmset_ee)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1686
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1687
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1688
subsubsection \<open>Interpreting multisets as factorizations\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1689
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1690
lemma (in monoid) mset_fmsetEx:
60495
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
  1691
  assumes elems: "\<And>X. X \<in> set_mset Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1692
  shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1693
proof -
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1694
  from surjE[OF surj_mset] obtain Cs' where Cs: "Cs = mset Cs'"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1695
    by blast
60515
484559628038 renamed multiset_of -> mset
nipkow
parents: 60495
diff changeset
  1696
  have "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> mset (map (assocs G) cs) = Cs"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1697
    using elems unfolding Cs
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1698
  proof (induction Cs')
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1699
    case (Cons a Cs')
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1700
    then obtain c cs where csP: "\<forall>x\<in>set cs. P x" and mset: "mset (map (assocs G) cs) = mset Cs'"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1701
            and cP: "P c" and a: "a = assocs G c"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1702
      by force
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1703
    then have tP: "\<forall>x\<in>set (c#cs). P x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1704
      by simp
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1705
    show ?case
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1706
      using tP mset a by fastforce
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1707
  qed auto
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1708
  then show ?thesis by (simp add: fmset_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1709
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1710
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1711
lemma (in monoid) mset_wfactorsEx:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1712
  assumes elems: "\<And>X. X \<in> set_mset Cs \<Longrightarrow> \<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1713
  shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1714
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1715
  have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1716
    by (intro mset_fmsetEx, rule elems)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1717
  then obtain cs where p[rule_format]: "\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1718
    and Cs[symmetric]: "fmset G cs = Cs" by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1719
  from p have cscarr: "set cs \<subseteq> carrier G" by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1720
  from p have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1721
    by (intro wfactors_prod_exists) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1722
  then obtain c where ccarr: "c \<in> carrier G" and cfs: "wfactors G cs c" by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1723
  with cscarr Cs show ?thesis by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1724
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1725
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1726
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1727
subsubsection \<open>Multiplication on multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1728
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1729
lemma (in factorial_monoid) mult_wfactors_fmset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1730
  assumes afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1731
    and bfs: "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1732
    and cfs: "wfactors G cs (a \<otimes> b)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1733
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1734
              "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"  "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1735
  shows "fmset G cs = fmset G as + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1736
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1737
  from assms have "wfactors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1738
    by (intro wfactors_mult)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1739
  with carr cfs have "essentially_equal G cs (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1740
    by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1741
  with carr have "fmset G cs = fmset G (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1742
    by (intro ee_fmset) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1743
  also have "fmset G (as@bs) = fmset G as + fmset G bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1744
    by (simp add: fmset_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1745
  finally show "fmset G cs = fmset G as + fmset G bs" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1746
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1747
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1748
lemma (in factorial_monoid) mult_factors_fmset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1749
  assumes afs: "factors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1750
    and bfs: "factors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1751
    and cfs: "factors G cs (a \<otimes> b)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1752
    and "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"  "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1753
  shows "fmset G cs = fmset G as + fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1754
  using assms by (blast intro: factors_wfactors mult_wfactors_fmset)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1755
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1756
lemma (in comm_monoid_cancel) fmset_wfactors_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1757
  assumes mset: "fmset G cs = fmset G as + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1758
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1759
      "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"  "set cs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1760
    and fs: "wfactors G as a"  "wfactors G bs b"  "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1761
  shows "c \<sim> a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1762
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1763
  from carr fs have m: "wfactors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1764
    by (intro wfactors_mult)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1765
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1766
  from mset have "fmset G cs = fmset G (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1767
    by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1768
  then have "essentially_equal G cs (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1769
    by (rule fmset_ee) (simp_all add: carr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1770
  then show "c \<sim> a \<otimes> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1771
    by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp_all add: assms m)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1772
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1773
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1774
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1775
subsubsection \<open>Divisibility on multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1776
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1777
lemma (in factorial_monoid) divides_fmsubset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1778
  assumes ab: "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1779
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1780
    and bfs: "wfactors G bs b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1781
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1782
  shows "fmset G as \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1783
  using ab
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1784
proof (elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1785
  fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1786
  assume ccarr: "c \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1787
  from wfactors_exist [OF this]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1788
  obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1789
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1790
  note carr = carr ccarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1791
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1792
  assume "b = a \<otimes> c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1793
  with afs bfs cfs carr have "fmset G bs = fmset G as + fmset G cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1794
    by (intro mult_wfactors_fmset[OF afs cfs]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1795
  then show ?thesis by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1796
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1797
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1798
lemma (in comm_monoid_cancel) fmsubset_divides:
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1799
  assumes msubset: "fmset G as \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1800
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1801
    and bfs: "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1802
    and acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1803
    and bcarr: "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1804
    and ascarr: "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1805
    and bscarr: "set bs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1806
  shows "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1807
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1808
  from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1809
  from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1810
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1811
  have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = fmset G bs - fmset G as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1812
  proof (intro mset_wfactorsEx, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1813
    fix X
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61382
diff changeset
  1814
    assume "X \<in># fmset G bs - fmset G as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1815
    then have "X \<in># fmset G bs" by (rule in_diffD)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1816
    then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1817
    then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1818
    then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1819
    with bscarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1820
    from xbs birr have xirr: "irreducible G x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1821
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1822
    from xcarr and xirr and X show "\<exists>x. x \<in> carrier G \<and> irreducible G x \<and> X = assocs G x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1823
      by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1824
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1825
  then obtain c cs
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1826
    where ccarr: "c \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1827
      and cscarr: "set cs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1828
      and csf: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1829
      and csmset: "fmset G cs = fmset G bs - fmset G as" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1830
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1831
  from csmset msubset
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1832
  have "fmset G bs = fmset G as + fmset G cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1833
    by (simp add: multiset_eq_iff subseteq_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1834
  then have basc: "b \<sim> a \<otimes> c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1835
    by (rule fmset_wfactors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1836
  then show ?thesis
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1837
  proof (elim associatedE2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1838
    fix u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1839
    assume "u \<in> Units G"  "b = a \<otimes> c \<otimes> u"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1840
    with acarr ccarr show "a divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1841
      by (fast intro: dividesI[of "c \<otimes> u"] m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1842
  qed (simp_all add: acarr bcarr ccarr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1843
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1844
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1845
lemma (in factorial_monoid) divides_as_fmsubset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1846
  assumes "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1847
    and "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1848
    and "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1849
    and "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1850
    and "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1851
    and "set bs \<subseteq> carrier G"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1852
  shows "a divides b = (fmset G as \<subseteq># fmset G bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1853
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1854
  by (blast intro: divides_fmsubset fmsubset_divides)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1855
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1856
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1857
text \<open>Proper factors on multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1858
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1859
lemma (in factorial_monoid) fmset_properfactor:
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1860
  assumes asubb: "fmset G as \<subseteq># fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1861
    and anb: "fmset G as \<noteq> fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1862
    and "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1863
    and "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1864
    and "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1865
    and "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1866
    and "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1867
    and "set bs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1868
  shows "properfactor G a b"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1869
proof (rule properfactorI)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1870
  show "a divides b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1871
    using assms asubb fmsubset_divides by blast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1872
  show "\<not> b divides a"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1873
    by (meson anb assms asubb factorial_monoid.divides_fmsubset factorial_monoid_axioms subset_mset.antisym)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1874
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1875
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1876
lemma (in factorial_monoid) properfactor_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1877
  assumes pf: "properfactor G a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1878
    and "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1879
    and "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1880
    and "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1881
    and "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1882
    and "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1883
    and "set bs \<subseteq> carrier G"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1884
  shows "fmset G as \<subseteq># fmset G bs \<and> fmset G as \<noteq> fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1885
  using pf
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1886
  apply safe
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1887
   apply (meson assms divides_as_fmsubset monoid.properfactor_divides monoid_axioms)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  1888
  by (meson assms associated_def comm_monoid_cancel.ee_wfactorsD comm_monoid_cancel.fmset_ee factorial_monoid_axioms factorial_monoid_def properfactorE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1889
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1890
subsection \<open>Irreducible Elements are Prime\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1891
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63524
diff changeset
  1892
lemma (in factorial_monoid) irreducible_prime:
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1893
  assumes pirr: "irreducible G p" and pcarr: "p \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1894
  shows "prime G p"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1895
  using pirr
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1896
proof (elim irreducibleE, intro primeI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1897
  fix a b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1898
  assume acarr: "a \<in> carrier G"  and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1899
    and pdvdab: "p divides (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1900
    and pnunit: "p \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1901
  assume irreduc[rule_format]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1902
    "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1903
  from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1904
    by (rule dividesE)
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1905
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1906
    using wfactors_exist [OF acarr] by blast
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1907
  obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1908
    using wfactors_exist [OF bcarr] by blast
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1909
  obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1910
    using wfactors_exist [OF ccarr] by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1911
  note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1912
  from pirr cfs  abpc have "wfactors G (p # cs) (a \<otimes> b)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1913
    by (simp add: wfactors_mult_single)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1914
  moreover have  "wfactors G (as @ bs) (a \<otimes> b)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1915
    by (rule wfactors_mult [OF afs bfs]) fact+
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1916
  ultimately have "essentially_equal G (p # cs) (as @ bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1917
    by (rule wfactors_unique) simp+
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1918
  then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1919
    by (fast elim: essentially_equalE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1920
  then have "p \<in> set ds"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1921
    by (simp add: perm_set_eq[symmetric])
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1922
  with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1923
    unfolding list_all2_conv_all_nth set_conv_nth by force
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1924
  then consider "p' \<in> set as" | "p' \<in> set bs" by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1925
  then show "p divides a \<or> p divides b"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1926
    using afs bfs divides_cong_l pp' wfactors_dividesI
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1927
    by (meson acarr ascarr bcarr bscarr pcarr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1928
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1929
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1930
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67399
diff changeset
  1931
\<comment> \<open>A version using @{const factors}, more complicated\<close>
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63524
diff changeset
  1932
lemma (in factorial_monoid) factors_irreducible_prime:
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1933
  assumes pirr: "irreducible G p" and pcarr: "p \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1934
  shows "prime G p"
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1935
proof (rule primeI)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1936
  show "p \<notin> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1937
    by (meson irreducibleE pirr)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1938
  have irreduc: "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b p\<rbrakk> \<Longrightarrow> b \<in> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1939
    using pirr by (auto simp: irreducible_def)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1940
  show "p divides a \<or> p divides b" 
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1941
    if acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and pdvdab: "p divides (a \<otimes> b)" for a b
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1942
  proof -
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1943
    from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1944
      by (rule dividesE)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1945
    note [simp] = pcarr acarr bcarr ccarr
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1946
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1947
    show "p divides a \<or> p divides b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1948
    proof (cases "a \<in> Units G")
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1949
      case True
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1950
      then have "p divides b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1951
        by (metis acarr associatedI2' associated_def bcarr divides_trans m_comm pcarr pdvdab) 
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1952
      then show ?thesis ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1953
    next
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1954
      case anunit: False
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1955
      show ?thesis
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1956
      proof (cases "b \<in> Units G")
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1957
        case True 
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1958
        then have "p divides a"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1959
          by (meson acarr bcarr divides_unit irreducible_prime pcarr pdvdab pirr prime_def)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1960
        then show ?thesis ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1961
      next
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1962
        case bnunit: False
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1963
        then have cnunit: "c \<notin> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1964
          by (metis abpc acarr anunit bcarr ccarr irreducible_prodE irreducible_prod_rI pcarr pirr)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1965
        then have abnunit: "a \<otimes> b \<notin> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1966
          using acarr anunit bcarr unit_factor by blast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1967
        obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1968
          using factors_exist [OF acarr anunit] by blast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1969
        obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1970
          using factors_exist [OF bcarr bnunit] by blast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1971
        obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1972
          using factors_exist [OF ccarr cnunit] by auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1973
        note [simp] = ascarr bscarr cscarr
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1974
        from pirr cfac abpc have abfac': "factors G (p # cs) (a \<otimes> b)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1975
          by (simp add: factors_mult_single)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1976
        from afac and bfac have "factors G (as @ bs) (a \<otimes> b)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1977
          by (rule factors_mult) fact+
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1978
        with abfac' have "essentially_equal G (p # cs) (as @ bs)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1979
          using abnunit factors_unique by auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1980
        then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1981
          by (fast elim: essentially_equalE)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1982
        then have "p \<in> set ds"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1983
          by (simp add: perm_set_eq[symmetric])
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1984
        with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1985
          unfolding list_all2_conv_all_nth set_conv_nth by force
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1986
        then consider "p' \<in> set as" | "p' \<in> set bs" by auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1987
        then show "p divides a \<or> p divides b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  1988
          by (meson afac bfac divides_cong_l factors_dividesI pp' ascarr bscarr pcarr)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1989
      qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1990
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1991
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1992
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1993
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1994
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1995
subsection \<open>Greatest Common Divisors and Lowest Common Multiples\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1996
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1997
subsubsection \<open>Definitions\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1998
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1999
definition isgcd :: "[('a,_) monoid_scheme, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ gcdof\<index> _ _)" [81,81,81] 80)
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  2000
  where "x gcdof\<^bsub>G\<^esub> a b \<longleftrightarrow> x divides\<^bsub>G\<^esub> a \<and> x divides\<^bsub>G\<^esub> b \<and>
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2001
    (\<forall>y\<in>carrier G. (y divides\<^bsub>G\<^esub> a \<and> y divides\<^bsub>G\<^esub> b \<longrightarrow> y divides\<^bsub>G\<^esub> x))"
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2002
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2003
definition islcm :: "[_, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ lcmof\<index> _ _)" [81,81,81] 80)
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  2004
  where "x lcmof\<^bsub>G\<^esub> a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and>
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2005
    (\<forall>y\<in>carrier G. (a divides\<^bsub>G\<^esub> y \<and> b divides\<^bsub>G\<^esub> y \<longrightarrow> x divides\<^bsub>G\<^esub> y))"
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2006
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2007
definition somegcd :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  2008
  where "somegcd G a b = (SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b)"
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2009
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2010
definition somelcm :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  2011
  where "somelcm G a b = (SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b)"
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2012
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2013
definition "SomeGcd G A = inf (division_rel G) A"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2014
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2015
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2016
locale gcd_condition_monoid = comm_monoid_cancel +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2017
  assumes gcdof_exists: "\<lbrakk>a \<in> carrier G; b \<in> carrier G\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> carrier G \<and> c gcdof a b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2018
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2019
locale primeness_condition_monoid = comm_monoid_cancel +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2020
  assumes irreducible_prime: "\<lbrakk>a \<in> carrier G; irreducible G a\<rbrakk> \<Longrightarrow> prime G a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2021
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2022
locale divisor_chain_condition_monoid = comm_monoid_cancel +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2023
  assumes division_wellfounded: "wf {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2024
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2025
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2026
subsubsection \<open>Connections to \texttt{Lattice.thy}\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2027
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2028
lemma gcdof_greatestLower:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2029
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2030
  assumes carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2031
  shows "(x \<in> carrier G \<and> x gcdof a b) = greatest (division_rel G) x (Lower (division_rel G) {a, b})"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2032
  by (auto simp: isgcd_def greatest_def Lower_def elem_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2033
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2034
lemma lcmof_leastUpper:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2035
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2036
  assumes carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2037
  shows "(x \<in> carrier G \<and> x lcmof a b) = least (division_rel G) x (Upper (division_rel G) {a, b})"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2038
  by (auto simp: islcm_def least_def Upper_def elem_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2039
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2040
lemma somegcd_meet:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2041
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2042
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2043
  shows "somegcd G a b = meet (division_rel G) a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2044
  by (simp add: somegcd_def meet_def inf_def gcdof_greatestLower[OF carr])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2045
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2046
lemma (in monoid) isgcd_divides_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2047
  assumes "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2048
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2049
  shows "a gcdof a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2050
  using assms unfolding isgcd_def by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2051
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2052
lemma (in monoid) isgcd_divides_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2053
  assumes "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2054
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2055
  shows "b gcdof a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2056
  using assms unfolding isgcd_def by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2057
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2058
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2059
subsubsection \<open>Existence of gcd and lcm\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2060
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2061
lemma (in factorial_monoid) gcdof_exists:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2062
  assumes acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2063
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2064
  shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2065
proof -
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2066
  from wfactors_exist [OF acarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2067
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2068
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2069
  from afs have airr: "\<forall>a \<in> set as. irreducible G a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2070
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2071
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2072
  from wfactors_exist [OF bcarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2073
  obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2074
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2075
  from bfs have birr: "\<forall>b \<in> set bs. irreducible G b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2076
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2077
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2078
  have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and>
63919
9aed2da07200 # after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63847
diff changeset
  2079
    fmset G cs = fmset G as \<inter># fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2080
  proof (intro mset_wfactorsEx)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2081
    fix X
63919
9aed2da07200 # after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63847
diff changeset
  2082
    assume "X \<in># fmset G as \<inter># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2083
    then have "X \<in># fmset G as" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2084
    then have "X \<in> set (map (assocs G) as)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2085
      by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2086
    then have "\<exists>x. X = assocs G x \<and> x \<in> set as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2087
      by (induct as) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2088
    then obtain x where X: "X = assocs G x" and xas: "x \<in> set as"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2089
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2090
    with ascarr have xcarr: "x \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2091
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2092
    from xas airr have xirr: "irreducible G x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2093
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2094
    from xcarr and xirr and X show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2095
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2096
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2097
  then obtain c cs
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2098
    where ccarr: "c \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2099
      and cscarr: "set cs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2100
      and csirr: "wfactors G cs c"
63919
9aed2da07200 # after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63847
diff changeset
  2101
      and csmset: "fmset G cs = fmset G as \<inter># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2102
    by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2103
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2104
  have "c gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2105
  proof (simp add: isgcd_def, safe)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2106
    from csmset
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2107
    have "fmset G cs \<subseteq># fmset G as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2108
      by (simp add: multiset_inter_def subset_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2109
    then show "c divides a" by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2110
  next
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2111
    from csmset have "fmset G cs \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2112
      by (simp add: multiset_inter_def subseteq_mset_def, force)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2113
    then show "c divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2114
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2115
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2116
    fix y
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2117
    assume "y \<in> carrier G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2118
    from wfactors_exist [OF this]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2119
    obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2120
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2121
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2122
    assume "y divides a"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2123
    then have ya: "fmset G ys \<subseteq># fmset G as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2124
      by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2125
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2126
    assume "y divides b"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2127
    then have yb: "fmset G ys \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2128
      by (rule divides_fmsubset) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2129
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2130
    from ya yb csmset have "fmset G ys \<subseteq># fmset G cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2131
      by (simp add: subset_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2132
    then show "y divides c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2133
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2134
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2135
  with ccarr show "\<exists>c. c \<in> carrier G \<and> c gcdof a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2136
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2137
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2138
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2139
lemma (in factorial_monoid) lcmof_exists:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2140
  assumes acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2141
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2142
  shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2143
proof -
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2144
  from wfactors_exist [OF acarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2145
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2146
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2147
  from afs have airr: "\<forall>a \<in> set as. irreducible G a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2148
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2149
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2150
  from wfactors_exist [OF bcarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2151
  obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2152
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2153
  from bfs have birr: "\<forall>b \<in> set bs. irreducible G b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2154
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2155
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2156
  have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and>
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2157
    fmset G cs = (fmset G as - fmset G bs) + fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2158
  proof (intro mset_wfactorsEx)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2159
    fix X
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61382
diff changeset
  2160
    assume "X \<in># (fmset G as - fmset G bs) + fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2161
    then have "X \<in># fmset G as \<or> X \<in># fmset G bs"
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61382
diff changeset
  2162
      by (auto dest: in_diffD)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2163
    then consider "X \<in> set_mset (fmset G as)" | "X \<in> set_mset (fmset G bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2164
      by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2165
    then show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2166
    proof cases
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2167
      case 1
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2168
      then have "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2169
      then have "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2170
      then obtain x where xas: "x \<in> set as" and X: "X = assocs G x" by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2171
      with ascarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2172
      from xas airr have xirr: "irreducible G x" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2173
      from xcarr and xirr and X show ?thesis by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2174
    next
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2175
      case 2
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2176
      then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2177
      then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2178
      then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2179
      with bscarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2180
      from xbs birr have xirr: "irreducible G x" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2181
      from xcarr and xirr and X show ?thesis by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2182
    qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2183
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2184
  then obtain c cs
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2185
    where ccarr: "c \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2186
      and cscarr: "set cs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2187
      and csirr: "wfactors G cs c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2188
      and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2189
    by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2190
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2191
  have "c lcmof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2192
  proof (simp add: islcm_def, safe)
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2193
    from csmset have "fmset G as \<subseteq># fmset G cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2194
      by (simp add: subseteq_mset_def, force)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2195
    then show "a divides c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2196
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2197
  next
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2198
    from csmset have "fmset G bs \<subseteq># fmset G cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2199
      by (simp add: subset_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2200
    then show "b divides c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2201
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2202
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2203
    fix y
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2204
    assume "y \<in> carrier G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2205
    from wfactors_exist [OF this]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2206
    obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2207
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2208
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2209
    assume "a divides y"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2210
    then have ya: "fmset G as \<subseteq># fmset G ys"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2211
      by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2212
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2213
    assume "b divides y"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2214
    then have yb: "fmset G bs \<subseteq># fmset G ys"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2215
      by (rule divides_fmsubset) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2216
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2217
    from ya yb csmset have "fmset G cs \<subseteq># fmset G ys"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2218
      using subset_eq_diff_conv subset_mset.le_diff_conv2 by fastforce
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2219
    then show "c divides y"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2220
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2221
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2222
  with ccarr show "\<exists>c. c \<in> carrier G \<and> c lcmof a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2223
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2224
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2225
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2226
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2227
subsection \<open>Conditions for Factoriality\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2228
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2229
subsubsection \<open>Gcd condition\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2230
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2231
lemma (in gcd_condition_monoid) division_weak_lower_semilattice [simp]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2232
  "weak_lower_semilattice (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2233
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2234
  interpret weak_partial_order "division_rel G" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2235
  show ?thesis
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2236
  proof (unfold_locales, simp_all)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2237
    fix x y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2238
    assume carr: "x \<in> carrier G"  "y \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2239
    from gcdof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z gcdof x y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2240
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2241
    with carr have "greatest (division_rel G) z (Lower (division_rel G) {x, y})"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2242
      by (subst gcdof_greatestLower[symmetric], simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2243
    then show "\<exists>z. greatest (division_rel G) z (Lower (division_rel G) {x, y})"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2244
      by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2245
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2246
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2247
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2248
lemma (in gcd_condition_monoid) gcdof_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2249
  assumes a'a: "a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2250
    and agcd: "a gcdof b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2251
    and a'carr: "a' \<in> carrier G" and carr': "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2252
  shows "a' gcdof b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2253
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2254
  note carr = a'carr carr'
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2255
  interpret weak_lower_semilattice "division_rel G" by simp
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2256
  have "is_glb (division_rel G) a' {b, c}"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2257
    by (subst greatest_Lower_cong_l[of _ a]) (simp_all add: a'a carr gcdof_greatestLower[symmetric] agcd)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2258
  then have "a' \<in> carrier G \<and> a' gcdof b c"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2259
    by (simp add: gcdof_greatestLower carr')
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2260
  then show ?thesis ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2261
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2262
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2263
lemma (in gcd_condition_monoid) gcd_closed [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2264
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2265
  shows "somegcd G a b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2266
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2267
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2268
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2269
    apply (simp add: somegcd_meet[OF carr])
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2270
    apply (rule meet_closed[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2271
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2272
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2273
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2274
lemma (in gcd_condition_monoid) gcd_isgcd:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2275
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2276
  shows "(somegcd G a b) gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2277
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2278
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2279
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2280
  from carr have "somegcd G a b \<in> carrier G \<and> (somegcd G a b) gcdof a b"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2281
    by (simp add: gcdof_greatestLower inf_of_two_greatest meet_def somegcd_meet)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2282
  then show "(somegcd G a b) gcdof a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2283
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2284
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2285
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2286
lemma (in gcd_condition_monoid) gcd_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2287
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2288
  shows "\<exists>x\<in>carrier G. x = somegcd G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2289
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2290
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2291
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2292
  show ?thesis
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 53374
diff changeset
  2293
    by (metis carr(1) carr(2) gcd_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2294
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2295
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2296
lemma (in gcd_condition_monoid) gcd_divides_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2297
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2298
  shows "(somegcd G a b) divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2299
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2300
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2301
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2302
  show ?thesis
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 53374
diff changeset
  2303
    by (metis carr(1) carr(2) gcd_isgcd isgcd_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2304
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2305
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2306
lemma (in gcd_condition_monoid) gcd_divides_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2307
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2308
  shows "(somegcd G a b) divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2309
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2310
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2311
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2312
  show ?thesis
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 53374
diff changeset
  2313
    by (metis carr gcd_isgcd isgcd_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2314
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2315
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2316
lemma (in gcd_condition_monoid) gcd_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2317
  assumes sub: "z divides x"  "z divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2318
    and L: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2319
  shows "z divides (somegcd G x y)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2320
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2321
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2322
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2323
  show ?thesis
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 53374
diff changeset
  2324
    by (metis gcd_isgcd isgcd_def assms)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2325
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2326
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2327
lemma (in gcd_condition_monoid) gcd_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2328
  assumes xx': "x \<sim> x'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2329
    and carr: "x \<in> carrier G"  "x' \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2330
  shows "somegcd G x y \<sim> somegcd G x' y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2331
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2332
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2333
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2334
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2335
    apply (simp add: somegcd_meet carr)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2336
    apply (rule meet_cong_l[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2337
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2338
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2339
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2340
lemma (in gcd_condition_monoid) gcd_cong_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2341
  assumes carr: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2342
    and yy': "y \<sim> y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2343
  shows "somegcd G x y \<sim> somegcd G x y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2344
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2345
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2346
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2347
    apply (simp add: somegcd_meet carr)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2348
    apply (rule meet_cong_r[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2349
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2350
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2351
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2352
(*
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2353
lemma (in gcd_condition_monoid) asc_cong_gcd_l [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2354
  assumes carr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2355
  shows "asc_cong (\<lambda>a. somegcd G a b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2356
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2357
unfolding CONG_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2358
by clarsimp (blast intro: gcd_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2359
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2360
lemma (in gcd_condition_monoid) asc_cong_gcd_r [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2361
  assumes carr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2362
  shows "asc_cong (\<lambda>b. somegcd G a b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2363
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2364
unfolding CONG_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2365
by clarsimp (blast intro: gcd_cong_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2366
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2367
lemmas (in gcd_condition_monoid) asc_cong_gcd_split [simp] =
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2368
    assoc_split[OF _ asc_cong_gcd_l] assoc_split[OF _ asc_cong_gcd_r]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2369
*)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2370
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2371
lemma (in gcd_condition_monoid) gcdI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2372
  assumes dvd: "a divides b"  "a divides c"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2373
    and others: "\<And>y. \<lbrakk>y\<in>carrier G; y divides b; y divides c\<rbrakk> \<Longrightarrow> y divides a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2374
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2375
  shows "a \<sim> somegcd G b c"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2376
proof -
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2377
  have "\<exists>a. a \<in> carrier G \<and> a gcdof b c"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2378
    by (simp add: bcarr ccarr gcdof_exists)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2379
  moreover have "\<And>x. x \<in> carrier G \<and> x gcdof b c \<Longrightarrow> a \<sim> x"
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2380
    by (simp add: acarr associated_def dvd isgcd_def others)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2381
  ultimately show ?thesis
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2382
    unfolding somegcd_def by (blast intro: someI2_ex)
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2383
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2384
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2385
lemma (in gcd_condition_monoid) gcdI2:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2386
  assumes "a gcdof b c" and "a \<in> carrier G" and "b \<in> carrier G" and "c \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2387
  shows "a \<sim> somegcd G b c"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2388
  using assms unfolding isgcd_def
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2389
  by (simp add: gcdI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2390
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2391
lemma (in gcd_condition_monoid) SomeGcd_ex:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2392
  assumes "finite A"  "A \<subseteq> carrier G"  "A \<noteq> {}"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2393
  shows "\<exists>x\<in> carrier G. x = SomeGcd G A"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2394
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2395
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2396
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2397
  show ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2398
    apply (simp add: SomeGcd_def)
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2399
    apply (rule finite_inf_closed[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2400
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2401
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2402
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2403
lemma (in gcd_condition_monoid) gcd_assoc:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2404
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2405
  shows "somegcd G (somegcd G a b) c \<sim> somegcd G a (somegcd G b c)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2406
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2407
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2408
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2409
  show ?thesis
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2410
    unfolding associated_def
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2411
    by (meson carr divides_trans gcd_divides gcd_divides_l gcd_divides_r gcd_exists)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2412
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2413
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2414
lemma (in gcd_condition_monoid) gcd_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2415
  assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2416
  shows "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2417
proof - (* following Jacobson, Basic Algebra, p.140 *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2418
  let ?d = "somegcd G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2419
  let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2420
  note carr[simp] = acarr bcarr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2421
  have dcarr: "?d \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2422
  have ecarr: "?e \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2423
  note carr = carr dcarr ecarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2424
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2425
  have "?d divides a" by (simp add: gcd_divides_l)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2426
  then have cd'ca: "c \<otimes> ?d divides (c \<otimes> a)" by (simp add: divides_mult_lI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2427
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2428
  have "?d divides b" by (simp add: gcd_divides_r)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2429
  then have cd'cb: "c \<otimes> ?d divides (c \<otimes> b)" by (simp add: divides_mult_lI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2430
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2431
  from cd'ca cd'cb have cd'e: "c \<otimes> ?d divides ?e"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2432
    by (rule gcd_divides) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2433
  then obtain u where ucarr[simp]: "u \<in> carrier G" and e_cdu: "?e = c \<otimes> ?d \<otimes> u"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2434
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2435
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2436
  note carr = carr ucarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2437
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2438
  have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2439
  then obtain x where xcarr: "x \<in> carrier G" and ca_ex: "c \<otimes> a = ?e \<otimes> x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2440
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2441
  with e_cdu have ca_cdux: "c \<otimes> a = c \<otimes> ?d \<otimes> u \<otimes> x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2442
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2443
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2444
  from ca_cdux xcarr have "c \<otimes> a = c \<otimes> (?d \<otimes> u \<otimes> x)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2445
    by (simp add: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2446
  then have "a = ?d \<otimes> u \<otimes> x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2447
    by (rule l_cancel[of c a]) (simp add: xcarr)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2448
  then have du'a: "?d \<otimes> u divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2449
    by (rule dividesI[OF xcarr])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2450
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2451
  have "?e divides c \<otimes> b" by (intro gcd_divides_r) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2452
  then obtain x where xcarr: "x \<in> carrier G" and cb_ex: "c \<otimes> b = ?e \<otimes> x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2453
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2454
  with e_cdu have cb_cdux: "c \<otimes> b = c \<otimes> ?d \<otimes> u \<otimes> x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2455
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2456
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2457
  from cb_cdux xcarr have "c \<otimes> b = c \<otimes> (?d \<otimes> u \<otimes> x)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2458
    by (simp add: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2459
  with xcarr have "b = ?d \<otimes> u \<otimes> x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2460
    by (intro l_cancel[of c b]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2461
  then have du'b: "?d \<otimes> u divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2462
    by (intro dividesI[OF xcarr])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2463
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2464
  from du'a du'b carr have du'd: "?d \<otimes> u divides ?d"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2465
    by (intro gcd_divides) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2466
  then have uunit: "u \<in> Units G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2467
  proof (elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2468
    fix v
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2469
    assume vcarr[simp]: "v \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2470
    assume d: "?d = ?d \<otimes> u \<otimes> v"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2471
    have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2472
    also have "?d \<otimes> u \<otimes> v = ?d \<otimes> (u \<otimes> v)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2473
    finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" .
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2474
    then have i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2475
    then have i1: "\<one> = v \<otimes> u" by (simp add: m_comm)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2476
    from vcarr i1[symmetric] i2[symmetric] show "u \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2477
      by (auto simp: Units_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2478
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2479
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2480
  from e_cdu uunit have "somegcd G (c \<otimes> a) (c \<otimes> b) \<sim> c \<otimes> somegcd G a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2481
    by (intro associatedI2[of u]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2482
  from this[symmetric] show "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2483
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2484
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2485
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2486
lemma (in monoid) assoc_subst:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2487
  assumes ab: "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2488
    and cP: "\<forall>a b. a \<in> carrier G \<and> b \<in> carrier G \<and> a \<sim> b
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2489
      \<longrightarrow> f a \<in> carrier G \<and> f b \<in> carrier G \<and> f a \<sim> f b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2490
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2491
  shows "f a \<sim> f b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2492
  using assms by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2493
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2494
lemma (in gcd_condition_monoid) relprime_mult:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2495
  assumes abrelprime: "somegcd G a b \<sim> \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2496
    and acrelprime: "somegcd G a c \<sim> \<one>"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2497
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2498
  shows "somegcd G a (b \<otimes> c) \<sim> \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2499
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2500
  have "c = c \<otimes> \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2501
  also from abrelprime[symmetric]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2502
  have "\<dots> \<sim> c \<otimes> somegcd G a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2503
    by (rule assoc_subst) (simp add: mult_cong_r)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2504
  also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2505
    by (rule gcd_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2506
  finally have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2507
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2508
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2509
  from carr have a: "a \<sim> somegcd G a (c \<otimes> a)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2510
    by (fast intro: gcdI divides_prod_l)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2511
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2512
  have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2513
    by (simp add: m_comm)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2514
  also from a have "\<dots> \<sim> somegcd G (somegcd G a (c \<otimes> a)) (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2515
    by (rule assoc_subst) (simp add: gcd_cong_l)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2516
  also from gcd_assoc have "\<dots> \<sim> somegcd G a (somegcd G (c \<otimes> a) (c \<otimes> b))"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2517
    by (rule assoc_subst) simp+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2518
  also from c[symmetric] have "\<dots> \<sim> somegcd G a c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2519
    by (rule assoc_subst) (simp add: gcd_cong_r)+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2520
  also note acrelprime
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2521
  finally show "somegcd G a (b \<otimes> c) \<sim> \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2522
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2523
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2524
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2525
lemma (in gcd_condition_monoid) primeness_condition: "primeness_condition_monoid G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2526
proof -
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2527
  have *: "p divides a \<or> p divides b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2528
    if pcarr[simp]: "p \<in> carrier G" and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2529
      and pirr: "irreducible G p" and pdvdab: "p divides a \<otimes> b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2530
    for p a b
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2531
  proof -
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2532
    from pirr have pnunit: "p \<notin> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2533
      and r: "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b p\<rbrakk> \<Longrightarrow> b \<in> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2534
      by (fast elim: irreducibleE)+
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2535
    show "p divides a \<or> p divides b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2536
    proof (rule ccontr, clarsimp)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2537
      assume npdvda: "\<not> p divides a" and npdvdb: "\<not> p divides b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2538
      have "\<one> \<sim> somegcd G p a"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2539
      proof (intro gcdI unit_divides)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2540
        show "\<And>y. \<lbrakk>y \<in> carrier G; y divides p; y divides a\<rbrakk> \<Longrightarrow> y \<in> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2541
          by (meson divides_trans npdvda pcarr properfactorI r)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2542
      qed auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2543
      with pcarr acarr have pa: "somegcd G p a \<sim> \<one>"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2544
        by (fast intro: associated_sym[of "\<one>"] gcd_closed)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2545
      have "\<one> \<sim> somegcd G p b"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2546
      proof (intro gcdI unit_divides)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2547
        show "\<And>y. \<lbrakk>y \<in> carrier G; y divides p; y divides b\<rbrakk> \<Longrightarrow> y \<in> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2548
          by (meson divides_trans npdvdb pcarr properfactorI r)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2549
      qed auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2550
      with pcarr bcarr have pb: "somegcd G p b \<sim> \<one>"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2551
        by (fast intro: associated_sym[of "\<one>"] gcd_closed)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2552
      have "p \<sim> somegcd G p (a \<otimes> b)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2553
        using pdvdab by (simp add: gcdI2 isgcd_divides_l)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2554
      also from pa pb pcarr acarr bcarr have "somegcd G p (a \<otimes> b) \<sim> \<one>"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2555
        by (rule relprime_mult)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2556
      finally have "p \<sim> \<one>"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2557
        by simp
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2558
      with pcarr have "p \<in> Units G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2559
        by (fast intro: assoc_unit_l)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2560
      with pnunit show False ..
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2561
    qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2562
  qed
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2563
  show ?thesis
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2564
    by unfold_locales (metis * primeI irreducibleE)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2565
qed    
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2566
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2567
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2568
sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2569
  by (rule primeness_condition)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2570
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2571
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2572
subsubsection \<open>Divisor chain condition\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2573
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2574
lemma (in divisor_chain_condition_monoid) wfactors_exist:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2575
  assumes acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2576
  shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2577
proof -
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2578
  have r: "a \<in> carrier G \<Longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2579
    using division_wellfounded
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2580
  proof (induction rule: wf_induct_rule)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2581
    case (less x)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2582
    then have xcarr: "x \<in> carrier G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2583
      by auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2584
    show ?case
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2585
    proof (cases "x \<in> Units G")
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2586
      case True
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2587
      then show ?thesis
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2588
        by (metis bot.extremum list.set(1) unit_wfactors)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2589
    next
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2590
      case xnunit: False
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2591
      show ?thesis
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2592
      proof (cases "irreducible G x")
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2593
        case True
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2594
        then show ?thesis
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2595
          by (rule_tac x="[x]" in exI) (simp add: wfactors_def xcarr)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2596
      next
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2597
        case False
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2598
        then obtain y where ycarr: "y \<in> carrier G" and ynunit: "y \<notin> Units G" and pfyx: "properfactor G y x"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2599
          by (meson irreducible_def xnunit)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2600
        obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2601
          using less ycarr pfyx by blast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2602
        then obtain z where zcarr: "z \<in> carrier G" and x: "x = y \<otimes> z"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2603
          by (meson dividesE pfyx properfactorE2)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2604
        from zcarr ycarr have "properfactor G z x"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2605
          using m_comm properfactorI3 x ynunit by blast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2606
        with less zcarr obtain zs where zscarr: "set zs \<subseteq> carrier G" and zfs: "wfactors G zs z"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2607
          by blast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2608
        from yscarr zscarr have xscarr: "set (ys@zs) \<subseteq> carrier G"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2609
          by simp
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2610
        have "wfactors G (ys@zs) (y\<otimes>z)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2611
          using xscarr ycarr yfs zcarr zfs by auto
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2612
        then have "wfactors G (ys@zs) x"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2613
          by (simp add: x)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2614
        with xscarr show "\<exists>xs. set xs \<subseteq> carrier G \<and> wfactors G xs x"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2615
          by fast
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2616
      qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2617
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2618
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2619
  from acarr show ?thesis by (rule r)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2620
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2621
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2622
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2623
subsubsection \<open>Primeness condition\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2624
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2625
lemma (in comm_monoid_cancel) multlist_prime_pos:
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2626
  assumes aprime: "prime G a" and carr: "a \<in> carrier G" 
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2627
     and as: "set as \<subseteq> carrier G" "a divides (foldr (\<otimes>) as \<one>)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2628
   shows "\<exists>i<length as. a divides (as!i)"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2629
  using as
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2630
proof (induction as)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2631
  case Nil
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2632
  then show ?case
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2633
    by simp (meson Units_one_closed aprime carr divides_unit primeE)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2634
next
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2635
  case (Cons x as)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2636
  then have "x \<in> carrier G"  "set as \<subseteq> carrier G" and "a divides x \<otimes> foldr (\<otimes>) as \<one>"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2637
    by (auto simp: )
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2638
  with carr aprime have "a divides x \<or> a divides foldr (\<otimes>) as \<one>"
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2639
    by (intro prime_divides) simp+
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2640
  then show ?case
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2641
    using Cons.IH Cons.prems(1) by force
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2642
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2643
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2644
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2645
lemma (in primeness_condition_monoid) wfactors_unique__hlp_induct:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2646
  "\<forall>a as'. a \<in> carrier G \<and> set as \<subseteq> carrier G \<and> set as' \<subseteq> carrier G \<and>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2647
           wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'"
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2648
proof (induct as)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2649
  case Nil
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2650
  show ?case
68478
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2651
    apply (clarsimp simp: wfactors_def)
f75a7d2be8c5 de-applying Divisibility
paulson <lp15@cam.ac.uk>
parents: 68474
diff changeset
  2652
    by (metis Units_one_closed assoc_unit_r list_update_nonempty unit_wfactors_empty unitfactor_ee wfactorsI)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2653
next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2654
  case (Cons ah as)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2655
  then show ?case
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2656
  proof clarsimp
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2657
    fix a as'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2658
    assume ih [rule_format]:
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2659
      "\<forall>a as'. a \<in> carrier G \<and> set as' \<subseteq> carrier G \<and> wfactors G as a \<and>
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2660
        wfactors G as' a \<longrightarrow> essentially_equal G as as'"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2661
      and acarr: "a \<in> carrier G" and ahcarr: "ah \<in> carrier G"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2662
      and ascarr: "set as \<subseteq> carrier G" and as'carr: "set as' \<subseteq> carrier G"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2663
      and afs: "wfactors G (ah # as) a"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2664
      and afs': "wfactors G as' a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2665
    then have ahdvda: "ah divides a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2666
      by (intro wfactors_dividesI[of "ah#as" "a"]) simp_all
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2667
    then obtain a' where a'carr: "a' \<in> carrier G" and a: "a = ah \<otimes> a'"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2668
      by blast
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2669
    have a'fs: "wfactors G as a'"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2670
      apply (rule wfactorsE[OF afs], rule wfactorsI, simp)
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2671
      by (metis a a'carr ahcarr ascarr assoc_l_cancel factorsI factors_def factors_mult_single list.set_intros(1) list.set_intros(2) multlist_closed)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2672
    from afs have ahirr: "irreducible G ah"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2673
      by (elim wfactorsE) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2674
    with ascarr have ahprime: "prime G ah"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2675
      by (intro irreducible_prime ahcarr)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2676
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2677
    note carr [simp] = acarr ahcarr ascarr as'carr a'carr
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2678
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2679
    note ahdvda
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  2680
    also from afs' have "a divides (foldr (\<otimes>) as' \<one>)"
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2681
      by (elim wfactorsE associatedE, simp)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 67343
diff changeset
  2682
    finally have "ah divides (foldr (\<otimes>) as' \<one>)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2683
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2684
    with ahprime have "\<exists>i<length as'. ah divides as'!i"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2685
      by (intro multlist_prime_pos) simp_all
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2686
    then obtain i where len: "i<length as'" and ahdvd: "ah divides as'!i"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2687
      by blast
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2688
    from afs' carr have irrasi: "irreducible G (as'!i)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2689
      by (fast intro: nth_mem[OF len] elim: wfactorsE)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2690
    from len carr have asicarr[simp]: "as'!i \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2691
      unfolding set_conv_nth by force
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2692
    note carr = carr asicarr
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2693
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2694
    from ahdvd obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2695
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2696
    with carr irrasi[simplified asi] have asiah: "as'!i \<sim> ah"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2697
      by (metis ahprime associatedI2 irreducible_prodE primeE)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2698
    note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as']
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2699
    note partscarr [simp] = setparts[THEN subset_trans[OF _ as'carr]]
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2700
    note carr = carr partscarr
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2701
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2702
    have "\<exists>aa_1. aa_1 \<in> carrier G \<and> wfactors G (take i as') aa_1"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2703
      by (meson afs' in_set_takeD partscarr(1) wfactorsE wfactors_prod_exists)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2704
    then obtain aa_1 where aa1carr: "aa_1 \<in> carrier G" and aa1fs: "wfactors G (take i as') aa_1"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2705
      by auto
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2706
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2707
    have "\<exists>aa_2. aa_2 \<in> carrier G \<and> wfactors G (drop (Suc i) as') aa_2"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2708
      by (meson afs' in_set_dropD partscarr(2) wfactors_def wfactors_prod_exists)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2709
    then obtain aa_2 where aa2carr: "aa_2 \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2710
      and aa2fs: "wfactors G (drop (Suc i) as') aa_2"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2711
      by auto
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2712
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2713
    note carr = carr aa1carr[simp] aa2carr[simp]
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2714
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2715
    from aa1fs aa2fs
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2716
    have v1: "wfactors G (take i as' @ drop (Suc i) as') (aa_1 \<otimes> aa_2)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2717
      by (intro wfactors_mult, simp+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2718
    then have v1': "wfactors G (as'!i # take i as' @ drop (Suc i) as') (as'!i \<otimes> (aa_1 \<otimes> aa_2))"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2719
      using irrasi wfactors_mult_single by auto
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2720
    from aa2carr carr aa1fs aa2fs have "wfactors G (as'!i # drop (Suc i) as') (as'!i \<otimes> aa_2)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2721
      by (metis irrasi wfactors_mult_single)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2722
    with len carr aa1carr aa2carr aa1fs
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2723
    have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \<otimes> (as'!i \<otimes> aa_2))"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2724
      using wfactors_mult by auto
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2725
    from len have as': "as' = (take i as' @ as'!i # drop (Suc i) as')"
58247
98d0f85d247f enamed drop_Suc_conv_tl and nth_drop' to Cons_nth_drop_Suc
nipkow
parents: 57865
diff changeset
  2726
      by (simp add: Cons_nth_drop_Suc)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2727
    with carr have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2728
      by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2729
    with v2 afs' carr aa1carr aa2carr nth_mem[OF len] have "aa_1 \<otimes> (as'!i \<otimes> aa_2) \<sim> a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2730
      by (metis as' ee_wfactorsD m_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2731
    then have t1: "as'!i \<otimes> (aa_1 \<otimes> aa_2) \<sim> a"
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 53374
diff changeset
  2732
      by (metis aa1carr aa2carr asicarr m_lcomm)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2733
    from carr asiah have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> as'!i \<otimes> (aa_1 \<otimes> aa_2)"
55242
413ec965f95d Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents: 53374
diff changeset
  2734
      by (metis associated_sym m_closed mult_cong_l)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2735
    also note t1
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2736
    finally have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2737
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2738
    with carr aa1carr aa2carr a'carr nth_mem[OF len] have a': "aa_1 \<otimes> aa_2 \<sim> a'"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2739
      by (simp add: a, fast intro: assoc_l_cancel[of ah _ a'])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2740
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2741
    note v1
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2742
    also note a'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2743
    finally have "wfactors G (take i as' @ drop (Suc i) as') a'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2744
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2745
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2746
    from a'fs this carr have "essentially_equal G as (take i as' @ drop (Suc i) as')"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2747
      by (intro ih[of a']) simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2748
    then have ee1: "essentially_equal G (ah # as) (ah # take i as' @ drop (Suc i) as')"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2749
      by (elim essentially_equalE) (fastforce intro: essentially_equalI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2750
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2751
    from carr have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as')
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2752
      (as' ! i # take i as' @ drop (Suc i) as')"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2753
    proof (intro essentially_equalI)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2754
      show "ah # take i as' @ drop (Suc i) as' <~~> ah # take i as' @ drop (Suc i) as'"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2755
        by simp
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2756
    next
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2757
      show "ah # take i as' @ drop (Suc i) as' [\<sim>] as' ! i # take i as' @ drop (Suc i) as'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2758
        by (simp add: list_all2_append) (simp add: asiah[symmetric])
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2759
    qed
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2760
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2761
    note ee1
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2762
    also note ee2
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2763
    also have "essentially_equal G (as' ! i # take i as' @ drop (Suc i) as')
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2764
                                   (take i as' @ as' ! i # drop (Suc i) as')"
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2765
      by (metis as' as'carr listassoc_refl essentially_equalI perm_append_Cons)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2766
    finally have "essentially_equal G (ah # as) (take i as' @ as' ! i # drop (Suc i) as')"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2767
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2768
    then show "essentially_equal G (ah # as) as'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2769
      by (subst as')
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2770
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2771
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2772
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2773
lemma (in primeness_condition_monoid) wfactors_unique:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2774
  assumes "wfactors G as a"  "wfactors G as' a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2775
    and "a \<in> carrier G"  "set as \<subseteq> carrier G"  "set as' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2776
  shows "essentially_equal G as as'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2777
  by (rule wfactors_unique__hlp_induct[rule_format, of a]) (simp add: assms)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2778
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2779
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2780
subsubsection \<open>Application to factorial monoids\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2781
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2782
text \<open>Number of factors for wellfoundedness\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2783
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2784
definition factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2785
  where "factorcount G a =
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2786
    (THE c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2787
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2788
lemma (in monoid) ee_length:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2789
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2790
  shows "length as = length bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2791
  by (rule essentially_equalE[OF ee]) (metis list_all2_conv_all_nth perm_length)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2792
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2793
lemma (in factorial_monoid) factorcount_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2794
  assumes carr[simp]: "a \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2795
  shows "\<exists>c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2796
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2797
  have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2798
    by (intro wfactors_exist) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2799
  then obtain as where ascarr[simp]: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2800
    by (auto simp del: carr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2801
  have "\<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> length as = length as'"
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  2802
    by (metis afs ascarr assms ee_length wfactors_unique)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2803
  then show "\<exists>c. \<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> c = length as'" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2804
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2805
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2806
lemma (in factorial_monoid) factorcount_unique:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2807
  assumes afs: "wfactors G as a"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2808
    and acarr[simp]: "a \<in> carrier G" and ascarr: "set as \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2809
  shows "factorcount G a = length as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2810
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2811
  have "\<exists>ac. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2812
    by (rule factorcount_exists) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2813
  then obtain ac where alen: "\<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2814
    by auto
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2815
  then have ac: "ac = factorcount G a"
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2816
    unfolding factorcount_def using ascarr by (blast intro: theI2 afs)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2817
  from ascarr afs have "ac = length as"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2818
    by (simp add: alen)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2819
  with ac show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2820
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2821
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2822
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2823
lemma (in factorial_monoid) divides_fcount:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2824
  assumes dvd: "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2825
    and acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2826
    and bcarr:"b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2827
  shows "factorcount G a \<le> factorcount G b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2828
proof (rule dividesE[OF dvd])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2829
  fix c
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2830
  from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2831
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2832
  then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2833
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2834
  with acarr have fca: "factorcount G a = length as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2835
    by (intro factorcount_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2836
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2837
  assume ccarr: "c \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2838
  then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2839
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2840
  then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2841
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2842
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2843
  note [simp] = acarr bcarr ccarr ascarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2844
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2845
  assume b: "b = a \<otimes> c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2846
  from afs cfs have "wfactors G (as@cs) (a \<otimes> c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2847
    by (intro wfactors_mult) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2848
  with b have "wfactors G (as@cs) b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2849
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2850
  then have "factorcount G b = length (as@cs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2851
    by (intro factorcount_unique) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2852
  then have "factorcount G b = length as + length cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2853
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2854
  with fca show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2855
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2856
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2857
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2858
lemma (in factorial_monoid) associated_fcount:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2859
  assumes acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2860
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2861
    and asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2862
  shows "factorcount G a = factorcount G b"
68488
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2863
  using assms
dfbd80c3d180 more modernisaton and de-applying
paulson <lp15@cam.ac.uk>
parents: 68478
diff changeset
  2864
  by (auto simp: associated_def factorial_monoid.divides_fcount factorial_monoid_axioms le_antisym)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2865
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2866
lemma (in factorial_monoid) properfactor_fcount:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2867
  assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2868
    and pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2869
  shows "factorcount G a < factorcount G b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2870
proof (rule properfactorE[OF pf], elim dividesE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2871
  fix c
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2872
  from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2873
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2874
  then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2875
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2876
  with acarr have fca: "factorcount G a = length as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2877
    by (intro factorcount_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2878
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2879
  assume ccarr: "c \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2880
  then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2881
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2882
  then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2883
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2884
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2885
  assume b: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2886
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2887
  have "wfactors G (as@cs) (a \<otimes> c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2888
    by (rule wfactors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2889
  with b have "wfactors G (as@cs) b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2890
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2891
  with ascarr cscarr bcarr have "factorcount G b = length (as@cs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2892
    by (simp add: factorcount_unique)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2893
  then have fcb: "factorcount G b = length as + length cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2894
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2895
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2896
  assume nbdvda: "\<not> b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2897
  have "c \<notin> Units G"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  2898
  proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2899
    assume cunit:"c \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2900
    have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2901
      by (simp add: b)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2902
    also from ccarr acarr cunit have "\<dots> = a \<otimes> (c \<otimes> inv c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2903
      by (fast intro: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2904
    also from ccarr cunit have "\<dots> = a \<otimes> \<one>" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2905
    also from acarr have "\<dots> = a" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2906
    finally have "a = b \<otimes> inv c" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2907
    with ccarr cunit have "b divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2908
      by (fast intro: dividesI[of "inv c"])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2909
    with nbdvda show False by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2910
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2911
  with cfs have "length cs > 0"
68474
346bdafaf5fa More clear-up of Divisibility
paulson <lp15@cam.ac.uk>
parents: 68470
diff changeset
  2912
    by (metis Units_one_closed assoc_unit_r ccarr foldr.simps(1) id_apply length_greater_0_conv wfactors_def)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2913
  with fca fcb show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2914
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2915
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2916
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2917
sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2918
  apply unfold_locales
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2919
  apply (rule wfUNIVI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2920
  apply (rule measure_induct[of "factorcount G"])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2921
  apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2922
  apply (metis properfactor_fcount)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2923
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2924
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2925
sublocale factorial_monoid \<subseteq> primeness_condition_monoid
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63524
diff changeset
  2926
  by standard (rule irreducible_prime)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2927
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2928
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2929
lemma (in factorial_monoid) primeness_condition: "primeness_condition_monoid G" ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2930
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2931
lemma (in factorial_monoid) gcd_condition [simp]: "gcd_condition_monoid G"
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60515
diff changeset
  2932
  by standard (rule gcdof_exists)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2933
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2934
sublocale factorial_monoid \<subseteq> gcd_condition_monoid
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60515
diff changeset
  2935
  by standard (rule gcdof_exists)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2936
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2937
lemma (in factorial_monoid) division_weak_lattice [simp]: "weak_lattice (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2938
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2939
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2940
    by simp
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2941
  show "weak_lattice (division_rel G)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2942
  proof (unfold_locales, simp_all)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2943
    fix x y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2944
    assume carr: "x \<in> carrier G"  "y \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2945
    from lcmof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z lcmof x y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2946
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2947
    with carr have "least (division_rel G) z (Upper (division_rel G) {x, y})"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2948
      by (simp add: lcmof_leastUpper[symmetric])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2949
    then show "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2950
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2951
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2952
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2953
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2954
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2955
subsection \<open>Factoriality Theorems\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2956
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2957
theorem factorial_condition_one: (* Jacobson theorem 2.21 *)
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2958
  "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G \<longleftrightarrow> factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2959
proof (rule iffI, clarify)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2960
  assume dcc: "divisor_chain_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2961
    and pc: "primeness_condition_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2962
  interpret divisor_chain_condition_monoid "G" by (rule dcc)
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2963
  interpret primeness_condition_monoid "G" by (rule pc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2964
  show "factorial_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2965
    by (fast intro: factorial_monoidI wfactors_exist wfactors_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2966
next
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2967
  assume "factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2968
  then interpret factorial_monoid "G" .
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2969
  show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2970
    by rule unfold_locales
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2971
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2972
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2973
theorem factorial_condition_two: (* Jacobson theorem 2.22 *)
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2974
  "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G \<longleftrightarrow> factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2975
proof (rule iffI, clarify)
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
  2976
  assume dcc: "divisor_chain_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2977
    and gc: "gcd_condition_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2978
  interpret divisor_chain_condition_monoid "G" by (rule dcc)
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2979
  interpret gcd_condition_monoid "G" by (rule gc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2980
  show "factorial_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2981
    by (simp add: factorial_condition_one[symmetric], rule, unfold_locales)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2982
next
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2983
  assume "factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2984
  then interpret factorial_monoid "G" .
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2985
  show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2986
    by rule unfold_locales
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2987
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2988
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2989
end