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