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