src/HOL/Algebra/Divisibility.thy
author haftmann
Thu, 23 Nov 2017 17:03:27 +0000
changeset 67087 733017b19de9
parent 66579 2db3fe23fdaf
child 67343 f0f13aa282f4
permissions -rw-r--r--
generalized more lemmas
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
66579
2db3fe23fdaf Revert 5a42eddc11c1.
ballarin
parents: 66501
diff changeset
     9
  imports "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)
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
   757
  apply (metis assms(2,3) associatedI2 m_closed properfactor_cong_r)
63832
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"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1007
  from perm_assoc_switch_r [OF this] obtain fs' where a: "as [\<sim>] fs'" and p: "fs' <~~> bs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1008
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1009
  from p have "bs <~~> fs'" by (rule perm_sym)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1010
  with a[symmetric] carr show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1011
    by (iprover intro: essentially_equalI perm_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1012
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1013
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1014
lemma (in monoid) ee_trans [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1015
  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
  1016
    and ascarr: "set as \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1017
    and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1018
    and cscarr: "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1019
  shows "essentially_equal G as cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1020
  using ab bc
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1021
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1022
  fix abs bcs
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1023
  assume "abs [\<sim>] bs" and pb: "bs <~~> bcs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1024
  from perm_assoc_switch [OF this] obtain bs' where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1025
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1026
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1027
  assume "as <~~> abs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1028
  with p have pp: "as <~~> bs'" by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1029
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1030
  from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1031
  from pb bscarr have c2: "set bcs \<subseteq> carrier G" by (rule perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1032
  note a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1033
  also assume "bcs [\<sim>] cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1034
  finally (listassoc_trans) have "bs' [\<sim>] cs" by (simp add: c1 c2 cscarr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1035
  with pp show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1036
    by (rule essentially_equalI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1037
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1038
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1039
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1040
subsubsection \<open>Properties of lists of elements\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1041
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1042
text \<open>Multiplication of factors in a list\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1043
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1044
lemma (in monoid) multlist_closed [simp, intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1045
  assumes ascarr: "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1046
  shows "foldr (op \<otimes>) fs \<one> \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1047
  using ascarr by (induct fs) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1048
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1049
lemma  (in comm_monoid) multlist_dividesI (*[intro]*):
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1050
  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
  1051
  shows "f divides (foldr (op \<otimes>) fs \<one>)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1052
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1053
  apply (induct fs)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1054
   apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1055
  apply (case_tac "f = a")
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1056
   apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1057
   apply (fast intro: dividesI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1058
  apply clarsimp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1059
  apply (metis assms(2) divides_prod_l multlist_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1060
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1061
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1062
lemma (in comm_monoid_cancel) multlist_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1063
  assumes "fs [\<sim>] fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1064
    and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1065
  shows "foldr (op \<otimes>) fs \<one> \<sim> foldr (op \<otimes>) fs' \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1066
  using assms
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1067
proof (induct fs arbitrary: fs', simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1068
  case (Cons a as fs')
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1069
  then show ?case
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1070
    apply (induct fs', simp)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1071
  proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1072
    fix b bs
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1073
    assume "a \<sim> b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1074
      and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1075
      and ascarr: "set as \<subseteq> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1076
    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
  1077
      by (fast intro: mult_cong_l)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1078
    also
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1079
    assume "as [\<sim>] bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1080
      and bscarr: "set bs \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1081
      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
  1082
    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
  1083
    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
  1084
      by (fast intro: mult_cong_r)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1085
    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
  1086
      by (simp add: ascarr bscarr acarr bcarr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1087
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1088
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1089
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1090
lemma (in comm_monoid) multlist_perm_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1091
  assumes prm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1092
    and ascarr: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1093
  shows "foldr (op \<otimes>) as \<one> = foldr (op \<otimes>) bs \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1094
  using prm ascarr
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1095
  apply (induct, simp, clarsimp simp add: m_ac, clarsimp)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1096
proof clarsimp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1097
  fix xs ys zs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1098
  assume "xs <~~> ys"  "set xs \<subseteq> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1099
  then have "set ys \<subseteq> carrier G" by (rule perm_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1100
  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
  1101
  ultimately show "foldr op \<otimes> ys \<one> = foldr op \<otimes> zs \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1102
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1103
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1104
lemma (in comm_monoid_cancel) multlist_ee_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1105
  assumes "essentially_equal G fs fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1106
    and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1107
  shows "foldr (op \<otimes>) fs \<one> \<sim> foldr (op \<otimes>) fs' \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1108
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1109
  apply (elim essentially_equalE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1110
  apply (simp add: multlist_perm_cong multlist_listassoc_cong perm_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1111
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1112
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1113
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1114
subsubsection \<open>Factorization in irreducible elements\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1115
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1116
lemma wfactorsI:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1117
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1118
  assumes "\<forall>f\<in>set fs. irreducible G f"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1119
    and "foldr (op \<otimes>) fs \<one> \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1120
  shows "wfactors G fs a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1121
  using assms unfolding wfactors_def by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1122
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1123
lemma wfactorsE:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1124
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1125
  assumes wf: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1126
    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
  1127
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1128
  using wf unfolding wfactors_def by (fast dest: e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1129
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1130
lemma (in monoid) factorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1131
  assumes "\<forall>f\<in>set fs. irreducible G f"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1132
    and "foldr (op \<otimes>) fs \<one> = a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1133
  shows "factors G fs a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1134
  using assms unfolding factors_def by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1135
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1136
lemma factorsE:
28599
12d914277b8d Removed 'includes'.
ballarin
parents: 27717
diff changeset
  1137
  fixes G (structure)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1138
  assumes f: "factors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1139
    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
  1140
  shows "P"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1141
  using f unfolding factors_def by (simp add: e)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1142
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1143
lemma (in monoid) factors_wfactors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1144
  assumes "factors G as a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1145
  shows "wfactors G as a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1146
  using assms by (blast elim: factorsE intro: wfactorsI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1147
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1148
lemma (in monoid) wfactors_factors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1149
  assumes "wfactors G as a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1150
  shows "\<exists>a'. factors G as a' \<and> a' \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1151
  using assms by (blast elim: wfactorsE intro: factorsI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1152
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1153
lemma (in monoid) factors_closed [dest]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1154
  assumes "factors G fs a" and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1155
  shows "a \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1156
  using assms by (elim factorsE, clarsimp)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1157
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1158
lemma (in monoid) nunit_factors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1159
  assumes anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1160
    and fs: "factors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1161
  shows "length as > 0"
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1162
proof -
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1163
  from anunit Units_one_closed have "a \<noteq> \<one>" by auto
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1164
  with fs show ?thesis by (auto elim: factorsE)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  1165
qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1166
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1167
lemma (in monoid) unit_wfactors [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1168
  assumes aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1169
  shows "wfactors G [] a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1170
  using aunit by (intro wfactorsI) (simp, simp add: Units_assoc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1171
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1172
lemma (in comm_monoid_cancel) unit_wfactors_empty:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1173
  assumes aunit: "a \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1174
    and wf: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1175
    and carr[simp]: "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1176
  shows "fs = []"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1177
proof (cases fs)
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1178
  case Nil
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1179
  then show ?thesis .
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1180
next
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1181
  case fs: (Cons f fs')
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1182
  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
  1183
    by (simp_all add: fs)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1184
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1185
  from fs wf have "irreducible G f" by (simp add: wfactors_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1186
  then have fnunit: "f \<notin> Units G" by (fast elim: irreducibleE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1187
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1188
  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
  1189
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1190
  note aunit
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1191
  also from fs wf
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1192
  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
  1193
  have "a \<sim> f \<otimes> foldr (op \<otimes>) fs' \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1194
    by (simp add: Units_closed[OF aunit] a[symmetric])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1195
  finally have "f \<otimes> foldr (op \<otimes>) fs' \<one> \<in> Units G" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1196
  then have "f \<in> Units G" by (intro unit_factor[of f], simp+)
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  1197
  with fnunit show ?thesis by contradiction
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1198
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1199
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1200
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1201
text \<open>Comparing wfactors\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1202
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1203
lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1204
  assumes fact: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1205
    and asc: "fs [\<sim>] fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1206
    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
  1207
  shows "wfactors G fs' a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1208
  using fact
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1209
  apply (elim wfactorsE, intro wfactorsI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1210
   apply (metis assms(2) assms(4) assms(5) irrlist_listassoc_cong)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1211
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1212
  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
  1213
    by (simp add: multlist_listassoc_cong carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1214
  also assume "foldr op \<otimes> fs \<one> \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1215
  finally show "foldr op \<otimes> fs' \<one> \<sim> a" by (simp add: carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1216
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1217
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1218
lemma (in comm_monoid) wfactors_perm_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1219
  assumes "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1220
    and "fs <~~> fs'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1221
    and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1222
  shows "wfactors G fs' a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1223
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1224
  apply (elim wfactorsE, intro wfactorsI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1225
   apply (rule irrlist_perm_cong, assumption+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1226
  apply (simp add: multlist_perm_cong[symmetric])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1227
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1228
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1229
lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1230
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1231
    and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1232
    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
  1233
  shows "wfactors G as b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1234
  using ee
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1235
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1236
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1237
  assume prm: "as <~~> fs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1238
  with carr have fscarr: "set fs \<subseteq> carrier G" by (simp add: perm_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1239
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1240
  note bfs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1241
  also assume [symmetric]: "fs [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1242
  also (wfactors_listassoc_cong_l)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1243
  note prm[symmetric]
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1244
  finally (wfactors_perm_cong_l)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1245
  show "wfactors G as b" by (simp add: carr fscarr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1246
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1247
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1248
lemma (in monoid) wfactors_cong_r [trans]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1249
  assumes fac: "wfactors G fs a" and aa': "a \<sim> a'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1250
    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
  1251
  shows "wfactors G fs a'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1252
  using fac
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1253
proof (elim wfactorsE, intro wfactorsI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1254
  assume "foldr op \<otimes> fs \<one> \<sim> a" also note aa'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1255
  finally show "foldr op \<otimes> fs \<one> \<sim> a'" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1256
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1257
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1258
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1259
subsubsection \<open>Essentially equal factorizations\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1260
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1261
lemma (in comm_monoid_cancel) unitfactor_ee:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1262
  assumes uunit: "u \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1263
    and carr: "set as \<subseteq> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1264
  shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1265
    (is "essentially_equal G ?as' as")
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1266
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1267
  apply (intro essentially_equalI[of _ ?as'], simp)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1268
  apply (cases as, simp)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1269
  apply (clarsimp, fast intro: associatedI2[of u])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1270
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1271
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1272
lemma (in comm_monoid_cancel) factors_cong_unit:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1273
  assumes uunit: "u \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1274
    and anunit: "a \<notin> Units G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1275
    and afs: "factors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1276
    and ascarr: "set as \<subseteq> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1277
  shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1278
    (is "factors G ?as' ?a'")
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1279
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1280
  apply (elim factorsE, clarify)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1281
  apply (cases as)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1282
   apply (simp add: nunit_factors)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1283
  apply clarsimp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1284
  apply (elim factorsE, intro factorsI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1285
   apply (clarsimp, fast intro: irreducible_prod_rI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1286
  apply (simp add: m_ac Units_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1287
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1288
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1289
lemma (in comm_monoid) perm_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1290
  assumes prm: "as <~~> bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1291
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1292
    and bfs: "wfactors G bs b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1293
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1294
    and ascarr [simp]: "set as \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1295
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1296
  using afs bfs
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1297
proof (elim wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1298
  from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1299
  assume "foldr op \<otimes> as \<one> \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1300
  then have "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1301
  also from prm
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1302
  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
  1303
  also assume "foldr op \<otimes> bs \<one> \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1304
  finally show "a \<sim> b" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1305
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1306
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1307
lemma (in comm_monoid_cancel) listassoc_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1308
  assumes assoc: "as [\<sim>] bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1309
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1310
    and bfs: "wfactors G bs b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1311
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1312
    and [simp]: "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1313
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1314
  using afs bfs
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1315
proof (elim wfactorsE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1316
  assume "foldr op \<otimes> as \<one> \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1317
  then have "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1318
  also from assoc
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1319
  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
  1320
  also assume "foldr op \<otimes> bs \<one> \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1321
  finally show "a \<sim> b" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1322
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1323
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1324
lemma (in comm_monoid_cancel) ee_wfactorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1325
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1326
    and afs: "wfactors G as a" and bfs: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1327
    and [simp]: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1328
    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
  1329
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1330
  using ee
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1331
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1332
  fix fs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1333
  assume prm: "as <~~> fs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1334
  then have as'carr[simp]: "set fs \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1335
    by (simp add: perm_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1336
  from afs prm have afs': "wfactors G fs a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1337
    by (rule wfactors_perm_cong_l) simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1338
  assume "fs [\<sim>] bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1339
  from this afs' bfs show "a \<sim> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1340
    by (rule listassoc_wfactorsD) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1341
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1342
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1343
lemma (in comm_monoid_cancel) ee_factorsD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1344
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1345
    and afs: "factors G as a" and bfs:"factors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1346
    and "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1347
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1348
  using assms by (blast intro: factors_wfactors dest: ee_wfactorsD)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1349
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1350
lemma (in factorial_monoid) ee_factorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1351
  assumes ab: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1352
    and afs: "factors G as a" and anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1353
    and bfs: "factors G bs b" and bnunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1354
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1355
  shows "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1356
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1357
  note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1358
    factors_closed[OF bfs bscarr] bscarr[THEN subsetD]
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1359
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1360
  from ab carr obtain u where uunit: "u \<in> Units G" and a: "a = b \<otimes> u"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1361
    by (elim associatedE2)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1362
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1363
  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
  1364
    (is "essentially_equal G ?bs' bs")
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1365
    by (rule unitfactor_ee)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1366
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1367
  from bscarr uunit have bs'carr: "set ?bs' \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1368
    by (cases bs) (simp_all add: Units_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1369
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1370
  from uunit bnunit bfs bscarr have fac: "factors G ?bs' (b \<otimes> u)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1371
    by (rule factors_cong_unit)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1372
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1373
  from afs fac[simplified a[symmetric]] ascarr bs'carr anunit
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1374
  have "essentially_equal G as ?bs'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1375
    by (blast intro: factors_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1376
  also note ee
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1377
  finally show "essentially_equal G as bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1378
    by (simp add: ascarr bscarr bs'carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1379
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1380
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1381
lemma (in factorial_monoid) ee_wfactorsI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1382
  assumes asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1383
    and asf: "wfactors G as a" and bsf: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1384
    and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1385
    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
  1386
  shows "essentially_equal G as bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1387
  using assms
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1388
proof (cases "a \<in> Units G")
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1389
  case aunit: True
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1390
  also note asc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1391
  finally have bunit: "b \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1392
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1393
  from aunit asf ascarr have e: "as = []"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1394
    by (rule unit_wfactors_empty)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1395
  from bunit bsf bscarr have e': "bs = []"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1396
    by (rule unit_wfactors_empty)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1397
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1398
  have "essentially_equal G [] []"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1399
    by (fast intro: essentially_equalI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1400
  then show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1401
    by (simp add: e e')
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1402
next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1403
  case anunit: False
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1404
  have bnunit: "b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1405
  proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1406
    assume "b \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1407
    also note asc[symmetric]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1408
    finally have "a \<in> Units G" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1409
    with anunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1410
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1411
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1412
  from wfactors_factors[OF asf ascarr] obtain a' where fa': "factors G as a'" and a': "a' \<sim> a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1413
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1414
  from fa' ascarr have a'carr[simp]: "a' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1415
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1416
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1417
  have a'nunit: "a' \<notin> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1418
  proof clarify
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1419
    assume "a' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1420
    also note a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1421
    finally have "a \<in> Units G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1422
    with anunit
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1423
    show "False" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1424
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1425
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1426
  from wfactors_factors[OF bsf bscarr] obtain b' where fb': "factors G bs b'" and b': "b' \<sim> b"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1427
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1428
  from fb' bscarr have b'carr[simp]: "b' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1429
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1430
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1431
  have b'nunit: "b' \<notin> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1432
  proof clarify
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1433
    assume "b' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1434
    also note b'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1435
    finally have "b \<in> Units G" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1436
    with bnunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1437
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1438
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1439
  note a'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1440
  also note asc
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1441
  also note b'[symmetric]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1442
  finally have "a' \<sim> b'" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1443
  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
  1444
    by (rule ee_factorsI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1445
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1446
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1447
lemma (in factorial_monoid) ee_wfactors:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1448
  assumes asf: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1449
    and bsf: "wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1450
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1451
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1452
  shows asc: "a \<sim> b = essentially_equal G as bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1453
  using assms by (fast intro: ee_wfactorsI ee_wfactorsD)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1454
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1455
lemma (in factorial_monoid) wfactors_exist [intro, simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1456
  assumes acarr[simp]: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1457
  shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1458
proof (cases "a \<in> Units G")
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1459
  case True
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1460
  then have "wfactors G [] a" by (rule unit_wfactors)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1461
  then show ?thesis by (intro exI) force
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1462
next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1463
  case False
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1464
  with factors_exist [OF acarr] obtain fs where fscarr: "set fs \<subseteq> carrier G" and f: "factors G fs a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1465
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1466
  from f have "wfactors G fs a" by (rule factors_wfactors) fact
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1467
  with fscarr show ?thesis by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1468
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1469
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1470
lemma (in monoid) wfactors_prod_exists [intro, simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1471
  assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1472
  shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1473
  unfolding wfactors_def using assms by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1474
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1475
lemma (in factorial_monoid) wfactors_unique:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1476
  assumes "wfactors G fs a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1477
    and "wfactors G fs' a"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1478
    and "a \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1479
    and "set fs \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1480
    and "set fs' \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1481
  shows "essentially_equal G fs fs'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1482
  using assms by (fast intro: ee_wfactorsI[of a a])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1483
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1484
lemma (in monoid) factors_mult_single:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1485
  assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1486
  shows "factors G (a # fb) (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1487
  using assms unfolding factors_def by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1488
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1489
lemma (in monoid_cancel) wfactors_mult_single:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1490
  assumes f: "irreducible G a"  "wfactors G fb b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1491
    "a \<in> carrier G"  "b \<in> carrier G"  "set fb \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1492
  shows "wfactors G (a # fb) (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1493
  using assms unfolding wfactors_def by (simp add: mult_cong_r)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1494
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1495
lemma (in monoid) factors_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1496
  assumes factors: "factors G fa a"  "factors G fb b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1497
    and ascarr: "set fa \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1498
    and bscarr: "set fb \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1499
  shows "factors G (fa @ fb) (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1500
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1501
  unfolding factors_def
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1502
  apply safe
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1503
   apply force
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1504
  apply hypsubst_thin
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1505
  apply (induct fa)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1506
   apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1507
  apply (simp add: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1508
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1509
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1510
lemma (in comm_monoid_cancel) wfactors_mult [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1511
  assumes asf: "wfactors G as a" and bsf:"wfactors G bs b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1512
    and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1513
    and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1514
  shows "wfactors G (as @ bs) (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1515
  using wfactors_factors[OF asf ascarr] and wfactors_factors[OF bsf bscarr]
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1516
proof clarsimp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1517
  fix a' b'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1518
  assume asf': "factors G as a'" and a'a: "a' \<sim> a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1519
    and bsf': "factors G bs b'" and b'b: "b' \<sim> b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1520
  from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1521
  from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1522
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1523
  note carr = acarr bcarr a'carr b'carr ascarr bscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1524
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1525
  from asf' bsf' have "factors G (as @ bs) (a' \<otimes> b')"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1526
    by (rule factors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1527
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1528
  with carr have abf': "wfactors G (as @ bs) (a' \<otimes> b')"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1529
    by (intro factors_wfactors) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1530
  also from b'b carr have trb: "a' \<otimes> b' \<sim> a' \<otimes> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1531
    by (intro mult_cong_r)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1532
  also from a'a carr have tra: "a' \<otimes> b \<sim> a \<otimes> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1533
    by (intro mult_cong_l)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1534
  finally show "wfactors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1535
    by (simp add: carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1536
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1537
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1538
lemma (in comm_monoid) factors_dividesI:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1539
  assumes "factors G fs a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1540
    and "f \<in> set fs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1541
    and "set fs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1542
  shows "f divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1543
  using assms by (fast elim: factorsE intro: multlist_dividesI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1544
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1545
lemma (in comm_monoid) wfactors_dividesI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1546
  assumes p: "wfactors G fs a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1547
    and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1548
    and f: "f \<in> set fs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1549
  shows "f divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1550
  using wfactors_factors[OF p fscarr]
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1551
proof clarsimp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1552
  fix a'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1553
  assume fsa': "factors G fs a'" and a'a: "a' \<sim> a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1554
  with fscarr have a'carr: "a' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1555
    by (simp add: factors_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1556
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1557
  from fsa' fscarr f have "f divides a'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1558
    by (fast intro: factors_dividesI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1559
  also note a'a
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1560
  finally show "f divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1561
    by (simp add: f fscarr[THEN subsetD] acarr a'carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1562
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1563
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1564
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1565
subsubsection \<open>Factorial monoids and wfactors\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1566
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1567
lemma (in comm_monoid_cancel) factorial_monoidI:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1568
  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
  1569
    and wfactors_unique:
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1570
      "\<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
  1571
        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
  1572
  shows "factorial_monoid G"
28823
dcbef866c9e2 tuned unfold_locales invocation
haftmann
parents: 28600
diff changeset
  1573
proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1574
  fix a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1575
  assume acarr: "a \<in> carrier G" and anunit: "a \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1576
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1577
  from wfactors_exists[OF acarr]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1578
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1579
    by blast
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1580
  from wfactors_factors [OF afs ascarr] obtain a' where afs': "factors G as a'" and a'a: "a' \<sim> a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1581
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1582
  from afs' ascarr have a'carr: "a' \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1583
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1584
  have a'nunit: "a' \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1585
  proof clarify
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1586
    assume "a' \<in> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1587
    also note a'a
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1588
    finally have "a \<in> Units G" by (simp add: acarr)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1589
    with anunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1590
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1591
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1592
  from a'carr acarr a'a obtain u where uunit: "u \<in> Units G" and a': "a' = a \<otimes> u"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1593
    by (blast elim: associatedE2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1594
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1595
  note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1596
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1597
  have "a = a \<otimes> \<one>" by simp
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
  1598
  also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: uunit)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1599
  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
  1600
  finally have a: "a = a' \<otimes> inv u" .
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1601
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1602
  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
  1603
    by (cases as) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1604
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1605
  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
  1606
    by (simp add: a factors_cong_unit)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1607
  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
  1608
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1609
qed (blast intro: factors_wfactors wfactors_unique)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1610
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1611
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1612
subsection \<open>Factorizations as Multisets\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1613
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1614
text \<open>Gives useful operations like intersection\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1615
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1616
(* FIXME: use class_of x instead of closure_of {x} *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1617
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1618
abbreviation "assocs G x \<equiv> eq_closure_of (division_rel G) {x}"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1619
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1620
definition "fmset G as = mset (map (\<lambda>a. assocs G a) as)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1621
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1622
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1623
text \<open>Helper lemmas\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1624
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1625
lemma (in monoid) assocs_repr_independence:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1626
  assumes "y \<in> assocs G x"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1627
    and "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1628
  shows "assocs G x = assocs G y"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1629
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1630
  apply safe
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1631
   apply (elim closure_ofE2, intro closure_ofI2[of _ _ y])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1632
     apply (clarsimp, iprover intro: associated_trans associated_sym, simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1633
  apply (elim closure_ofE2, intro closure_ofI2[of _ _ x])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1634
    apply (clarsimp, iprover intro: associated_trans, simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1635
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1636
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1637
lemma (in monoid) assocs_self:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1638
  assumes "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1639
  shows "x \<in> assocs G x"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1640
  using assms by (fastforce intro: closure_ofI2)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1641
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1642
lemma (in monoid) assocs_repr_independenceD:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1643
  assumes repr: "assocs G x = assocs G y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1644
    and ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1645
  shows "y \<in> assocs G x"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1646
  unfolding repr using ycarr by (intro assocs_self)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1647
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1648
lemma (in comm_monoid) assocs_assoc:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1649
  assumes "a \<in> assocs G b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1650
    and "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1651
  shows "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1652
  using assms by (elim closure_ofE2) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1653
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1654
lemmas (in comm_monoid) assocs_eqD = assocs_repr_independenceD[THEN assocs_assoc]
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1655
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1656
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1657
subsubsection \<open>Comparing multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1658
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1659
lemma (in monoid) fmset_perm_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1660
  assumes prm: "as <~~> bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1661
  shows "fmset G as = fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1662
  using perm_map[OF prm] unfolding mset_eq_perm fmset_def by blast
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_cancel) eqc_listassoc_cong:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1665
  assumes "as [\<sim>] bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1666
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1667
  shows "map (assocs G) as = map (assocs G) bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1668
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1669
  apply (induct as arbitrary: bs, simp)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1670
  apply (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1, safe)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1671
   apply (clarsimp elim!: closure_ofE2) defer 1
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1672
   apply (clarsimp elim!: closure_ofE2) defer 1
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1673
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1674
  fix a x z
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1675
  assume carr[simp]: "a \<in> carrier G"  "x \<in> carrier G"  "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1676
  assume "x \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1677
  also assume "a \<sim> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1678
  finally have "x \<sim> z" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1679
  with carr show "x \<in> assocs G z"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1680
    by (intro closure_ofI2) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1681
next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1682
  fix a x z
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1683
  assume carr[simp]: "a \<in> carrier G"  "x \<in> carrier G"  "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1684
  assume "x \<sim> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1685
  also assume [symmetric]: "a \<sim> z"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1686
  finally have "x \<sim> a" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1687
  with carr show "x \<in> assocs G a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1688
    by (intro closure_ofI2) simp_all
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1689
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1690
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1691
lemma (in comm_monoid_cancel) fmset_listassoc_cong:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1692
  assumes "as [\<sim>] bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1693
    and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1694
  shows "fmset G as = fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1695
  using assms unfolding fmset_def by (simp add: eqc_listassoc_cong)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1696
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1697
lemma (in comm_monoid_cancel) ee_fmset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1698
  assumes ee: "essentially_equal G as bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1699
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1700
  shows "fmset G as = fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1701
  using ee
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1702
proof (elim essentially_equalE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1703
  fix as'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1704
  assume prm: "as <~~> as'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1705
  from prm ascarr have as'carr: "set as' \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1706
    by (rule perm_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1707
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1708
  from prm have "fmset G as = fmset G as'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1709
    by (rule fmset_perm_cong)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1710
  also assume "as' [\<sim>] bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1711
  with as'carr bscarr have "fmset G as' = fmset G bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1712
    by (simp add: fmset_listassoc_cong)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1713
  finally show "fmset G as = fmset G bs" .
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1714
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1715
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1716
lemma (in monoid_cancel) fmset_ee__hlp_induct:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1717
  assumes prm: "cas <~~> cbs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1718
    and cdef: "cas = map (assocs G) as"  "cbs = map (assocs G) bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1719
  shows "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and>
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1720
    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
  1721
  apply (rule perm.induct[of cas cbs], rule prm)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1722
     apply safe
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1723
     apply (simp_all del: mset_map)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1724
    apply (simp add: map_eq_Cons_conv)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1725
    apply blast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1726
   apply force
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1727
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1728
  fix ys as bs
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1729
  assume p1: "map (assocs G) as <~~> ys"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1730
    and r1[rule_format]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1731
      "\<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
  1732
        \<longrightarrow> (\<exists>as'. asa <~~> as' \<and> map (assocs G) as' = map (assocs G) bs)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1733
    and p2: "ys <~~> map (assocs G) bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1734
    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
  1735
      \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bsa)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1736
    and p3: "map (assocs G) as <~~> map (assocs G) bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1737
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1738
  from p1 have "mset (map (assocs G) as) = mset ys"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1739
    by (simp add: mset_eq_perm del: mset_map)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1740
  then have setys: "set (map (assocs G) as) = set ys"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1741
    by (rule mset_eq_setD)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1742
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1743
  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
  1744
  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
  1745
  then have "\<exists>yy. ys = map (assocs G) yy"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1746
  proof (induct ys)
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1747
    case Nil
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1748
    then show ?case by simp
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1749
  next
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1750
    case Cons
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1751
    then show ?case
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1752
    proof clarsimp
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1753
      fix yy x
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1754
      show "\<exists>yya. assocs G x # map (assocs G) yy = map (assocs G) yya"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1755
        by (rule exI[of _ "x#yy"]) simp
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1756
    qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1757
  qed
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1758
  then obtain yy where ys: "ys = map (assocs G) yy" ..
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1759
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1760
  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
  1761
    by (intro r1) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1762
  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
  1763
    by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1764
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1765
  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
  1766
    by (intro r2) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1767
  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
  1768
    by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1769
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1770
  from perm_map_switch [OF as'yy yyas'']
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1771
  obtain cs where as'cs: "as' <~~> cs" and csas'': "map (assocs G) cs = map (assocs G) as''"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1772
    by blast
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1773
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1774
  from asas' and as'cs have ascs: "as <~~> cs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1775
    by fast
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1776
  from csas'' and as''bs have "map (assocs G) cs = map (assocs G) bs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1777
    by simp
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1778
  with ascs show "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1779
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1780
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1781
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1782
lemma (in comm_monoid_cancel) fmset_ee:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1783
  assumes mset: "fmset G as = fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1784
    and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1785
  shows "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1786
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1787
  from mset have mpp: "map (assocs G) as <~~> map (assocs G) bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1788
    by (simp add: fmset_def mset_eq_perm del: mset_map)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1789
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1790
  define cas where "cas = map (assocs G) as"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1791
  define cbs where "cbs = map (assocs G) bs"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1792
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1793
  from cas_def cbs_def mpp have [rule_format]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1794
    "\<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
  1795
      \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1796
    by (intro fmset_ee__hlp_induct, simp+)
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1797
  with mpp cas_def cbs_def have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1798
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1799
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1800
  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
  1801
    by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1802
  from tm have lene: "length as' = length bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1803
    by (rule map_eq_imp_length_eq)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1804
  from tp have "set as = set as'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1805
    by (simp add: mset_eq_perm mset_eq_setD)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1806
  with ascarr have as'carr: "set as' \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1807
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1808
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1809
  from tm as'carr[THEN subsetD] bscarr[THEN subsetD] have "as' [\<sim>] bs"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44655
diff changeset
  1810
    by (induct as' arbitrary: bs) (simp, fastforce dest: assocs_eqD[THEN associated_sym])
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1811
  with tp show "essentially_equal G as bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1812
    by (fast intro: essentially_equalI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1813
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1814
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1815
lemma (in comm_monoid_cancel) ee_is_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1816
  assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1817
  shows "essentially_equal G as bs = (fmset G as = fmset G bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1818
  using assms by (fast intro: ee_fmset fmset_ee)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1819
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1820
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1821
subsubsection \<open>Interpreting multisets as factorizations\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1822
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1823
lemma (in monoid) mset_fmsetEx:
60495
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
  1824
  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
  1825
  shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1826
proof -
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1827
  from surjE[OF surj_mset] obtain Cs' where Cs: "Cs = mset Cs'"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1828
    by blast
60515
484559628038 renamed multiset_of -> mset
nipkow
parents: 60495
diff changeset
  1829
  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
  1830
    using elems
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1831
    unfolding Cs
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1832
    apply (induct Cs', simp)
63524
4ec755485732 adding mset_map to the simp rules
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63167
diff changeset
  1833
  proof (clarsimp simp del: mset_map)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1834
    fix a Cs' cs
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1835
    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
  1836
      and csP: "\<forall>x\<in>set cs. P x"
60515
484559628038 renamed multiset_of -> mset
nipkow
parents: 60495
diff changeset
  1837
      and mset: "mset (map (assocs G) cs) = mset Cs'"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1838
    from ih obtain c where cP: "P c" and a: "a = assocs G c"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1839
      by auto
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1840
    from cP csP have tP: "\<forall>x\<in>set (c#cs). P x"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1841
      by simp
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1842
    from mset a have "mset (map (assocs G) (c#cs)) = add_mset a (mset Cs')"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1843
      by simp
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1844
    with tP show "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and> mset (map (assocs G) cs) = add_mset a (mset Cs')"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1845
      by fast
60143
2cd31c81e0e7 added simp rules for ==>
nipkow
parents: 58889
diff changeset
  1846
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1847
  then show ?thesis by (simp add: fmset_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1848
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1849
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1850
lemma (in monoid) mset_wfactorsEx:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1851
  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
  1852
  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
  1853
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1854
  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
  1855
    by (intro mset_fmsetEx, rule elems)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1856
  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
  1857
    and Cs[symmetric]: "fmset G cs = Cs" by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1858
  from p have cscarr: "set cs \<subseteq> carrier G" by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1859
  from p have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1860
    by (intro wfactors_prod_exists) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1861
  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
  1862
  with cscarr Cs show ?thesis by fast
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
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1866
subsubsection \<open>Multiplication on multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1867
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1868
lemma (in factorial_monoid) mult_wfactors_fmset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1869
  assumes afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1870
    and bfs: "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1871
    and cfs: "wfactors G cs (a \<otimes> b)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1872
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1873
              "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"  "set cs \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1874
  shows "fmset G cs = fmset G as + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1875
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1876
  from assms have "wfactors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1877
    by (intro wfactors_mult)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1878
  with carr cfs have "essentially_equal G cs (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1879
    by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1880
  with carr have "fmset G cs = fmset G (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1881
    by (intro ee_fmset) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1882
  also have "fmset G (as@bs) = fmset G as + fmset G bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1883
    by (simp add: fmset_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1884
  finally show "fmset G cs = fmset G as + fmset G bs" .
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1885
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1886
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1887
lemma (in factorial_monoid) mult_factors_fmset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1888
  assumes afs: "factors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1889
    and bfs: "factors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1890
    and cfs: "factors G cs (a \<otimes> b)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1891
    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
  1892
  shows "fmset G cs = fmset G as + fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1893
  using assms by (blast intro: factors_wfactors mult_wfactors_fmset)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1894
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1895
lemma (in comm_monoid_cancel) fmset_wfactors_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1896
  assumes mset: "fmset G cs = fmset G as + fmset G bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1897
    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
  1898
      "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
  1899
    and fs: "wfactors G as a"  "wfactors G bs b"  "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1900
  shows "c \<sim> a \<otimes> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1901
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1902
  from carr fs have m: "wfactors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1903
    by (intro wfactors_mult)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1904
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1905
  from mset have "fmset G cs = fmset G (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1906
    by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1907
  then have "essentially_equal G cs (as@bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1908
    by (rule fmset_ee) (simp_all add: carr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1909
  then show "c \<sim> a \<otimes> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1910
    by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp_all add: assms m)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1911
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1912
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1913
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1914
subsubsection \<open>Divisibility on multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1915
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1916
lemma (in factorial_monoid) divides_fmsubset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1917
  assumes ab: "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1918
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1919
    and bfs: "wfactors G bs b"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1920
    and carr: "a \<in> carrier G"  "b \<in> carrier G"  "set as \<subseteq> carrier G"  "set bs \<subseteq> carrier G"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1921
  shows "fmset G as \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1922
  using ab
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1923
proof (elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1924
  fix c
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1925
  assume ccarr: "c \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1926
  from wfactors_exist [OF this]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1927
  obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  1928
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1929
  note carr = carr ccarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1930
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1931
  assume "b = a \<otimes> c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1932
  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
  1933
    by (intro mult_wfactors_fmset[OF afs cfs]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1934
  then show ?thesis by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1935
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1936
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1937
lemma (in comm_monoid_cancel) fmsubset_divides:
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1938
  assumes msubset: "fmset G as \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1939
    and afs: "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1940
    and bfs: "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1941
    and acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1942
    and bcarr: "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1943
    and ascarr: "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1944
    and bscarr: "set bs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1945
  shows "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1946
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1947
  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
  1948
  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
  1949
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1950
  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
  1951
  proof (intro mset_wfactorsEx, simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1952
    fix X
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61382
diff changeset
  1953
    assume "X \<in># fmset G bs - fmset G as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1954
    then have "X \<in># fmset G bs" by (rule in_diffD)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1955
    then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1956
    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
  1957
    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
  1958
    with bscarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1959
    from xbs birr have xirr: "irreducible G x" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1960
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1961
    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
  1962
      by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1963
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1964
  then obtain c cs
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1965
    where ccarr: "c \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1966
      and cscarr: "set cs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1967
      and csf: "wfactors G cs c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1968
      and csmset: "fmset G cs = fmset G bs - fmset G as" by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1969
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1970
  from csmset msubset
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1971
  have "fmset G bs = fmset G as + fmset G cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1972
    by (simp add: multiset_eq_iff subseteq_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1973
  then have basc: "b \<sim> a \<otimes> c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1974
    by (rule fmset_wfactors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1975
  then show ?thesis
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1976
  proof (elim associatedE2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1977
    fix u
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1978
    assume "u \<in> Units G"  "b = a \<otimes> c \<otimes> u"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1979
    with acarr ccarr show "a divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1980
      by (fast intro: dividesI[of "c \<otimes> u"] m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1981
  qed (simp_all add: acarr bcarr ccarr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1982
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1983
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1984
lemma (in factorial_monoid) divides_as_fmsubset:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1985
  assumes "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1986
    and "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1987
    and "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1988
    and "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1989
    and "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1990
    and "set bs \<subseteq> carrier G"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1991
  shows "a divides b = (fmset G as \<subseteq># fmset G bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1992
  using assms
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  1993
  by (blast intro: divides_fmsubset fmsubset_divides)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1994
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1995
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  1996
text \<open>Proper factors on multisets\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1997
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  1998
lemma (in factorial_monoid) fmset_properfactor:
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  1999
  assumes asubb: "fmset G as \<subseteq># fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2000
    and anb: "fmset G as \<noteq> fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2001
    and "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2002
    and "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2003
    and "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2004
    and "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2005
    and "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2006
    and "set bs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2007
  shows "properfactor G a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2008
  apply (rule properfactorI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2009
   apply (rule fmsubset_divides[of as bs], fact+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2010
proof
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2011
  assume "b divides a"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2012
  then have "fmset G bs \<subseteq># fmset G as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2013
    by (rule divides_fmsubset) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2014
  with asubb have "fmset G as = fmset G bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2015
    by (rule subset_mset.antisym)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2016
  with anb show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2017
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2018
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2019
lemma (in factorial_monoid) properfactor_fmset:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2020
  assumes pf: "properfactor G a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2021
    and "wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2022
    and "wfactors G bs b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2023
    and "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2024
    and "b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2025
    and "set as \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2026
    and "set bs \<subseteq> carrier G"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2027
  shows "fmset G as \<subseteq># fmset G bs \<and> fmset G as \<noteq> fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2028
  using pf
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2029
  apply (elim properfactorE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2030
  apply rule
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2031
   apply (intro divides_fmsubset, assumption)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2032
        apply (rule assms)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2033
  using assms(2,3,4,6,7) divides_as_fmsubset
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2034
  apply auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2035
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2036
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2037
subsection \<open>Irreducible Elements are Prime\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2038
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63524
diff changeset
  2039
lemma (in factorial_monoid) irreducible_prime:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2040
  assumes pirr: "irreducible G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2041
    and pcarr: "p \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2042
  shows "prime G p"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2043
  using pirr
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2044
proof (elim irreducibleE, intro primeI)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2045
  fix a b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2046
  assume acarr: "a \<in> carrier G"  and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2047
    and pdvdab: "p divides (a \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2048
    and pnunit: "p \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2049
  assume irreduc[rule_format]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2050
    "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2051
  from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2052
    by (rule dividesE)
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2053
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2054
  from wfactors_exist [OF acarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2055
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2056
    by blast
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2057
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2058
  from wfactors_exist [OF bcarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2059
  obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2060
    by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2061
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2062
  from wfactors_exist [OF ccarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2063
  obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2064
    by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2065
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2066
  note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2067
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2068
  from afs and bfs have abfs: "wfactors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2069
    by (rule wfactors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2070
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2071
  from pirr cfs have pcfs: "wfactors G (p # cs) (p \<otimes> c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2072
    by (rule wfactors_mult_single) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2073
  with abpc have abfs': "wfactors G (p # cs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2074
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2075
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2076
  from abfs' abfs have "essentially_equal G (p # cs) (as @ bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2077
    by (rule wfactors_unique) simp+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2078
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2079
  then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2080
    by (fast elim: essentially_equalE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2081
  then have "p \<in> set ds"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2082
    by (simp add: perm_set_eq[symmetric])
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2083
  with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2084
    unfolding list_all2_conv_all_nth set_conv_nth by force
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2085
  then consider "p' \<in> set as" | "p' \<in> set bs" by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2086
  then show "p divides a \<or> p divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2087
  proof cases
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2088
    case 1
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2089
    with ascarr have [simp]: "p' \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2090
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2091
    note pp'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2092
    also from afs
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2093
    have "p' divides a" by (rule wfactors_dividesI) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2094
    finally have "p divides a" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2095
    then show ?thesis ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2096
  next
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2097
    case 2
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2098
    with bscarr have [simp]: "p' \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2099
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2100
    note pp'
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2101
    also from bfs
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2102
    have "p' divides b" by (rule wfactors_dividesI) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2103
    finally have "p divides b" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2104
    then show ?thesis ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2105
  qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2106
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2107
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2108
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62430
diff changeset
  2109
\<comment>"A version using @{const factors}, more complicated"
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63524
diff changeset
  2110
lemma (in factorial_monoid) factors_irreducible_prime:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2111
  assumes pirr: "irreducible G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2112
    and pcarr: "p \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2113
  shows "prime G p"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2114
  using pirr
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2115
  apply (elim irreducibleE, intro primeI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2116
   apply assumption
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2117
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2118
  fix a b
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2119
  assume acarr: "a \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2120
    and bcarr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2121
    and pdvdab: "p divides (a \<otimes> b)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2122
  assume irreduc[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2123
  from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2124
    by (rule dividesE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2125
  note [simp] = pcarr acarr bcarr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2126
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2127
  show "p divides a \<or> p divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2128
  proof (cases "a \<in> Units G")
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2129
    case aunit: True
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2130
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2131
    note pdvdab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2132
    also have "a \<otimes> b = b \<otimes> a" by (simp add: m_comm)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2133
    also from aunit have bab: "b \<otimes> a \<sim> b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2134
      by (intro associatedI2[of "a"], simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2135
    finally have "p divides b" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2136
    then show ?thesis ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2137
  next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2138
    case anunit: False
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2139
    show ?thesis
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2140
    proof (cases "b \<in> Units G")
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2141
      case bunit: True
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2142
      note pdvdab
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2143
      also from bunit
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2144
      have baa: "a \<otimes> b \<sim> a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2145
        by (intro associatedI2[of "b"], simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2146
      finally have "p divides a" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2147
      then show ?thesis ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2148
    next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2149
      case bnunit: False
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2150
      have cnunit: "c \<notin> Units G"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  2151
      proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2152
        assume cunit: "c \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2153
        from bnunit have "properfactor G a (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2154
          by (intro properfactorI3[of _ _ b], simp+)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2155
        also note abpc
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2156
        also from cunit have "p \<otimes> c \<sim> p"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2157
          by (intro associatedI2[of c], simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2158
        finally have "properfactor G a p" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2159
        with acarr have "a \<in> Units G" by (fast intro: irreduc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2160
        with anunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2161
      qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2162
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2163
      have abnunit: "a \<otimes> b \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2164
      proof clarsimp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2165
        assume "a \<otimes> b \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2166
        then have "a \<in> Units G" by (rule unit_factor) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2167
        with anunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2168
      qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2169
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2170
      from factors_exist [OF acarr anunit]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2171
      obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2172
        by blast
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2173
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2174
      from factors_exist [OF bcarr bnunit]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2175
      obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2176
        by blast
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2177
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2178
      from factors_exist [OF ccarr cnunit]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2179
      obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2180
        by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2181
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2182
      note [simp] = ascarr bscarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2183
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2184
      from afac and bfac have abfac: "factors G (as @ bs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2185
        by (rule factors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2186
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2187
      from pirr cfac have pcfac: "factors G (p # cs) (p \<otimes> c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2188
        by (rule factors_mult_single) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2189
      with abpc have abfac': "factors G (p # cs) (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2190
        by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2191
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2192
      from abfac' abfac have "essentially_equal G (p # cs) (as @ bs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2193
        by (rule factors_unique) (fact | simp)+
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2194
      then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2195
        by (fast elim: essentially_equalE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2196
      then have "p \<in> set ds"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2197
        by (simp add: perm_set_eq[symmetric])
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2198
      with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2199
        unfolding list_all2_conv_all_nth set_conv_nth by force
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2200
      then consider "p' \<in> set as" | "p' \<in> set bs" by auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2201
      then show "p divides a \<or> p divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2202
      proof cases
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2203
        case 1
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2204
        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
  2205
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2206
        note pp'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2207
        also from afac 1 have "p' divides a" by (rule factors_dividesI) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2208
        finally have "p divides a" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2209
        then show ?thesis ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2210
      next
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2211
        case 2
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2212
        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
  2213
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2214
        note pp'
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  2215
        also from bfac
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2216
        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
  2217
        finally have "p divides b" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2218
        then show ?thesis ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2219
      qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2220
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2221
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2222
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2223
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2224
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2225
subsection \<open>Greatest Common Divisors and Lowest Common Multiples\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2226
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2227
subsubsection \<open>Definitions\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2228
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2229
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
  2230
  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
  2231
    (\<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
  2232
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2233
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
  2234
  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
  2235
    (\<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
  2236
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2237
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
  2238
  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
  2239
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2240
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
  2241
  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
  2242
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2243
definition "SomeGcd G A = inf (division_rel G) A"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2244
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2245
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2246
locale gcd_condition_monoid = comm_monoid_cancel +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2247
  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
  2248
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2249
locale primeness_condition_monoid = comm_monoid_cancel +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2250
  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
  2251
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2252
locale divisor_chain_condition_monoid = comm_monoid_cancel +
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2253
  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
  2254
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2255
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2256
subsubsection \<open>Connections to \texttt{Lattice.thy}\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2257
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2258
lemma gcdof_greatestLower:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2259
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2260
  assumes carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2261
  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
  2262
  by (auto simp: isgcd_def greatest_def Lower_def elem_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2263
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2264
lemma lcmof_leastUpper:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2265
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2266
  assumes carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2267
  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
  2268
  by (auto simp: islcm_def least_def Upper_def elem_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2269
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2270
lemma somegcd_meet:
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2271
  fixes G (structure)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2272
  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
  2273
  shows "somegcd G a b = meet (division_rel G) a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2274
  by (simp add: somegcd_def meet_def inf_def gcdof_greatestLower[OF carr])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2275
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2276
lemma (in monoid) isgcd_divides_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2277
  assumes "a divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2278
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2279
  shows "a gcdof a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2280
  using assms unfolding isgcd_def by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2281
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2282
lemma (in monoid) isgcd_divides_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2283
  assumes "b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2284
    and "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2285
  shows "b gcdof a b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2286
  using assms unfolding isgcd_def by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2287
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2288
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2289
subsubsection \<open>Existence of gcd and lcm\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2290
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2291
lemma (in factorial_monoid) gcdof_exists:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2292
  assumes acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2293
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2294
  shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2295
proof -
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2296
  from wfactors_exist [OF acarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2297
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2298
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2299
  from afs have airr: "\<forall>a \<in> set as. irreducible G a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2300
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2301
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2302
  from wfactors_exist [OF bcarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2303
  obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2304
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2305
  from bfs have birr: "\<forall>b \<in> set bs. irreducible G b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2306
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2307
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2308
  have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and>
63919
9aed2da07200 # after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63847
diff changeset
  2309
    fmset G cs = fmset G as \<inter># fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2310
  proof (intro mset_wfactorsEx)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2311
    fix X
63919
9aed2da07200 # after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63847
diff changeset
  2312
    assume "X \<in># fmset G as \<inter># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2313
    then have "X \<in># fmset G as" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2314
    then have "X \<in> set (map (assocs G) as)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2315
      by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2316
    then have "\<exists>x. X = assocs G x \<and> x \<in> set as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2317
      by (induct as) auto
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2318
    then obtain x where X: "X = assocs G x" and xas: "x \<in> set as"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2319
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2320
    with ascarr have xcarr: "x \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2321
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2322
    from xas airr have xirr: "irreducible G x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2323
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2324
    from xcarr and xirr and X show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2325
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2326
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2327
  then obtain c cs
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2328
    where ccarr: "c \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2329
      and cscarr: "set cs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2330
      and csirr: "wfactors G cs c"
63919
9aed2da07200 # after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63847
diff changeset
  2331
      and csmset: "fmset G cs = fmset G as \<inter># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2332
    by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2333
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2334
  have "c gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2335
  proof (simp add: isgcd_def, safe)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2336
    from csmset
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2337
    have "fmset G cs \<subseteq># fmset G as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2338
      by (simp add: multiset_inter_def subset_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2339
    then show "c divides a" by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2340
  next
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2341
    from csmset have "fmset G cs \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2342
      by (simp add: multiset_inter_def subseteq_mset_def, force)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2343
    then show "c divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2344
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2345
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2346
    fix y
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2347
    assume "y \<in> carrier G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2348
    from wfactors_exist [OF this]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2349
    obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2350
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2351
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2352
    assume "y divides a"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2353
    then have ya: "fmset G ys \<subseteq># fmset G as"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2354
      by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2355
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2356
    assume "y divides b"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2357
    then have yb: "fmset G ys \<subseteq># fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2358
      by (rule divides_fmsubset) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2359
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2360
    from ya yb csmset have "fmset G ys \<subseteq># fmset G cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2361
      by (simp add: subset_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2362
    then show "y divides c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2363
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2364
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2365
  with ccarr show "\<exists>c. c \<in> carrier G \<and> c gcdof a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2366
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2367
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2368
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2369
lemma (in factorial_monoid) lcmof_exists:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2370
  assumes acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2371
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2372
  shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2373
proof -
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2374
  from wfactors_exist [OF acarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2375
  obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2376
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2377
  from afs have airr: "\<forall>a \<in> set as. irreducible G a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2378
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2379
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2380
  from wfactors_exist [OF bcarr]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2381
  obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2382
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2383
  from bfs have birr: "\<forall>b \<in> set bs. irreducible G b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2384
    by (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2385
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2386
  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
  2387
    fmset G cs = (fmset G as - fmset G bs) + fmset G bs"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2388
  proof (intro mset_wfactorsEx)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2389
    fix X
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61382
diff changeset
  2390
    assume "X \<in># (fmset G as - fmset G bs) + fmset G bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2391
    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
  2392
      by (auto dest: in_diffD)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2393
    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
  2394
      by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2395
    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
  2396
    proof cases
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2397
      case 1
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2398
      then have "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2399
      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
  2400
      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
  2401
      with ascarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2402
      from xas airr have xirr: "irreducible G x" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2403
      from xcarr and xirr and X show ?thesis by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2404
    next
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2405
      case 2
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2406
      then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2407
      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
  2408
      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
  2409
      with bscarr have xcarr: "x \<in> carrier G" by fast
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2410
      from xbs birr have xirr: "irreducible G x" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2411
      from xcarr and xirr and X show ?thesis by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2412
    qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2413
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2414
  then obtain c cs
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2415
    where ccarr: "c \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2416
      and cscarr: "set cs \<subseteq> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2417
      and csirr: "wfactors G cs c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2418
      and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2419
    by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2420
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2421
  have "c lcmof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2422
  proof (simp add: islcm_def, safe)
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2423
    from csmset have "fmset G as \<subseteq># fmset G cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2424
      by (simp add: subseteq_mset_def, force)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2425
    then show "a divides c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2426
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2427
  next
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2428
    from csmset have "fmset G bs \<subseteq># fmset G cs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2429
      by (simp add: subset_mset_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2430
    then show "b divides c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2431
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2432
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2433
    fix y
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2434
    assume "y \<in> carrier G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2435
    from wfactors_exist [OF this]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2436
    obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2437
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2438
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2439
    assume "a divides y"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2440
    then have ya: "fmset G as \<subseteq># fmset G ys"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2441
      by (rule divides_fmsubset) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2442
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2443
    assume "b divides y"
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2444
    then have yb: "fmset G bs \<subseteq># fmset G ys"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2445
      by (rule divides_fmsubset) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2446
64587
8355a6e2df79 standardized notation
haftmann
parents: 63919
diff changeset
  2447
    from ya yb csmset have "fmset G cs \<subseteq># fmset G ys"
60397
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 60143
diff changeset
  2448
      apply (simp add: subseteq_mset_def, clarify)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2449
      apply (case_tac "count (fmset G as) a < count (fmset G bs) a")
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2450
       apply simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2451
      apply simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2452
      done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2453
    then show "c divides y"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2454
      by (rule fmsubset_divides) fact+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2455
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2456
  with ccarr show "\<exists>c. c \<in> carrier G \<and> c lcmof a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2457
    by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2458
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2459
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2460
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2461
subsection \<open>Conditions for Factoriality\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2462
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2463
subsubsection \<open>Gcd condition\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2464
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2465
lemma (in gcd_condition_monoid) division_weak_lower_semilattice [simp]:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2466
  "weak_lower_semilattice (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2467
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2468
  interpret weak_partial_order "division_rel G" ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2469
  show ?thesis
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2470
    apply (unfold_locales, simp_all)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2471
  proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2472
    fix x y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2473
    assume carr: "x \<in> carrier G"  "y \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2474
    from gcdof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z gcdof x y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2475
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2476
    with carr have "greatest (division_rel G) z (Lower (division_rel G) {x, y})"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2477
      by (subst gcdof_greatestLower[symmetric], simp+)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2478
    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
  2479
      by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2480
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2481
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2482
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2483
lemma (in gcd_condition_monoid) gcdof_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2484
  assumes a'a: "a' \<sim> a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2485
    and agcd: "a gcdof b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2486
    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
  2487
  shows "a' gcdof b c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2488
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2489
  note carr = a'carr carr'
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2490
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2491
  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
  2492
    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
  2493
    apply (subst greatest_Lower_cong_l[of _ a])
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2494
        apply (simp add: a'a)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2495
       apply (simp add: carr)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2496
      apply (simp add: carr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2497
     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
  2498
    apply (simp add: gcdof_greatestLower[symmetric] agcd carr)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2499
    done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2500
  then show ?thesis ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2501
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2502
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2503
lemma (in gcd_condition_monoid) gcd_closed [simp]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2504
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2505
  shows "somegcd G a b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2506
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2507
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2508
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2509
    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
  2510
    apply (rule meet_closed[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2511
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2512
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2513
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2514
lemma (in gcd_condition_monoid) gcd_isgcd:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2515
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2516
  shows "(somegcd G a b) gcdof a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2517
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2518
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2519
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2520
  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
  2521
    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
  2522
    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
  2523
    apply (rule inf_of_two_greatest[simplified], assumption+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2524
    done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2525
  then show "(somegcd G a b) gcdof a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2526
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2527
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2528
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2529
lemma (in gcd_condition_monoid) gcd_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2530
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2531
  shows "\<exists>x\<in>carrier G. x = somegcd G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2532
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2533
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2534
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2535
  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
  2536
    by (metis carr(1) carr(2) gcd_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2537
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2538
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2539
lemma (in gcd_condition_monoid) gcd_divides_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2540
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2541
  shows "(somegcd G a b) divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2542
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2543
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2544
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2545
  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
  2546
    by (metis carr(1) carr(2) gcd_isgcd isgcd_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2547
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2548
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2549
lemma (in gcd_condition_monoid) gcd_divides_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2550
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2551
  shows "(somegcd G a b) divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2552
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2553
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2554
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2555
  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
  2556
    by (metis carr gcd_isgcd isgcd_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2557
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2558
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2559
lemma (in gcd_condition_monoid) gcd_divides:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2560
  assumes sub: "z divides x"  "z divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2561
    and L: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2562
  shows "z divides (somegcd G x y)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2563
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2564
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2565
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2566
  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
  2567
    by (metis gcd_isgcd isgcd_def assms)
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_cong_l:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2571
  assumes xx': "x \<sim> x'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2572
    and carr: "x \<in> carrier G"  "x' \<in> carrier G"  "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2573
  shows "somegcd G x y \<sim> somegcd G x' y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2574
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2575
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2576
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2577
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2578
    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
  2579
    apply (rule meet_cong_l[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2580
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2581
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2582
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2583
lemma (in gcd_condition_monoid) gcd_cong_r:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2584
  assumes carr: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2585
    and yy': "y \<sim> y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2586
  shows "somegcd G x y \<sim> somegcd G x y'"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2587
proof -
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2588
  interpret weak_lower_semilattice "division_rel G" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2589
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2590
    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
  2591
    apply (rule meet_cong_r[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2592
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2593
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2594
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2595
(*
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2596
lemma (in gcd_condition_monoid) asc_cong_gcd_l [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2597
  assumes carr: "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2598
  shows "asc_cong (\<lambda>a. somegcd G a b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2599
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2600
unfolding CONG_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2601
by clarsimp (blast intro: gcd_cong_l)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2602
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2603
lemma (in gcd_condition_monoid) asc_cong_gcd_r [intro]:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2604
  assumes carr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2605
  shows "asc_cong (\<lambda>b. somegcd G a b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2606
using carr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2607
unfolding CONG_def
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2608
by clarsimp (blast intro: gcd_cong_r)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2609
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2610
lemmas (in gcd_condition_monoid) asc_cong_gcd_split [simp] =
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2611
    assoc_split[OF _ asc_cong_gcd_l] assoc_split[OF _ asc_cong_gcd_r]
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2612
*)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2613
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2614
lemma (in gcd_condition_monoid) gcdI:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2615
  assumes dvd: "a divides b"  "a divides c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2616
    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
  2617
    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
  2618
  shows "a \<sim> somegcd G b c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2619
  apply (simp add: somegcd_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2620
  apply (rule someI2_ex)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2621
   apply (rule exI[of _ a], simp add: isgcd_def)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2622
   apply (simp add: assms)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2623
  apply (simp add: isgcd_def assms, clarify)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2624
  apply (insert assms, blast intro: associatedI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2625
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2626
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2627
lemma (in gcd_condition_monoid) gcdI2:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2628
  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
  2629
  shows "a \<sim> somegcd G b c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2630
  using assms unfolding isgcd_def by (blast intro: gcdI)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2631
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2632
lemma (in gcd_condition_monoid) SomeGcd_ex:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2633
  assumes "finite A"  "A \<subseteq> carrier G"  "A \<noteq> {}"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2634
  shows "\<exists>x\<in> carrier G. x = SomeGcd G A"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2635
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2636
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2637
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2638
  show ?thesis
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2639
    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
  2640
    apply (rule finite_inf_closed[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2641
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2642
qed
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) gcd_assoc:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2645
  assumes carr: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2646
  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
  2647
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2648
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2649
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2650
  show ?thesis
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  2651
    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
  2652
    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
  2653
    apply (rule weak_meet_assoc[simplified], fact+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2654
    done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2655
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2656
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2657
lemma (in gcd_condition_monoid) gcd_mult:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2658
  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
  2659
  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
  2660
proof - (* following Jacobson, Basic Algebra, p.140 *)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2661
  let ?d = "somegcd G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2662
  let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2663
  note carr[simp] = acarr bcarr ccarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2664
  have dcarr: "?d \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2665
  have ecarr: "?e \<in> carrier G" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2666
  note carr = carr dcarr ecarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2667
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2668
  have "?d divides a" by (simp add: gcd_divides_l)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2669
  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
  2670
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2671
  have "?d divides b" by (simp add: gcd_divides_r)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2672
  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
  2673
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2674
  from cd'ca cd'cb have cd'e: "c \<otimes> ?d divides ?e"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2675
    by (rule gcd_divides) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2676
  then obtain u where ucarr[simp]: "u \<in> carrier G" and e_cdu: "?e = c \<otimes> ?d \<otimes> u"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2677
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2678
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2679
  note carr = carr ucarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2680
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2681
  have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2682
  then obtain x where xcarr: "x \<in> carrier G" and ca_ex: "c \<otimes> a = ?e \<otimes> x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2683
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2684
  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
  2685
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2686
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2687
  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
  2688
    by (simp add: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2689
  then have "a = ?d \<otimes> u \<otimes> x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2690
    by (rule l_cancel[of c a]) (simp add: xcarr)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2691
  then have du'a: "?d \<otimes> u divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2692
    by (rule dividesI[OF xcarr])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2693
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2694
  have "?e divides c \<otimes> b" by (intro gcd_divides_r) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2695
  then obtain x where xcarr: "x \<in> carrier G" and cb_ex: "c \<otimes> b = ?e \<otimes> x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2696
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2697
  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
  2698
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2699
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2700
  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
  2701
    by (simp add: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2702
  with xcarr have "b = ?d \<otimes> u \<otimes> x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2703
    by (intro l_cancel[of c b]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2704
  then have du'b: "?d \<otimes> u divides b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2705
    by (intro dividesI[OF xcarr])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2706
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2707
  from du'a du'b carr have du'd: "?d \<otimes> u divides ?d"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2708
    by (intro gcd_divides) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2709
  then have uunit: "u \<in> Units G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2710
  proof (elim dividesE)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2711
    fix v
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2712
    assume vcarr[simp]: "v \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2713
    assume d: "?d = ?d \<otimes> u \<otimes> v"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2714
    have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2715
    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
  2716
    finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" .
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2717
    then have i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2718
    then have i1: "\<one> = v \<otimes> u" by (simp add: m_comm)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2719
    from vcarr i1[symmetric] i2[symmetric] show "u \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2720
      by (auto simp: Units_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2721
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2722
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2723
  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
  2724
    by (intro associatedI2[of u]) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2725
  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
  2726
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2727
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2728
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2729
lemma (in monoid) assoc_subst:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2730
  assumes ab: "a \<sim> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2731
    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
  2732
      \<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
  2733
    and carr: "a \<in> carrier G"  "b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2734
  shows "f a \<sim> f b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2735
  using assms by auto
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2736
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2737
lemma (in gcd_condition_monoid) relprime_mult:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2738
  assumes abrelprime: "somegcd G a b \<sim> \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2739
    and acrelprime: "somegcd G a c \<sim> \<one>"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2740
    and carr[simp]: "a \<in> carrier G"  "b \<in> carrier G"  "c \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2741
  shows "somegcd G a (b \<otimes> c) \<sim> \<one>"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2742
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2743
  have "c = c \<otimes> \<one>" by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2744
  also from abrelprime[symmetric]
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2745
  have "\<dots> \<sim> c \<otimes> somegcd G a b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2746
    by (rule assoc_subst) (simp add: mult_cong_r)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2747
  also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2748
    by (rule gcd_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2749
  finally have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2750
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2751
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2752
  from carr have a: "a \<sim> somegcd G a (c \<otimes> a)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2753
    by (fast intro: gcdI divides_prod_l)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2754
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2755
  have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2756
    by (simp add: m_comm)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2757
  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
  2758
    by (rule assoc_subst) (simp add: gcd_cong_l)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2759
  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
  2760
    by (rule assoc_subst) simp+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2761
  also from c[symmetric] have "\<dots> \<sim> somegcd G a c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2762
    by (rule assoc_subst) (simp add: gcd_cong_r)+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2763
  also note acrelprime
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2764
  finally show "somegcd G a (b \<otimes> c) \<sim> \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2765
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2766
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2767
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2768
lemma (in gcd_condition_monoid) primeness_condition: "primeness_condition_monoid G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2769
  apply unfold_locales
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2770
  apply (rule primeI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2771
   apply (elim irreducibleE, assumption)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2772
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2773
  fix p a b
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2774
  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
  2775
    and pirr: "irreducible G p"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2776
    and pdvdab: "p divides a \<otimes> b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2777
  from pirr have pnunit: "p \<notin> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2778
    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
  2779
    by (fast elim: irreducibleE)+
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2780
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2781
  show "p divides a \<or> p divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2782
  proof (rule ccontr, clarsimp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2783
    assume npdvda: "\<not> p divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2784
    with pcarr acarr have "\<one> \<sim> somegcd G p a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2785
      apply (intro gcdI, simp, simp, simp)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2786
           apply (fast intro: unit_divides)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2787
          apply (fast intro: unit_divides)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2788
         apply (clarsimp simp add: Unit_eq_dividesone[symmetric])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2789
         apply (rule r, rule, assumption)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2790
         apply (rule properfactorI, assumption)
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  2791
    proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2792
      fix y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2793
      assume ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2794
      assume "p divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2795
      also assume "y divides a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2796
      finally have "p divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2797
        by (simp add: pcarr ycarr acarr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2798
      with npdvda show False ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2799
    qed simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2800
    with pcarr acarr have pa: "somegcd G p a \<sim> \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2801
      by (fast intro: associated_sym[of "\<one>"] gcd_closed)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2802
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2803
    assume npdvdb: "\<not> p divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2804
    with pcarr bcarr have "\<one> \<sim> somegcd G p b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2805
      apply (intro gcdI, simp, simp, simp)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2806
           apply (fast intro: unit_divides)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2807
          apply (fast intro: unit_divides)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2808
         apply (clarsimp simp add: Unit_eq_dividesone[symmetric])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2809
         apply (rule r, rule, assumption)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2810
         apply (rule properfactorI, assumption)
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  2811
    proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2812
      fix y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2813
      assume ycarr: "y \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2814
      assume "p divides y"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2815
      also assume "y divides b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2816
      finally have "p divides b" by (simp add: pcarr ycarr bcarr)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2817
      with npdvdb
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2818
      show "False" ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2819
    qed simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2820
    with pcarr bcarr have pb: "somegcd G p b \<sim> \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2821
      by (fast intro: associated_sym[of "\<one>"] gcd_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2822
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2823
    from pcarr acarr bcarr pdvdab have "p gcdof p (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2824
      by (fast intro: isgcd_divides_l)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2825
    with pcarr acarr bcarr have "p \<sim> somegcd G p (a \<otimes> b)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2826
      by (fast intro: gcdI2)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2827
    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
  2828
      by (rule relprime_mult)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2829
    finally have "p \<sim> \<one>"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2830
      by (simp add: pcarr acarr bcarr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2831
    with pcarr have "p \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2832
      by (fast intro: assoc_unit_l)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2833
    with pnunit show False ..
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2834
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2835
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2836
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  2837
sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2838
  by (rule primeness_condition)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2839
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2840
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2841
subsubsection \<open>Divisor chain condition\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2842
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2843
lemma (in divisor_chain_condition_monoid) wfactors_exist:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2844
  assumes acarr: "a \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2845
  shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2846
proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2847
  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
  2848
  proof (rule wf_induct[OF division_wellfounded])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2849
    fix x
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2850
    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
  2851
                    \<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
  2852
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2853
    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
  2854
      apply clarify
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2855
      apply (cases "x \<in> Units G")
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2856
       apply (rule exI[of _ "[]"], simp)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2857
      apply (cases "irreducible G x")
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2858
       apply (rule exI[of _ "[x]"], simp add: wfactors_def)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2859
    proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2860
      assume xcarr: "x \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2861
        and xnunit: "x \<notin> Units G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2862
        and xnirr: "\<not> irreducible G x"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2863
      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
  2864
        apply -
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2865
        apply (rule ccontr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2866
        apply simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2867
        apply (subgoal_tac "irreducible G x", simp)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2868
        apply (rule irreducibleI, simp, simp)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2869
        done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2870
      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
  2871
        and pfyx: "properfactor G y x"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2872
        by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2873
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2874
      have ih': "\<And>y. \<lbrakk>y \<in> carrier G; properfactor G y x\<rbrakk>
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2875
          \<Longrightarrow> \<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2876
        by (rule ih[rule_format, simplified]) (simp add: xcarr)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2877
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2878
      from ih' [OF ycarr pfyx]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2879
      obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2880
        by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2881
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2882
      from pfyx have "y divides x" and nyx: "\<not> y \<sim> x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2883
        by (fast elim: properfactorE2)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2884
      then obtain z where zcarr: "z \<in> carrier G" and x: "x = y \<otimes> z"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2885
        by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2886
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2887
      from zcarr ycarr have "properfactor G z x"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2888
        apply (subst x)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2889
        apply (intro properfactorI3[of _ _ y])
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2890
            apply (simp add: m_comm)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2891
           apply (simp add: ynunit)+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2892
        done
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2893
      from ih' [OF zcarr this]
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2894
      obtain zs where zscarr: "set zs \<subseteq> carrier G" and zfs: "wfactors G zs z"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2895
        by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2896
      from yscarr zscarr have xscarr: "set (ys@zs) \<subseteq> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2897
        by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2898
      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
  2899
        by (rule wfactors_mult)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2900
      then have "wfactors G (ys@zs) x"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2901
        by (simp add: x)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2902
      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
  2903
        by fast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2904
    qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2905
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2906
  from acarr show ?thesis by (rule r)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2907
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2908
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2909
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  2910
subsubsection \<open>Primeness condition\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2911
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2912
lemma (in comm_monoid_cancel) multlist_prime_pos:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2913
  assumes carr: "a \<in> carrier G"  "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2914
    and aprime: "prime G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2915
    and "a divides (foldr (op \<otimes>) as \<one>)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2916
  shows "\<exists>i<length as. a divides (as!i)"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2917
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2918
  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
  2919
    \<longrightarrow> (\<exists>i. i < length as \<and> a divides (as!i))"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2920
    apply (induct as)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2921
     apply clarsimp defer 1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2922
     apply clarsimp defer 1
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2923
  proof -
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2924
    assume "a divides \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2925
    with carr have "a \<in> Units G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2926
      by (fast intro: divides_unit[of a \<one>])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2927
    with aprime show False
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2928
      by (elim primeE, simp)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2929
  next
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2930
    fix aa as
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2931
    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
  2932
      and carr': "aa \<in> carrier G"  "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2933
      and "a divides aa \<otimes> foldr op \<otimes> as \<one>"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2934
    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
  2935
      by (intro prime_divides) simp+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2936
    then show "\<exists>i<Suc (length as). a divides (aa # as) ! i"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2937
    proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2938
      assume "a divides aa"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2939
      then have p1: "a divides (aa#as)!0" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2940
      have "0 < Suc (length as)" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2941
      with p1 show ?thesis by fast
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2942
    next
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2943
      assume "a divides foldr op \<otimes> as \<one>"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2944
      from ih [OF this] obtain i where "a divides as ! i" and len: "i < length as" by auto
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2945
      then have p1: "a divides (aa#as) ! (Suc i)" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2946
      from len have "Suc i < Suc (length as)" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2947
      with p1 show ?thesis by force
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2948
   qed
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2949
  qed
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2950
  from assms show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2951
    by (intro r) auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2952
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2953
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  2954
lemma (in primeness_condition_monoid) wfactors_unique__hlp_induct:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2955
  "\<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
  2956
           wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'"
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2957
proof (induct as)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2958
  case Nil
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2959
  show ?case
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2960
  proof auto
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2961
    fix a as'
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2962
    assume a: "a \<in> carrier G"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2963
    assume "wfactors G [] a"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2964
    then obtain "\<one> \<sim> a" by (auto elim: wfactorsE)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2965
    with a have "a \<in> Units G" by (auto intro: assoc_unit_r)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2966
    moreover assume "wfactors G as' a"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2967
    moreover assume "set as' \<subseteq> carrier G"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2968
    ultimately have "as' = []" by (rule unit_wfactors_empty)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2969
    then show "essentially_equal G [] as'" by simp
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2970
  qed
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2971
next
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2972
  case (Cons ah as)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2973
  then show ?case
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2974
  proof clarsimp
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2975
    fix a as'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2976
    assume ih [rule_format]:
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2977
      "\<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
  2978
        wfactors G as' a \<longrightarrow> essentially_equal G as as'"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2979
      and acarr: "a \<in> carrier G" and ahcarr: "ah \<in> carrier G"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2980
      and ascarr: "set as \<subseteq> carrier G" and as'carr: "set as' \<subseteq> carrier G"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2981
      and afs: "wfactors G (ah # as) a"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2982
      and afs': "wfactors G as' a"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2983
    then have ahdvda: "ah divides a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2984
      by (intro wfactors_dividesI[of "ah#as" "a"]) simp_all
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2985
    then obtain a' where a'carr: "a' \<in> carrier G" and a: "a = ah \<otimes> a'"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2986
      by blast
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2987
    have a'fs: "wfactors G as a'"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2988
      apply (rule wfactorsE[OF afs], rule wfactorsI, simp)
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2989
      apply (simp add: a)
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  2990
      apply (insert ascarr a'carr)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2991
      apply (intro assoc_l_cancel[of ah _ a'] multlist_closed ahcarr, assumption+)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2992
      done
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2993
    from afs have ahirr: "irreducible G ah"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2994
      by (elim wfactorsE) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2995
    with ascarr have ahprime: "prime G ah"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  2996
      by (intro irreducible_prime ahcarr)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2997
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2998
    note carr [simp] = acarr ahcarr ascarr as'carr a'carr
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  2999
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3000
    note ahdvda
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3001
    also from afs' have "a divides (foldr (op \<otimes>) as' \<one>)"
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3002
      by (elim wfactorsE associatedE, simp)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3003
    finally have "ah divides (foldr (op \<otimes>) as' \<one>)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3004
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3005
    with ahprime have "\<exists>i<length as'. ah divides as'!i"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3006
      by (intro multlist_prime_pos) simp_all
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3007
    then obtain i where len: "i<length as'" and ahdvd: "ah divides as'!i"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3008
      by blast
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3009
    from afs' carr have irrasi: "irreducible G (as'!i)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3010
      by (fast intro: nth_mem[OF len] elim: wfactorsE)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3011
    from len carr have asicarr[simp]: "as'!i \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3012
      unfolding set_conv_nth by force
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3013
    note carr = carr asicarr
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3014
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3015
    from ahdvd obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3016
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3017
    with carr irrasi[simplified asi] have asiah: "as'!i \<sim> ah"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3018
      apply -
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3019
      apply (elim irreducible_prodE[of "ah" "x"], assumption+)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3020
       apply (rule associatedI2[of x], assumption+)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3021
      apply (rule irreducibleE[OF ahirr], simp)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3022
      done
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3023
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3024
    note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as']
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3025
    note partscarr [simp] = setparts[THEN subset_trans[OF _ as'carr]]
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3026
    note carr = carr partscarr
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3027
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3028
    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
  3029
      apply (intro wfactors_prod_exists)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3030
      using setparts afs'
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3031
       apply (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3032
      apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3033
      done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3034
    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
  3035
      by auto
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3036
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3037
    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
  3038
      apply (intro wfactors_prod_exists)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3039
      using setparts afs'
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3040
       apply (fast elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3041
      apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3042
      done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3043
    then obtain aa_2 where aa2carr: "aa_2 \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3044
      and aa2fs: "wfactors G (drop (Suc i) as') aa_2"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3045
      by auto
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3046
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3047
    note carr = carr aa1carr[simp] aa2carr[simp]
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3048
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3049
    from aa1fs aa2fs
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3050
    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
  3051
      by (intro wfactors_mult, simp+)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3052
    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
  3053
      apply (intro wfactors_mult_single)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3054
      using setparts afs'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3055
          apply (fast intro: nth_mem[OF len] elim: wfactorsE)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3056
         apply simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3057
      done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3058
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3059
    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
  3060
      by (metis irrasi wfactors_mult_single)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3061
    with len carr aa1carr aa2carr aa1fs
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3062
    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
  3063
      apply (intro wfactors_mult)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3064
           apply fast
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3065
          apply (simp, (fast intro: nth_mem[OF len])?)+
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3066
      done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3067
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3068
    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
  3069
      by (simp add: Cons_nth_drop_Suc)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3070
    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
  3071
      by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3072
    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
  3073
      by (metis as' ee_wfactorsD m_closed)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3074
    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
  3075
      by (metis aa1carr aa2carr asicarr m_lcomm)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3076
    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
  3077
      by (metis associated_sym m_closed mult_cong_l)
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3078
    also note t1
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3079
    finally have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3080
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3081
    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
  3082
      by (simp add: a, fast intro: assoc_l_cancel[of ah _ a'])
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3083
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3084
    note v1
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3085
    also note a'
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3086
    finally have "wfactors G (take i as' @ drop (Suc i) as') a'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3087
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3088
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3089
    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
  3090
      by (intro ih[of a']) simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3091
    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
  3092
      by (elim essentially_equalE) (fastforce intro: essentially_equalI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3093
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3094
    from carr have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as')
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3095
      (as' ! i # take i as' @ drop (Suc i) as')"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3096
    proof (intro essentially_equalI)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3097
      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
  3098
        by simp
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3099
    next
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3100
      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
  3101
        by (simp add: list_all2_append) (simp add: asiah[symmetric])
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3102
    qed
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3103
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3104
    note ee1
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3105
    also note ee2
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3106
    also have "essentially_equal G (as' ! i # take i as' @ drop (Suc i) as')
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3107
      (take i as' @ as' ! i # drop (Suc i) as')"
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3108
      apply (intro essentially_equalI)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3109
       apply (subgoal_tac "as' ! i # take i as' @ drop (Suc i) as' <~~>
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3110
          take i as' @ as' ! i # drop (Suc i) as'")
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
  3111
        apply simp
46129
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3112
       apply (rule perm_append_Cons)
229fcbebf732 tuned proofs
haftmann
parents: 44890
diff changeset
  3113
      apply simp
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
  3114
      done
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3115
    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
  3116
      by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3117
    then show "essentially_equal G (ah # as) as'"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3118
      by (subst as')
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3119
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3120
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3121
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3122
lemma (in primeness_condition_monoid) wfactors_unique:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3123
  assumes "wfactors G as a"  "wfactors G as' a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3124
    and "a \<in> carrier G"  "set as \<subseteq> carrier G"  "set as' \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3125
  shows "essentially_equal G as as'"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3126
  by (rule wfactors_unique__hlp_induct[rule_format, of a]) (simp add: assms)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3127
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3128
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  3129
subsubsection \<open>Application to factorial monoids\<close>
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  3130
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  3131
text \<open>Number of factors for wellfoundedness\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3132
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3133
definition factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3134
  where "factorcount G a =
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3135
    (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
  3136
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3137
lemma (in monoid) ee_length:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3138
  assumes ee: "essentially_equal G as bs"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3139
  shows "length as = length bs"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3140
  by (rule essentially_equalE[OF ee]) (metis list_all2_conv_all_nth perm_length)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3141
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3142
lemma (in factorial_monoid) factorcount_exists:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3143
  assumes carr[simp]: "a \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3144
  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
  3145
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3146
  have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3147
    by (intro wfactors_exist) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3148
  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
  3149
    by (auto simp del: carr)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3150
  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
  3151
    by (metis afs ascarr assms ee_length wfactors_unique)
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3152
  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
  3153
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3154
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3155
lemma (in factorial_monoid) factorcount_unique:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3156
  assumes afs: "wfactors G as a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3157
    and acarr[simp]: "a \<in> carrier G" and ascarr[simp]: "set as \<subseteq> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3158
  shows "factorcount G a = length as"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3159
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3160
  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
  3161
    by (rule factorcount_exists) simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3162
  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
  3163
    by auto
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3164
  have ac: "ac = factorcount G a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3165
    apply (simp add: factorcount_def)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3166
    apply (rule theI2)
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3167
      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
  3168
     apply (metis afs alen ascarr)+
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3169
    done
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3170
  from ascarr afs have "ac = length as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3171
    by (iprover intro: alen[rule_format])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3172
  with ac show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3173
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3174
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3175
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3176
lemma (in factorial_monoid) divides_fcount:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3177
  assumes dvd: "a divides b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3178
    and acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3179
    and bcarr:"b \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3180
  shows "factorcount G a \<le> factorcount G b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3181
proof (rule dividesE[OF dvd])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3182
  fix c
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3183
  from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3184
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3185
  then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3186
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3187
  with acarr have fca: "factorcount G a = length as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3188
    by (intro factorcount_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3189
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3190
  assume ccarr: "c \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3191
  then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3192
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3193
  then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3194
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3195
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3196
  note [simp] = acarr bcarr ccarr ascarr cscarr
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3197
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3198
  assume b: "b = a \<otimes> c"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3199
  from afs cfs have "wfactors G (as@cs) (a \<otimes> c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3200
    by (intro wfactors_mult) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3201
  with b have "wfactors G (as@cs) b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3202
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3203
  then have "factorcount G b = length (as@cs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3204
    by (intro factorcount_unique) simp_all
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3205
  then have "factorcount G b = length as + length cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3206
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3207
  with fca show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3208
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3209
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3210
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3211
lemma (in factorial_monoid) associated_fcount:
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3212
  assumes acarr: "a \<in> carrier G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3213
    and bcarr: "b \<in> carrier G"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3214
    and asc: "a \<sim> b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3215
  shows "factorcount G a = factorcount G b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3216
  apply (rule associatedE[OF asc])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3217
  apply (drule divides_fcount[OF _ acarr bcarr])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3218
  apply (drule divides_fcount[OF _ bcarr acarr])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3219
  apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3220
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3221
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3222
lemma (in factorial_monoid) properfactor_fcount:
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3223
  assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3224
    and pf: "properfactor G a b"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3225
  shows "factorcount G a < factorcount G b"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3226
proof (rule properfactorE[OF pf], elim dividesE)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3227
  fix c
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3228
  from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3229
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3230
  then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3231
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3232
  with acarr have fca: "factorcount G a = length as"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3233
    by (intro factorcount_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3234
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3235
  assume ccarr: "c \<in> carrier G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3236
  then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3237
    by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3238
  then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3239
    by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3240
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3241
  assume b: "b = a \<otimes> c"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3242
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3243
  have "wfactors G (as@cs) (a \<otimes> c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3244
    by (rule wfactors_mult) fact+
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3245
  with b have "wfactors G (as@cs) b"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3246
    by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3247
  with ascarr cscarr bcarr have "factorcount G b = length (as@cs)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3248
    by (simp add: factorcount_unique)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3249
  then have fcb: "factorcount G b = length as + length cs"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3250
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3251
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3252
  assume nbdvda: "\<not> b divides a"
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3253
  have "c \<notin> Units G"
63846
23134a486dc6 tuned proofs;
wenzelm
parents: 63832
diff changeset
  3254
  proof
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3255
    assume cunit:"c \<in> Units G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3256
    have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3257
      by (simp add: b)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3258
    also from ccarr acarr cunit have "\<dots> = a \<otimes> (c \<otimes> inv c)"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3259
      by (fast intro: m_assoc)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3260
    also from ccarr cunit have "\<dots> = a \<otimes> \<one>" by simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3261
    also from acarr have "\<dots> = a" by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3262
    finally have "a = b \<otimes> inv c" by simp
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3263
    with ccarr cunit have "b divides a"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3264
      by (fast intro: dividesI[of "inv c"])
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3265
    with nbdvda show False by simp
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3266
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3267
  with cfs have "length cs > 0"
36278
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3268
    apply -
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3269
    apply (rule ccontr, simp)
6b330b1fa0c0 Tidied up using s/l
paulson
parents: 35849
diff changeset
  3270
    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
  3271
    done
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3272
  with fca fcb show ?thesis
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3273
    by simp
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3274
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3275
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3276
sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3277
  apply unfold_locales
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3278
  apply (rule wfUNIVI)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3279
  apply (rule measure_induct[of "factorcount G"])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3280
  apply simp
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3281
  apply (metis properfactor_fcount)
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3282
  done
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3283
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3284
sublocale factorial_monoid \<subseteq> primeness_condition_monoid
63633
2accfb71e33b is_prime -> prime
eberlm <eberlm@in.tum.de>
parents: 63524
diff changeset
  3285
  by standard (rule irreducible_prime)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3286
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3287
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3288
lemma (in factorial_monoid) primeness_condition: "primeness_condition_monoid G" ..
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3289
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3290
lemma (in factorial_monoid) gcd_condition [simp]: "gcd_condition_monoid G"
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60515
diff changeset
  3291
  by standard (rule gcdof_exists)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3292
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3293
sublocale factorial_monoid \<subseteq> gcd_condition_monoid
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60515
diff changeset
  3294
  by standard (rule gcdof_exists)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3295
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3296
lemma (in factorial_monoid) division_weak_lattice [simp]: "weak_lattice (division_rel G)"
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3297
proof -
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3298
  interpret weak_lower_semilattice "division_rel G"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3299
    by simp
27713
95b36bfe7fc4 New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents: 27701
diff changeset
  3300
  show "weak_lattice (division_rel G)"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3301
  proof (unfold_locales, simp_all)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3302
    fix x y
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3303
    assume carr: "x \<in> carrier G"  "y \<in> carrier G"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3304
    from lcmof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z lcmof x y"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3305
      by blast
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3306
    with carr have "least (division_rel G) z (Upper (division_rel G) {x, y})"
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3307
      by (simp add: lcmof_leastUpper[symmetric])
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3308
    then show "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})"
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3309
      by blast
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3310
  qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3311
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3312
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3313
61382
efac889fccbc isabelle update_cartouches;
wenzelm
parents: 61169
diff changeset
  3314
subsection \<open>Factoriality Theorems\<close>
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3315
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3316
theorem factorial_condition_one: (* Jacobson theorem 2.21 *)
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3317
  "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G \<longleftrightarrow> factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3318
proof (rule iffI, clarify)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3319
  assume dcc: "divisor_chain_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3320
    and pc: "primeness_condition_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3321
  interpret divisor_chain_condition_monoid "G" by (rule dcc)
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3322
  interpret primeness_condition_monoid "G" by (rule pc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3323
  show "factorial_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3324
    by (fast intro: factorial_monoidI wfactors_exist wfactors_unique)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3325
next
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3326
  assume "factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3327
  then interpret factorial_monoid "G" .
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3328
  show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3329
    by rule unfold_locales
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3330
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3331
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3332
theorem factorial_condition_two: (* Jacobson theorem 2.22 *)
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3333
  "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G \<longleftrightarrow> factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3334
proof (rule iffI, clarify)
57865
dcfb33c26f50 tuned proofs -- fewer warnings;
wenzelm
parents: 57492
diff changeset
  3335
  assume dcc: "divisor_chain_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3336
    and gc: "gcd_condition_monoid G"
29237
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3337
  interpret divisor_chain_condition_monoid "G" by (rule dcc)
e90d9d51106b More porting to new locales.
ballarin
parents: 28823
diff changeset
  3338
  interpret gcd_condition_monoid "G" by (rule gc)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3339
  show "factorial_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3340
    by (simp add: factorial_condition_one[symmetric], rule, unfold_locales)
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3341
next
63847
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3342
  assume "factorial_monoid G"
34dccc2dd6db tuned proofs;
wenzelm
parents: 63846
diff changeset
  3343
  then interpret factorial_monoid "G" .
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3344
  show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G"
63832
a400b127853c misc tuning and modernization;
wenzelm
parents: 63793
diff changeset
  3345
    by rule unfold_locales
27701
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3346
qed
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3347
ed7a2e0fab59 New theory on divisibility.
ballarin
parents:
diff changeset
  3348
end