src/HOL/Algebra/Divisibility.thy
author paulson
Thu, 22 Apr 2010 20:39:48 +0100
changeset 36278 6b330b1fa0c0
parent 35849 b5522b51cb1e
child 36903 489c1fbbb028
permissions -rw-r--r--
Tidied up using s/l
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35849
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
     1
(*  Title:      Divisibility in monoids and rings
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
     2
    Author:     Clemens Ballarin, started 18 July 2008
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
     3
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
     4
Based on work by Stephan Hohe.
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
     5
*)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
     6
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
     7
theory Divisibility
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
     8
imports Permutation Coset Group
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
     9
begin
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    10
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
    11
section {* Factorial Monoids *}
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
    12
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
    13
subsection {* Monoids with Cancellation Law *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    14
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    15
locale monoid_cancel = monoid +
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    16
  assumes l_cancel: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    17
          "\<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    18
      and r_cancel: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    19
          "\<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    20
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    21
lemma (in monoid) monoid_cancelI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    22
  assumes l_cancel: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    23
          "\<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"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    24
      and r_cancel: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    25
          "\<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"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    26
  shows "monoid_cancel G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
    27
  proof qed fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    28
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    29
lemma (in monoid_cancel) is_monoid_cancel:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    30
  "monoid_cancel G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
    31
  ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    32
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
    33
sublocale group \<subseteq> monoid_cancel
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
    34
  proof qed simp+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    35
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    36
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    37
locale comm_monoid_cancel = monoid_cancel + comm_monoid
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    38
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    39
lemma comm_monoid_cancelI:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    40
  fixes G (structure)
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    41
  assumes "comm_monoid G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    42
  assumes cancel: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    43
          "\<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"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    44
  shows "comm_monoid_cancel G"
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    45
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
    46
  interpret comm_monoid G by fact
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    47
  show "comm_monoid_cancel G"
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
    48
    by unfold_locales (metis assms(2) m_ac(2))+
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
    49
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    50
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    51
lemma (in comm_monoid_cancel) is_comm_monoid_cancel:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    52
  "comm_monoid_cancel G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
    53
  by intro_locales
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    54
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
    55
sublocale comm_group \<subseteq> comm_monoid_cancel
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
    56
  ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    57
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    58
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
    59
subsection {* Products of Units in Monoids *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    60
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    61
lemma (in monoid) Units_m_closed[simp, intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    62
  assumes h1unit: "h1 \<in> Units G" and h2unit: "h2 \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    63
  shows "h1 \<otimes> h2 \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    64
unfolding Units_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    65
using assms
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
    66
by auto (metis Units_inv_closed Units_l_inv Units_m_closed Units_r_inv)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    67
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    68
lemma (in monoid) prod_unit_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    69
  assumes abunit[simp]: "a \<otimes> b \<in> Units G" and aunit[simp]: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    70
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    71
  shows "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    72
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    73
  have c: "inv (a \<otimes> b) \<otimes> a \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    74
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    75
  have "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = inv (a \<otimes> b) \<otimes> (a \<otimes> b)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    76
  also have "\<dots> = \<one>" by (simp add: Units_l_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    77
  finally have li: "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    78
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    79
  have "\<one> = inv a \<otimes> a" by (simp add: Units_l_inv[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    80
  also have "\<dots> = inv a \<otimes> \<one> \<otimes> a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    81
  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
    82
       by (simp add: Units_r_inv[OF abunit, symmetric] del: Units_r_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    83
  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
    84
    by (simp add: m_assoc del: Units_l_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    85
  also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by (simp add: Units_l_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    86
  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
    87
  finally have ri: "b \<otimes> (inv (a \<otimes> b) \<otimes> a) = \<one> " by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    88
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    89
  from c li ri
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    90
      show "b \<in> Units G" by (simp add: Units_def, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    91
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    92
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    93
lemma (in monoid) prod_unit_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    94
  assumes abunit[simp]: "a \<otimes> b \<in> Units G" and bunit[simp]: "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    95
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    96
  shows "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    97
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    98
  have c: "b \<otimes> inv (a \<otimes> b) \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
    99
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   100
  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
   101
    by (simp add: m_assoc del: Units_r_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   102
  also have "\<dots> = \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   103
  finally have li: "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   104
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   105
  have "\<one> = b \<otimes> inv b" by (simp add: Units_r_inv[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   106
  also have "\<dots> = b \<otimes> \<one> \<otimes> inv b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   107
  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
   108
       by (simp add: Units_l_inv[OF abunit, symmetric] del: Units_l_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   109
  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
   110
    by (simp add: m_assoc del: Units_l_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   111
  also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   112
  finally have ri: "(b \<otimes> inv (a \<otimes> b)) \<otimes> a = \<one> " by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   113
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   114
  from c li ri
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   115
      show "a \<in> Units G" by (simp add: Units_def, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   116
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   117
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   118
lemma (in comm_monoid) unit_factor:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   119
  assumes abunit: "a \<otimes> b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   120
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   121
  shows "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   122
using abunit[simplified Units_def]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   123
proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   124
  fix i
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   125
  assume [simp]: "i \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   126
    and li: "i \<otimes> (a \<otimes> b) = \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   127
    and ri: "a \<otimes> b \<otimes> i = \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   128
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   129
  have carr': "b \<otimes> i \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   130
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   131
  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
   132
  also have "\<dots> = i \<otimes> (b \<otimes> a)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   133
  also have "\<dots> = i \<otimes> (a \<otimes> b)" by (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   134
  also note li
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   135
  finally have li': "(b \<otimes> i) \<otimes> a = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   136
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   137
  have "a \<otimes> (b \<otimes> i) = a \<otimes> b \<otimes> i" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   138
  also note ri
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   139
  finally have ri': "a \<otimes> (b \<otimes> i) = \<one>" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   140
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   141
  from carr' li' ri'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   142
      show "a \<in> Units G" by (simp add: Units_def, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   143
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   144
35849
b5522b51cb1e standard headers;
wenzelm
parents: 35848
diff changeset
   145
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
   146
subsection {* Divisibility and Association *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   147
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   148
subsubsection {* Function definitions *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   149
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   150
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   151
  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
   152
  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
   153
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   154
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   155
  associated :: "[_, 'a, 'a] => bool" (infix "\<sim>\<index>" 55)
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   156
  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
   157
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   158
abbreviation
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   159
  "division_rel G == \<lparr>carrier = carrier G, eq = op \<sim>\<^bsub>G\<^esub>, le = op divides\<^bsub>G\<^esub>\<rparr>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   160
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   161
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   162
  properfactor :: "[_, 'a, 'a] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   163
  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
   164
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   165
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   166
  irreducible :: "[_, 'a] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   167
  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
   168
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   169
definition
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   170
  prime :: "[_, 'a] \<Rightarrow> bool" where
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   171
  "prime G p \<longleftrightarrow>
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   172
    p \<notin> Units G \<and> 
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   173
    (\<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
   174
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   175
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   176
subsubsection {* Divisibility *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   177
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   178
lemma dividesI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   179
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   180
  assumes carr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   181
    and p: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   182
  shows "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   183
unfolding factor_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   184
using assms by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   185
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   186
lemma dividesI' [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   187
   fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   188
  assumes p: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   189
    and carr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   190
  shows "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   191
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   192
by (fast intro: dividesI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   193
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   194
lemma dividesD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   195
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   196
  assumes "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   197
  shows "\<exists>c\<in>carrier G. b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   198
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   199
unfolding factor_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   200
by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   201
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   202
lemma dividesE [elim]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   203
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   204
  assumes d: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   205
    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
   206
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   207
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   208
  from dividesD[OF d]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   209
      obtain c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   210
      where "c\<in>carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   211
      and "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   212
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   213
  thus "P" by (elim elim)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   214
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   215
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   216
lemma (in monoid) divides_refl[simp, intro!]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   217
  assumes carr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   218
  shows "a divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   219
apply (intro dividesI[of "\<one>"])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   220
apply (simp, simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   221
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   222
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   223
lemma (in monoid) divides_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   224
  assumes dvds: "a divides b"  "b divides c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   225
    and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   226
  shows "a divides c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   227
using dvds[THEN dividesD]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   228
by (blast intro: dividesI m_assoc acarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   229
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   230
lemma (in monoid) divides_mult_lI [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   231
  assumes ab: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   232
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   233
  shows "(c \<otimes> a) divides (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   234
using ab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   235
apply (elim dividesE, simp add: m_assoc[symmetric] carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   236
apply (fast intro: dividesI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   237
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   238
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   239
lemma (in monoid_cancel) divides_mult_l [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   240
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   241
  shows "(c \<otimes> a) divides (c \<otimes> b) = a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   242
apply safe
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   243
 apply (elim dividesE, intro dividesI, assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   244
 apply (rule l_cancel[of c])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   245
    apply (simp add: m_assoc carr)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   246
apply (fast intro: divides_mult_lI carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   247
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   248
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   249
lemma (in comm_monoid) divides_mult_rI [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   250
  assumes ab: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   251
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   252
  shows "(a \<otimes> c) divides (b \<otimes> c)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   253
using carr ab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   254
apply (simp add: m_comm[of a c] m_comm[of b c])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   255
apply (rule divides_mult_lI, assumption+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   256
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   257
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   258
lemma (in comm_monoid_cancel) divides_mult_r [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   259
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   260
  shows "(a \<otimes> c) divides (b \<otimes> c) = a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   261
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   262
by (simp add: m_comm[of a c] m_comm[of b c])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   263
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   264
lemma (in monoid) divides_prod_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   265
  assumes ab: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   266
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   267
  shows "a divides (b \<otimes> c)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   268
using ab carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   269
by (fast intro: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   270
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   271
lemma (in comm_monoid) divides_prod_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   272
  assumes carr[intro]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   273
    and ab: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   274
  shows "a divides (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   275
using ab carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   276
apply (simp add: m_comm[of c b])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   277
apply (fast intro: divides_prod_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   278
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   279
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   280
lemma (in monoid) unit_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   281
  assumes uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   282
      and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   283
  shows "u divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   284
proof (intro dividesI[of "(inv u) \<otimes> a"], fast intro: uunit acarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   285
  from uunit acarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   286
      have xcarr: "inv u \<otimes> a \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   287
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   288
  from uunit acarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   289
       have "u \<otimes> (inv u \<otimes> a) = (u \<otimes> inv u) \<otimes> a" by (fast intro: m_assoc[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   290
  also have "\<dots> = \<one> \<otimes> a" by (simp add: Units_r_inv[OF uunit])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   291
  also from acarr 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   292
       have "\<dots> = a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   293
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   294
       show "a = u \<otimes> (inv u \<otimes> a)" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   295
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   296
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   297
lemma (in comm_monoid) divides_unit:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   298
  assumes udvd: "a divides u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   299
      and  carr: "a \<in> carrier G"  "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   300
  shows "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   301
using udvd carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   302
by (blast intro: unit_factor)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   303
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   304
lemma (in comm_monoid) Unit_eq_dividesone:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   305
  assumes ucarr: "u \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   306
  shows "u \<in> Units G = u divides \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   307
using ucarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   308
by (fast dest: divides_unit intro: unit_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   309
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   310
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   311
subsubsection {* Association *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   312
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   313
lemma associatedI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   314
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   315
  assumes "a divides b"  "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   316
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   317
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   318
by (simp add: associated_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   319
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   320
lemma (in monoid) associatedI2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   321
  assumes uunit[simp]: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   322
    and a: "a = b \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   323
    and bcarr[simp]: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   324
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   325
using uunit bcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   326
unfolding a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   327
apply (intro associatedI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   328
 apply (rule dividesI[of "inv u"], simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   329
 apply (simp add: m_assoc Units_closed Units_r_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   330
apply fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   331
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   332
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   333
lemma (in monoid) associatedI2':
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   334
  assumes a: "a = b \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   335
    and uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   336
    and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   337
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   338
using assms by (intro associatedI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   339
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   340
lemma associatedD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   341
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   342
  assumes "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   343
  shows "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   344
using assms by (simp add: associated_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   345
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   346
lemma (in monoid_cancel) associatedD2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   347
  assumes assoc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   348
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   349
  shows "\<exists>u\<in>Units G. a = b \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   350
using assoc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   351
unfolding associated_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   352
proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   353
  assume "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   354
  hence "\<exists>u\<in>carrier G. a = b \<otimes> u" by (rule dividesD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   355
  from this obtain u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   356
      where ucarr: "u \<in> carrier G" and a: "a = b \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   357
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   358
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   359
  assume "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   360
  hence "\<exists>u'\<in>carrier G. b = a \<otimes> u'" by (rule dividesD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   361
  from this obtain u'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   362
      where u'carr: "u' \<in> carrier G" and b: "b = a \<otimes> u'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   363
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   364
  note carr = carr ucarr u'carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   365
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   366
  from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   367
       have "a \<otimes> \<one> = a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   368
  also have "\<dots> = b \<otimes> u" by (simp add: a)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   369
  also have "\<dots> = a \<otimes> u' \<otimes> u" by (simp add: b)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   370
  also from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   371
       have "\<dots> = a \<otimes> (u' \<otimes> u)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   372
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   373
       have "a \<otimes> \<one> = a \<otimes> (u' \<otimes> u)" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   374
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   375
      have u1: "\<one> = u' \<otimes> u" by (fast dest: l_cancel)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   376
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   377
  from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   378
       have "b \<otimes> \<one> = b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   379
  also have "\<dots> = a \<otimes> u'" by (simp add: b)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   380
  also have "\<dots> = b \<otimes> u \<otimes> u'" by (simp add: a)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   381
  also from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   382
       have "\<dots> = b \<otimes> (u \<otimes> u')" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   383
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   384
       have "b \<otimes> \<one> = b \<otimes> (u \<otimes> u')" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   385
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   386
      have u2: "\<one> = u \<otimes> u'" by (fast dest: l_cancel)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   387
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   388
  from u'carr u1[symmetric] u2[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   389
      have "\<exists>u'\<in>carrier G. u' \<otimes> u = \<one> \<and> u \<otimes> u' = \<one>" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   390
  hence "u \<in> Units G" by (simp add: Units_def ucarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   391
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   392
  from ucarr this a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   393
      show "\<exists>u\<in>Units G. a = b \<otimes> u" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   394
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   395
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   396
lemma associatedE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   397
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   398
  assumes assoc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   399
    and e: "\<lbrakk>a divides b; b divides a\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   400
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   401
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   402
  from assoc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   403
      have "a divides b"  "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   404
      by (simp add: associated_def)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   405
  thus "P" by (elim e)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   406
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   407
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   408
lemma (in monoid_cancel) associatedE2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   409
  assumes assoc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   410
    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
   411
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   412
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   413
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   414
  from assoc and carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   415
      have "\<exists>u\<in>Units G. a = b \<otimes> u" by (rule associatedD2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   416
  from this obtain u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   417
      where "u \<in> Units G"  "a = b \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   418
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   419
  thus "P" by (elim e)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   420
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   421
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   422
lemma (in monoid) associated_refl [simp, intro!]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   423
  assumes "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   424
  shows "a \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   425
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   426
by (fast intro: associatedI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   427
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   428
lemma (in monoid) associated_sym [sym]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   429
  assumes "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   430
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   431
  shows "b \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   432
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   433
by (iprover intro: associatedI elim: associatedE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   434
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   435
lemma (in monoid) associated_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   436
  assumes "a \<sim> b"  "b \<sim> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   437
    and "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   438
  shows "a \<sim> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   439
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   440
by (iprover intro: associatedI divides_trans elim: associatedE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   441
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   442
lemma (in monoid) division_equiv [intro, simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   443
  "equivalence (division_rel G)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   444
  apply unfold_locales
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   445
  apply simp_all
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   446
  apply (metis associated_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   447
  apply (iprover intro: associated_trans)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   448
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   449
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   450
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   451
subsubsection {* Division and associativity *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   452
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   453
lemma divides_antisym:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   454
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   455
  assumes "a divides b"  "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   456
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   457
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   458
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   459
by (fast intro: associatedI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   460
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   461
lemma (in monoid) divides_cong_l [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   462
  assumes xx': "x \<sim> x'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   463
    and xdvdy: "x' divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   464
    and carr [simp]: "x \<in> carrier G"  "x' \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   465
  shows "x divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   466
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   467
  from xx'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   468
       have "x divides x'" by (simp add: associatedD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   469
  also note xdvdy
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   470
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   471
       show "x divides y" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   472
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   473
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   474
lemma (in monoid) divides_cong_r [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   475
  assumes xdvdy: "x divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   476
    and yy': "y \<sim> y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   477
    and carr[simp]: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   478
  shows "x divides y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   479
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   480
  note xdvdy
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   481
  also from yy'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   482
       have "y divides y'" by (simp add: associatedD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   483
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   484
       show "x divides y'" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   485
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   486
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   487
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
   488
  "weak_partial_order (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   489
  apply unfold_locales
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   490
  apply simp_all
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   491
  apply (simp add: associated_sym)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   492
  apply (blast intro: associated_trans)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   493
  apply (simp add: divides_antisym)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   494
  apply (blast intro: divides_trans)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   495
  apply (blast intro: divides_cong_l divides_cong_r associated_sym)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   496
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   497
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   498
    
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   499
subsubsection {* Multiplication and associativity *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   500
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   501
lemma (in monoid_cancel) mult_cong_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   502
  assumes "b \<sim> b'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   503
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "b' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   504
  shows "a \<otimes> b \<sim> a \<otimes> b'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   505
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   506
apply (elim associatedE2, intro associatedI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   507
apply (auto intro: m_assoc[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   508
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   509
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   510
lemma (in comm_monoid_cancel) mult_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   511
  assumes "a \<sim> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   512
    and carr: "a \<in> carrier G"  "a' \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   513
  shows "a \<otimes> b \<sim> a' \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   514
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   515
apply (elim associatedE2, intro associatedI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   516
    apply assumption
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   517
   apply (simp add: m_assoc Units_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   518
   apply (simp add: m_comm Units_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   519
  apply simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   520
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   521
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   522
lemma (in monoid_cancel) assoc_l_cancel:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   523
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "b' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   524
    and "a \<otimes> b \<sim> a \<otimes> b'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   525
  shows "b \<sim> b'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   526
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   527
apply (elim associatedE2, intro associatedI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   528
    apply assumption
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   529
   apply (rule l_cancel[of a])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   530
      apply (simp add: m_assoc Units_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   531
     apply fast+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   532
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   533
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   534
lemma (in comm_monoid_cancel) assoc_r_cancel:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   535
  assumes "a \<otimes> b \<sim> a' \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   536
    and carr: "a \<in> carrier G"  "a' \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   537
  shows "a \<sim> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   538
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   539
apply (elim associatedE2, intro associatedI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   540
    apply assumption
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   541
   apply (rule r_cancel[of a b])
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   542
      apply (metis Units_closed assms(3) assms(4) m_ac)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   543
     apply fast+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   544
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   545
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   546
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   547
subsubsection {* Units *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   548
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   549
lemma (in monoid_cancel) assoc_unit_l [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   550
  assumes asc: "a \<sim> b" and bunit: "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   551
    and carr: "a \<in> carrier G" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   552
  shows "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   553
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   554
by (fast elim: associatedE2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   555
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   556
lemma (in monoid_cancel) assoc_unit_r [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   557
  assumes aunit: "a \<in> Units G" and asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   558
    and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   559
  shows "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   560
using aunit bcarr associated_sym[OF asc]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   561
by (blast intro: assoc_unit_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   562
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   563
lemma (in comm_monoid) Units_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   564
  assumes aunit: "a \<in> Units G" and asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   565
    and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   566
  shows "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   567
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   568
by (blast intro: divides_unit elim: associatedE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   569
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   570
lemma (in monoid) Units_assoc:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   571
  assumes units: "a \<in> Units G"  "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   572
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   573
using units
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   574
by (fast intro: associatedI unit_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   575
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   576
lemma (in monoid) Units_are_ones:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   577
  "Units G {.=}\<^bsub>(division_rel G)\<^esub> {\<one>}"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   578
apply (simp add: set_eq_def elem_def, rule, simp_all)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   579
proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   580
  fix a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   581
  assume aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   582
  show "a \<sim> \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   583
  apply (rule associatedI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   584
   apply (fast intro: dividesI[of "inv a"] aunit Units_r_inv[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   585
  apply (fast intro: dividesI[of "a"] l_one[symmetric] Units_closed[OF aunit])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   586
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   587
next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   588
  have "\<one> \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   589
  moreover have "\<one> \<sim> \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   590
  ultimately show "\<exists>a \<in> Units G. \<one> \<sim> a" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   591
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   592
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   593
lemma (in comm_monoid) Units_Lower:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   594
  "Units G = Lower (division_rel G) (carrier G)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   595
apply (simp add: Units_def Lower_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   596
apply (rule, rule)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   597
 apply clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   598
  apply (rule unit_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   599
   apply (unfold Units_def, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   600
  apply assumption
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   601
apply clarsimp
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   602
apply (metis Unit_eq_dividesone Units_r_inv_ex m_ac(2) one_closed)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   603
done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   604
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   605
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   606
subsubsection {* Proper factors *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   607
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   608
lemma properfactorI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   609
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   610
  assumes "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   611
    and "\<not>(b divides a)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   612
  shows "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   613
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   614
unfolding properfactor_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   615
by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   616
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   617
lemma properfactorI2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   618
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   619
  assumes advdb: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   620
    and neq: "\<not>(a \<sim> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   621
  shows "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   622
apply (rule properfactorI, rule advdb)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   623
proof (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   624
  assume "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   625
  with advdb have "a \<sim> b" by (rule associatedI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   626
  with neq show "False" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   627
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   628
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   629
lemma (in comm_monoid_cancel) properfactorI3:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   630
  assumes p: "p = a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   631
    and nunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   632
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "p \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   633
  shows "properfactor G a p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   634
unfolding p
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   635
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   636
apply (intro properfactorI, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   637
proof (clarsimp, elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   638
  fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   639
  assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   640
  note [simp] = carr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   641
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   642
  have "a \<otimes> \<one> = a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   643
  also assume "a = a \<otimes> b \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   644
  also have "\<dots> = a \<otimes> (b \<otimes> c)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   645
  finally have "a \<otimes> \<one> = a \<otimes> (b \<otimes> c)" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   646
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   647
  hence rinv: "\<one> = b \<otimes> c" by (intro l_cancel[of "a" "\<one>" "b \<otimes> c"], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   648
  also have "\<dots> = c \<otimes> b" by (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   649
  finally have linv: "\<one> = c \<otimes> b" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   650
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   651
  from ccarr linv[symmetric] rinv[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   652
  have "b \<in> Units G" unfolding Units_def by fastsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   653
  with nunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   654
      show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   655
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   656
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   657
lemma properfactorE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   658
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   659
  assumes pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   660
    and r: "\<lbrakk>a divides b; \<not>(b divides a)\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   661
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   662
using pf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   663
unfolding properfactor_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   664
by (fast intro: r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   665
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   666
lemma properfactorE2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   667
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   668
  assumes pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   669
    and elim: "\<lbrakk>a divides b; \<not>(a \<sim> b)\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   670
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   671
using pf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   672
unfolding properfactor_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   673
by (fast elim: elim associatedE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   674
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   675
lemma (in monoid) properfactor_unitE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   676
  assumes uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   677
    and pf: "properfactor G a u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   678
    and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   679
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   680
using pf unit_divides[OF uunit acarr]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   681
by (fast elim: properfactorE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   682
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   683
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   684
lemma (in monoid) properfactor_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   685
  assumes pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   686
  shows "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   687
using pf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   688
by (elim properfactorE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   689
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   690
lemma (in monoid) properfactor_trans1 [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   691
  assumes dvds: "a divides b"  "properfactor G b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   692
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   693
  shows "properfactor G a c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   694
using dvds carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   695
apply (elim properfactorE, intro properfactorI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   696
 apply (iprover intro: divides_trans)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   697
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   698
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   699
lemma (in monoid) properfactor_trans2 [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   700
  assumes dvds: "properfactor G a b"  "b divides c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   701
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   702
  shows "properfactor G a c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   703
using dvds carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   704
apply (elim properfactorE, intro properfactorI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   705
 apply (iprover intro: divides_trans)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   706
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   707
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   708
lemma properfactor_lless:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   709
  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
   710
  shows "properfactor G = lless (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   711
apply (rule ext) apply (rule ext) apply rule
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   712
 apply (fastsimp elim: properfactorE2 intro: weak_llessI)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   713
apply (fastsimp elim: weak_llessE intro: properfactorI2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   714
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   715
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   716
lemma (in monoid) properfactor_cong_l [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   717
  assumes x'x: "x' \<sim> x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   718
    and pf: "properfactor G x y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   719
    and carr: "x \<in> carrier G"  "x' \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   720
  shows "properfactor G x' y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   721
using pf
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   722
unfolding properfactor_lless
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   723
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
   724
  interpret weak_partial_order "division_rel G" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   725
  from x'x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   726
       have "x' .=\<^bsub>division_rel G\<^esub> x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   727
  also assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   728
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   729
       show "x' \<sqsubset>\<^bsub>division_rel G\<^esub> y" by (simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   730
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   731
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   732
lemma (in monoid) properfactor_cong_r [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   733
  assumes pf: "properfactor G x y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   734
    and yy': "y \<sim> y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   735
    and carr: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   736
  shows "properfactor G x y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   737
using pf
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
   738
unfolding properfactor_lless
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   739
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
   740
  interpret weak_partial_order "division_rel G" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   741
  assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   742
  also from yy'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   743
       have "y .=\<^bsub>division_rel G\<^esub> y'" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   744
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   745
       show "x \<sqsubset>\<^bsub>division_rel G\<^esub> y'" by (simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   746
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   747
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   748
lemma (in monoid_cancel) properfactor_mult_lI [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   749
  assumes ab: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   750
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   751
  shows "properfactor G (c \<otimes> a) (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   752
using ab carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   753
by (fastsimp elim: properfactorE intro: properfactorI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   754
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   755
lemma (in monoid_cancel) properfactor_mult_l [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   756
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   757
  shows "properfactor G (c \<otimes> a) (c \<otimes> b) = properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   758
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   759
by (fastsimp elim: properfactorE intro: properfactorI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   760
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   761
lemma (in comm_monoid_cancel) properfactor_mult_rI [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   762
  assumes ab: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   763
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   764
  shows "properfactor G (a \<otimes> c) (b \<otimes> c)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   765
using ab carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   766
by (fastsimp elim: properfactorE intro: properfactorI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   767
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   768
lemma (in comm_monoid_cancel) properfactor_mult_r [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   769
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   770
  shows "properfactor G (a \<otimes> c) (b \<otimes> c) = properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   771
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   772
by (fastsimp elim: properfactorE intro: properfactorI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   773
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   774
lemma (in monoid) properfactor_prod_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   775
  assumes ab: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   776
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   777
  shows "properfactor G a (b \<otimes> c)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   778
by (intro properfactor_trans2[OF ab] divides_prod_r, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   779
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   780
lemma (in comm_monoid) properfactor_prod_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   781
  assumes ab: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   782
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   783
  shows "properfactor G a (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   784
by (intro properfactor_trans2[OF ab] divides_prod_l, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   785
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   786
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
   787
subsection {* Irreducible Elements and Primes *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   788
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   789
subsubsection {* Irreducible elements *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   790
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   791
lemma irreducibleI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   792
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   793
  assumes "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   794
    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
   795
  shows "irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   796
using assms 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   797
unfolding irreducible_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   798
by blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   799
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   800
lemma irreducibleE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   801
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   802
  assumes irr: "irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   803
     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"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   804
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   805
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   806
unfolding irreducible_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   807
by blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   808
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   809
lemma irreducibleD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   810
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   811
  assumes irr: "irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   812
     and pf: "properfactor G b a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   813
     and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   814
  shows "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   815
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   816
by (fast elim: irreducibleE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   817
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   818
lemma (in monoid_cancel) irreducible_cong [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   819
  assumes irred: "irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   820
    and aa': "a \<sim> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   821
    and carr[simp]: "a \<in> carrier G"  "a' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   822
  shows "irreducible G a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   823
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   824
apply (elim irreducibleE, intro irreducibleI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   825
apply simp_all
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   826
apply (metis assms(2) assms(3) assoc_unit_l)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   827
apply (metis assms(2) assms(3) assms(4) associated_sym properfactor_cong_r)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   828
done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   829
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   830
lemma (in monoid) irreducible_prod_rI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   831
  assumes airr: "irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   832
    and bunit: "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   833
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   834
  shows "irreducible G (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   835
using airr carr bunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   836
apply (elim irreducibleE, intro irreducibleI, clarify)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   837
 apply (subgoal_tac "a \<in> Units G", simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   838
 apply (intro prod_unit_r[of a b] carr bunit, assumption)
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   839
apply (metis assms associatedI2 m_closed properfactor_cong_r)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   840
done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   841
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   842
lemma (in comm_monoid) irreducible_prod_lI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   843
  assumes birr: "irreducible G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   844
    and aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   845
    and carr [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   846
  shows "irreducible G (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   847
apply (subst m_comm, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   848
apply (intro irreducible_prod_rI assms)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   849
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   850
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   851
lemma (in comm_monoid_cancel) irreducible_prodE [elim]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   852
  assumes irr: "irreducible G (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   853
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   854
    and e1: "\<lbrakk>irreducible G a; b \<in> Units G\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   855
    and e2: "\<lbrakk>a \<in> Units G; irreducible G b\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   856
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   857
using irr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   858
proof (elim irreducibleE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   859
  assume abnunit: "a \<otimes> b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   860
    and isunit[rule_format]: "\<forall>ba. ba \<in> carrier G \<and> properfactor G ba (a \<otimes> b) \<longrightarrow> ba \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   861
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   862
  show "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   863
  proof (cases "a \<in> Units G")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   864
    assume aunit: "a \<in>  Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   865
    have "irreducible G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   866
    apply (rule irreducibleI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   867
    proof (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   868
      assume "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   869
      with aunit have "(a \<otimes> b) \<in> Units G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   870
      with abnunit show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   871
    next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   872
      fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   873
      assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   874
        and "properfactor G c b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   875
      hence "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_l[of c b a])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   876
      from ccarr this show "c \<in> Units G" by (fast intro: isunit)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   877
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   878
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   879
    from aunit this show "P" by (rule e2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   880
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   881
    assume anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   882
    with carr have "properfactor G b (b \<otimes> a)" by (fast intro: properfactorI3)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   883
    hence bf: "properfactor G b (a \<otimes> b)" by (subst m_comm[of a b], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   884
    hence bunit: "b \<in> Units G" by (intro isunit, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   885
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   886
    have "irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   887
    apply (rule irreducibleI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   888
    proof (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   889
      assume "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   890
      with bunit have "(a \<otimes> b) \<in> Units G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   891
      with abnunit show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   892
    next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   893
      fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   894
      assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   895
        and "properfactor G c a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   896
      hence "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_r[of c a b])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   897
      from ccarr this show "c \<in> Units G" by (fast intro: isunit)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   898
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   899
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   900
    from this bunit show "P" by (rule e1)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   901
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   902
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   903
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   904
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   905
subsubsection {* Prime elements *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   906
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   907
lemma primeI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   908
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   909
  assumes "p \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   910
    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
   911
  shows "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   912
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   913
unfolding prime_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   914
by blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   915
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   916
lemma primeE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   917
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   918
  assumes pprime: "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   919
    and e: "\<lbrakk>p \<notin> Units G; \<forall>a\<in>carrier G. \<forall>b\<in>carrier G.
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   920
                          p divides a \<otimes> b \<longrightarrow> p divides a \<or> p divides b\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   921
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   922
using pprime
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   923
unfolding prime_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   924
by (blast dest: e)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   925
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   926
lemma (in comm_monoid_cancel) prime_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   927
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   928
    and pprime: "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   929
    and pdvd: "p divides a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   930
  shows "p divides a \<or> p divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   931
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   932
by (blast elim: primeE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   933
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   934
lemma (in monoid_cancel) prime_cong [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   935
  assumes pprime: "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   936
    and pp': "p \<sim> p'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   937
    and carr[simp]: "p \<in> carrier G"  "p' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   938
  shows "prime G p'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   939
using pprime
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   940
apply (elim primeE, intro primeI)
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   941
apply (metis assms(2) assms(3) assoc_unit_l)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   942
apply (metis assms(2) assms(3) assms(4) associated_sym divides_cong_l m_closed)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
   943
done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   944
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
   945
subsection {* Factorization and Factorial Monoids *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   946
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   947
subsubsection {* Function definitions *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   948
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   949
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   950
  factors :: "[_, 'a list, 'a] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   951
  where "factors G fs a \<longleftrightarrow> (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> = a"
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   952
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   953
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   954
  wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   955
  where "wfactors G fs a \<longleftrightarrow> (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> \<sim>\<^bsub>G\<^esub> a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   956
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   957
abbreviation
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   958
  list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44)
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   959
  where "list_assoc G == list_all2 (op \<sim>\<^bsub>G\<^esub>)"
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   960
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
   961
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   962
  essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool"
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
   963
  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
   964
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   965
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   966
locale factorial_monoid = comm_monoid_cancel +
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   967
  assumes factors_exist: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   968
          "\<lbrakk>a \<in> carrier G; a \<notin> Units G\<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   969
      and factors_unique: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   970
          "\<lbrakk>factors G fs a; factors G fs' a; a \<in> carrier G; a \<notin> Units G; 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   971
            set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   972
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   973
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   974
subsubsection {* Comparing lists of elements *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   975
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   976
text {* Association on lists *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   977
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   978
lemma (in monoid) listassoc_refl [simp, intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   979
  assumes "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   980
  shows "as [\<sim>] as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   981
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   982
by (induct as) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   983
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   984
lemma (in monoid) listassoc_sym [sym]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   985
  assumes "as [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   986
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   987
  shows "bs [\<sim>] as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   988
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   989
proof (induct as arbitrary: bs, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   990
  case Cons
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   991
  thus ?case
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   992
    apply (induct bs, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   993
    apply clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   994
    apply (iprover intro: associated_sym)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   995
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   996
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   997
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   998
lemma (in monoid) listassoc_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
   999
  assumes "as [\<sim>] bs" and "bs [\<sim>] cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1000
    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
  1001
  shows "as [\<sim>] cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1002
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1003
apply (simp add: list_all2_conv_all_nth set_conv_nth, safe)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1004
apply (rule associated_trans)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1005
    apply (subgoal_tac "as ! i \<sim> bs ! i", assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1006
    apply (simp, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1007
  apply blast+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1008
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1009
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1010
lemma (in monoid_cancel) irrlist_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1011
  assumes "\<forall>a\<in>set as. irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1012
    and "as [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1013
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1014
  shows "\<forall>a\<in>set bs. irreducible G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1015
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1016
apply (clarsimp simp add: list_all2_conv_all_nth set_conv_nth)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1017
apply (blast intro: irreducible_cong)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1018
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1019
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1020
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1021
text {* Permutations *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1022
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1023
lemma perm_map [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1024
  assumes p: "a <~~> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1025
  shows "map f a <~~> map f b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1026
using p
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1027
by induct auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1028
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1029
lemma perm_map_switch:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1030
  assumes m: "map f a = map f b" and p: "b <~~> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1031
  shows "\<exists>d. a <~~> d \<and> map f d = map f c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1032
using p m
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1033
by (induct arbitrary: a) (simp, force, force, blast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1034
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1035
lemma (in monoid) perm_assoc_switch:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1036
   assumes a:"as [\<sim>] bs" and p: "bs <~~> cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1037
   shows "\<exists>bs'. as <~~> bs' \<and> bs' [\<sim>] cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1038
using p a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1039
apply (induct bs cs arbitrary: as, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1040
  apply (clarsimp simp add: list_all2_Cons2, blast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1041
 apply (clarsimp simp add: list_all2_Cons2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1042
 apply blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1043
apply blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1044
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1045
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1046
lemma (in monoid) perm_assoc_switch_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1047
   assumes p: "as <~~> bs" and a:"bs [\<sim>] cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1048
   shows "\<exists>bs'. as [\<sim>] bs' \<and> bs' <~~> cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1049
using p a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1050
apply (induct as bs arbitrary: cs, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1051
  apply (clarsimp simp add: list_all2_Cons1, blast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1052
 apply (clarsimp simp add: list_all2_Cons1)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1053
 apply blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1054
apply blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1055
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1056
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1057
declare perm_sym [sym]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1058
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1059
lemma perm_setP:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1060
  assumes perm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1061
    and as: "P (set as)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1062
  shows "P (set bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1063
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1064
  from perm
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1065
      have "multiset_of as = multiset_of bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1066
      by (simp add: multiset_of_eq_perm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1067
  hence "set as = set bs" by (rule multiset_of_eq_setD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1068
  with as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1069
      show "P (set bs)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1070
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1071
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1072
lemmas (in monoid) perm_closed =
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1073
    perm_setP[of _ _ "\<lambda>as. as \<subseteq> carrier G"]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1074
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1075
lemmas (in monoid) irrlist_perm_cong =
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1076
    perm_setP[of _ _ "\<lambda>as. \<forall>a\<in>as. irreducible G a"]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1077
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1078
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1079
text {* Essentially equal factorizations *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1080
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1081
lemma (in monoid) essentially_equalI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1082
  assumes ex: "fs1 <~~> fs1'"  "fs1' [\<sim>] fs2"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1083
  shows "essentially_equal G fs1 fs2"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1084
using ex
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1085
unfolding essentially_equal_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1086
by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1087
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1088
lemma (in monoid) essentially_equalE:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1089
  assumes ee: "essentially_equal G fs1 fs2"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1090
    and e: "\<And>fs1'. \<lbrakk>fs1 <~~> fs1'; fs1' [\<sim>] fs2\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1091
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1092
using ee
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1093
unfolding essentially_equal_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1094
by (fast intro: e)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1095
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1096
lemma (in monoid) ee_refl [simp,intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1097
  assumes carr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1098
  shows "essentially_equal G as as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1099
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1100
by (fast intro: essentially_equalI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1101
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1102
lemma (in monoid) ee_sym [sym]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1103
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1104
    and carr: "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1105
  shows "essentially_equal G bs as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1106
using ee
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1107
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1108
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1109
  assume "as <~~> fs"  "fs [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1110
  hence "\<exists>fs'. as [\<sim>] fs' \<and> fs' <~~> bs" by (rule perm_assoc_switch_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1111
  from this obtain fs'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1112
      where a: "as [\<sim>] fs'" and p: "fs' <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1113
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1114
  from p have "bs <~~> fs'" by (rule perm_sym)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1115
  with a[symmetric] carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1116
      show ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1117
      by (iprover intro: essentially_equalI perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1118
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1119
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1120
lemma (in monoid) ee_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1121
  assumes ab: "essentially_equal G as bs" and bc: "essentially_equal G bs cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1122
    and ascarr: "set as \<subseteq> carrier G" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1123
    and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1124
    and cscarr: "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1125
  shows "essentially_equal G as cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1126
using ab bc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1127
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1128
  fix abs bcs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1129
  assume  "abs [\<sim>] bs" and pb: "bs <~~> bcs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1130
  hence "\<exists>bs'. abs <~~> bs' \<and> bs' [\<sim>] bcs" by (rule perm_assoc_switch)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1131
  from this obtain bs'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1132
      where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1133
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1134
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1135
  assume "as <~~> abs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1136
  with p
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1137
      have pp: "as <~~> bs'" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1138
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1139
  from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1140
  from pb bscarr have c2: "set bcs \<subseteq> carrier G" by (rule perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1141
  note a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1142
  also assume "bcs [\<sim>] cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1143
  finally (listassoc_trans) have"bs' [\<sim>] cs" by (simp add: c1 c2 cscarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1144
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1145
  with pp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1146
      show ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1147
      by (rule essentially_equalI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1148
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1149
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1150
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1151
subsubsection {* Properties of lists of elements *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1152
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1153
text {* Multiplication of factors in a list *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1154
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1155
lemma (in monoid) multlist_closed [simp, intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1156
  assumes ascarr: "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1157
  shows "foldr (op \<otimes>) fs \<one> \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1158
by (insert ascarr, induct fs, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1159
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1160
lemma  (in comm_monoid) multlist_dividesI (*[intro]*):
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1161
  assumes "f \<in> set fs" and "f \<in> carrier G" and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1162
  shows "f divides (foldr (op \<otimes>) fs \<one>)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1163
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1164
apply (induct fs)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1165
 apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1166
apply (case_tac "f = a", simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1167
 apply (fast intro: dividesI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1168
apply clarsimp
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  1169
apply (metis assms(2) divides_prod_l multlist_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1170
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1171
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1172
lemma (in comm_monoid_cancel) multlist_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1173
  assumes "fs [\<sim>] fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1174
    and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1175
  shows "foldr (op \<otimes>) fs \<one> \<sim> foldr (op \<otimes>) fs' \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1176
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1177
proof (induct fs arbitrary: fs', simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1178
  case (Cons a as fs')
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1179
  thus ?case
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1180
  apply (induct fs', simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1181
  proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1182
    fix b bs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1183
    assume "a \<sim> b" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1184
      and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1185
      and ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1186
    hence p: "a \<otimes> foldr op \<otimes> as \<one> \<sim> b \<otimes> foldr op \<otimes> as \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1187
        by (fast intro: mult_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1188
    also
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1189
      assume "as [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1190
         and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1191
         and "\<And>fs'. \<lbrakk>as [\<sim>] fs'; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> foldr op \<otimes> as \<one> \<sim> foldr op \<otimes> fs' \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1192
      hence "foldr op \<otimes> as \<one> \<sim> foldr op \<otimes> bs \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1193
      with ascarr bscarr bcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1194
          have "b \<otimes> foldr op \<otimes> as \<one> \<sim> b \<otimes> foldr op \<otimes> bs \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1195
          by (fast intro: mult_cong_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1196
   finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1197
       show "a \<otimes> foldr op \<otimes> as \<one> \<sim> b \<otimes> foldr op \<otimes> bs \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1198
       by (simp add: ascarr bscarr acarr bcarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1199
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1200
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1201
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1202
lemma (in comm_monoid) multlist_perm_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1203
  assumes prm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1204
    and ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1205
  shows "foldr (op \<otimes>) as \<one> = foldr (op \<otimes>) bs \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1206
using prm ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1207
apply (induct, simp, clarsimp simp add: m_ac, clarsimp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1208
proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1209
  fix xs ys zs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1210
  assume "xs <~~> ys"  "set xs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1211
  hence "set ys \<subseteq> carrier G" by (rule perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1212
  moreover assume "set ys \<subseteq> carrier G \<Longrightarrow> foldr op \<otimes> ys \<one> = foldr op \<otimes> zs \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1213
  ultimately show "foldr op \<otimes> ys \<one> = foldr op \<otimes> zs \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1214
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1215
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1216
lemma (in comm_monoid_cancel) multlist_ee_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1217
  assumes "essentially_equal G fs fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1218
    and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1219
  shows "foldr (op \<otimes>) fs \<one> \<sim> foldr (op \<otimes>) fs' \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1220
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1221
apply (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1222
apply (simp add: multlist_perm_cong multlist_listassoc_cong perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1223
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1224
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1225
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1226
subsubsection {* Factorization in irreducible elements *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1227
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1228
lemma wfactorsI:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1229
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1230
  assumes "\<forall>f\<in>set fs. irreducible G f"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1231
    and "foldr (op \<otimes>) fs \<one> \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1232
  shows "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1233
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1234
unfolding wfactors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1235
by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1236
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1237
lemma wfactorsE:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1238
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1239
  assumes wf: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1240
    and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (op \<otimes>) fs \<one> \<sim> a\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1241
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1242
using wf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1243
unfolding wfactors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1244
by (fast dest: e)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1245
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1246
lemma (in monoid) factorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1247
  assumes "\<forall>f\<in>set fs. irreducible G f"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1248
    and "foldr (op \<otimes>) fs \<one> = a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1249
  shows "factors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1250
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1251
unfolding factors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1252
by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1253
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1254
lemma factorsE:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1255
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1256
  assumes f: "factors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1257
    and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (op \<otimes>) fs \<one> = a\<rbrakk> \<Longrightarrow> P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1258
  shows "P"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1259
using f
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1260
unfolding factors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1261
by (simp add: e)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1262
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1263
lemma (in monoid) factors_wfactors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1264
  assumes "factors G as a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1265
  shows "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1266
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1267
by (blast elim: factorsE intro: wfactorsI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1268
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1269
lemma (in monoid) wfactors_factors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1270
  assumes "wfactors G as a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1271
  shows "\<exists>a'. factors G as a' \<and> a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1272
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1273
by (blast elim: wfactorsE intro: factorsI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1274
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1275
lemma (in monoid) factors_closed [dest]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1276
  assumes "factors G fs a" and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1277
  shows "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1278
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1279
by (elim factorsE, clarsimp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1280
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1281
lemma (in monoid) nunit_factors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1282
  assumes anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1283
    and fs: "factors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1284
  shows "length as > 0"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1285
apply (insert fs, elim factorsE)
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  1286
apply (metis Units_one_closed assms(1) foldr.simps(1) length_greater_0_conv)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  1287
done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1288
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1289
lemma (in monoid) unit_wfactors [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1290
  assumes aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1291
  shows "wfactors G [] a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1292
using aunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1293
by (intro wfactorsI) (simp, simp add: Units_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1294
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1295
lemma (in comm_monoid_cancel) unit_wfactors_empty:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1296
  assumes aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1297
    and wf: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1298
    and carr[simp]: "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1299
  shows "fs = []"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1300
proof (rule ccontr, cases fs, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1301
  fix f fs'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1302
  assume fs: "fs = f # fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1303
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1304
  from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1305
      have fcarr[simp]: "f \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1306
      and carr'[simp]: "set fs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1307
      by (simp add: fs)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1308
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1309
  from fs wf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1310
      have "irreducible G f" by (simp add: wfactors_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1311
  hence fnunit: "f \<notin> Units G" by (fast elim: irreducibleE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1312
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1313
  from fs wf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1314
      have a: "f \<otimes> foldr (op \<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1315
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1316
  note aunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1317
  also from fs wf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1318
       have a: "f \<otimes> foldr (op \<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1319
       have "a \<sim> f \<otimes> foldr (op \<otimes>) fs' \<one>" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1320
       by (simp add: Units_closed[OF aunit] a[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1321
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1322
       have "f \<otimes> foldr (op \<otimes>) fs' \<one> \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1323
  hence "f \<in> Units G" by (intro unit_factor[of f], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1324
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1325
  with fnunit show "False" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1326
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1327
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1328
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1329
text {* Comparing wfactors *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1330
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1331
lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1332
  assumes fact: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1333
    and asc: "fs [\<sim>] fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1334
    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
  1335
  shows "wfactors G fs' a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1336
using fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1337
apply (elim wfactorsE, intro wfactorsI)
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  1338
apply (metis assms(2) assms(4) assms(5) irrlist_listassoc_cong)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1339
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1340
  from asc[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1341
       have "foldr op \<otimes> fs' \<one> \<sim> foldr op \<otimes> fs \<one>" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1342
       by (simp add: multlist_listassoc_cong carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1343
  also assume "foldr op \<otimes> fs \<one> \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1344
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1345
       show "foldr op \<otimes> fs' \<one> \<sim> a" by (simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1346
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1347
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1348
lemma (in comm_monoid) wfactors_perm_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1349
  assumes "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1350
    and "fs <~~> fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1351
    and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1352
  shows "wfactors G fs' a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1353
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1354
apply (elim wfactorsE, intro wfactorsI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1355
 apply (rule irrlist_perm_cong, assumption+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1356
apply (simp add: multlist_perm_cong[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1357
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1358
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1359
lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1360
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1361
    and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1362
    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
  1363
  shows "wfactors G as b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1364
using ee
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1365
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1366
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1367
  assume prm: "as <~~> fs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1368
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1369
       have fscarr: "set fs \<subseteq> carrier G" by (simp add: perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1370
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1371
  note bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1372
  also assume [symmetric]: "fs [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1373
  also (wfactors_listassoc_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1374
       note prm[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1375
  finally (wfactors_perm_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1376
       show "wfactors G as b" by (simp add: carr fscarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1377
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1378
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1379
lemma (in monoid) wfactors_cong_r [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1380
  assumes fac: "wfactors G fs a" and aa': "a \<sim> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1381
    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
  1382
  shows "wfactors G fs a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1383
using fac
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1384
proof (elim wfactorsE, intro wfactorsI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1385
  assume "foldr op \<otimes> fs \<one> \<sim> a" also note aa'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1386
  finally show "foldr op \<otimes> fs \<one> \<sim> a'" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1387
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1388
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1389
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1390
subsubsection {* Essentially equal factorizations *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1391
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1392
lemma (in comm_monoid_cancel) unitfactor_ee:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1393
  assumes uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1394
    and carr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1395
  shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as" (is "essentially_equal G ?as' as")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1396
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1397
apply (intro essentially_equalI[of _ ?as'], simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1398
apply (cases as, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1399
apply (clarsimp, fast intro: associatedI2[of u])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1400
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1401
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1402
lemma (in comm_monoid_cancel) factors_cong_unit:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1403
  assumes uunit: "u \<in> Units G" and anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1404
    and afs: "factors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1405
    and ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1406
  shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)" (is "factors G ?as' ?a'")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1407
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1408
apply (elim factorsE, clarify)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1409
apply (cases as)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1410
 apply (simp add: nunit_factors)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1411
apply clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1412
apply (elim factorsE, intro factorsI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1413
 apply (clarsimp, fast intro: irreducible_prod_rI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1414
apply (simp add: m_ac Units_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1415
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1416
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1417
lemma (in comm_monoid) perm_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1418
  assumes prm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1419
    and afs: "wfactors G as a" and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1420
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1421
    and ascarr[simp]: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1422
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1423
using afs bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1424
proof (elim wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1425
  from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1426
  assume "foldr op \<otimes> as \<one> \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1427
  hence "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1428
  also from prm
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1429
       have "foldr op \<otimes> as \<one> = foldr op \<otimes> bs \<one>" by (rule multlist_perm_cong, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1430
  also assume "foldr op \<otimes> bs \<one> \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1431
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1432
       show "a \<sim> b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1433
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1434
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1435
lemma (in comm_monoid_cancel) listassoc_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1436
  assumes assoc: "as [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1437
    and afs: "wfactors G as a" and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1438
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1439
    and [simp]: "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1440
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1441
using afs bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1442
proof (elim wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1443
  assume "foldr op \<otimes> as \<one> \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1444
  hence "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1445
  also from assoc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1446
       have "foldr op \<otimes> as \<one> \<sim> foldr op \<otimes> bs \<one>" by (rule multlist_listassoc_cong, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1447
  also assume "foldr op \<otimes> bs \<one> \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1448
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1449
       show "a \<sim> b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1450
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1451
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1452
lemma (in comm_monoid_cancel) ee_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1453
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1454
    and afs: "wfactors G as a" and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1455
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1456
    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
  1457
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1458
using ee
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1459
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1460
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1461
  assume prm: "as <~~> fs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1462
  hence as'carr[simp]: "set fs \<subseteq> carrier G" by (simp add: perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1463
  from afs prm
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1464
      have afs': "wfactors G fs a" by (rule wfactors_perm_cong_l, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1465
  assume "fs [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1466
  from this afs' bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1467
      show "a \<sim> b" by (rule listassoc_wfactorsD, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1468
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1469
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1470
lemma (in comm_monoid_cancel) ee_factorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1471
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1472
    and afs: "factors G as a" and bfs:"factors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1473
    and "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1474
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1475
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1476
by (blast intro: factors_wfactors dest: ee_wfactorsD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1477
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1478
lemma (in factorial_monoid) ee_factorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1479
  assumes ab: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1480
    and afs: "factors G as a" and anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1481
    and bfs: "factors G bs b" and bnunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1482
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1483
  shows "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1484
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1485
  note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1486
                    factors_closed[OF bfs bscarr] bscarr[THEN subsetD]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1487
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1488
  from ab carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1489
      have "\<exists>u\<in>Units G. a = b \<otimes> u" by (fast elim: associatedE2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1490
  from this obtain u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1491
      where uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1492
      and a: "a = b \<otimes> u" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1493
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1494
  from uunit bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1495
      have ee: "essentially_equal G (bs[0 := (bs!0 \<otimes> u)]) bs" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1496
                (is "essentially_equal G ?bs' bs")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1497
      by (rule unitfactor_ee)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1498
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1499
  from bscarr uunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1500
      have bs'carr: "set ?bs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1501
      by (cases bs) (simp add: Units_closed)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1502
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1503
  from uunit bnunit bfs bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1504
      have fac: "factors G ?bs' (b \<otimes> u)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1505
      by (rule factors_cong_unit)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1506
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1507
  from afs fac[simplified a[symmetric]] ascarr bs'carr anunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1508
       have "essentially_equal G as ?bs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1509
       by (blast intro: factors_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1510
  also note ee
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1511
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1512
      show "essentially_equal G as bs" by (simp add: ascarr bscarr bs'carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1513
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1514
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1515
lemma (in factorial_monoid) ee_wfactorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1516
  assumes asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1517
    and asf: "wfactors G as a" and bsf: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1518
    and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1519
    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
  1520
  shows "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1521
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1522
proof (cases "a \<in> Units G")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1523
  assume aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1524
  also note asc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1525
  finally have bunit: "b \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1526
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1527
  from aunit asf ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1528
      have e: "as = []" by (rule unit_wfactors_empty)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1529
  from bunit bsf bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1530
      have e': "bs = []" by (rule unit_wfactors_empty)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1531
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1532
  have "essentially_equal G [] []"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1533
      by (fast intro: essentially_equalI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1534
  thus ?thesis by (simp add: e e')
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1535
next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1536
  assume anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1537
  have bnunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1538
  proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1539
    assume "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1540
    also note asc[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1541
    finally have "a \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1542
    with anunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1543
         show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1544
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1545
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1546
  have "\<exists>a'. factors G as a' \<and> a' \<sim> a" by (rule wfactors_factors[OF asf ascarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1547
  from this obtain a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1548
      where fa': "factors G as a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1549
      and a': "a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1550
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1551
  from fa' ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1552
      have a'carr[simp]: "a' \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1553
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1554
  have a'nunit: "a' \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1555
  proof (clarify)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1556
    assume "a' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1557
    also note a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1558
    finally have "a \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1559
    with anunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1560
         show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1561
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1562
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1563
  have "\<exists>b'. factors G bs b' \<and> b' \<sim> b" by (rule wfactors_factors[OF bsf bscarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1564
  from this obtain b'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1565
      where fb': "factors G bs b'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1566
      and b': "b' \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1567
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1568
  from fb' bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1569
      have b'carr[simp]: "b' \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1570
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1571
  have b'nunit: "b' \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1572
  proof (clarify)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1573
    assume "b' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1574
    also note b'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1575
    finally have "b \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1576
    with bnunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1577
        show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1578
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1579
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1580
  note a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1581
  also note asc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1582
  also note b'[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1583
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1584
       have "a' \<sim> b'" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1585
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1586
  from this fa' a'nunit fb' b'nunit ascarr bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1587
  show "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1588
      by (rule ee_factorsI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1589
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1590
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1591
lemma (in factorial_monoid) ee_wfactors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1592
  assumes asf: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1593
    and bsf: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1594
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1595
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1596
  shows asc: "a \<sim> b = essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1597
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1598
by (fast intro: ee_wfactorsI ee_wfactorsD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1599
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1600
lemma (in factorial_monoid) wfactors_exist [intro, simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1601
  assumes acarr[simp]: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1602
  shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1603
proof (cases "a \<in> Units G")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1604
  assume "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1605
  hence "wfactors G [] a" by (rule unit_wfactors)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1606
  thus ?thesis by (intro exI) force
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1607
next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1608
  assume "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1609
  hence "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by (intro factors_exist acarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1610
  from this obtain fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1611
      where fscarr: "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1612
      and f: "factors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1613
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1614
  from f have "wfactors G fs a" by (rule factors_wfactors) fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1615
  from fscarr this
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1616
      show ?thesis by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1617
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1618
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1619
lemma (in monoid) wfactors_prod_exists [intro, simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1620
  assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1621
  shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1622
unfolding wfactors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1623
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1624
by blast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1625
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1626
lemma (in factorial_monoid) wfactors_unique:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1627
  assumes "wfactors G fs a" and "wfactors G fs' a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1628
    and "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1629
    and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1630
  shows "essentially_equal G fs fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1631
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1632
by (fast intro: ee_wfactorsI[of a a])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1633
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1634
lemma (in monoid) factors_mult_single:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1635
  assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1636
  shows "factors G (a # fb) (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1637
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1638
unfolding factors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1639
by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1640
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1641
lemma (in monoid_cancel) wfactors_mult_single:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1642
  assumes f: "irreducible G a"  "wfactors G fb b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1643
        "a \<in> carrier G"  "b \<in> carrier G"  "set fb \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1644
  shows "wfactors G (a # fb) (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1645
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1646
unfolding wfactors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1647
by (simp add: mult_cong_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1648
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1649
lemma (in monoid) factors_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1650
  assumes factors: "factors G fa a"  "factors G fb b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1651
    and ascarr: "set fa \<subseteq> carrier G" and bscarr:"set fb \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1652
  shows "factors G (fa @ fb) (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1653
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1654
unfolding factors_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1655
apply (safe, force)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1656
apply (induct fa)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1657
 apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1658
apply (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1659
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1660
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1661
lemma (in comm_monoid_cancel) wfactors_mult [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1662
  assumes asf: "wfactors G as a" and bsf:"wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1663
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1664
    and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1665
  shows "wfactors G (as @ bs) (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1666
apply (insert wfactors_factors[OF asf ascarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1667
apply (insert wfactors_factors[OF bsf bscarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1668
proof (clarsimp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1669
  fix a' b'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1670
  assume asf': "factors G as a'" and a'a: "a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1671
     and bsf': "factors G bs b'" and b'b: "b' \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1672
  from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1673
  from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1674
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1675
  note carr = acarr bcarr a'carr b'carr ascarr bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1676
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1677
  from asf' bsf'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1678
      have "factors G (as @ bs) (a' \<otimes> b')" by (rule factors_mult) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1679
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1680
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1681
       have abf': "wfactors G (as @ bs) (a' \<otimes> b')" by (intro factors_wfactors) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1682
  also from b'b carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1683
       have trb: "a' \<otimes> b' \<sim> a' \<otimes> b" by (intro mult_cong_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1684
  also from a'a carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1685
       have tra: "a' \<otimes> b \<sim> a \<otimes> b" by (intro mult_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1686
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1687
       show "wfactors G (as @ bs) (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1688
       by (simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1689
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1690
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1691
lemma (in comm_monoid) factors_dividesI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1692
  assumes "factors G fs a" and "f \<in> set fs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1693
    and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1694
  shows "f divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1695
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1696
by (fast elim: factorsE intro: multlist_dividesI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1697
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1698
lemma (in comm_monoid) wfactors_dividesI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1699
  assumes p: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1700
    and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1701
    and f: "f \<in> set fs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1702
  shows "f divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1703
apply (insert wfactors_factors[OF p fscarr], clarsimp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1704
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1705
  fix a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1706
  assume fsa': "factors G fs a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1707
    and a'a: "a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1708
  with fscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1709
      have a'carr: "a' \<in> carrier G" by (simp add: factors_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1710
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1711
  from fsa' fscarr f
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1712
       have "f divides a'" by (fast intro: factors_dividesI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1713
  also note a'a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1714
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1715
       show "f divides a" by (simp add: f fscarr[THEN subsetD] acarr a'carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1716
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1717
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1718
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1719
subsubsection {* Factorial monoids and wfactors *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1720
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1721
lemma (in comm_monoid_cancel) factorial_monoidI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1722
  assumes wfactors_exists: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1723
          "\<And>a. a \<in> carrier G \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1724
      and wfactors_unique: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1725
          "\<And>a fs fs'. \<lbrakk>a \<in> carrier G; set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G; 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1726
                       wfactors G fs a; wfactors G fs' a\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1727
  shows "factorial_monoid G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
  1728
proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1729
  fix a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1730
  assume acarr: "a \<in> carrier G" and anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1731
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1732
  from wfactors_exists[OF acarr]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1733
  obtain as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1734
      where ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1735
      and afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1736
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1737
  from afs ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1738
      have "\<exists>a'. factors G as a' \<and> a' \<sim> a" by (rule wfactors_factors)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1739
  from this obtain a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1740
      where afs': "factors G as a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1741
      and a'a: "a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1742
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1743
  from afs' ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1744
      have a'carr: "a' \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1745
  have a'nunit: "a' \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1746
  proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1747
    assume "a' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1748
    also note a'a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1749
    finally have "a \<in> Units G" by (simp add: acarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1750
    with anunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1751
        show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1752
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1753
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1754
  from a'carr acarr a'a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1755
      have "\<exists>u. u \<in> Units G \<and> a' = a \<otimes> u" by (blast elim: associatedE2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1756
  from this obtain  u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1757
      where uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1758
      and a': "a' = a \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1759
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1760
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1761
  note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1762
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1763
  have "a = a \<otimes> \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1764
  also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: Units_r_inv uunit)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1765
  also have "\<dots> = a' \<otimes> inv u" by (simp add: m_assoc[symmetric] a'[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1766
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1767
       have a: "a = a' \<otimes> inv u" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1768
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1769
  from ascarr uunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1770
      have cr: "set (as[0:=(as!0 \<otimes> inv u)]) \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1771
      by (cases as, clarsimp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1772
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1773
  from afs' uunit a'nunit acarr ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1774
      have "factors G (as[0:=(as!0 \<otimes> inv u)]) a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1775
      by (simp add: a factors_cong_unit)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1776
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1777
  with cr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1778
      show "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1779
qed (blast intro: factors_wfactors wfactors_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1780
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1781
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
  1782
subsection {* Factorizations as Multisets *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1783
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1784
text {* Gives useful operations like intersection *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1785
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1786
(* FIXME: use class_of x instead of closure_of {x} *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1787
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1788
abbreviation
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1789
  "assocs G x == eq_closure_of (division_rel G) {x}"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1790
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  1791
definition
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  1792
  "fmset G as = multiset_of (map (\<lambda>a. assocs G a) as)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1793
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1794
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1795
text {* Helper lemmas *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1796
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1797
lemma (in monoid) assocs_repr_independence:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1798
  assumes "y \<in> assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1799
    and "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1800
  shows "assocs G x = assocs G y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1801
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1802
apply safe
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1803
 apply (elim closure_ofE2, intro closure_ofI2[of _ _ y])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1804
   apply (clarsimp, iprover intro: associated_trans associated_sym, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1805
apply (elim closure_ofE2, intro closure_ofI2[of _ _ x])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1806
  apply (clarsimp, iprover intro: associated_trans, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1807
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1808
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1809
lemma (in monoid) assocs_self:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1810
  assumes "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1811
  shows "x \<in> assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1812
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1813
by (fastsimp intro: closure_ofI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1814
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1815
lemma (in monoid) assocs_repr_independenceD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1816
  assumes repr: "assocs G x = assocs G y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1817
    and ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1818
  shows "y \<in> assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1819
unfolding repr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1820
using ycarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1821
by (intro assocs_self)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1822
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1823
lemma (in comm_monoid) assocs_assoc:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1824
  assumes "a \<in> assocs G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1825
    and "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1826
  shows "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1827
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1828
by (elim closure_ofE2, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1829
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1830
lemmas (in comm_monoid) assocs_eqD =
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1831
    assocs_repr_independenceD[THEN assocs_assoc]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1832
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1833
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1834
subsubsection {* Comparing multisets *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1835
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1836
lemma (in monoid) fmset_perm_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1837
  assumes prm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1838
  shows "fmset G as = fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1839
using perm_map[OF prm]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1840
by (simp add: multiset_of_eq_perm fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1841
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1842
lemma (in comm_monoid_cancel) eqc_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1843
  assumes "as [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1844
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1845
  shows "map (assocs G) as = map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1846
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1847
apply (induct as arbitrary: bs, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1848
apply (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1, safe)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1849
 apply (clarsimp elim!: closure_ofE2) defer 1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1850
 apply (clarsimp elim!: closure_ofE2) defer 1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1851
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1852
  fix a x z
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1853
  assume carr[simp]: "a \<in> carrier G"  "x \<in> carrier G"  "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1854
  assume "x \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1855
  also assume "a \<sim> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1856
  finally have "x \<sim> z" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1857
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1858
      show "x \<in> assocs G z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1859
      by (intro closure_ofI2) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1860
next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1861
  fix a x z
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1862
  assume carr[simp]: "a \<in> carrier G"  "x \<in> carrier G"  "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1863
  assume "x \<sim> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1864
  also assume [symmetric]: "a \<sim> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1865
  finally have "x \<sim> a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1866
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1867
      show "x \<in> assocs G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1868
      by (intro closure_ofI2) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1869
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1870
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1871
lemma (in comm_monoid_cancel) fmset_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1872
  assumes "as [\<sim>] bs" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1873
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1874
  shows "fmset G as = fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1875
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1876
unfolding fmset_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1877
by (simp add: eqc_listassoc_cong)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1878
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1879
lemma (in comm_monoid_cancel) ee_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1880
  assumes ee: "essentially_equal G as bs" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1881
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1882
  shows "fmset G as = fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1883
using ee
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1884
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1885
  fix as'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1886
  assume prm: "as <~~> as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1887
  from prm ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1888
      have as'carr: "set as' \<subseteq> carrier G" by (rule perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1889
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1890
  from prm
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1891
       have "fmset G as = fmset G as'" by (rule fmset_perm_cong)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1892
  also assume "as' [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1893
       with as'carr bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1894
       have "fmset G as' = fmset G bs" by (simp add: fmset_listassoc_cong)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1895
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1896
       show "fmset G as = fmset G bs" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1897
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1898
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1899
lemma (in monoid_cancel) fmset_ee__hlp_induct:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1900
  assumes prm: "cas <~~> cbs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1901
    and cdef: "cas = map (assocs G) as"  "cbs = map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1902
  shows "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1903
                 cbs = map (assocs G) bs) \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1904
apply (rule perm.induct[of cas cbs], rule prm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1905
apply safe apply simp_all
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1906
  apply (simp add: map_eq_Cons_conv, blast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1907
 apply force
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1908
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1909
  fix ys as bs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1910
  assume p1: "map (assocs G) as <~~> ys"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1911
    and r1[rule_format]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1912
        "\<forall>asa bs. map (assocs G) as = map (assocs G) asa \<and>
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1913
                  ys = map (assocs G) bs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1914
                  \<longrightarrow> (\<exists>as'. asa <~~> as' \<and> map (assocs G) as' = map (assocs G) bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1915
    and p2: "ys <~~> map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1916
    and r2[rule_format]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1917
        "\<forall>as bsa. ys = map (assocs G) as \<and>
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1918
                  map (assocs G) bs = map (assocs G) bsa
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1919
                  \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bsa)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1920
    and p3: "map (assocs G) as <~~> map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1921
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1922
  from p1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1923
      have "multiset_of (map (assocs G) as) = multiset_of ys"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1924
      by (simp add: multiset_of_eq_perm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1925
  hence setys: "set (map (assocs G) as) = set ys" by (rule multiset_of_eq_setD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1926
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1927
  have "set (map (assocs G) as) = { assocs G x | x. x \<in> set as}" by clarsimp fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1928
  with setys have "set ys \<subseteq> { assocs G x | x. x \<in> set as}" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1929
  hence "\<exists>yy. ys = map (assocs G) yy"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1930
    apply (induct ys, simp, clarsimp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1931
  proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1932
    fix yy x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1933
    show "\<exists>yya. (assocs G x) # map (assocs G) yy =
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1934
                map (assocs G) yya"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1935
    by (rule exI[of _ "x#yy"], simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1936
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1937
  from this obtain yy
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1938
      where ys: "ys = map (assocs G) yy"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1939
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1940
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1941
  from p1 ys
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1942
      have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) yy"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1943
      by (intro r1, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1944
  from this obtain as'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1945
      where asas': "as <~~> as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1946
      and as'yy: "map (assocs G) as' = map (assocs G) yy"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1947
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1948
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1949
  from p2 ys
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1950
      have "\<exists>as'. yy <~~> as' \<and> map (assocs G) as' = map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1951
      by (intro r2, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1952
  from this obtain as''
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1953
      where yyas'': "yy <~~> as''"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1954
      and as''bs: "map (assocs G) as'' = map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1955
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1956
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1957
  from as'yy and yyas''
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1958
      have "\<exists>cs. as' <~~> cs \<and> map (assocs G) cs = map (assocs G) as''"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1959
      by (rule perm_map_switch)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1960
  from this obtain cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1961
      where as'cs: "as' <~~> cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1962
      and csas'': "map (assocs G) cs = map (assocs G) as''"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1963
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1964
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1965
  from asas' and as'cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1966
      have ascs: "as <~~> cs" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1967
  from csas'' and as''bs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1968
      have "map (assocs G) cs = map (assocs G) bs" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1969
  from ascs and this
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1970
  show "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1971
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1972
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1973
lemma (in comm_monoid_cancel) fmset_ee:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1974
  assumes mset: "fmset G as = fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1975
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1976
  shows "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1977
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1978
  from mset
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1979
      have mpp: "map (assocs G) as <~~> map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1980
      by (simp add: fmset_def multiset_of_eq_perm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1981
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1982
  have "\<exists>cas. cas = map (assocs G) as" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1983
  from this obtain cas where cas: "cas = map (assocs G) as" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1984
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1985
  have "\<exists>cbs. cbs = map (assocs G) bs" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1986
  from this obtain cbs where cbs: "cbs = map (assocs G) bs" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1987
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1988
  from cas cbs mpp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1989
      have [rule_format]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1990
           "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1991
                     cbs = map (assocs G) bs) 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1992
                     \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1993
      by (intro fmset_ee__hlp_induct, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1994
  with mpp cas cbs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1995
      have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1996
      by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1997
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1998
  from this obtain as'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1999
      where tp: "as <~~> as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2000
      and tm: "map (assocs G) as' = map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2001
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2002
  from tm have lene: "length as' = length bs" by (rule map_eq_imp_length_eq)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2003
  from tp have "set as = set as'" by (simp add: multiset_of_eq_perm multiset_of_eq_setD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2004
  with ascarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2005
      have as'carr: "set as' \<subseteq> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2006
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2007
  from tm as'carr[THEN subsetD] bscarr[THEN subsetD]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2008
  have "as' [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2009
    by (induct as' arbitrary: bs) (simp, fastsimp dest: assocs_eqD[THEN associated_sym])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2010
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2011
  from tp and this
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2012
    show "essentially_equal G as bs" by (fast intro: essentially_equalI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2013
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2014
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2015
lemma (in comm_monoid_cancel) ee_is_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2016
  assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2017
  shows "essentially_equal G as bs = (fmset G as = fmset G bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2018
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2019
by (fast intro: ee_fmset fmset_ee)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2020
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2021
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2022
subsubsection {* Interpreting multisets as factorizations *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2023
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2024
lemma (in monoid) mset_fmsetEx:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2025
  assumes elems: "\<And>X. X \<in> set_of Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2026
  shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2027
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2028
  have "\<exists>Cs'. Cs = multiset_of Cs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2029
      by (rule surjE[OF surj_multiset_of], fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2030
  from this obtain Cs'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2031
      where Cs: "Cs = multiset_of Cs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2032
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2033
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2034
  have "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> multiset_of (map (assocs G) cs) = Cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2035
  using elems
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2036
  unfolding Cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2037
    apply (induct Cs', simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2038
    apply clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2039
    apply (subgoal_tac "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2040
                             multiset_of (map (assocs G) cs) = multiset_of Cs'")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2041
  proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2042
    fix a Cs' cs 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2043
    assume ih: "\<And>X. X = a \<or> X \<in> set Cs' \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2044
      and csP: "\<forall>x\<in>set cs. P x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2045
      and mset: "multiset_of (map (assocs G) cs) = multiset_of Cs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2046
    from ih
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2047
        have "\<exists>x. P x \<and> a = assocs G x" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2048
    from this obtain c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2049
        where cP: "P c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2050
        and a: "a = assocs G c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2051
        by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2052
    from cP csP
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2053
        have tP: "\<forall>x\<in>set (c#cs). P x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2054
    from mset a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2055
    have "multiset_of (map (assocs G) (c#cs)) = multiset_of Cs' + {#a#}" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2056
    from tP this
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2057
    show "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and>
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2058
               multiset_of (map (assocs G) cs) =
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2059
               multiset_of Cs' + {#a#}" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2060
  qed simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2061
  thus ?thesis by (simp add: fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2062
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2063
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2064
lemma (in monoid) mset_wfactorsEx:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2065
  assumes elems: "\<And>X. X \<in> set_of Cs 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2066
                      \<Longrightarrow> \<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2067
  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
  2068
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2069
  have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2070
      by (intro mset_fmsetEx, rule elems)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2071
  from this obtain cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2072
      where p[rule_format]: "\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2073
      and Cs[symmetric]: "fmset G cs = Cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2074
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2075
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2076
  from p
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2077
      have cscarr: "set cs \<subseteq> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2078
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2079
  from p
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2080
      have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2081
      by (intro wfactors_prod_exists) fast+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2082
  from this obtain c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2083
      where ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2084
      and cfs: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2085
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2086
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2087
  with cscarr Cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2088
      show ?thesis by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2089
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2090
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2091
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2092
subsubsection {* Multiplication on multisets *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2093
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2094
lemma (in factorial_monoid) mult_wfactors_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2095
  assumes afs: "wfactors G as a" and bfs: "wfactors G bs b" and cfs: "wfactors G cs (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2096
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2097
              "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"  "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2098
  shows "fmset G cs = fmset G as + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2099
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2100
  from assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2101
       have "wfactors G (as @ bs) (a \<otimes> b)" by (intro wfactors_mult)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2102
  with carr cfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2103
       have "essentially_equal G cs (as@bs)" by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2104
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2105
       have "fmset G cs = fmset G (as@bs)" by (intro ee_fmset, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2106
  also have "fmset G (as@bs) = fmset G as + fmset G bs" by (simp add: fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2107
  finally show "fmset G cs = fmset G as + fmset G bs" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2108
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2109
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2110
lemma (in factorial_monoid) mult_factors_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2111
  assumes afs: "factors G as a" and bfs: "factors G bs b" and cfs: "factors G cs (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2112
    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
  2113
  shows "fmset G cs = fmset G as + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2114
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2115
by (blast intro: factors_wfactors mult_wfactors_fmset)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2116
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2117
lemma (in comm_monoid_cancel) fmset_wfactors_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2118
  assumes mset: "fmset G cs = fmset G as + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2119
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2120
          "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"  "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2121
    and fs: "wfactors G as a"  "wfactors G bs b"  "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2122
  shows "c \<sim> a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2123
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2124
  from carr fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2125
       have m: "wfactors G (as @ bs) (a \<otimes> b)" by (intro wfactors_mult)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2126
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2127
  from mset
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2128
       have "fmset G cs = fmset G (as@bs)" by (simp add: fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2129
  then have "essentially_equal G cs (as@bs)" by (rule fmset_ee) (simp add: carr)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2130
  then show "c \<sim> a \<otimes> b" by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp add: assms m)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2131
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2132
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2133
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2134
subsubsection {* Divisibility on multisets *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2135
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2136
lemma (in factorial_monoid) divides_fmsubset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2137
  assumes ab: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2138
    and afs: "wfactors G as a" and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2139
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2140
  shows "fmset G as \<le> fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2141
using ab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2142
proof (elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2143
  fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2144
  assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2145
  hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2146
  from this obtain cs 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2147
      where cscarr: "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2148
      and cfs: "wfactors G cs c" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2149
  note carr = carr ccarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2150
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2151
  assume "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2152
  with afs bfs cfs carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2153
      have "fmset G bs = fmset G as + fmset G cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2154
      by (intro mult_wfactors_fmset[OF afs cfs]) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2155
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2156
  thus ?thesis by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2157
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2158
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2159
lemma (in comm_monoid_cancel) fmsubset_divides:
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2160
  assumes msubset: "fmset G as \<le> fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2161
    and afs: "wfactors G as a" and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2162
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2163
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2164
  shows "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2165
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2166
  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
  2167
  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
  2168
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2169
  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
  2170
  proof (intro mset_wfactorsEx, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2171
    fix X
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2172
    assume "count (fmset G as) X < count (fmset G bs) X"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2173
    hence "0 < count (fmset G bs) X" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2174
    hence "X \<in> set_of (fmset G bs)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2175
    hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2176
    hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2177
    from this obtain x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2178
        where xbs: "x \<in> set bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2179
        and X: "X = assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2180
        by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2181
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2182
    with bscarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2183
    from xbs birr have xirr: "irreducible G x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2184
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2185
    from xcarr and xirr and X
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2186
        show "\<exists>x. x \<in> carrier G \<and> irreducible G x \<and> X = assocs G x" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2187
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2188
  from this obtain c cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2189
      where ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2190
      and cscarr: "set cs \<subseteq> carrier G" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2191
      and csf: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2192
      and csmset: "fmset G cs = fmset G bs - fmset G as" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2193
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2194
  from csmset msubset
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2195
      have "fmset G bs = fmset G as + fmset G cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2196
      by (simp add: multiset_eq_conv_count_eq mset_le_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2197
  hence basc: "b \<sim> a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2198
      by (rule fmset_wfactors_mult) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2199
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2200
  thus ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2201
  proof (elim associatedE2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2202
    fix u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2203
    assume "u \<in> Units G"  "b = a \<otimes> c \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2204
    with acarr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2205
        show "a divides b" by (fast intro: dividesI[of "c \<otimes> u"] m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2206
  qed (simp add: acarr bcarr ccarr)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2207
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2208
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2209
lemma (in factorial_monoid) divides_as_fmsubset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2210
  assumes "wfactors G as a" and "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2211
    and "a \<in> carrier G" and "b \<in> carrier G" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2212
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2213
  shows "a divides b = (fmset G as \<le> fmset G bs)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2214
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2215
by (blast intro: divides_fmsubset fmsubset_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2216
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2217
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2218
text {* Proper factors on multisets *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2219
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2220
lemma (in factorial_monoid) fmset_properfactor:
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2221
  assumes asubb: "fmset G as \<le> fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2222
    and anb: "fmset G as \<noteq> fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2223
    and "wfactors G as a" and "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2224
    and "a \<in> carrier G" and "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2225
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2226
  shows "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2227
apply (rule properfactorI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2228
apply (rule fmsubset_divides[of as bs], fact+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2229
proof
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2230
  assume "b divides a"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2231
  hence "fmset G bs \<le> fmset G as"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2232
      by (rule divides_fmsubset) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2233
  with asubb
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2234
      have "fmset G as = fmset G bs" by (rule order_antisym)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2235
  with anb
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2236
      show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2237
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2238
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2239
lemma (in factorial_monoid) properfactor_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2240
  assumes pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2241
    and "wfactors G as a" and "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2242
    and "a \<in> carrier G" and "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2243
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2244
  shows "fmset G as \<le> fmset G bs \<and> fmset G as \<noteq> fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2245
using pf
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2246
apply (elim properfactorE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2247
apply rule
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2248
 apply (intro divides_fmsubset, assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2249
  apply (rule assms)+
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  2250
apply (metis assms divides_fmsubset fmsubset_divides)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  2251
done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2252
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
  2253
subsection {* Irreducible Elements are Prime *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2254
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2255
lemma (in factorial_monoid) irreducible_is_prime:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2256
  assumes pirr: "irreducible G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2257
    and pcarr: "p \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2258
  shows "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2259
using pirr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2260
proof (elim irreducibleE, intro primeI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2261
  fix a b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2262
  assume acarr: "a \<in> carrier G"  and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2263
    and pdvdab: "p divides (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2264
    and pnunit: "p \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2265
  assume irreduc[rule_format]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2266
         "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2267
  from pdvdab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2268
      have "\<exists>c\<in>carrier G. a \<otimes> b = p \<otimes> c" by (rule dividesD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2269
  from this obtain c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2270
      where ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2271
      and abpc: "a \<otimes> b = p \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2272
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2273
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2274
  from acarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2275
  from this obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2276
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2277
  from bcarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs b" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2278
  from this obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2279
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2280
  from ccarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs c" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2281
  from this obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2282
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2283
  note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2284
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2285
  from afs and bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2286
      have abfs: "wfactors G (as @ bs) (a \<otimes> b)" by (rule wfactors_mult) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2287
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2288
  from pirr cfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2289
      have pcfs: "wfactors G (p # cs) (p \<otimes> c)" by (rule wfactors_mult_single) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2290
  with abpc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2291
      have abfs': "wfactors G (p # cs) (a \<otimes> b)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2292
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2293
  from abfs' abfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2294
      have "essentially_equal G (p # cs) (as @ bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2295
      by (rule wfactors_unique) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2296
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2297
  hence "\<exists>ds. p # cs <~~> ds \<and> ds [\<sim>] (as @ bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2298
      by (fast elim: essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2299
  from this obtain ds
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2300
      where "p # cs <~~> ds"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2301
      and dsassoc: "ds [\<sim>] (as @ bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2302
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2303
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2304
  then have "p \<in> set ds"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2305
       by (simp add: perm_set_eq[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2306
  with dsassoc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2307
       have "\<exists>p'. p' \<in> set (as@bs) \<and> p \<sim> p'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2308
       unfolding list_all2_conv_all_nth set_conv_nth
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2309
       by force
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2310
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2311
  from this obtain p'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2312
       where "p' \<in> set (as@bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2313
       and pp': "p \<sim> p'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2314
       by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2315
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2316
  hence "p' \<in> set as \<or> p' \<in> set bs" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2317
  moreover
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2318
  {
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2319
    assume p'elem: "p' \<in> set as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2320
    with ascarr have [simp]: "p' \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2321
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2322
    note pp'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2323
    also from afs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2324
         have "p' divides a" by (rule wfactors_dividesI) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2325
    finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2326
         have "p divides a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2327
  }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2328
  moreover
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2329
  {
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2330
    assume p'elem: "p' \<in> set bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2331
    with bscarr have [simp]: "p' \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2332
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2333
    note pp'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2334
    also from bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2335
         have "p' divides b" by (rule wfactors_dividesI) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2336
    finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2337
         have "p divides b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2338
  }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2339
  ultimately
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2340
      show "p divides a \<or> p divides b" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2341
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2342
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2343
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2344
--"A version using @{const factors}, more complicated"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2345
lemma (in factorial_monoid) factors_irreducible_is_prime:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2346
  assumes pirr: "irreducible G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2347
    and pcarr: "p \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2348
  shows "prime G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2349
using pirr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2350
apply (elim irreducibleE, intro primeI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2351
 apply assumption
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2352
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2353
  fix a b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2354
  assume acarr: "a \<in> carrier G" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2355
    and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2356
    and pdvdab: "p divides (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2357
  assume irreduc[rule_format]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2358
         "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2359
  from pdvdab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2360
      have "\<exists>c\<in>carrier G. a \<otimes> b = p \<otimes> c" by (rule dividesD)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2361
  from this obtain c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2362
      where ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2363
      and abpc: "a \<otimes> b = p \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2364
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2365
  note [simp] = pcarr acarr bcarr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2366
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2367
  show "p divides a \<or> p divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2368
  proof (cases "a \<in> Units G")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2369
    assume aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2370
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2371
    note pdvdab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2372
    also have "a \<otimes> b = b \<otimes> a" by (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2373
    also from aunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2374
         have bab: "b \<otimes> a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2375
         by (intro associatedI2[of "a"], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2376
    finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2377
         have "p divides b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2378
    thus "p divides a \<or> p divides b" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2379
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2380
    assume anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2381
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2382
    show "p divides a \<or> p divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2383
    proof (cases "b \<in> Units G")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2384
      assume bunit: "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2385
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2386
      note pdvdab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2387
      also from bunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2388
           have baa: "a \<otimes> b \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2389
           by (intro associatedI2[of "b"], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2390
      finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2391
           have "p divides a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2392
      thus "p divides a \<or> p divides b" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2393
    next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2394
      assume bnunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2395
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2396
      have cnunit: "c \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2397
      proof (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2398
        assume cunit: "c \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2399
        from bnunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2400
             have "properfactor G a (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2401
             by (intro properfactorI3[of _ _ b], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2402
        also note abpc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2403
        also from cunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2404
             have "p \<otimes> c \<sim> p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2405
             by (intro associatedI2[of c], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2406
        finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2407
             have "properfactor G a p" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2408
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2409
        with acarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2410
             have "a \<in> Units G" by (fast intro: irreduc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2411
        with anunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2412
             show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2413
      qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2414
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2415
      have abnunit: "a \<otimes> b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2416
      proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2417
        assume abunit: "a \<otimes> b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2418
        hence "a \<in> Units G" by (rule unit_factor) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2419
        with anunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2420
             show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2421
      qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2422
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2423
      from acarr anunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by (rule factors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2424
      then obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2425
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2426
      from bcarr bnunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs b" by (rule factors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2427
      then obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2428
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2429
      from ccarr cnunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs c" by (rule factors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2430
      then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2431
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2432
      note [simp] = ascarr bscarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2433
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2434
      from afac and bfac
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2435
          have abfac: "factors G (as @ bs) (a \<otimes> b)" by (rule factors_mult) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2436
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2437
      from pirr cfac
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2438
          have pcfac: "factors G (p # cs) (p \<otimes> c)" by (rule factors_mult_single) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2439
      with abpc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2440
          have abfac': "factors G (p # cs) (a \<otimes> b)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2441
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2442
      from abfac' abfac
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2443
          have "essentially_equal G (p # cs) (as @ bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2444
          by (rule factors_unique) (fact | simp)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2445
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2446
      hence "\<exists>ds. p # cs <~~> ds \<and> ds [\<sim>] (as @ bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2447
          by (fast elim: essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2448
      from this obtain ds
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2449
          where "p # cs <~~> ds"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2450
          and dsassoc: "ds [\<sim>] (as @ bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2451
          by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2452
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2453
      then have "p \<in> set ds"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2454
           by (simp add: perm_set_eq[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2455
      with dsassoc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2456
           have "\<exists>p'. p' \<in> set (as@bs) \<and> p \<sim> p'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2457
           unfolding list_all2_conv_all_nth set_conv_nth
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2458
           by force
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2459
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2460
      from this obtain p'
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2461
          where "p' \<in> set (as@bs)"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2462
          and pp': "p \<sim> p'" by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2463
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2464
      hence "p' \<in> set as \<or> p' \<in> set bs" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2465
      moreover
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2466
      {
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2467
        assume p'elem: "p' \<in> set as"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2468
        with ascarr have [simp]: "p' \<in> carrier G" by fast
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2469
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2470
        note pp'
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2471
        also from afac p'elem
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2472
             have "p' divides a" by (rule factors_dividesI) fact+
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2473
        finally
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2474
             have "p divides a" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2475
      }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2476
      moreover
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2477
      {
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2478
        assume p'elem: "p' \<in> set bs"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2479
        with bscarr have [simp]: "p' \<in> carrier G" by fast
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2480
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2481
        note pp'
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2482
        also from bfac
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2483
             have "p' divides b" by (rule factors_dividesI) fact+
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2484
        finally have "p divides b" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2485
      }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2486
      ultimately
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2487
          show "p divides a \<or> p divides b" by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2488
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2489
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2490
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2491
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2492
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
  2493
subsection {* Greatest Common Divisors and Lowest Common Multiples *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2494
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2495
subsubsection {* Definitions *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2496
35847
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2497
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2498
  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
  2499
  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
  2500
    (\<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
  2501
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2502
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2503
  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
  2504
  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
  2505
    (\<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
  2506
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2507
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2508
  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
  2509
  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
  2510
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2511
definition
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2512
  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
  2513
  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
  2514
19f1f7066917 eliminated old constdefs;
wenzelm
parents: 35416
diff changeset
  2515
definition
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  2516
  "SomeGcd G A = inf (division_rel G) A"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2517
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2518
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2519
locale gcd_condition_monoid = comm_monoid_cancel +
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2520
  assumes gcdof_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2521
          "\<lbrakk>a \<in> carrier G; b \<in> carrier G\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> carrier G \<and> c gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2522
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2523
locale primeness_condition_monoid = comm_monoid_cancel +
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2524
  assumes irreducible_prime:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2525
          "\<lbrakk>a \<in> carrier G; irreducible G a\<rbrakk> \<Longrightarrow> prime G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2526
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2527
locale divisor_chain_condition_monoid = comm_monoid_cancel +
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2528
  assumes division_wellfounded:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2529
          "wf {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2530
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2531
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2532
subsubsection {* Connections to \texttt{Lattice.thy} *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2533
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2534
lemma gcdof_greatestLower:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2535
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2536
  assumes carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2537
  shows "(x \<in> carrier G \<and> x gcdof a b) =
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2538
         greatest (division_rel G) x (Lower (division_rel G) {a, b})"
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2539
unfolding isgcd_def greatest_def Lower_def elem_def
32456
341c83339aeb tuned the simp rules for Int involving insert and intervals.
nipkow
parents: 29237
diff changeset
  2540
by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2541
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2542
lemma lcmof_leastUpper:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2543
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2544
  assumes carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2545
  shows "(x \<in> carrier G \<and> x lcmof a b) =
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2546
         least (division_rel G) x (Upper (division_rel G) {a, b})"
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2547
unfolding islcm_def least_def Upper_def elem_def
32456
341c83339aeb tuned the simp rules for Int involving insert and intervals.
nipkow
parents: 29237
diff changeset
  2548
by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2549
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2550
lemma somegcd_meet:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2551
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2552
  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
  2553
  shows "somegcd G a b = meet (division_rel G) a b"
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2554
unfolding somegcd_def meet_def inf_def
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2555
by (simp add: gcdof_greatestLower[OF carr])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2556
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2557
lemma (in monoid) isgcd_divides_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2558
  assumes "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2559
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2560
  shows "a gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2561
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2562
unfolding isgcd_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2563
by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2564
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2565
lemma (in monoid) isgcd_divides_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2566
  assumes "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2567
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2568
  shows "b gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2569
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2570
unfolding isgcd_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2571
by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2572
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2573
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2574
subsubsection {* Existence of gcd and lcm *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2575
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2576
lemma (in factorial_monoid) gcdof_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2577
  assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2578
  shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2579
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2580
  from acarr have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2581
  from this obtain as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2582
      where ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2583
      and afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2584
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2585
  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
  2586
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2587
  from bcarr have "\<exists>bs. set bs \<subseteq> carrier G \<and> wfactors G bs b" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2588
  from this obtain bs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2589
      where bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2590
      and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2591
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2592
  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
  2593
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2594
  have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2595
               fmset G cs = fmset G as #\<inter> fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2596
  proof (intro mset_wfactorsEx)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2597
    fix X
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2598
    assume "X \<in> set_of (fmset G as #\<inter> fmset G bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2599
    hence "X \<in> set_of (fmset G as)" by (simp add: multiset_inter_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2600
    hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2601
    hence "\<exists>x. X = assocs G x \<and> x \<in> set as" by (induct as) auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2602
    from this obtain x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2603
        where X: "X = assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2604
        and xas: "x \<in> set as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2605
        by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2606
    with ascarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2607
    from xas airr have xirr: "irreducible G x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2608
 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2609
    from xcarr and xirr and X
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2610
        show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2611
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2612
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2613
  from this obtain c cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2614
      where ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2615
      and cscarr: "set cs \<subseteq> carrier G" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2616
      and csirr: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2617
      and csmset: "fmset G cs = fmset G as #\<inter> fmset G bs" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2618
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2619
  have "c gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2620
  proof (simp add: isgcd_def, safe)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2621
    from csmset
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2622
        have "fmset G cs \<le> fmset G as"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2623
        by (simp add: multiset_inter_def mset_le_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2624
    thus "c divides a" by (rule fmsubset_divides) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2625
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2626
    from csmset
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2627
        have "fmset G cs \<le> fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2628
        by (simp add: multiset_inter_def mset_le_def, force)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2629
    thus "c divides b" by (rule fmsubset_divides) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2630
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2631
    fix y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2632
    assume ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2633
    hence "\<exists>ys. set ys \<subseteq> carrier G \<and> wfactors G ys y" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2634
    from this obtain ys
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2635
        where yscarr: "set ys \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2636
        and yfs: "wfactors G ys y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2637
        by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2638
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2639
    assume "y divides a"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2640
    hence ya: "fmset G ys \<le> fmset G as" by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2641
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2642
    assume "y divides b"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2643
    hence yb: "fmset G ys \<le> fmset G bs" by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2644
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2645
    from ya yb csmset
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2646
    have "fmset G ys \<le> fmset G cs" by (simp add: mset_le_def multiset_inter_count)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2647
    thus "y divides c" by (rule fmsubset_divides) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2648
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2649
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2650
  with ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2651
      show "\<exists>c. c \<in> carrier G \<and> c gcdof a b" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2652
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2653
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2654
lemma (in factorial_monoid) lcmof_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2655
  assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2656
  shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2657
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2658
  from acarr have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2659
  from this obtain as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2660
      where ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2661
      and afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2662
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2663
  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
  2664
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2665
  from bcarr have "\<exists>bs. set bs \<subseteq> carrier G \<and> wfactors G bs b" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2666
  from this obtain bs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2667
      where bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2668
      and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2669
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2670
  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
  2671
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2672
  have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2673
               fmset G cs = (fmset G as - fmset G bs) + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2674
  proof (intro mset_wfactorsEx)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2675
    fix X
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2676
    assume "X \<in> set_of ((fmset G as - fmset G bs) + fmset G bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2677
    hence "X \<in> set_of (fmset G as) \<or> X \<in> set_of (fmset G bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2678
       by (cases "X :# fmset G bs", simp, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2679
    moreover
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2680
    {
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2681
      assume "X \<in> set_of (fmset G as)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2682
      hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2683
      hence "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2684
      from this obtain x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2685
          where xas: "x \<in> set as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2686
          and X: "X = assocs G x" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2687
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2688
      with ascarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2689
      from xas airr have xirr: "irreducible G x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2690
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2691
      from xcarr and xirr and X
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2692
          have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2693
    }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2694
    moreover
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2695
    {
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2696
      assume "X \<in> set_of (fmset G bs)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2697
      hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2698
      hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2699
      from this obtain x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2700
          where xbs: "x \<in> set bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2701
          and X: "X = assocs G x" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2702
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2703
      with bscarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2704
      from xbs birr have xirr: "irreducible G x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2705
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2706
      from xcarr and xirr and X
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2707
          have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2708
    }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2709
    ultimately
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2710
    show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2711
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2712
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2713
  from this obtain c cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2714
      where ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2715
      and cscarr: "set cs \<subseteq> carrier G" 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2716
      and csirr: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2717
      and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2718
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2719
  have "c lcmof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2720
  proof (simp add: islcm_def, safe)
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2721
    from csmset have "fmset G as \<le> fmset G cs" by (simp add: mset_le_def, force)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2722
    thus "a divides c" by (rule fmsubset_divides) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2723
  next
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2724
    from csmset have "fmset G bs \<le> fmset G cs" by (simp add: mset_le_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2725
    thus "b divides c" by (rule fmsubset_divides) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2726
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2727
    fix y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2728
    assume ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2729
    hence "\<exists>ys. set ys \<subseteq> carrier G \<and> wfactors G ys y" by (rule wfactors_exist)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2730
    from this obtain ys
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2731
        where yscarr: "set ys \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2732
        and yfs: "wfactors G ys y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2733
        by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2734
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2735
    assume "a divides y"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2736
    hence ya: "fmset G as \<le> fmset G ys" by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2737
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2738
    assume "b divides y"
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2739
    hence yb: "fmset G bs \<le> fmset G ys" by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2740
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2741
    from ya yb csmset
35272
c283ae736bea switched notations for pointwise and multiset order
haftmann
parents: 32960
diff changeset
  2742
    have "fmset G cs \<le> fmset G ys"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2743
      apply (simp add: mset_le_def, clarify)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2744
      apply (case_tac "count (fmset G as) a < count (fmset G bs) a")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2745
       apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2746
      apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2747
    done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2748
    thus "c divides y" by (rule fmsubset_divides) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2749
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2750
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2751
  with ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2752
      show "\<exists>c. c \<in> carrier G \<and> c lcmof a b" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2753
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2754
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2755
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
  2756
subsection {* Conditions for Factoriality *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2757
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2758
subsubsection {* Gcd condition *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2759
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2760
lemma (in gcd_condition_monoid) division_weak_lower_semilattice [simp]:
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2761
  shows "weak_lower_semilattice (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2762
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2763
  interpret weak_partial_order "division_rel G" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2764
  show ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2765
  apply (unfold_locales, simp_all)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2766
  proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2767
    fix x y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2768
    assume carr: "x \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2769
    hence "\<exists>z. z \<in> carrier G \<and> z gcdof x y" by (rule gcdof_exists)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2770
    from this obtain z
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2771
        where zcarr: "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2772
        and isgcd: "z gcdof x y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2773
        by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2774
    with carr
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2775
    have "greatest (division_rel G) z (Lower (division_rel G) {x, y})"
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2776
        by (subst gcdof_greatestLower[symmetric], simp+)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2777
    thus "\<exists>z. greatest (division_rel G) z (Lower (division_rel G) {x, y})" by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2778
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2779
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2780
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2781
lemma (in gcd_condition_monoid) gcdof_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2782
  assumes a'a: "a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2783
    and agcd: "a gcdof b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2784
    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
  2785
  shows "a' gcdof b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2786
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2787
  note carr = a'carr carr'
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2788
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2789
  have "a' \<in> carrier G \<and> a' gcdof b c"
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2790
    apply (simp add: gcdof_greatestLower carr')
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2791
    apply (subst greatest_Lower_cong_l[of _ a])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2792
       apply (simp add: a'a)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2793
      apply (simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2794
     apply (simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2795
    apply (simp add: carr)
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2796
    apply (simp add: gcdof_greatestLower[symmetric] agcd carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2797
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2798
  thus ?thesis ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2799
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2800
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2801
lemma (in gcd_condition_monoid) gcd_closed [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2802
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2803
  shows "somegcd G a b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2804
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2805
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2806
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2807
    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
  2808
    apply (rule meet_closed[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2809
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2810
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2811
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2812
lemma (in gcd_condition_monoid) gcd_isgcd:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2813
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2814
  shows "(somegcd G a b) gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2815
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2816
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2817
  from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2818
  have "somegcd G a b \<in> carrier G \<and> (somegcd G a b) gcdof a b"
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2819
    apply (subst gcdof_greatestLower, simp, simp)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2820
    apply (simp add: somegcd_meet[OF carr] meet_def)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2821
    apply (rule inf_of_two_greatest[simplified], assumption+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2822
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2823
  thus "(somegcd G a b) gcdof a b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2824
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2825
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2826
lemma (in gcd_condition_monoid) gcd_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2827
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2828
  shows "\<exists>x\<in>carrier G. x = somegcd G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2829
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2830
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2831
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2832
    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
  2833
    apply (rule meet_closed[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2834
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2835
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2836
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2837
lemma (in gcd_condition_monoid) gcd_divides_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2838
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2839
  shows "(somegcd G a b) divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2840
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2841
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2842
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2843
    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
  2844
    apply (rule meet_left[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2845
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2846
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2847
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2848
lemma (in gcd_condition_monoid) gcd_divides_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2849
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2850
  shows "(somegcd G a b) divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2851
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2852
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2853
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2854
    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
  2855
    apply (rule meet_right[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2856
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2857
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2858
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2859
lemma (in gcd_condition_monoid) gcd_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2860
  assumes sub: "z divides x"  "z divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2861
    and L: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2862
  shows "z divides (somegcd G x y)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2863
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2864
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2865
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2866
    apply (simp add: somegcd_meet L)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2867
    apply (rule meet_le[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2868
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2869
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2870
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2871
lemma (in gcd_condition_monoid) gcd_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2872
  assumes xx': "x \<sim> x'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2873
    and carr: "x \<in> carrier G"  "x' \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2874
  shows "somegcd G x y \<sim> somegcd G x' y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2875
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2876
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2877
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2878
    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
  2879
    apply (rule meet_cong_l[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2880
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2881
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2882
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2883
lemma (in gcd_condition_monoid) gcd_cong_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2884
  assumes carr: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2885
    and yy': "y \<sim> y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2886
  shows "somegcd G x y \<sim> somegcd G x y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2887
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2888
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2889
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2890
    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
  2891
    apply (rule meet_cong_r[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2892
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2893
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2894
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2895
(*
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2896
lemma (in gcd_condition_monoid) asc_cong_gcd_l [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2897
  assumes carr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2898
  shows "asc_cong (\<lambda>a. somegcd G a b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2899
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2900
unfolding CONG_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2901
by clarsimp (blast intro: gcd_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2902
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2903
lemma (in gcd_condition_monoid) asc_cong_gcd_r [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2904
  assumes carr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2905
  shows "asc_cong (\<lambda>b. somegcd G a b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2906
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2907
unfolding CONG_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2908
by clarsimp (blast intro: gcd_cong_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2909
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2910
lemmas (in gcd_condition_monoid) asc_cong_gcd_split [simp] = 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2911
    assoc_split[OF _ asc_cong_gcd_l] assoc_split[OF _ asc_cong_gcd_r]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2912
*)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2913
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2914
lemma (in gcd_condition_monoid) gcdI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2915
  assumes dvd: "a divides b"  "a divides c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2916
    and others: "\<forall>y\<in>carrier G. y divides b \<and> y divides c \<longrightarrow> y divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2917
    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
  2918
  shows "a \<sim> somegcd G b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2919
apply (simp add: somegcd_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2920
apply (rule someI2_ex)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2921
 apply (rule exI[of _ a], simp add: isgcd_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2922
 apply (simp add: assms)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2923
apply (simp add: isgcd_def assms, clarify)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2924
apply (insert assms, blast intro: associatedI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2925
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2926
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2927
lemma (in gcd_condition_monoid) gcdI2:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2928
  assumes "a gcdof b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2929
    and "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
  2930
  shows "a \<sim> somegcd G b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2931
using assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2932
unfolding isgcd_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2933
by (blast intro: gcdI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2934
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2935
lemma (in gcd_condition_monoid) SomeGcd_ex:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2936
  assumes "finite A"  "A \<subseteq> carrier G"  "A \<noteq> {}"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2937
  shows "\<exists>x\<in> carrier G. x = SomeGcd G A"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2938
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2939
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2940
  show ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2941
    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
  2942
    apply (rule finite_inf_closed[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2943
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2944
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2945
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2946
lemma (in gcd_condition_monoid) gcd_assoc:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2947
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2948
  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
  2949
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2950
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2951
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2952
    apply (subst (2 3) somegcd_meet, (simp add: carr)+)
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2953
    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
  2954
    apply (rule weak_meet_assoc[simplified], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2955
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2956
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2957
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2958
lemma (in gcd_condition_monoid) gcd_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2959
  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
  2960
  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
  2961
proof - (* following Jacobson, Basic Algebra, p.140 *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2962
  let ?d = "somegcd G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2963
  let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2964
  note carr[simp] = acarr bcarr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2965
  have dcarr: "?d \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2966
  have ecarr: "?e \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2967
  note carr = carr dcarr ecarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2968
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2969
  have "?d divides a" by (simp add: gcd_divides_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2970
  hence cd'ca: "c \<otimes> ?d divides (c \<otimes> a)" by (simp add: divides_mult_lI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2971
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2972
  have "?d divides b" by (simp add: gcd_divides_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2973
  hence cd'cb: "c \<otimes> ?d divides (c \<otimes> b)" by (simp add: divides_mult_lI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2974
  
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2975
  from cd'ca cd'cb
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2976
      have cd'e: "c \<otimes> ?d divides ?e"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2977
      by (rule gcd_divides) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2978
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2979
  hence "\<exists>u. u \<in> carrier G \<and> ?e = c \<otimes> ?d \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2980
      by (elim dividesE, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2981
  from this obtain u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2982
      where ucarr[simp]: "u \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2983
      and e_cdu: "?e = c \<otimes> ?d \<otimes> u"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2984
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2985
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2986
  note carr = carr ucarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2987
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2988
  have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2989
  hence "\<exists>x. x \<in> carrier G \<and> c \<otimes> a = ?e \<otimes> x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2990
      by (elim dividesE, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2991
  from this obtain x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2992
      where xcarr: "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2993
      and ca_ex: "c \<otimes> a = ?e \<otimes> x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2994
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2995
  with e_cdu
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2996
      have ca_cdux: "c \<otimes> a = c \<otimes> ?d \<otimes> u \<otimes> x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2997
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2998
  from ca_cdux xcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2999
       have "c \<otimes> a = c \<otimes> (?d \<otimes> u \<otimes> x)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3000
  then have "a = ?d \<otimes> u \<otimes> x" by (rule l_cancel[of c a]) (simp add: xcarr)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3001
  hence du'a: "?d \<otimes> u divides a" by (rule dividesI[OF xcarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3002
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3003
  have "?e divides c \<otimes> b" by (intro gcd_divides_r, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3004
  hence "\<exists>x. x \<in> carrier G \<and> c \<otimes> b = ?e \<otimes> x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3005
      by (elim dividesE, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3006
  from this obtain x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3007
      where xcarr: "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3008
      and cb_ex: "c \<otimes> b = ?e \<otimes> x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3009
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3010
  with e_cdu
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3011
      have cb_cdux: "c \<otimes> b = c \<otimes> ?d \<otimes> u \<otimes> x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3012
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3013
  from cb_cdux xcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3014
      have "c \<otimes> b = c \<otimes> (?d \<otimes> u \<otimes> x)" by (simp add: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3015
  with xcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3016
      have "b = ?d \<otimes> u \<otimes> x" by (intro l_cancel[of c b], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3017
  hence du'b: "?d \<otimes> u divides b" by (intro dividesI[OF xcarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3018
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3019
  from du'a du'b carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3020
      have du'd: "?d \<otimes> u divides ?d"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3021
      by (intro gcd_divides, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3022
  hence uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3023
  proof (elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3024
    fix v
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3025
    assume vcarr[simp]: "v \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3026
    assume d: "?d = ?d \<otimes> u \<otimes> v"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3027
    have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3028
    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
  3029
    finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3030
    hence i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3031
    hence i1: "\<one> = v \<otimes> u" by (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3032
    from vcarr i1[symmetric] i2[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3033
        show "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3034
        by (unfold Units_def, simp, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3035
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3036
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3037
  from e_cdu uunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3038
      have "somegcd G (c \<otimes> a) (c \<otimes> b) \<sim> c \<otimes> somegcd G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3039
      by (intro associatedI2[of u], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3040
  from this[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3041
      show "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3042
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3043
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3044
lemma (in monoid) assoc_subst:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3045
  assumes ab: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3046
    and cP: "ALL a b. a : carrier G & b : carrier G & a \<sim> b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3047
      --> f a : carrier G & f b : carrier G & f a \<sim> f b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3048
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3049
  shows "f a \<sim> f b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3050
  using assms by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3051
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3052
lemma (in gcd_condition_monoid) relprime_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3053
  assumes abrelprime: "somegcd G a b \<sim> \<one>" and acrelprime: "somegcd G a c \<sim> \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3054
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3055
  shows "somegcd G a (b \<otimes> c) \<sim> \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3056
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3057
  have "c = c \<otimes> \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3058
  also from abrelprime[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3059
       have "\<dots> \<sim> c \<otimes> somegcd G a b"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  3060
         by (rule assoc_subst) (simp add: mult_cong_r)+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3061
  also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by (rule gcd_mult) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3062
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3063
       have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3064
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3065
  from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3066
       have a: "a \<sim> somegcd G a (c \<otimes> a)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3067
       by (fast intro: gcdI divides_prod_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3068
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3069
  have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)" by (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3070
  also from a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3071
       have "\<dots> \<sim> somegcd G (somegcd G a (c \<otimes> a)) (c \<otimes> b)"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  3072
         by (rule assoc_subst) (simp add: gcd_cong_l)+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3073
  also from gcd_assoc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3074
       have "\<dots> \<sim> somegcd G a (somegcd G (c \<otimes> a) (c \<otimes> b))"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3075
       by (rule assoc_subst) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3076
  also from c[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3077
       have "\<dots> \<sim> somegcd G a c"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  3078
         by (rule assoc_subst) (simp add: gcd_cong_r)+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3079
  also note acrelprime
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3080
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3081
       show "somegcd G a (b \<otimes> c) \<sim> \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3082
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3083
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3084
lemma (in gcd_condition_monoid) primeness_condition:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3085
  "primeness_condition_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3086
apply unfold_locales
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3087
apply (rule primeI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3088
 apply (elim irreducibleE, assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3089
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3090
  fix p a b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3091
  assume pcarr: "p \<in> carrier G" and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3092
    and pirr: "irreducible G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3093
    and pdvdab: "p divides a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3094
  from pirr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3095
      have pnunit: "p \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3096
      and r[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3097
      by - (fast elim: irreducibleE)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3098
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3099
  show "p divides a \<or> p divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3100
  proof (rule ccontr, clarsimp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3101
    assume npdvda: "\<not> p divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3102
    with pcarr acarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3103
    have "\<one> \<sim> somegcd G p a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3104
    apply (intro gcdI, simp, simp, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3105
      apply (fast intro: unit_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3106
     apply (fast intro: unit_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3107
    apply (clarsimp simp add: Unit_eq_dividesone[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3108
    apply (rule r, rule, assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3109
    apply (rule properfactorI, assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3110
    proof (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3111
      fix y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3112
      assume ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3113
      assume "p divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3114
      also assume "y divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3115
      finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3116
          have "p divides a" by (simp add: pcarr ycarr acarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3117
      with npdvda
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3118
          show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3119
    qed simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3120
    with pcarr acarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3121
        have pa: "somegcd G p a \<sim> \<one>" by (fast intro: associated_sym[of "\<one>"] gcd_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3122
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3123
    assume npdvdb: "\<not> p divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3124
    with pcarr bcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3125
    have "\<one> \<sim> somegcd G p b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3126
    apply (intro gcdI, simp, simp, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3127
      apply (fast intro: unit_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3128
     apply (fast intro: unit_divides)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3129
    apply (clarsimp simp add: Unit_eq_dividesone[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3130
    apply (rule r, rule, assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3131
    apply (rule properfactorI, assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3132
    proof (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3133
      fix y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3134
      assume ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3135
      assume "p divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3136
      also assume "y divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3137
      finally have "p divides b" by (simp add: pcarr ycarr bcarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3138
      with npdvdb
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3139
          show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3140
    qed simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3141
    with pcarr bcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3142
        have pb: "somegcd G p b \<sim> \<one>" by (fast intro: associated_sym[of "\<one>"] gcd_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3143
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3144
    from pcarr acarr bcarr pdvdab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3145
        have "p gcdof p (a \<otimes> b)" by (fast intro: isgcd_divides_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3146
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3147
    with pcarr acarr bcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3148
         have "p \<sim> somegcd G p (a \<otimes> b)" by (fast intro: gcdI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3149
    also from pa pb pcarr acarr bcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3150
         have "somegcd G p (a \<otimes> b) \<sim> \<one>" by (rule relprime_mult)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3151
    finally have "p \<sim> \<one>" by (simp add: pcarr acarr bcarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3152
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3153
    with pcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3154
        have "p \<in> Units G" by (fast intro: assoc_unit_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3155
    with pnunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3156
        show "False" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3157
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3158
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3159
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3160
sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3161
  by (rule primeness_condition)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3162
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3163
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3164
subsubsection {* Divisor chain condition *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3165
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3166
lemma (in divisor_chain_condition_monoid) wfactors_exist:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3167
  assumes acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3168
  shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3169
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3170
  have r[rule_format]: "a \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3171
    apply (rule wf_induct[OF division_wellfounded])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3172
  proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3173
    fix x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3174
    assume ih: "\<forall>y. (y, x) \<in> {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3175
                    \<longrightarrow> y \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3176
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3177
    show "x \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as x)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3178
    apply clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3179
    apply (cases "x \<in> Units G")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3180
     apply (rule exI[of _ "[]"], simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3181
    apply (cases "irreducible G x")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3182
     apply (rule exI[of _ "[x]"], simp add: wfactors_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3183
    proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3184
      assume xcarr: "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3185
        and xnunit: "x \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3186
        and xnirr: "\<not> irreducible G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3187
      hence "\<exists>y. y \<in> carrier G \<and> properfactor G y x \<and> y \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3188
        apply - apply (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3189
        apply (subgoal_tac "irreducible G x", simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3190
        apply (rule irreducibleI, simp, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3191
      done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3192
      from this obtain y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3193
          where ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3194
          and ynunit: "y \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3195
          and pfyx: "properfactor G y x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3196
          by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3197
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3198
      have ih':
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3199
           "\<And>y. \<lbrakk>y \<in> carrier G; properfactor G y x\<rbrakk>
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3200
                \<Longrightarrow> \<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3201
          by (rule ih[rule_format, simplified]) (simp add: xcarr)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3202
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3203
      from ycarr pfyx
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3204
          have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3205
          by (rule ih')
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3206
      from this obtain ys
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3207
          where yscarr: "set ys \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3208
          and yfs: "wfactors G ys y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3209
          by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3210
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3211
      from pfyx
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3212
          have "y divides x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3213
          and nyx: "\<not> y \<sim> x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3214
          by - (fast elim: properfactorE2)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3215
      hence "\<exists>z. z \<in> carrier G \<and> x = y \<otimes> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3216
          by (fast elim: dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3217
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3218
      from this obtain z
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3219
          where zcarr: "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3220
          and x: "x = y \<otimes> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3221
          by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3222
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3223
      from zcarr ycarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3224
      have "properfactor G z x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3225
        apply (subst x)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3226
        apply (intro properfactorI3[of _ _ y])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3227
         apply (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3228
        apply (simp add: ynunit)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3229
      done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3230
      with zcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3231
          have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3232
          by (rule ih')
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3233
      from this obtain zs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3234
          where zscarr: "set zs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3235
          and zfs: "wfactors G zs z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3236
          by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3237
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3238
      from yscarr zscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3239
          have xscarr: "set (ys@zs) \<subseteq> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3240
      from yfs zfs ycarr zcarr yscarr zscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3241
          have "wfactors G (ys@zs) (y\<otimes>z)" by (rule wfactors_mult)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3242
      hence "wfactors G (ys@zs) x" by (simp add: x)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3243
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3244
      from xscarr this
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3245
          show "\<exists>xs. set xs \<subseteq> carrier G \<and> wfactors G xs x" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3246
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3247
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3248
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3249
  from acarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3250
      show ?thesis by (rule r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3251
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3252
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3253
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3254
subsubsection {* Primeness condition *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3255
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3256
lemma (in comm_monoid_cancel) multlist_prime_pos:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3257
  assumes carr: "a \<in> carrier G"  "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3258
    and aprime: "prime G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3259
    and "a divides (foldr (op \<otimes>) as \<one>)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3260
  shows "\<exists>i<length as. a divides (as!i)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3261
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3262
  have r[rule_format]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3263
       "set as \<subseteq> carrier G \<and> a divides (foldr (op \<otimes>) as \<one>)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3264
        \<longrightarrow> (\<exists>i. i < length as \<and> a divides (as!i))"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3265
    apply (induct as)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3266
     apply clarsimp defer 1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3267
     apply clarsimp defer 1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3268
  proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3269
    assume "a divides \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3270
    with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3271
        have "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3272
        by (fast intro: divides_unit[of a \<one>])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3273
    with aprime
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3274
        show "False" by (elim primeE, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3275
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3276
    fix aa as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3277
    assume ih[rule_format]: "a divides foldr op \<otimes> as \<one> \<longrightarrow> (\<exists>i<length as. a divides as ! i)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3278
      and carr': "aa \<in> carrier G"  "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3279
      and "a divides aa \<otimes> foldr op \<otimes> as \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3280
    with carr aprime
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3281
        have "a divides aa \<or> a divides foldr op \<otimes> as \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3282
        by (intro prime_divides) simp+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3283
    moreover {
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3284
      assume "a divides aa"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3285
      hence p1: "a divides (aa#as)!0" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3286
      have "0 < Suc (length as)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3287
      with p1 have "\<exists>i<Suc (length as). a divides (aa # as) ! i" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3288
    }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3289
    moreover {
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3290
      assume "a divides foldr op \<otimes> as \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3291
      hence "\<exists>i. i < length as \<and> a divides as ! i" by (rule ih)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3292
      from this obtain i where "a divides as ! i" and len: "i < length as" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3293
      hence p1: "a divides (aa#as) ! (Suc i)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3294
      from len have "Suc i < Suc (length as)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3295
      with p1 have "\<exists>i<Suc (length as). a divides (aa # as) ! i" by force
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3296
   }
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3297
   ultimately
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3298
      show "\<exists>i<Suc (length as). a divides (aa # as) ! i" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3299
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3300
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3301
  from assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3302
      show ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3303
      by (intro r, safe)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3304
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3305
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3306
lemma (in primeness_condition_monoid) wfactors_unique__hlp_induct:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3307
  "\<forall>a as'. a \<in> carrier G \<and> set as \<subseteq> carrier G \<and> set as' \<subseteq> carrier G \<and> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3308
           wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3309
apply (induct as)
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3310
apply (metis Units_one_closed essentially_equal_def foldr.simps(1) is_monoid_cancel listassoc_refl monoid_cancel.assoc_unit_r perm_refl unit_wfactors_empty wfactorsE)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3311
apply clarsimp 
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3312
proof -
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3313
 fix a as ah as'
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3314
  assume ih[rule_format]: 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3315
         "\<forall>a as'. a \<in> carrier G \<and> set as' \<subseteq> carrier G \<and> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3316
                  wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3317
    and acarr: "a \<in> carrier G" and ahcarr: "ah \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3318
    and ascarr: "set as \<subseteq> carrier G" and as'carr: "set as' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3319
    and afs: "wfactors G (ah # as) a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3320
    and afs': "wfactors G as' a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3321
  hence ahdvda: "ah divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3322
      by (intro wfactors_dividesI[of "ah#as" "a"], simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3323
  hence "\<exists>a'\<in> carrier G. a = ah \<otimes> a'" by (fast elim: dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3324
  from this obtain a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3325
      where a'carr: "a' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3326
      and a: "a = ah \<otimes> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3327
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3328
  have a'fs: "wfactors G as a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3329
    apply (rule wfactorsE[OF afs], rule wfactorsI, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3330
    apply (simp add: a, insert ascarr a'carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3331
    apply (intro assoc_l_cancel[of ah _ a'] multlist_closed ahcarr, assumption+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3332
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3333
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3334
  from afs have ahirr: "irreducible G ah" by (elim wfactorsE, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3335
  with ascarr have ahprime: "prime G ah" by (intro irreducible_prime ahcarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3336
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3337
  note carr [simp] = acarr ahcarr ascarr as'carr a'carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3338
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3339
  note ahdvda
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3340
  also from afs'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3341
       have "a divides (foldr (op \<otimes>) as' \<one>)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3342
       by (elim wfactorsE associatedE, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3343
  finally have "ah divides (foldr (op \<otimes>) as' \<one>)" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3344
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3345
  with ahprime
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3346
      have "\<exists>i<length as'. ah divides as'!i"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3347
      by (intro multlist_prime_pos, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3348
  from this obtain i
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3349
      where len: "i<length as'" and ahdvd: "ah divides as'!i"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3350
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3351
  from afs' carr have irrasi: "irreducible G (as'!i)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3352
      by (fast intro: nth_mem[OF len] elim: wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3353
  from len carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3354
      have asicarr[simp]: "as'!i \<in> carrier G" by (unfold set_conv_nth, force)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3355
  note carr = carr asicarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3356
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3357
  from ahdvd have "\<exists>x \<in> carrier G. as'!i = ah \<otimes> x" by (fast elim: dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3358
  from this obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3359
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3360
  with carr irrasi[simplified asi]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3361
      have asiah: "as'!i \<sim> ah" apply -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3362
    apply (elim irreducible_prodE[of "ah" "x"], assumption+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3363
     apply (rule associatedI2[of x], assumption+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3364
    apply (rule irreducibleE[OF ahirr], simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3365
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3366
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3367
  note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as']
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3368
  note partscarr [simp] = setparts[THEN subset_trans[OF _ as'carr]]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3369
  note carr = carr partscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3370
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3371
  have "\<exists>aa_1. aa_1 \<in> carrier G \<and> wfactors G (take i as') aa_1"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3372
    apply (intro wfactors_prod_exists)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3373
    using setparts afs' by (fast elim: wfactorsE, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3374
  from this obtain aa_1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3375
      where aa1carr: "aa_1 \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3376
      and aa1fs: "wfactors G (take i as') aa_1"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3377
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3378
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3379
  have "\<exists>aa_2. aa_2 \<in> carrier G \<and> wfactors G (drop (Suc i) as') aa_2"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3380
    apply (intro wfactors_prod_exists)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3381
    using setparts afs' by (fast elim: wfactorsE, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3382
  from this obtain aa_2
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3383
      where aa2carr: "aa_2 \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3384
      and aa2fs: "wfactors G (drop (Suc i) as') aa_2"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3385
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3386
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3387
  note carr = carr aa1carr[simp] aa2carr[simp]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3388
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3389
  from aa1fs aa2fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3390
      have v1: "wfactors G (take i as' @ drop (Suc i) as') (aa_1 \<otimes> aa_2)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3391
      by (intro wfactors_mult, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3392
  hence v1': "wfactors G (as'!i # take i as' @ drop (Suc i) as') (as'!i \<otimes> (aa_1 \<otimes> aa_2))"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3393
      apply (intro wfactors_mult_single)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3394
      using setparts afs'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3395
      by (fast intro: nth_mem[OF len] elim: wfactorsE, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3396
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3397
  from aa2carr carr aa1fs aa2fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3398
      have "wfactors G (as'!i # drop (Suc i) as') (as'!i \<otimes> aa_2)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3399
    apply (intro wfactors_mult_single)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3400
        apply (rule wfactorsE[OF afs'], fast intro: nth_mem[OF len])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3401
       apply (fast intro: nth_mem[OF len])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3402
      apply fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3403
     apply fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3404
    apply assumption
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3405
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3406
  with len carr aa1carr aa2carr aa1fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3407
      have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \<otimes> (as'!i \<otimes> aa_2))"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3408
    apply (intro wfactors_mult)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3409
         apply fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3410
        apply (simp, (fast intro: nth_mem[OF len])?)+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3411
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3412
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3413
  from len
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3414
      have as': "as' = (take i as' @ as'!i # drop (Suc i) as')"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3415
      by (simp add: drop_Suc_conv_tl)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3416
  with carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3417
      have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3418
      by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3419
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3420
  with v2 afs' carr aa1carr aa2carr nth_mem[OF len]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3421
      have "aa_1 \<otimes> (as'!i \<otimes> aa_2) \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3422
    apply (intro ee_wfactorsD[of "take i as' @ as'!i # drop (Suc i) as'"  "as'"])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3423
          apply fast+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3424
        apply (simp, fast)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3425
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3426
  then
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3427
  have t1: "as'!i \<otimes> (aa_1 \<otimes> aa_2) \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3428
    apply (simp add: m_assoc[symmetric])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3429
    apply (simp add: m_comm)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3430
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3431
  from carr asiah
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3432
  have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> as'!i \<otimes> (aa_1 \<otimes> aa_2)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3433
      apply (intro mult_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3434
      apply (fast intro: associated_sym, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3435
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3436
  also note t1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3437
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3438
      have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3439
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3440
  with carr aa1carr aa2carr a'carr nth_mem[OF len]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3441
      have a': "aa_1 \<otimes> aa_2 \<sim> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3442
      by (simp add: a, fast intro: assoc_l_cancel[of ah _ a'])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3443
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3444
  note v1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3445
  also note a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3446
  finally have "wfactors G (take i as' @ drop (Suc i) as') a'" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3447
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3448
  from a'fs this carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3449
      have "essentially_equal G as (take i as' @ drop (Suc i) as')"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3450
      by (intro ih[of a']) simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3451
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3452
  hence ee1: "essentially_equal G (ah # as) (ah # take i as' @ drop (Suc i) as')"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3453
    apply (elim essentially_equalE) apply (fastsimp intro: essentially_equalI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3454
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3455
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3456
  from carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3457
  have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as')
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3458
                                 (as' ! i # take i as' @ drop (Suc i) as')"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3459
  proof (intro essentially_equalI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3460
    show "ah # take i as' @ drop (Suc i) as' <~~> ah # take i as' @ drop (Suc i) as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3461
        by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3462
  next show "ah # take i as' @ drop (Suc i) as' [\<sim>]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3463
       as' ! i # take i as' @ drop (Suc i) as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3464
    apply (simp add: list_all2_append)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3465
    apply (simp add: asiah[symmetric] ahcarr asicarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3466
    done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3467
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3468
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3469
  note ee1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3470
  also note ee2
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3471
  also have "essentially_equal G (as' ! i # take i as' @ drop (Suc i) as')
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3472
                                 (take i as' @ as' ! i # drop (Suc i) as')"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3473
    apply (intro essentially_equalI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3474
    apply (subgoal_tac "as' ! i # take i as' @ drop (Suc i) as' <~~> 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3475
                        take i as' @ as' ! i # drop (Suc i) as'")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3476
apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3477
     apply (rule perm_append_Cons)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3478
    apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3479
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3480
  finally
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3481
      have "essentially_equal G (ah # as) 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3482
                                (take i as' @ as' ! i # drop (Suc i) as')" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3483
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3484
  thus "essentially_equal G (ah # as) as'" by (subst as', assumption)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3485
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3486
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3487
lemma (in primeness_condition_monoid) wfactors_unique:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3488
  assumes "wfactors G as a"  "wfactors G as' a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3489
    and "a \<in> carrier G"  "set as \<subseteq> carrier G"  "set as' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3490
  shows "essentially_equal G as as'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3491
apply (rule wfactors_unique__hlp_induct[rule_format, of a])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3492
apply (simp add: assms)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3493
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3494
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3495
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3496
subsubsection {* Application to factorial monoids *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3497
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3498
text {* Number of factors for wellfoundedness *}
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3499
35848
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  3500
definition
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  3501
  factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" where
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  3502
  "factorcount G a =
5443079512ea slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents: 35847
diff changeset
  3503
    (THE c. (ALL 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
  3504
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3505
lemma (in monoid) ee_length:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3506
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3507
  shows "length as = length bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3508
apply (rule essentially_equalE[OF ee])
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3509
apply (metis list_all2_conv_all_nth perm_length)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3510
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3511
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3512
lemma (in factorial_monoid) factorcount_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3513
  assumes carr[simp]: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3514
  shows "EX c. ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3515
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3516
  have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (intro wfactors_exist, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3517
  from this obtain as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3518
      where ascarr[simp]: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3519
      and afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3520
      by (auto simp del: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3521
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3522
  have "ALL 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
  3523
    by (metis afs ascarr assms ee_length wfactors_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3524
  thus "EX c. ALL as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> c = length as'" ..
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3525
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3526
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3527
lemma (in factorial_monoid) factorcount_unique:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3528
  assumes afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3529
    and acarr[simp]: "a \<in> carrier G" and ascarr[simp]: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3530
  shows "factorcount G a = length as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3531
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3532
  have "EX ac. ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" by (rule factorcount_exists, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3533
  from this obtain ac where
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3534
      alen: "ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3535
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3536
  have ac: "ac = factorcount G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3537
    apply (simp add: factorcount_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3538
    apply (rule theI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3539
      apply (rule alen)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3540
     apply (elim allE[of _ "as"], rule allE[OF alen, of "as"], simp add: ascarr afs)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3541
    apply (elim allE[of _ "as"], rule allE[OF alen, of "as"], simp add: ascarr afs)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3542
  done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3543
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3544
  from ascarr afs have "ac = length as" by (iprover intro: alen[rule_format])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3545
  with ac show ?thesis by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3546
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3547
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3548
lemma (in factorial_monoid) divides_fcount:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3549
  assumes dvd: "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3550
    and acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3551
  shows "factorcount G a <= factorcount G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3552
apply (rule dividesE[OF dvd])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3553
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3554
  fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3555
  from assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3556
      have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3557
  from this obtain as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3558
      where ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3559
      and afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3560
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3561
  with acarr have fca: "factorcount G a = length as" by (intro factorcount_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3562
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3563
  assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3564
  hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3565
  from this obtain cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3566
      where cscarr: "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3567
      and cfs: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3568
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3569
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3570
  note [simp] = acarr bcarr ccarr ascarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3571
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3572
  assume b: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3573
  from afs cfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3574
      have "wfactors G (as@cs) (a \<otimes> c)" by (intro wfactors_mult, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3575
  with b have "wfactors G (as@cs) b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3576
  hence "factorcount G b = length (as@cs)" by (intro factorcount_unique, simp+)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3577
  hence "factorcount G b = length as + length cs" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3578
  with fca show ?thesis by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3579
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3580
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3581
lemma (in factorial_monoid) associated_fcount:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3582
  assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3583
    and asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3584
  shows "factorcount G a = factorcount G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3585
apply (rule associatedE[OF asc])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3586
apply (drule divides_fcount[OF _ acarr bcarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3587
apply (drule divides_fcount[OF _ bcarr acarr])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3588
apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3589
done
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3590
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3591
lemma (in factorial_monoid) properfactor_fcount:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3592
  assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3593
    and pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3594
  shows "factorcount G a < factorcount G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3595
apply (rule properfactorE[OF pf], elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3596
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3597
  fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3598
  from assms
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3599
  have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3600
  from this obtain as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3601
      where ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3602
      and afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3603
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3604
  with acarr have fca: "factorcount G a = length as" by (intro factorcount_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3605
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3606
  assume ccarr: "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3607
  hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3608
  from this obtain cs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3609
      where cscarr: "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3610
      and cfs: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3611
      by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3612
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3613
  assume b: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3614
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3615
  have "wfactors G (as@cs) (a \<otimes> c)" by (rule wfactors_mult) fact+
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3616
  with b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3617
      have "wfactors G (as@cs) b" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3618
  with ascarr cscarr bcarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3619
      have "factorcount G b = length (as@cs)" by (simp add: factorcount_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3620
  hence fcb: "factorcount G b = length as + length cs" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3621
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3622
  assume nbdvda: "\<not> b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3623
  have "c \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3624
  proof (rule ccontr, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3625
    assume cunit:"c \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3626
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3627
    have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c" by (simp add: b)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3628
    also with ccarr acarr cunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3629
        have "\<dots> = a \<otimes> (c \<otimes> inv c)" by (fast intro: m_assoc)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3630
    also with ccarr cunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3631
        have "\<dots> = a \<otimes> \<one>" by (simp add: Units_r_inv)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3632
    also with acarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3633
        have "\<dots> = a" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3634
    finally have "a = b \<otimes> inv c" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3635
    with ccarr cunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3636
    have "b divides a" by (fast intro: dividesI[of "inv c"])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3637
    with nbdvda show False by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3638
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3639
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3640
  with cfs have "length cs > 0"
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3641
    apply -
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3642
    apply (rule ccontr, simp)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3643
    apply (metis Units_one_closed ccarr cscarr l_one one_closed properfactorI3 properfactor_fmset unit_wfactors)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3644
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3645
  with fca fcb show ?thesis by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3646
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3647
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3648
sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3649
apply unfold_locales
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3650
apply (rule wfUNIVI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3651
apply (rule measure_induct[of "factorcount G"])
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3652
apply simp
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3653
apply (metis properfactor_fcount)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3654
done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3655
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3656
sublocale factorial_monoid \<subseteq> primeness_condition_monoid
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
  3657
  proof qed (rule irreducible_is_prime)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3658
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3659
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3660
lemma (in factorial_monoid) primeness_condition:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3661
  shows "primeness_condition_monoid G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
  3662
  ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3663
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3664
lemma (in factorial_monoid) gcd_condition [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3665
  shows "gcd_condition_monoid G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
  3666
  proof qed (rule gcdof_exists)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3667
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3668
sublocale factorial_monoid \<subseteq> gcd_condition_monoid
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
  3669
  proof qed (rule gcdof_exists)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3670
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3671
lemma (in factorial_monoid) division_weak_lattice [simp]:
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3672
  shows "weak_lattice (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3673
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3674
  interpret weak_lower_semilattice "division_rel G" by simp
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3675
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3676
  show "weak_lattice (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3677
  apply (unfold_locales, simp_all)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3678
  proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3679
    fix x y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3680
    assume carr: "x \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3681
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3682
    hence "\<exists>z. z \<in> carrier G \<and> z lcmof x y" by (rule lcmof_exists)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3683
    from this obtain z
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3684
        where zcarr: "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3685
        and isgcd: "z lcmof x y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3686
        by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3687
    with carr
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3688
    have "least (division_rel G) z (Upper (division_rel G) {x, y})"
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3689
        by (simp add: lcmof_leastUpper[symmetric])
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3690
    thus "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})" by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3691
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3692
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3693
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3694
27717
21bbd410ba04 Generalised polynomial lemmas from cring to ring.
ballarin
parents: 27713
diff changeset
  3695
subsection {* Factoriality Theorems *}
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3696
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3697
theorem factorial_condition_one: (* Jacobson theorem 2.21 *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3698
  shows "(divisor_chain_condition_monoid G \<and> primeness_condition_monoid G) = 
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3699
         factorial_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3700
apply rule
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3701
proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3702
  assume dcc: "divisor_chain_condition_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3703
     and pc: "primeness_condition_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3704
  interpret divisor_chain_condition_monoid "G" by (rule dcc)
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3705
  interpret primeness_condition_monoid "G" by (rule pc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3706
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3707
  show "factorial_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3708
      by (fast intro: factorial_monoidI wfactors_exist wfactors_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3709
next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3710
  assume fm: "factorial_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3711
  interpret factorial_monoid "G" by (rule fm)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3712
  show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3713
      by rule unfold_locales
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3714
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3715
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3716
theorem factorial_condition_two: (* Jacobson theorem 2.22 *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3717
  shows "(divisor_chain_condition_monoid G \<and> gcd_condition_monoid G) = factorial_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3718
apply rule
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3719
proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3720
    assume dcc: "divisor_chain_condition_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3721
     and gc: "gcd_condition_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3722
  interpret divisor_chain_condition_monoid "G" by (rule dcc)
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3723
  interpret gcd_condition_monoid "G" by (rule gc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3724
  show "factorial_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3725
      by (simp add: factorial_condition_one[symmetric], rule, unfold_locales)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3726
next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3727
  assume fm: "factorial_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3728
  interpret factorial_monoid "G" by (rule fm)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3729
  show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3730
      by rule unfold_locales
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3731
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3732
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3733
end