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