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