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.
ballari