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