| author | wenzelm | 
| Sun, 15 Nov 2009 00:23:26 +0100 | |
| changeset 33689 | d0a9ce721e0c | 
| parent 33657 | a4179bf442d1 | 
| child 33946 | fcc20072df9a | 
| permissions | -rw-r--r-- | 
| 32479 | 1 | (* Authors: Christophe Tabacznyj, Lawrence C. Paulson, Amine Chaieb, | 
| 31798 | 2 | Thomas M. Rasmussen, Jeremy Avigad, Tobias Nipkow | 
| 31706 | 3 | |
| 4 | ||
| 32479 | 5 | This file deals with the functions gcd and lcm. Definitions and | 
| 6 | lemmas are proved uniformly for the natural numbers and integers. | |
| 31706 | 7 | |
| 8 | This file combines and revises a number of prior developments. | |
| 9 | ||
| 10 | The original theories "GCD" and "Primes" were by Christophe Tabacznyj | |
| 11 | and Lawrence C. Paulson, based on \cite{davenport92}. They introduced
 | |
| 12 | gcd, lcm, and prime for the natural numbers. | |
| 13 | ||
| 14 | The original theory "IntPrimes" was by Thomas M. Rasmussen, and | |
| 15 | extended gcd, lcm, primes to the integers. Amine Chaieb provided | |
| 16 | another extension of the notions to the integers, and added a number | |
| 17 | of results to "Primes" and "GCD". IntPrimes also defined and developed | |
| 18 | the congruence relations on the integers. The notion was extended to | |
| 19 | the natural numbers by Chiaeb. | |
| 20 | ||
| 32036 
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
 avigad parents: 
31952diff
changeset | 21 | Jeremy Avigad combined all of these, made everything uniform for the | 
| 
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
 avigad parents: 
31952diff
changeset | 22 | natural numbers and the integers, and added a number of new theorems. | 
| 
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
 avigad parents: 
31952diff
changeset | 23 | |
| 31798 | 24 | Tobias Nipkow cleaned up a lot. | 
| 21256 | 25 | *) | 
| 26 | ||
| 31706 | 27 | |
| 28 | header {* GCD *}
 | |
| 21256 | 29 | |
| 30 | theory GCD | |
| 33318 
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
 haftmann parents: 
33197diff
changeset | 31 | imports Fact Parity | 
| 31706 | 32 | begin | 
| 33 | ||
| 34 | declare One_nat_def [simp del] | |
| 35 | ||
| 36 | subsection {* gcd *}
 | |
| 37 | ||
| 31992 | 38 | class gcd = zero + one + dvd + | 
| 31706 | 39 | |
| 40 | fixes | |
| 41 | gcd :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" and | |
| 42 | lcm :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" | |
| 43 | ||
| 21256 | 44 | begin | 
| 45 | ||
| 31706 | 46 | abbreviation | 
| 47 | coprime :: "'a \<Rightarrow> 'a \<Rightarrow> bool" | |
| 48 | where | |
| 49 | "coprime x y == (gcd x y = 1)" | |
| 50 | ||
| 51 | end | |
| 52 | ||
| 53 | ||
| 54 | (* definitions for the natural numbers *) | |
| 55 | ||
| 56 | instantiation nat :: gcd | |
| 57 | ||
| 58 | begin | |
| 21256 | 59 | |
| 31706 | 60 | fun | 
| 61 | gcd_nat :: "nat \<Rightarrow> nat \<Rightarrow> nat" | |
| 62 | where | |
| 63 | "gcd_nat x y = | |
| 64 | (if y = 0 then x else gcd y (x mod y))" | |
| 65 | ||
| 66 | definition | |
| 67 | lcm_nat :: "nat \<Rightarrow> nat \<Rightarrow> nat" | |
| 68 | where | |
| 69 | "lcm_nat x y = x * y div (gcd x y)" | |
| 70 | ||
| 71 | instance proof qed | |
| 72 | ||
| 73 | end | |
| 74 | ||
| 75 | ||
| 76 | (* definitions for the integers *) | |
| 77 | ||
| 78 | instantiation int :: gcd | |
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 79 | |
| 31706 | 80 | begin | 
| 21256 | 81 | |
| 31706 | 82 | definition | 
| 83 | gcd_int :: "int \<Rightarrow> int \<Rightarrow> int" | |
| 84 | where | |
| 85 | "gcd_int x y = int (gcd (nat (abs x)) (nat (abs y)))" | |
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 86 | |
| 31706 | 87 | definition | 
| 88 | lcm_int :: "int \<Rightarrow> int \<Rightarrow> int" | |
| 89 | where | |
| 90 | "lcm_int x y = int (lcm (nat (abs x)) (nat (abs y)))" | |
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 91 | |
| 31706 | 92 | instance proof qed | 
| 93 | ||
| 94 | end | |
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 95 | |
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 96 | |
| 31706 | 97 | subsection {* Set up Transfer *}
 | 
| 98 | ||
| 99 | ||
| 100 | lemma transfer_nat_int_gcd: | |
| 101 | "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> gcd (nat x) (nat y) = nat (gcd x y)" | |
| 102 | "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> lcm (nat x) (nat y) = nat (lcm x y)" | |
| 32479 | 103 | unfolding gcd_int_def lcm_int_def | 
| 31706 | 104 | by auto | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 105 | |
| 31706 | 106 | lemma transfer_nat_int_gcd_closures: | 
| 107 | "x >= (0::int) \<Longrightarrow> y >= 0 \<Longrightarrow> gcd x y >= 0" | |
| 108 | "x >= (0::int) \<Longrightarrow> y >= 0 \<Longrightarrow> lcm x y >= 0" | |
| 109 | by (auto simp add: gcd_int_def lcm_int_def) | |
| 110 | ||
| 111 | declare TransferMorphism_nat_int[transfer add return: | |
| 112 | transfer_nat_int_gcd transfer_nat_int_gcd_closures] | |
| 113 | ||
| 114 | lemma transfer_int_nat_gcd: | |
| 115 | "gcd (int x) (int y) = int (gcd x y)" | |
| 116 | "lcm (int x) (int y) = int (lcm x y)" | |
| 32479 | 117 | by (unfold gcd_int_def lcm_int_def, auto) | 
| 31706 | 118 | |
| 119 | lemma transfer_int_nat_gcd_closures: | |
| 120 | "is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> gcd x y >= 0" | |
| 121 | "is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> lcm x y >= 0" | |
| 122 | by (auto simp add: gcd_int_def lcm_int_def) | |
| 123 | ||
| 124 | declare TransferMorphism_int_nat[transfer add return: | |
| 125 | transfer_int_nat_gcd transfer_int_nat_gcd_closures] | |
| 126 | ||
| 127 | ||
| 128 | subsection {* GCD *}
 | |
| 129 | ||
| 130 | (* was gcd_induct *) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 131 | lemma gcd_nat_induct: | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 132 | fixes m n :: nat | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 133 | assumes "\<And>m. P m 0" | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 134 | and "\<And>m n. 0 < n \<Longrightarrow> P n (m mod n) \<Longrightarrow> P m n" | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 135 | shows "P m n" | 
| 31706 | 136 | apply (rule gcd_nat.induct) | 
| 137 | apply (case_tac "y = 0") | |
| 138 | using assms apply simp_all | |
| 139 | done | |
| 140 | ||
| 141 | (* specific to int *) | |
| 142 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 143 | lemma gcd_neg1_int [simp]: "gcd (-x::int) y = gcd x y" | 
| 31706 | 144 | by (simp add: gcd_int_def) | 
| 145 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 146 | lemma gcd_neg2_int [simp]: "gcd (x::int) (-y) = gcd x y" | 
| 31706 | 147 | by (simp add: gcd_int_def) | 
| 148 | ||
| 31813 | 149 | lemma abs_gcd_int[simp]: "abs(gcd (x::int) y) = gcd x y" | 
| 150 | by(simp add: gcd_int_def) | |
| 151 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 152 | lemma gcd_abs_int: "gcd (x::int) y = gcd (abs x) (abs y)" | 
| 31813 | 153 | by (simp add: gcd_int_def) | 
| 154 | ||
| 155 | lemma gcd_abs1_int[simp]: "gcd (abs x) (y::int) = gcd x y" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 156 | by (metis abs_idempotent gcd_abs_int) | 
| 31813 | 157 | |
| 158 | lemma gcd_abs2_int[simp]: "gcd x (abs y::int) = gcd x y" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 159 | by (metis abs_idempotent gcd_abs_int) | 
| 31706 | 160 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 161 | lemma gcd_cases_int: | 
| 31706 | 162 | fixes x :: int and y | 
| 163 | assumes "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> P (gcd x y)" | |
| 164 | and "x >= 0 \<Longrightarrow> y <= 0 \<Longrightarrow> P (gcd x (-y))" | |
| 165 | and "x <= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> P (gcd (-x) y)" | |
| 166 | and "x <= 0 \<Longrightarrow> y <= 0 \<Longrightarrow> P (gcd (-x) (-y))" | |
| 167 | shows "P (gcd x y)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 168 | by (insert prems, auto simp add: gcd_neg1_int gcd_neg2_int, arith) | 
| 21256 | 169 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 170 | lemma gcd_ge_0_int [simp]: "gcd (x::int) y >= 0" | 
| 31706 | 171 | by (simp add: gcd_int_def) | 
| 172 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 173 | lemma lcm_neg1_int: "lcm (-x::int) y = lcm x y" | 
| 31706 | 174 | by (simp add: lcm_int_def) | 
| 175 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 176 | lemma lcm_neg2_int: "lcm (x::int) (-y) = lcm x y" | 
| 31706 | 177 | by (simp add: lcm_int_def) | 
| 178 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 179 | lemma lcm_abs_int: "lcm (x::int) y = lcm (abs x) (abs y)" | 
| 31706 | 180 | by (simp add: lcm_int_def) | 
| 21256 | 181 | |
| 31814 | 182 | lemma abs_lcm_int [simp]: "abs (lcm i j::int) = lcm i j" | 
| 183 | by(simp add:lcm_int_def) | |
| 184 | ||
| 185 | lemma lcm_abs1_int[simp]: "lcm (abs x) (y::int) = lcm x y" | |
| 186 | by (metis abs_idempotent lcm_int_def) | |
| 187 | ||
| 188 | lemma lcm_abs2_int[simp]: "lcm x (abs y::int) = lcm x y" | |
| 189 | by (metis abs_idempotent lcm_int_def) | |
| 190 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 191 | lemma lcm_cases_int: | 
| 31706 | 192 | fixes x :: int and y | 
| 193 | assumes "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> P (lcm x y)" | |
| 194 | and "x >= 0 \<Longrightarrow> y <= 0 \<Longrightarrow> P (lcm x (-y))" | |
| 195 | and "x <= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> P (lcm (-x) y)" | |
| 196 | and "x <= 0 \<Longrightarrow> y <= 0 \<Longrightarrow> P (lcm (-x) (-y))" | |
| 197 | shows "P (lcm x y)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 198 | by (insert prems, auto simp add: lcm_neg1_int lcm_neg2_int, arith) | 
| 31706 | 199 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 200 | lemma lcm_ge_0_int [simp]: "lcm (x::int) y >= 0" | 
| 31706 | 201 | by (simp add: lcm_int_def) | 
| 202 | ||
| 203 | (* was gcd_0, etc. *) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 204 | lemma gcd_0_nat [simp]: "gcd (x::nat) 0 = x" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 205 | by simp | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 206 | |
| 31706 | 207 | (* was igcd_0, etc. *) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 208 | lemma gcd_0_int [simp]: "gcd (x::int) 0 = abs x" | 
| 31706 | 209 | by (unfold gcd_int_def, auto) | 
| 210 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 211 | lemma gcd_0_left_nat [simp]: "gcd 0 (x::nat) = x" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 212 | by simp | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 213 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 214 | lemma gcd_0_left_int [simp]: "gcd 0 (x::int) = abs x" | 
| 31706 | 215 | by (unfold gcd_int_def, auto) | 
| 216 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 217 | lemma gcd_red_nat: "gcd (x::nat) y = gcd y (x mod y)" | 
| 31706 | 218 | by (case_tac "y = 0", auto) | 
| 219 | ||
| 220 | (* weaker, but useful for the simplifier *) | |
| 221 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 222 | lemma gcd_non_0_nat: "y ~= (0::nat) \<Longrightarrow> gcd (x::nat) y = gcd y (x mod y)" | 
| 31706 | 223 | by simp | 
| 224 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 225 | lemma gcd_1_nat [simp]: "gcd (m::nat) 1 = 1" | 
| 21263 | 226 | by simp | 
| 21256 | 227 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 228 | lemma gcd_Suc_0 [simp]: "gcd (m::nat) (Suc 0) = Suc 0" | 
| 31706 | 229 | by (simp add: One_nat_def) | 
| 230 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 231 | lemma gcd_1_int [simp]: "gcd (m::int) 1 = 1" | 
| 31706 | 232 | by (simp add: gcd_int_def) | 
| 30082 
43c5b7bfc791
make more proofs work whether or not One_nat_def is a simp rule
 huffman parents: 
30042diff
changeset | 233 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 234 | lemma gcd_idem_nat: "gcd (x::nat) x = x" | 
| 31798 | 235 | by simp | 
| 31706 | 236 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 237 | lemma gcd_idem_int: "gcd (x::int) x = abs x" | 
| 31813 | 238 | by (auto simp add: gcd_int_def) | 
| 31706 | 239 | |
| 240 | declare gcd_nat.simps [simp del] | |
| 21256 | 241 | |
| 242 | text {*
 | |
| 27556 | 243 |   \medskip @{term "gcd m n"} divides @{text m} and @{text n}.  The
 | 
| 21256 | 244 | conjunctions don't seem provable separately. | 
| 245 | *} | |
| 246 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 247 | lemma gcd_dvd1_nat [iff]: "(gcd (m::nat)) n dvd m" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 248 | and gcd_dvd2_nat [iff]: "(gcd m n) dvd n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 249 | apply (induct m n rule: gcd_nat_induct) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 250 | apply (simp_all add: gcd_non_0_nat) | 
| 21256 | 251 | apply (blast dest: dvd_mod_imp_dvd) | 
| 31706 | 252 | done | 
| 253 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 254 | lemma gcd_dvd1_int [iff]: "gcd (x::int) y dvd x" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 255 | by (metis gcd_int_def int_dvd_iff gcd_dvd1_nat) | 
| 21256 | 256 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 257 | lemma gcd_dvd2_int [iff]: "gcd (x::int) y dvd y" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 258 | by (metis gcd_int_def int_dvd_iff gcd_dvd2_nat) | 
| 31706 | 259 | |
| 31730 | 260 | lemma dvd_gcd_D1_nat: "k dvd gcd m n \<Longrightarrow> (k::nat) dvd m" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 261 | by(metis gcd_dvd1_nat dvd_trans) | 
| 31730 | 262 | |
| 263 | lemma dvd_gcd_D2_nat: "k dvd gcd m n \<Longrightarrow> (k::nat) dvd n" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 264 | by(metis gcd_dvd2_nat dvd_trans) | 
| 31730 | 265 | |
| 266 | lemma dvd_gcd_D1_int: "i dvd gcd m n \<Longrightarrow> (i::int) dvd m" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 267 | by(metis gcd_dvd1_int dvd_trans) | 
| 31730 | 268 | |
| 269 | lemma dvd_gcd_D2_int: "i dvd gcd m n \<Longrightarrow> (i::int) dvd n" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 270 | by(metis gcd_dvd2_int dvd_trans) | 
| 31730 | 271 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 272 | lemma gcd_le1_nat [simp]: "a \<noteq> 0 \<Longrightarrow> gcd (a::nat) b \<le> a" | 
| 31706 | 273 | by (rule dvd_imp_le, auto) | 
| 274 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 275 | lemma gcd_le2_nat [simp]: "b \<noteq> 0 \<Longrightarrow> gcd (a::nat) b \<le> b" | 
| 31706 | 276 | by (rule dvd_imp_le, auto) | 
| 277 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 278 | lemma gcd_le1_int [simp]: "a > 0 \<Longrightarrow> gcd (a::int) b \<le> a" | 
| 31706 | 279 | by (rule zdvd_imp_le, auto) | 
| 21256 | 280 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 281 | lemma gcd_le2_int [simp]: "b > 0 \<Longrightarrow> gcd (a::int) b \<le> b" | 
| 31706 | 282 | by (rule zdvd_imp_le, auto) | 
| 283 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 284 | lemma gcd_greatest_nat: "(k::nat) dvd m \<Longrightarrow> k dvd n \<Longrightarrow> k dvd gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 285 | by (induct m n rule: gcd_nat_induct) (simp_all add: gcd_non_0_nat dvd_mod) | 
| 31706 | 286 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 287 | lemma gcd_greatest_int: | 
| 31813 | 288 | "(k::int) dvd m \<Longrightarrow> k dvd n \<Longrightarrow> k dvd gcd m n" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 289 | apply (subst gcd_abs_int) | 
| 31706 | 290 | apply (subst abs_dvd_iff [symmetric]) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 291 | apply (rule gcd_greatest_nat [transferred]) | 
| 31813 | 292 | apply auto | 
| 31706 | 293 | done | 
| 21256 | 294 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 295 | lemma gcd_greatest_iff_nat [iff]: "(k dvd gcd (m::nat) n) = | 
| 31706 | 296 | (k dvd m & k dvd n)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 297 | by (blast intro!: gcd_greatest_nat intro: dvd_trans) | 
| 31706 | 298 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 299 | lemma gcd_greatest_iff_int: "((k::int) dvd gcd m n) = (k dvd m & k dvd n)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 300 | by (blast intro!: gcd_greatest_int intro: dvd_trans) | 
| 21256 | 301 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 302 | lemma gcd_zero_nat [simp]: "(gcd (m::nat) n = 0) = (m = 0 & n = 0)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 303 | by (simp only: dvd_0_left_iff [symmetric] gcd_greatest_iff_nat) | 
| 21256 | 304 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 305 | lemma gcd_zero_int [simp]: "(gcd (m::int) n = 0) = (m = 0 & n = 0)" | 
| 31706 | 306 | by (auto simp add: gcd_int_def) | 
| 21256 | 307 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 308 | lemma gcd_pos_nat [simp]: "(gcd (m::nat) n > 0) = (m ~= 0 | n ~= 0)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 309 | by (insert gcd_zero_nat [of m n], arith) | 
| 21256 | 310 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 311 | lemma gcd_pos_int [simp]: "(gcd (m::int) n > 0) = (m ~= 0 | n ~= 0)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 312 | by (insert gcd_zero_int [of m n], insert gcd_ge_0_int [of m n], arith) | 
| 31706 | 313 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 314 | lemma gcd_commute_nat: "gcd (m::nat) n = gcd n m" | 
| 33657 | 315 | by (rule dvd_antisym, auto) | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 316 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 317 | lemma gcd_commute_int: "gcd (m::int) n = gcd n m" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 318 | by (auto simp add: gcd_int_def gcd_commute_nat) | 
| 31706 | 319 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 320 | lemma gcd_assoc_nat: "gcd (gcd (k::nat) m) n = gcd k (gcd m n)" | 
| 33657 | 321 | apply (rule dvd_antisym) | 
| 31706 | 322 | apply (blast intro: dvd_trans)+ | 
| 323 | done | |
| 21256 | 324 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 325 | lemma gcd_assoc_int: "gcd (gcd (k::int) m) n = gcd k (gcd m n)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 326 | by (auto simp add: gcd_int_def gcd_assoc_nat) | 
| 31706 | 327 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 328 | lemmas gcd_left_commute_nat = | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 329 | mk_left_commute[of gcd, OF gcd_assoc_nat gcd_commute_nat] | 
| 31706 | 330 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 331 | lemmas gcd_left_commute_int = | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 332 | mk_left_commute[of gcd, OF gcd_assoc_int gcd_commute_int] | 
| 31706 | 333 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 334 | lemmas gcd_ac_nat = gcd_assoc_nat gcd_commute_nat gcd_left_commute_nat | 
| 31706 | 335 |   -- {* gcd is an AC-operator *}
 | 
| 21256 | 336 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 337 | lemmas gcd_ac_int = gcd_assoc_int gcd_commute_int gcd_left_commute_int | 
| 31706 | 338 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 339 | lemma gcd_unique_nat: "(d::nat) dvd a \<and> d dvd b \<and> | 
| 31706 | 340 | (\<forall>e. e dvd a \<and> e dvd b \<longrightarrow> e dvd d) \<longleftrightarrow> d = gcd a b" | 
| 341 | apply auto | |
| 33657 | 342 | apply (rule dvd_antisym) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 343 | apply (erule (1) gcd_greatest_nat) | 
| 31706 | 344 | apply auto | 
| 345 | done | |
| 21256 | 346 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 347 | lemma gcd_unique_int: "d >= 0 & (d::int) dvd a \<and> d dvd b \<and> | 
| 31706 | 348 | (\<forall>e. e dvd a \<and> e dvd b \<longrightarrow> e dvd d) \<longleftrightarrow> d = gcd a b" | 
| 33657 | 349 | apply (case_tac "d = 0") | 
| 350 | apply simp | |
| 351 | apply (rule iffI) | |
| 352 | apply (rule zdvd_antisym_nonneg) | |
| 353 | apply (auto intro: gcd_greatest_int) | |
| 31706 | 354 | done | 
| 30082 
43c5b7bfc791
make more proofs work whether or not One_nat_def is a simp rule
 huffman parents: 
30042diff
changeset | 355 | |
| 31798 | 356 | lemma gcd_proj1_if_dvd_nat [simp]: "(x::nat) dvd y \<Longrightarrow> gcd x y = x" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 357 | by (metis dvd.eq_iff gcd_unique_nat) | 
| 31798 | 358 | |
| 359 | lemma gcd_proj2_if_dvd_nat [simp]: "(y::nat) dvd x \<Longrightarrow> gcd x y = y" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 360 | by (metis dvd.eq_iff gcd_unique_nat) | 
| 31798 | 361 | |
| 362 | lemma gcd_proj1_if_dvd_int[simp]: "x dvd y \<Longrightarrow> gcd (x::int) y = abs x" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 363 | by (metis abs_dvd_iff abs_eq_0 gcd_0_left_int gcd_abs_int gcd_unique_int) | 
| 31798 | 364 | |
| 365 | lemma gcd_proj2_if_dvd_int[simp]: "y dvd x \<Longrightarrow> gcd (x::int) y = abs y" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 366 | by (metis gcd_proj1_if_dvd_int gcd_commute_int) | 
| 31798 | 367 | |
| 368 | ||
| 21256 | 369 | text {*
 | 
| 370 | \medskip Multiplication laws | |
| 371 | *} | |
| 372 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 373 | lemma gcd_mult_distrib_nat: "(k::nat) * gcd m n = gcd (k * m) (k * n)" | 
| 21256 | 374 |     -- {* \cite[page 27]{davenport92} *}
 | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 375 | apply (induct m n rule: gcd_nat_induct) | 
| 31706 | 376 | apply simp | 
| 21256 | 377 | apply (case_tac "k = 0") | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 378 | apply (simp_all add: mod_geq gcd_non_0_nat mod_mult_distrib2) | 
| 31706 | 379 | done | 
| 21256 | 380 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 381 | lemma gcd_mult_distrib_int: "abs (k::int) * gcd m n = gcd (k * m) (k * n)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 382 | apply (subst (1 2) gcd_abs_int) | 
| 31813 | 383 | apply (subst (1 2) abs_mult) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 384 | apply (rule gcd_mult_distrib_nat [transferred]) | 
| 31706 | 385 | apply auto | 
| 386 | done | |
| 21256 | 387 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 388 | lemma coprime_dvd_mult_nat: "coprime (k::nat) n \<Longrightarrow> k dvd m * n \<Longrightarrow> k dvd m" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 389 | apply (insert gcd_mult_distrib_nat [of m k n]) | 
| 21256 | 390 | apply simp | 
| 391 | apply (erule_tac t = m in ssubst) | |
| 392 | apply simp | |
| 393 | done | |
| 394 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 395 | lemma coprime_dvd_mult_int: | 
| 31813 | 396 | "coprime (k::int) n \<Longrightarrow> k dvd m * n \<Longrightarrow> k dvd m" | 
| 397 | apply (subst abs_dvd_iff [symmetric]) | |
| 398 | apply (subst dvd_abs_iff [symmetric]) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 399 | apply (subst (asm) gcd_abs_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 400 | apply (rule coprime_dvd_mult_nat [transferred]) | 
| 31813 | 401 | prefer 4 apply assumption | 
| 402 | apply auto | |
| 403 | apply (subst abs_mult [symmetric], auto) | |
| 31706 | 404 | done | 
| 405 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 406 | lemma coprime_dvd_mult_iff_nat: "coprime (k::nat) n \<Longrightarrow> | 
| 31706 | 407 | (k dvd m * n) = (k dvd m)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 408 | by (auto intro: coprime_dvd_mult_nat) | 
| 31706 | 409 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 410 | lemma coprime_dvd_mult_iff_int: "coprime (k::int) n \<Longrightarrow> | 
| 31706 | 411 | (k dvd m * n) = (k dvd m)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 412 | by (auto intro: coprime_dvd_mult_int) | 
| 31706 | 413 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 414 | lemma gcd_mult_cancel_nat: "coprime k n \<Longrightarrow> gcd ((k::nat) * m) n = gcd m n" | 
| 33657 | 415 | apply (rule dvd_antisym) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 416 | apply (rule gcd_greatest_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 417 | apply (rule_tac n = k in coprime_dvd_mult_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 418 | apply (simp add: gcd_assoc_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 419 | apply (simp add: gcd_commute_nat) | 
| 31706 | 420 | apply (simp_all add: mult_commute) | 
| 421 | done | |
| 21256 | 422 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 423 | lemma gcd_mult_cancel_int: | 
| 31813 | 424 | "coprime (k::int) n \<Longrightarrow> gcd (k * m) n = gcd m n" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 425 | apply (subst (1 2) gcd_abs_int) | 
| 31813 | 426 | apply (subst abs_mult) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 427 | apply (rule gcd_mult_cancel_nat [transferred], auto) | 
| 31706 | 428 | done | 
| 21256 | 429 | |
| 430 | text {* \medskip Addition laws *}
 | |
| 431 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 432 | lemma gcd_add1_nat [simp]: "gcd ((m::nat) + n) n = gcd m n" | 
| 31706 | 433 | apply (case_tac "n = 0") | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 434 | apply (simp_all add: gcd_non_0_nat) | 
| 31706 | 435 | done | 
| 436 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 437 | lemma gcd_add2_nat [simp]: "gcd (m::nat) (m + n) = gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 438 | apply (subst (1 2) gcd_commute_nat) | 
| 31706 | 439 | apply (subst add_commute) | 
| 440 | apply simp | |
| 441 | done | |
| 442 | ||
| 443 | (* to do: add the other variations? *) | |
| 444 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 445 | lemma gcd_diff1_nat: "(m::nat) >= n \<Longrightarrow> gcd (m - n) n = gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 446 | by (subst gcd_add1_nat [symmetric], auto) | 
| 31706 | 447 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 448 | lemma gcd_diff2_nat: "(n::nat) >= m \<Longrightarrow> gcd (n - m) n = gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 449 | apply (subst gcd_commute_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 450 | apply (subst gcd_diff1_nat [symmetric]) | 
| 31706 | 451 | apply auto | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 452 | apply (subst gcd_commute_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 453 | apply (subst gcd_diff1_nat) | 
| 31706 | 454 | apply assumption | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 455 | apply (rule gcd_commute_nat) | 
| 31706 | 456 | done | 
| 457 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 458 | lemma gcd_non_0_int: "(y::int) > 0 \<Longrightarrow> gcd x y = gcd y (x mod y)" | 
| 31706 | 459 | apply (frule_tac b = y and a = x in pos_mod_sign) | 
| 460 | apply (simp del: pos_mod_sign add: gcd_int_def abs_if nat_mod_distrib) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 461 | apply (auto simp add: gcd_non_0_nat nat_mod_distrib [symmetric] | 
| 31706 | 462 | zmod_zminus1_eq_if) | 
| 463 | apply (frule_tac a = x in pos_mod_bound) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 464 | apply (subst (1 2) gcd_commute_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 465 | apply (simp del: pos_mod_bound add: nat_diff_distrib gcd_diff2_nat | 
| 31706 | 466 | nat_le_eq_zle) | 
| 467 | done | |
| 21256 | 468 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 469 | lemma gcd_red_int: "gcd (x::int) y = gcd y (x mod y)" | 
| 31706 | 470 | apply (case_tac "y = 0") | 
| 471 | apply force | |
| 472 | apply (case_tac "y > 0") | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 473 | apply (subst gcd_non_0_int, auto) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 474 | apply (insert gcd_non_0_int [of "-y" "-x"]) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 475 | apply (auto simp add: gcd_neg1_int gcd_neg2_int) | 
| 31706 | 476 | done | 
| 477 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 478 | lemma gcd_add1_int [simp]: "gcd ((m::int) + n) n = gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 479 | by (metis gcd_red_int mod_add_self1 zadd_commute) | 
| 31706 | 480 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 481 | lemma gcd_add2_int [simp]: "gcd m ((m::int) + n) = gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 482 | by (metis gcd_add1_int gcd_commute_int zadd_commute) | 
| 21256 | 483 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 484 | lemma gcd_add_mult_nat: "gcd (m::nat) (k * m + n) = gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 485 | by (metis mod_mult_self3 gcd_commute_nat gcd_red_nat) | 
| 21256 | 486 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 487 | lemma gcd_add_mult_int: "gcd (m::int) (k * m + n) = gcd m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 488 | by (metis gcd_commute_int gcd_red_int mod_mult_self1 zadd_commute) | 
| 31798 | 489 | |
| 21256 | 490 | |
| 31706 | 491 | (* to do: differences, and all variations of addition rules | 
| 492 | as simplification rules for nat and int *) | |
| 493 | ||
| 31798 | 494 | (* FIXME remove iff *) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 495 | lemma gcd_dvd_prod_nat [iff]: "gcd (m::nat) n dvd k * n" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 496 | using mult_dvd_mono [of 1] by auto | 
| 22027 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 497 | |
| 31706 | 498 | (* to do: add the three variations of these, and for ints? *) | 
| 499 | ||
| 31992 | 500 | lemma finite_divisors_nat[simp]: | 
| 501 |   assumes "(m::nat) ~= 0" shows "finite{d. d dvd m}"
 | |
| 31734 | 502 | proof- | 
| 503 |   have "finite{d. d <= m}" by(blast intro: bounded_nat_set_is_finite)
 | |
| 504 | from finite_subset[OF _ this] show ?thesis using assms | |
| 505 | by(bestsimp intro!:dvd_imp_le) | |
| 506 | qed | |
| 507 | ||
| 31995 | 508 | lemma finite_divisors_int[simp]: | 
| 31734 | 509 |   assumes "(i::int) ~= 0" shows "finite{d. d dvd i}"
 | 
| 510 | proof- | |
| 511 |   have "{d. abs d <= abs i} = {- abs i .. abs i}" by(auto simp:abs_if)
 | |
| 512 |   hence "finite{d. abs d <= abs i}" by simp
 | |
| 513 | from finite_subset[OF _ this] show ?thesis using assms | |
| 514 | by(bestsimp intro!:dvd_imp_le_int) | |
| 515 | qed | |
| 516 | ||
| 31995 | 517 | lemma Max_divisors_self_nat[simp]: "n\<noteq>0 \<Longrightarrow> Max{d::nat. d dvd n} = n"
 | 
| 518 | apply(rule antisym) | |
| 519 | apply (fastsimp intro: Max_le_iff[THEN iffD2] simp: dvd_imp_le) | |
| 520 | apply simp | |
| 521 | done | |
| 522 | ||
| 523 | lemma Max_divisors_self_int[simp]: "n\<noteq>0 \<Longrightarrow> Max{d::int. d dvd n} = abs n"
 | |
| 524 | apply(rule antisym) | |
| 525 | apply(rule Max_le_iff[THEN iffD2]) | |
| 526 | apply simp | |
| 527 | apply fastsimp | |
| 528 | apply (metis Collect_def abs_ge_self dvd_imp_le_int mem_def zle_trans) | |
| 529 | apply simp | |
| 530 | done | |
| 531 | ||
| 31734 | 532 | lemma gcd_is_Max_divisors_nat: | 
| 533 |   "m ~= 0 \<Longrightarrow> n ~= 0 \<Longrightarrow> gcd (m::nat) n = (Max {d. d dvd m & d dvd n})"
 | |
| 534 | apply(rule Max_eqI[THEN sym]) | |
| 31995 | 535 | apply (metis finite_Collect_conjI finite_divisors_nat) | 
| 31734 | 536 | apply simp | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 537 | apply(metis Suc_diff_1 Suc_neq_Zero dvd_imp_le gcd_greatest_iff_nat gcd_pos_nat) | 
| 31734 | 538 | apply simp | 
| 539 | done | |
| 540 | ||
| 541 | lemma gcd_is_Max_divisors_int: | |
| 542 |   "m ~= 0 ==> n ~= 0 ==> gcd (m::int) n = (Max {d. d dvd m & d dvd n})"
 | |
| 543 | apply(rule Max_eqI[THEN sym]) | |
| 31995 | 544 | apply (metis finite_Collect_conjI finite_divisors_int) | 
| 31734 | 545 | apply simp | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 546 | apply (metis gcd_greatest_iff_int gcd_pos_int zdvd_imp_le) | 
| 31734 | 547 | apply simp | 
| 548 | done | |
| 549 | ||
| 22027 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 550 | |
| 31706 | 551 | subsection {* Coprimality *}
 | 
| 552 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 553 | lemma div_gcd_coprime_nat: | 
| 31706 | 554 | assumes nz: "(a::nat) \<noteq> 0 \<or> b \<noteq> 0" | 
| 555 | shows "coprime (a div gcd a b) (b div gcd a b)" | |
| 22367 | 556 | proof - | 
| 27556 | 557 | let ?g = "gcd a b" | 
| 22027 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 558 | let ?a' = "a div ?g" | 
| 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 559 | let ?b' = "b div ?g" | 
| 27556 | 560 | let ?g' = "gcd ?a' ?b'" | 
| 22027 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 561 | have dvdg: "?g dvd a" "?g dvd b" by simp_all | 
| 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 562 | have dvdg': "?g' dvd ?a'" "?g' dvd ?b'" by simp_all | 
| 22367 | 563 | from dvdg dvdg' obtain ka kb ka' kb' where | 
| 564 | kab: "a = ?g * ka" "b = ?g * kb" "?a' = ?g' * ka'" "?b' = ?g' * kb'" | |
| 22027 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 565 | unfolding dvd_def by blast | 
| 31706 | 566 | then have "?g * ?a' = (?g * ?g') * ka'" "?g * ?b' = (?g * ?g') * kb'" | 
| 567 | by simp_all | |
| 22367 | 568 | then have dvdgg':"?g * ?g' dvd a" "?g* ?g' dvd b" | 
| 569 | by (auto simp add: dvd_mult_div_cancel [OF dvdg(1)] | |
| 570 | dvd_mult_div_cancel [OF dvdg(2)] dvd_def) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 571 | have "?g \<noteq> 0" using nz by (simp add: gcd_zero_nat) | 
| 31706 | 572 | then have gp: "?g > 0" by arith | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 573 | from gcd_greatest_nat [OF dvdgg'] have "?g * ?g' dvd ?g" . | 
| 22367 | 574 | with dvd_mult_cancel1 [OF gp] show "?g' = 1" by simp | 
| 22027 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 575 | qed | 
| 
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
 chaieb parents: 
21404diff
changeset | 576 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 577 | lemma div_gcd_coprime_int: | 
| 31706 | 578 | assumes nz: "(a::int) \<noteq> 0 \<or> b \<noteq> 0" | 
| 579 | shows "coprime (a div gcd a b) (b div gcd a b)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 580 | apply (subst (1 2 3) gcd_abs_int) | 
| 31813 | 581 | apply (subst (1 2) abs_div) | 
| 582 | apply simp | |
| 583 | apply simp | |
| 584 | apply(subst (1 2) abs_gcd_int) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 585 | apply (rule div_gcd_coprime_nat [transferred]) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 586 | using nz apply (auto simp add: gcd_abs_int [symmetric]) | 
| 31706 | 587 | done | 
| 588 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 589 | lemma coprime_nat: "coprime (a::nat) b \<longleftrightarrow> (\<forall>d. d dvd a \<and> d dvd b \<longleftrightarrow> d = 1)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 590 | using gcd_unique_nat[of 1 a b, simplified] by auto | 
| 31706 | 591 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 592 | lemma coprime_Suc_0_nat: | 
| 31706 | 593 | "coprime (a::nat) b \<longleftrightarrow> (\<forall>d. d dvd a \<and> d dvd b \<longleftrightarrow> d = Suc 0)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 594 | using coprime_nat by (simp add: One_nat_def) | 
| 31706 | 595 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 596 | lemma coprime_int: "coprime (a::int) b \<longleftrightarrow> | 
| 31706 | 597 | (\<forall>d. d >= 0 \<and> d dvd a \<and> d dvd b \<longleftrightarrow> d = 1)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 598 | using gcd_unique_int [of 1 a b] | 
| 31706 | 599 | apply clarsimp | 
| 600 | apply (erule subst) | |
| 601 | apply (rule iffI) | |
| 602 | apply force | |
| 603 | apply (drule_tac x = "abs e" in exI) | |
| 604 | apply (case_tac "e >= 0") | |
| 605 | apply force | |
| 606 | apply force | |
| 607 | done | |
| 608 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 609 | lemma gcd_coprime_nat: | 
| 31706 | 610 | assumes z: "gcd (a::nat) b \<noteq> 0" and a: "a = a' * gcd a b" and | 
| 611 | b: "b = b' * gcd a b" | |
| 612 | shows "coprime a' b'" | |
| 613 | ||
| 614 | apply (subgoal_tac "a' = a div gcd a b") | |
| 615 | apply (erule ssubst) | |
| 616 | apply (subgoal_tac "b' = b div gcd a b") | |
| 617 | apply (erule ssubst) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 618 | apply (rule div_gcd_coprime_nat) | 
| 31706 | 619 | using prems | 
| 620 | apply force | |
| 621 | apply (subst (1) b) | |
| 622 | using z apply force | |
| 623 | apply (subst (1) a) | |
| 624 | using z apply force | |
| 625 | done | |
| 626 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 627 | lemma gcd_coprime_int: | 
| 31706 | 628 | assumes z: "gcd (a::int) b \<noteq> 0" and a: "a = a' * gcd a b" and | 
| 629 | b: "b = b' * gcd a b" | |
| 630 | shows "coprime a' b'" | |
| 631 | ||
| 632 | apply (subgoal_tac "a' = a div gcd a b") | |
| 633 | apply (erule ssubst) | |
| 634 | apply (subgoal_tac "b' = b div gcd a b") | |
| 635 | apply (erule ssubst) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 636 | apply (rule div_gcd_coprime_int) | 
| 31706 | 637 | using prems | 
| 638 | apply force | |
| 639 | apply (subst (1) b) | |
| 640 | using z apply force | |
| 641 | apply (subst (1) a) | |
| 642 | using z apply force | |
| 643 | done | |
| 644 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 645 | lemma coprime_mult_nat: assumes da: "coprime (d::nat) a" and db: "coprime d b" | 
| 31706 | 646 | shows "coprime d (a * b)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 647 | apply (subst gcd_commute_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 648 | using da apply (subst gcd_mult_cancel_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 649 | apply (subst gcd_commute_nat, assumption) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 650 | apply (subst gcd_commute_nat, rule db) | 
| 31706 | 651 | done | 
| 652 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 653 | lemma coprime_mult_int: assumes da: "coprime (d::int) a" and db: "coprime d b" | 
| 31706 | 654 | shows "coprime d (a * b)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 655 | apply (subst gcd_commute_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 656 | using da apply (subst gcd_mult_cancel_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 657 | apply (subst gcd_commute_int, assumption) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 658 | apply (subst gcd_commute_int, rule db) | 
| 31706 | 659 | done | 
| 660 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 661 | lemma coprime_lmult_nat: | 
| 31706 | 662 | assumes dab: "coprime (d::nat) (a * b)" shows "coprime d a" | 
| 663 | proof - | |
| 664 | have "gcd d a dvd gcd d (a * b)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 665 | by (rule gcd_greatest_nat, auto) | 
| 31706 | 666 | with dab show ?thesis | 
| 667 | by auto | |
| 668 | qed | |
| 669 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 670 | lemma coprime_lmult_int: | 
| 31798 | 671 | assumes "coprime (d::int) (a * b)" shows "coprime d a" | 
| 31706 | 672 | proof - | 
| 673 | have "gcd d a dvd gcd d (a * b)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 674 | by (rule gcd_greatest_int, auto) | 
| 31798 | 675 | with assms show ?thesis | 
| 31706 | 676 | by auto | 
| 677 | qed | |
| 678 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 679 | lemma coprime_rmult_nat: | 
| 31798 | 680 | assumes "coprime (d::nat) (a * b)" shows "coprime d b" | 
| 31706 | 681 | proof - | 
| 682 | have "gcd d b dvd gcd d (a * b)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 683 | by (rule gcd_greatest_nat, auto intro: dvd_mult) | 
| 31798 | 684 | with assms show ?thesis | 
| 31706 | 685 | by auto | 
| 686 | qed | |
| 687 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 688 | lemma coprime_rmult_int: | 
| 31706 | 689 | assumes dab: "coprime (d::int) (a * b)" shows "coprime d b" | 
| 690 | proof - | |
| 691 | have "gcd d b dvd gcd d (a * b)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 692 | by (rule gcd_greatest_int, auto intro: dvd_mult) | 
| 31706 | 693 | with dab show ?thesis | 
| 694 | by auto | |
| 695 | qed | |
| 696 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 697 | lemma coprime_mul_eq_nat: "coprime (d::nat) (a * b) \<longleftrightarrow> | 
| 31706 | 698 | coprime d a \<and> coprime d b" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 699 | using coprime_rmult_nat[of d a b] coprime_lmult_nat[of d a b] | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 700 | coprime_mult_nat[of d a b] | 
| 31706 | 701 | by blast | 
| 702 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 703 | lemma coprime_mul_eq_int: "coprime (d::int) (a * b) \<longleftrightarrow> | 
| 31706 | 704 | coprime d a \<and> coprime d b" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 705 | using coprime_rmult_int[of d a b] coprime_lmult_int[of d a b] | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 706 | coprime_mult_int[of d a b] | 
| 31706 | 707 | by blast | 
| 708 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 709 | lemma gcd_coprime_exists_nat: | 
| 31706 | 710 | assumes nz: "gcd (a::nat) b \<noteq> 0" | 
| 711 | shows "\<exists>a' b'. a = a' * gcd a b \<and> b = b' * gcd a b \<and> coprime a' b'" | |
| 712 | apply (rule_tac x = "a div gcd a b" in exI) | |
| 713 | apply (rule_tac x = "b div gcd a b" in exI) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 714 | using nz apply (auto simp add: div_gcd_coprime_nat dvd_div_mult) | 
| 31706 | 715 | done | 
| 716 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 717 | lemma gcd_coprime_exists_int: | 
| 31706 | 718 | assumes nz: "gcd (a::int) b \<noteq> 0" | 
| 719 | shows "\<exists>a' b'. a = a' * gcd a b \<and> b = b' * gcd a b \<and> coprime a' b'" | |
| 720 | apply (rule_tac x = "a div gcd a b" in exI) | |
| 721 | apply (rule_tac x = "b div gcd a b" in exI) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 722 | using nz apply (auto simp add: div_gcd_coprime_int dvd_div_mult_self) | 
| 31706 | 723 | done | 
| 724 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 725 | lemma coprime_exp_nat: "coprime (d::nat) a \<Longrightarrow> coprime d (a^n)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 726 | by (induct n, simp_all add: coprime_mult_nat) | 
| 31706 | 727 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 728 | lemma coprime_exp_int: "coprime (d::int) a \<Longrightarrow> coprime d (a^n)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 729 | by (induct n, simp_all add: coprime_mult_int) | 
| 31706 | 730 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 731 | lemma coprime_exp2_nat [intro]: "coprime (a::nat) b \<Longrightarrow> coprime (a^n) (b^m)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 732 | apply (rule coprime_exp_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 733 | apply (subst gcd_commute_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 734 | apply (rule coprime_exp_nat) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 735 | apply (subst gcd_commute_nat, assumption) | 
| 31706 | 736 | done | 
| 737 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 738 | lemma coprime_exp2_int [intro]: "coprime (a::int) b \<Longrightarrow> coprime (a^n) (b^m)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 739 | apply (rule coprime_exp_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 740 | apply (subst gcd_commute_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 741 | apply (rule coprime_exp_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 742 | apply (subst gcd_commute_int, assumption) | 
| 31706 | 743 | done | 
| 744 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 745 | lemma gcd_exp_nat: "gcd ((a::nat)^n) (b^n) = (gcd a b)^n" | 
| 31706 | 746 | proof (cases) | 
| 747 | assume "a = 0 & b = 0" | |
| 748 | thus ?thesis by simp | |
| 749 | next assume "~(a = 0 & b = 0)" | |
| 750 | hence "coprime ((a div gcd a b)^n) ((b div gcd a b)^n)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 751 | by (auto simp:div_gcd_coprime_nat) | 
| 31706 | 752 | hence "gcd ((a div gcd a b)^n * (gcd a b)^n) | 
| 753 | ((b div gcd a b)^n * (gcd a b)^n) = (gcd a b)^n" | |
| 754 | apply (subst (1 2) mult_commute) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 755 | apply (subst gcd_mult_distrib_nat [symmetric]) | 
| 31706 | 756 | apply simp | 
| 757 | done | |
| 758 | also have "(a div gcd a b)^n * (gcd a b)^n = a^n" | |
| 759 | apply (subst div_power) | |
| 760 | apply auto | |
| 761 | apply (rule dvd_div_mult_self) | |
| 762 | apply (rule dvd_power_same) | |
| 763 | apply auto | |
| 764 | done | |
| 765 | also have "(b div gcd a b)^n * (gcd a b)^n = b^n" | |
| 766 | apply (subst div_power) | |
| 767 | apply auto | |
| 768 | apply (rule dvd_div_mult_self) | |
| 769 | apply (rule dvd_power_same) | |
| 770 | apply auto | |
| 771 | done | |
| 772 | finally show ?thesis . | |
| 773 | qed | |
| 774 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 775 | lemma gcd_exp_int: "gcd ((a::int)^n) (b^n) = (gcd a b)^n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 776 | apply (subst (1 2) gcd_abs_int) | 
| 31706 | 777 | apply (subst (1 2) power_abs) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 778 | apply (rule gcd_exp_nat [where n = n, transferred]) | 
| 31706 | 779 | apply auto | 
| 780 | done | |
| 781 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 782 | lemma coprime_divprod_nat: "(d::nat) dvd a * b \<Longrightarrow> coprime d a \<Longrightarrow> d dvd b" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 783 | using coprime_dvd_mult_iff_nat[of d a b] | 
| 31706 | 784 | by (auto simp add: mult_commute) | 
| 785 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 786 | lemma coprime_divprod_int: "(d::int) dvd a * b \<Longrightarrow> coprime d a \<Longrightarrow> d dvd b" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 787 | using coprime_dvd_mult_iff_int[of d a b] | 
| 31706 | 788 | by (auto simp add: mult_commute) | 
| 789 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 790 | lemma division_decomp_nat: assumes dc: "(a::nat) dvd b * c" | 
| 31706 | 791 | shows "\<exists>b' c'. a = b' * c' \<and> b' dvd b \<and> c' dvd c" | 
| 792 | proof- | |
| 793 | let ?g = "gcd a b" | |
| 794 |   {assume "?g = 0" with dc have ?thesis by auto}
 | |
| 795 | moreover | |
| 796 |   {assume z: "?g \<noteq> 0"
 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 797 | from gcd_coprime_exists_nat[OF z] | 
| 31706 | 798 | obtain a' b' where ab': "a = a' * ?g" "b = b' * ?g" "coprime a' b'" | 
| 799 | by blast | |
| 800 | have thb: "?g dvd b" by auto | |
| 801 | from ab'(1) have "a' dvd a" unfolding dvd_def by blast | |
| 802 | with dc have th0: "a' dvd b*c" using dvd_trans[of a' a "b*c"] by simp | |
| 803 | from dc ab'(1,2) have "a'*?g dvd (b'*?g) *c" by auto | |
| 804 | hence "?g*a' dvd ?g * (b' * c)" by (simp add: mult_assoc) | |
| 805 | with z have th_1: "a' dvd b' * c" by auto | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 806 | from coprime_dvd_mult_nat[OF ab'(3)] th_1 | 
| 31706 | 807 | have thc: "a' dvd c" by (subst (asm) mult_commute, blast) | 
| 808 | from ab' have "a = ?g*a'" by algebra | |
| 809 | with thb thc have ?thesis by blast } | |
| 810 | ultimately show ?thesis by blast | |
| 811 | qed | |
| 812 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 813 | lemma division_decomp_int: assumes dc: "(a::int) dvd b * c" | 
| 31706 | 814 | shows "\<exists>b' c'. a = b' * c' \<and> b' dvd b \<and> c' dvd c" | 
| 815 | proof- | |
| 816 | let ?g = "gcd a b" | |
| 817 |   {assume "?g = 0" with dc have ?thesis by auto}
 | |
| 818 | moreover | |
| 819 |   {assume z: "?g \<noteq> 0"
 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 820 | from gcd_coprime_exists_int[OF z] | 
| 31706 | 821 | obtain a' b' where ab': "a = a' * ?g" "b = b' * ?g" "coprime a' b'" | 
| 822 | by blast | |
| 823 | have thb: "?g dvd b" by auto | |
| 824 | from ab'(1) have "a' dvd a" unfolding dvd_def by blast | |
| 825 | with dc have th0: "a' dvd b*c" | |
| 826 | using dvd_trans[of a' a "b*c"] by simp | |
| 827 | from dc ab'(1,2) have "a'*?g dvd (b'*?g) *c" by auto | |
| 828 | hence "?g*a' dvd ?g * (b' * c)" by (simp add: mult_assoc) | |
| 829 | with z have th_1: "a' dvd b' * c" by auto | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 830 | from coprime_dvd_mult_int[OF ab'(3)] th_1 | 
| 31706 | 831 | have thc: "a' dvd c" by (subst (asm) mult_commute, blast) | 
| 832 | from ab' have "a = ?g*a'" by algebra | |
| 833 | with thb thc have ?thesis by blast } | |
| 834 | ultimately show ?thesis by blast | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 835 | qed | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 836 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 837 | lemma pow_divides_pow_nat: | 
| 31706 | 838 | assumes ab: "(a::nat) ^ n dvd b ^n" and n:"n \<noteq> 0" | 
| 839 | shows "a dvd b" | |
| 840 | proof- | |
| 841 | let ?g = "gcd a b" | |
| 842 | from n obtain m where m: "n = Suc m" by (cases n, simp_all) | |
| 843 |   {assume "?g = 0" with ab n have ?thesis by auto }
 | |
| 844 | moreover | |
| 845 |   {assume z: "?g \<noteq> 0"
 | |
| 846 | hence zn: "?g ^ n \<noteq> 0" using n by (simp add: neq0_conv) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 847 | from gcd_coprime_exists_nat[OF z] | 
| 31706 | 848 | obtain a' b' where ab': "a = a' * ?g" "b = b' * ?g" "coprime a' b'" | 
| 849 | by blast | |
| 850 | from ab have "(a' * ?g) ^ n dvd (b' * ?g)^n" | |
| 851 | by (simp add: ab'(1,2)[symmetric]) | |
| 852 | hence "?g^n*a'^n dvd ?g^n *b'^n" | |
| 853 | by (simp only: power_mult_distrib mult_commute) | |
| 854 | with zn z n have th0:"a'^n dvd b'^n" by auto | |
| 855 | have "a' dvd a'^n" by (simp add: m) | |
| 856 | with th0 have "a' dvd b'^n" using dvd_trans[of a' "a'^n" "b'^n"] by simp | |
| 857 | hence th1: "a' dvd b'^m * b'" by (simp add: m mult_commute) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 858 | from coprime_dvd_mult_nat[OF coprime_exp_nat [OF ab'(3), of m]] th1 | 
| 31706 | 859 | have "a' dvd b'" by (subst (asm) mult_commute, blast) | 
| 860 | hence "a'*?g dvd b'*?g" by simp | |
| 861 | with ab'(1,2) have ?thesis by simp } | |
| 862 | ultimately show ?thesis by blast | |
| 863 | qed | |
| 864 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 865 | lemma pow_divides_pow_int: | 
| 31706 | 866 | assumes ab: "(a::int) ^ n dvd b ^n" and n:"n \<noteq> 0" | 
| 867 | shows "a dvd b" | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 868 | proof- | 
| 31706 | 869 | let ?g = "gcd a b" | 
| 870 | from n obtain m where m: "n = Suc m" by (cases n, simp_all) | |
| 871 |   {assume "?g = 0" with ab n have ?thesis by auto }
 | |
| 872 | moreover | |
| 873 |   {assume z: "?g \<noteq> 0"
 | |
| 874 | hence zn: "?g ^ n \<noteq> 0" using n by (simp add: neq0_conv) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 875 | from gcd_coprime_exists_int[OF z] | 
| 31706 | 876 | obtain a' b' where ab': "a = a' * ?g" "b = b' * ?g" "coprime a' b'" | 
| 877 | by blast | |
| 878 | from ab have "(a' * ?g) ^ n dvd (b' * ?g)^n" | |
| 879 | by (simp add: ab'(1,2)[symmetric]) | |
| 880 | hence "?g^n*a'^n dvd ?g^n *b'^n" | |
| 881 | by (simp only: power_mult_distrib mult_commute) | |
| 882 | with zn z n have th0:"a'^n dvd b'^n" by auto | |
| 883 | have "a' dvd a'^n" by (simp add: m) | |
| 884 | with th0 have "a' dvd b'^n" | |
| 885 | using dvd_trans[of a' "a'^n" "b'^n"] by simp | |
| 886 | hence th1: "a' dvd b'^m * b'" by (simp add: m mult_commute) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 887 | from coprime_dvd_mult_int[OF coprime_exp_int [OF ab'(3), of m]] th1 | 
| 31706 | 888 | have "a' dvd b'" by (subst (asm) mult_commute, blast) | 
| 889 | hence "a'*?g dvd b'*?g" by simp | |
| 890 | with ab'(1,2) have ?thesis by simp } | |
| 891 | ultimately show ?thesis by blast | |
| 892 | qed | |
| 893 | ||
| 31798 | 894 | (* FIXME move to Divides(?) *) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 895 | lemma pow_divides_eq_nat [simp]: "n ~= 0 \<Longrightarrow> ((a::nat)^n dvd b^n) = (a dvd b)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 896 | by (auto intro: pow_divides_pow_nat dvd_power_same) | 
| 31706 | 897 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 898 | lemma pow_divides_eq_int [simp]: "n ~= 0 \<Longrightarrow> ((a::int)^n dvd b^n) = (a dvd b)" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 899 | by (auto intro: pow_divides_pow_int dvd_power_same) | 
| 31706 | 900 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 901 | lemma divides_mult_nat: | 
| 31706 | 902 | assumes mr: "(m::nat) dvd r" and nr: "n dvd r" and mn:"coprime m n" | 
| 903 | shows "m * n dvd r" | |
| 904 | proof- | |
| 905 | from mr nr obtain m' n' where m': "r = m*m'" and n': "r = n*n'" | |
| 906 | unfolding dvd_def by blast | |
| 907 | from mr n' have "m dvd n'*n" by (simp add: mult_commute) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 908 | hence "m dvd n'" using coprime_dvd_mult_iff_nat[OF mn] by simp | 
| 31706 | 909 | then obtain k where k: "n' = m*k" unfolding dvd_def by blast | 
| 910 | from n' k show ?thesis unfolding dvd_def by auto | |
| 911 | qed | |
| 912 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 913 | lemma divides_mult_int: | 
| 31706 | 914 | assumes mr: "(m::int) dvd r" and nr: "n dvd r" and mn:"coprime m n" | 
| 915 | shows "m * n dvd r" | |
| 916 | proof- | |
| 917 | from mr nr obtain m' n' where m': "r = m*m'" and n': "r = n*n'" | |
| 918 | unfolding dvd_def by blast | |
| 919 | from mr n' have "m dvd n'*n" by (simp add: mult_commute) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 920 | hence "m dvd n'" using coprime_dvd_mult_iff_int[OF mn] by simp | 
| 31706 | 921 | then obtain k where k: "n' = m*k" unfolding dvd_def by blast | 
| 922 | from n' k show ?thesis unfolding dvd_def by auto | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 923 | qed | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 924 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 925 | lemma coprime_plus_one_nat [simp]: "coprime ((n::nat) + 1) n" | 
| 31706 | 926 | apply (subgoal_tac "gcd (n + 1) n dvd (n + 1 - n)") | 
| 927 | apply force | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 928 | apply (rule dvd_diff_nat) | 
| 31706 | 929 | apply auto | 
| 930 | done | |
| 931 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 932 | lemma coprime_Suc_nat [simp]: "coprime (Suc n) n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 933 | using coprime_plus_one_nat by (simp add: One_nat_def) | 
| 31706 | 934 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 935 | lemma coprime_plus_one_int [simp]: "coprime ((n::int) + 1) n" | 
| 31706 | 936 | apply (subgoal_tac "gcd (n + 1) n dvd (n + 1 - n)") | 
| 937 | apply force | |
| 938 | apply (rule dvd_diff) | |
| 939 | apply auto | |
| 940 | done | |
| 941 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 942 | lemma coprime_minus_one_nat: "(n::nat) \<noteq> 0 \<Longrightarrow> coprime (n - 1) n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 943 | using coprime_plus_one_nat [of "n - 1"] | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 944 | gcd_commute_nat [of "n - 1" n] by auto | 
| 31706 | 945 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 946 | lemma coprime_minus_one_int: "coprime ((n::int) - 1) n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 947 | using coprime_plus_one_int [of "n - 1"] | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 948 | gcd_commute_int [of "n - 1" n] by auto | 
| 31706 | 949 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 950 | lemma setprod_coprime_nat [rule_format]: | 
| 31706 | 951 | "(ALL i: A. coprime (f i) (x::nat)) --> coprime (PROD i:A. f i) x" | 
| 952 | apply (case_tac "finite A") | |
| 953 | apply (induct set: finite) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 954 | apply (auto simp add: gcd_mult_cancel_nat) | 
| 31706 | 955 | done | 
| 956 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 957 | lemma setprod_coprime_int [rule_format]: | 
| 31706 | 958 | "(ALL i: A. coprime (f i) (x::int)) --> coprime (PROD i:A. f i) x" | 
| 959 | apply (case_tac "finite A") | |
| 960 | apply (induct set: finite) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 961 | apply (auto simp add: gcd_mult_cancel_int) | 
| 31706 | 962 | done | 
| 963 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 964 | lemma coprime_common_divisor_nat: "coprime (a::nat) b \<Longrightarrow> x dvd a \<Longrightarrow> | 
| 31706 | 965 | x dvd b \<Longrightarrow> x = 1" | 
| 966 | apply (subgoal_tac "x dvd gcd a b") | |
| 967 | apply simp | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 968 | apply (erule (1) gcd_greatest_nat) | 
| 31706 | 969 | done | 
| 970 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 971 | lemma coprime_common_divisor_int: "coprime (a::int) b \<Longrightarrow> x dvd a \<Longrightarrow> | 
| 31706 | 972 | x dvd b \<Longrightarrow> abs x = 1" | 
| 973 | apply (subgoal_tac "x dvd gcd a b") | |
| 974 | apply simp | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 975 | apply (erule (1) gcd_greatest_int) | 
| 31706 | 976 | done | 
| 977 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 978 | lemma coprime_divisors_nat: "(d::int) dvd a \<Longrightarrow> e dvd b \<Longrightarrow> coprime a b \<Longrightarrow> | 
| 31706 | 979 | coprime d e" | 
| 980 | apply (auto simp add: dvd_def) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 981 | apply (frule coprime_lmult_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 982 | apply (subst gcd_commute_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 983 | apply (subst (asm) (2) gcd_commute_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 984 | apply (erule coprime_lmult_int) | 
| 31706 | 985 | done | 
| 986 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 987 | lemma invertible_coprime_nat: "(x::nat) * y mod m = 1 \<Longrightarrow> coprime x m" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 988 | apply (metis coprime_lmult_nat gcd_1_nat gcd_commute_nat gcd_red_nat) | 
| 31706 | 989 | done | 
| 990 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 991 | lemma invertible_coprime_int: "(x::int) * y mod m = 1 \<Longrightarrow> coprime x m" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 992 | apply (metis coprime_lmult_int gcd_1_int gcd_commute_int gcd_red_int) | 
| 31706 | 993 | done | 
| 994 | ||
| 995 | ||
| 996 | subsection {* Bezout's theorem *}
 | |
| 997 | ||
| 998 | (* Function bezw returns a pair of witnesses to Bezout's theorem -- | |
| 999 | see the theorems that follow the definition. *) | |
| 1000 | fun | |
| 1001 | bezw :: "nat \<Rightarrow> nat \<Rightarrow> int * int" | |
| 1002 | where | |
| 1003 | "bezw x y = | |
| 1004 | (if y = 0 then (1, 0) else | |
| 1005 | (snd (bezw y (x mod y)), | |
| 1006 | fst (bezw y (x mod y)) - snd (bezw y (x mod y)) * int(x div y)))" | |
| 1007 | ||
| 1008 | lemma bezw_0 [simp]: "bezw x 0 = (1, 0)" by simp | |
| 1009 | ||
| 1010 | lemma bezw_non_0: "y > 0 \<Longrightarrow> bezw x y = (snd (bezw y (x mod y)), | |
| 1011 | fst (bezw y (x mod y)) - snd (bezw y (x mod y)) * int(x div y))" | |
| 1012 | by simp | |
| 1013 | ||
| 1014 | declare bezw.simps [simp del] | |
| 1015 | ||
| 1016 | lemma bezw_aux [rule_format]: | |
| 1017 | "fst (bezw x y) * int x + snd (bezw x y) * int y = int (gcd x y)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1018 | proof (induct x y rule: gcd_nat_induct) | 
| 31706 | 1019 | fix m :: nat | 
| 1020 | show "fst (bezw m 0) * int m + snd (bezw m 0) * int 0 = int (gcd m 0)" | |
| 1021 | by auto | |
| 1022 | next fix m :: nat and n | |
| 1023 | assume ngt0: "n > 0" and | |
| 1024 | ih: "fst (bezw n (m mod n)) * int n + | |
| 1025 | snd (bezw n (m mod n)) * int (m mod n) = | |
| 1026 | int (gcd n (m mod n))" | |
| 1027 | thus "fst (bezw m n) * int m + snd (bezw m n) * int n = int (gcd m n)" | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1028 | apply (simp add: bezw_non_0 gcd_non_0_nat) | 
| 31706 | 1029 | apply (erule subst) | 
| 1030 | apply (simp add: ring_simps) | |
| 1031 | apply (subst mod_div_equality [of m n, symmetric]) | |
| 1032 | (* applying simp here undoes the last substitution! | |
| 1033 | what is procedure cancel_div_mod? *) | |
| 1034 | apply (simp only: ring_simps zadd_int [symmetric] | |
| 1035 | zmult_int [symmetric]) | |
| 1036 | done | |
| 1037 | qed | |
| 1038 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1039 | lemma bezout_int: | 
| 31706 | 1040 | fixes x y | 
| 1041 | shows "EX u v. u * (x::int) + v * y = gcd x y" | |
| 1042 | proof - | |
| 1043 | have bezout_aux: "!!x y. x \<ge> (0::int) \<Longrightarrow> y \<ge> 0 \<Longrightarrow> | |
| 1044 | EX u v. u * x + v * y = gcd x y" | |
| 1045 | apply (rule_tac x = "fst (bezw (nat x) (nat y))" in exI) | |
| 1046 | apply (rule_tac x = "snd (bezw (nat x) (nat y))" in exI) | |
| 1047 | apply (unfold gcd_int_def) | |
| 1048 | apply simp | |
| 1049 | apply (subst bezw_aux [symmetric]) | |
| 1050 | apply auto | |
| 1051 | done | |
| 1052 | have "(x \<ge> 0 \<and> y \<ge> 0) | (x \<ge> 0 \<and> y \<le> 0) | (x \<le> 0 \<and> y \<ge> 0) | | |
| 1053 | (x \<le> 0 \<and> y \<le> 0)" | |
| 1054 | by auto | |
| 1055 | moreover have "x \<ge> 0 \<Longrightarrow> y \<ge> 0 \<Longrightarrow> ?thesis" | |
| 1056 | by (erule (1) bezout_aux) | |
| 1057 | moreover have "x >= 0 \<Longrightarrow> y <= 0 \<Longrightarrow> ?thesis" | |
| 1058 | apply (insert bezout_aux [of x "-y"]) | |
| 1059 | apply auto | |
| 1060 | apply (rule_tac x = u in exI) | |
| 1061 | apply (rule_tac x = "-v" in exI) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1062 | apply (subst gcd_neg2_int [symmetric]) | 
| 31706 | 1063 | apply auto | 
| 1064 | done | |
| 1065 | moreover have "x <= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> ?thesis" | |
| 1066 | apply (insert bezout_aux [of "-x" y]) | |
| 1067 | apply auto | |
| 1068 | apply (rule_tac x = "-u" in exI) | |
| 1069 | apply (rule_tac x = v in exI) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1070 | apply (subst gcd_neg1_int [symmetric]) | 
| 31706 | 1071 | apply auto | 
| 1072 | done | |
| 1073 | moreover have "x <= 0 \<Longrightarrow> y <= 0 \<Longrightarrow> ?thesis" | |
| 1074 | apply (insert bezout_aux [of "-x" "-y"]) | |
| 1075 | apply auto | |
| 1076 | apply (rule_tac x = "-u" in exI) | |
| 1077 | apply (rule_tac x = "-v" in exI) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1078 | apply (subst gcd_neg1_int [symmetric]) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1079 | apply (subst gcd_neg2_int [symmetric]) | 
| 31706 | 1080 | apply auto | 
| 1081 | done | |
| 1082 | ultimately show ?thesis by blast | |
| 1083 | qed | |
| 1084 | ||
| 1085 | text {* versions of Bezout for nat, by Amine Chaieb *}
 | |
| 1086 | ||
| 1087 | lemma ind_euclid: | |
| 1088 | assumes c: " \<forall>a b. P (a::nat) b \<longleftrightarrow> P b a" and z: "\<forall>a. P a 0" | |
| 1089 | and add: "\<forall>a b. P a b \<longrightarrow> P a (a + b)" | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1090 | shows "P a b" | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1091 | proof(induct n\<equiv>"a+b" arbitrary: a b rule: nat_less_induct) | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1092 | fix n a b | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1093 | assume H: "\<forall>m < n. \<forall>a b. m = a + b \<longrightarrow> P a b" "n = a + b" | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1094 | have "a = b \<or> a < b \<or> b < a" by arith | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1095 |   moreover {assume eq: "a= b"
 | 
| 31706 | 1096 | from add[rule_format, OF z[rule_format, of a]] have "P a b" using eq | 
| 1097 | by simp} | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1098 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1099 |   {assume lt: "a < b"
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1100 | hence "a + b - a < n \<or> a = 0" using H(2) by arith | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1101 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1102 |     {assume "a =0" with z c have "P a b" by blast }
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1103 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1104 |     {assume ab: "a + b - a < n"
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1105 | have th0: "a + b - a = a + (b - a)" using lt by arith | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1106 | from add[rule_format, OF H(1)[rule_format, OF ab th0]] | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1107 | have "P a b" by (simp add: th0[symmetric])} | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1108 | ultimately have "P a b" by blast} | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1109 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1110 |   {assume lt: "a > b"
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1111 | hence "b + a - b < n \<or> b = 0" using H(2) by arith | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1112 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1113 |     {assume "b =0" with z c have "P a b" by blast }
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1114 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1115 |     {assume ab: "b + a - b < n"
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1116 | have th0: "b + a - b = b + (a - b)" using lt by arith | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1117 | from add[rule_format, OF H(1)[rule_format, OF ab th0]] | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1118 | have "P b a" by (simp add: th0[symmetric]) | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1119 | hence "P a b" using c by blast } | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1120 | ultimately have "P a b" by blast} | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1121 | ultimately show "P a b" by blast | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1122 | qed | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1123 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1124 | lemma bezout_lemma_nat: | 
| 31706 | 1125 | assumes ex: "\<exists>(d::nat) x y. d dvd a \<and> d dvd b \<and> | 
| 1126 | (a * x = b * y + d \<or> b * x = a * y + d)" | |
| 1127 | shows "\<exists>d x y. d dvd a \<and> d dvd a + b \<and> | |
| 1128 | (a * x = (a + b) * y + d \<or> (a + b) * x = a * y + d)" | |
| 1129 | using ex | |
| 1130 | apply clarsimp | |
| 1131 | apply (rule_tac x="d" in exI, simp add: dvd_add) | |
| 1132 | apply (case_tac "a * x = b * y + d" , simp_all) | |
| 1133 | apply (rule_tac x="x + y" in exI) | |
| 1134 | apply (rule_tac x="y" in exI) | |
| 1135 | apply algebra | |
| 1136 | apply (rule_tac x="x" in exI) | |
| 1137 | apply (rule_tac x="x + y" in exI) | |
| 1138 | apply algebra | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1139 | done | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1140 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1141 | lemma bezout_add_nat: "\<exists>(d::nat) x y. d dvd a \<and> d dvd b \<and> | 
| 31706 | 1142 | (a * x = b * y + d \<or> b * x = a * y + d)" | 
| 1143 | apply(induct a b rule: ind_euclid) | |
| 1144 | apply blast | |
| 1145 | apply clarify | |
| 1146 | apply (rule_tac x="a" in exI, simp add: dvd_add) | |
| 1147 | apply clarsimp | |
| 1148 | apply (rule_tac x="d" in exI) | |
| 1149 | apply (case_tac "a * x = b * y + d", simp_all add: dvd_add) | |
| 1150 | apply (rule_tac x="x+y" in exI) | |
| 1151 | apply (rule_tac x="y" in exI) | |
| 1152 | apply algebra | |
| 1153 | apply (rule_tac x="x" in exI) | |
| 1154 | apply (rule_tac x="x+y" in exI) | |
| 1155 | apply algebra | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1156 | done | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1157 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1158 | lemma bezout1_nat: "\<exists>(d::nat) x y. d dvd a \<and> d dvd b \<and> | 
| 31706 | 1159 | (a * x - b * y = d \<or> b * x - a * y = d)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1160 | using bezout_add_nat[of a b] | 
| 31706 | 1161 | apply clarsimp | 
| 1162 | apply (rule_tac x="d" in exI, simp) | |
| 1163 | apply (rule_tac x="x" in exI) | |
| 1164 | apply (rule_tac x="y" in exI) | |
| 1165 | apply auto | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1166 | done | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1167 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1168 | lemma bezout_add_strong_nat: assumes nz: "a \<noteq> (0::nat)" | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1169 | shows "\<exists>d x y. d dvd a \<and> d dvd b \<and> a * x = b * y + d" | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1170 | proof- | 
| 31706 | 1171 | from nz have ap: "a > 0" by simp | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1172 | from bezout_add_nat[of a b] | 
| 31706 | 1173 | have "(\<exists>d x y. d dvd a \<and> d dvd b \<and> a * x = b * y + d) \<or> | 
| 1174 | (\<exists>d x y. d dvd a \<and> d dvd b \<and> b * x = a * y + d)" by blast | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1175 | moreover | 
| 31706 | 1176 |     {fix d x y assume H: "d dvd a" "d dvd b" "a * x = b * y + d"
 | 
| 1177 | from H have ?thesis by blast } | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1178 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1179 |  {fix d x y assume H: "d dvd a" "d dvd b" "b * x = a * y + d"
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1180 |    {assume b0: "b = 0" with H  have ?thesis by simp}
 | 
| 31706 | 1181 | moreover | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1182 |    {assume b: "b \<noteq> 0" hence bp: "b > 0" by simp
 | 
| 31706 | 1183 | from b dvd_imp_le [OF H(2)] have "d < b \<or> d = b" | 
| 1184 | by auto | |
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1185 | moreover | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1186 |      {assume db: "d=b"
 | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1187 | from prems have ?thesis apply simp | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1188 | apply (rule exI[where x = b], simp) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1189 | apply (rule exI[where x = b]) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1190 | by (rule exI[where x = "a - 1"], simp add: diff_mult_distrib2)} | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1191 | moreover | 
| 31706 | 1192 |     {assume db: "d < b"
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1193 |         {assume "x=0" hence ?thesis  using prems by simp }
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1194 | moreover | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1195 |         {assume x0: "x \<noteq> 0" hence xp: "x > 0" by simp
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1196 | from db have "d \<le> b - 1" by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1197 | hence "d*b \<le> b*(b - 1)" by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1198 | with xp mult_mono[of "1" "x" "d*b" "b*(b - 1)"] | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1199 | have dble: "d*b \<le> x*b*(b - 1)" using bp by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1200 | from H (3) have "d + (b - 1) * (b*x) = d + (b - 1) * (a*y + d)" | 
| 31706 | 1201 | by simp | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1202 | hence "d + (b - 1) * a * y + (b - 1) * d = d + (b - 1) * b * x" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1203 | by (simp only: mult_assoc right_distrib) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1204 | hence "a * ((b - 1) * y) + d * (b - 1 + 1) = d + x*b*(b - 1)" | 
| 31706 | 1205 | by algebra | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1206 | hence "a * ((b - 1) * y) = d + x*b*(b - 1) - d*b" using bp by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1207 | hence "a * ((b - 1) * y) = d + (x*b*(b - 1) - d*b)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1208 | by (simp only: diff_add_assoc[OF dble, of d, symmetric]) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1209 | hence "a * ((b - 1) * y) = b*(x*(b - 1) - d) + d" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1210 | by (simp only: diff_mult_distrib2 add_commute mult_ac) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1211 | hence ?thesis using H(1,2) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1212 | apply - | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1213 | apply (rule exI[where x=d], simp) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1214 | apply (rule exI[where x="(b - 1) * y"]) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1215 | by (rule exI[where x="x*(b - 1) - d"], simp)} | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1216 | ultimately have ?thesis by blast} | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1217 | ultimately have ?thesis by blast} | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1218 | ultimately have ?thesis by blast} | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1219 | ultimately show ?thesis by blast | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1220 | qed | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1221 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1222 | lemma bezout_nat: assumes a: "(a::nat) \<noteq> 0" | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1223 | shows "\<exists>x y. a * x = b * y + gcd a b" | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1224 | proof- | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1225 | let ?g = "gcd a b" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1226 | from bezout_add_strong_nat[OF a, of b] | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1227 | obtain d x y where d: "d dvd a" "d dvd b" "a * x = b * y + d" by blast | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1228 | from d(1,2) have "d dvd ?g" by simp | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1229 | then obtain k where k: "?g = d*k" unfolding dvd_def by blast | 
| 31706 | 1230 | from d(3) have "a * x * k = (b * y + d) *k " by auto | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1231 | hence "a * (x * k) = b * (y*k) + ?g" by (algebra add: k) | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1232 | thus ?thesis by blast | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1233 | qed | 
| 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1234 | |
| 31706 | 1235 | |
| 1236 | subsection {* LCM *}
 | |
| 1237 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1238 | lemma lcm_altdef_int: "lcm (a::int) b = (abs a) * (abs b) div gcd a b" | 
| 31706 | 1239 | by (simp add: lcm_int_def lcm_nat_def zdiv_int | 
| 1240 | zmult_int [symmetric] gcd_int_def) | |
| 1241 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1242 | lemma prod_gcd_lcm_nat: "(m::nat) * n = gcd m n * lcm m n" | 
| 31706 | 1243 | unfolding lcm_nat_def | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1244 | by (simp add: dvd_mult_div_cancel [OF gcd_dvd_prod_nat]) | 
| 31706 | 1245 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1246 | lemma prod_gcd_lcm_int: "abs(m::int) * abs n = gcd m n * lcm m n" | 
| 31706 | 1247 | unfolding lcm_int_def gcd_int_def | 
| 1248 | apply (subst int_mult [symmetric]) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1249 | apply (subst prod_gcd_lcm_nat [symmetric]) | 
| 31706 | 1250 | apply (subst nat_abs_mult_distrib [symmetric]) | 
| 1251 | apply (simp, simp add: abs_mult) | |
| 1252 | done | |
| 1253 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1254 | lemma lcm_0_nat [simp]: "lcm (m::nat) 0 = 0" | 
| 31706 | 1255 | unfolding lcm_nat_def by simp | 
| 1256 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1257 | lemma lcm_0_int [simp]: "lcm (m::int) 0 = 0" | 
| 31706 | 1258 | unfolding lcm_int_def by simp | 
| 1259 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1260 | lemma lcm_0_left_nat [simp]: "lcm (0::nat) n = 0" | 
| 31706 | 1261 | unfolding lcm_nat_def by simp | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1262 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1263 | lemma lcm_0_left_int [simp]: "lcm (0::int) n = 0" | 
| 31706 | 1264 | unfolding lcm_int_def by simp | 
| 1265 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1266 | lemma lcm_commute_nat: "lcm (m::nat) n = lcm n m" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1267 | unfolding lcm_nat_def by (simp add: gcd_commute_nat ring_simps) | 
| 31706 | 1268 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1269 | lemma lcm_commute_int: "lcm (m::int) n = lcm n m" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1270 | unfolding lcm_int_def by (subst lcm_commute_nat, rule refl) | 
| 31706 | 1271 | |
| 1272 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1273 | lemma lcm_pos_nat: | 
| 31798 | 1274 | "(m::nat) > 0 \<Longrightarrow> n>0 \<Longrightarrow> lcm m n > 0" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1275 | by (metis gr0I mult_is_0 prod_gcd_lcm_nat) | 
| 27669 
4b1642284dd7
Tuned and simplified proofs; Rules added to presburger's and algebra's context; moved Bezout theorems from Primes.thy
 chaieb parents: 
27651diff
changeset | 1276 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1277 | lemma lcm_pos_int: | 
| 31798 | 1278 | "(m::int) ~= 0 \<Longrightarrow> n ~= 0 \<Longrightarrow> lcm m n > 0" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1279 | apply (subst lcm_abs_int) | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1280 | apply (rule lcm_pos_nat [transferred]) | 
| 31798 | 1281 | apply auto | 
| 31706 | 1282 | done | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1283 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1284 | lemma dvd_pos_nat: | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1285 | fixes n m :: nat | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1286 | assumes "n > 0" and "m dvd n" | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1287 | shows "m > 0" | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1288 | using assms by (cases m) auto | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1289 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1290 | lemma lcm_least_nat: | 
| 31706 | 1291 | assumes "(m::nat) dvd k" and "n dvd k" | 
| 27556 | 1292 | shows "lcm m n dvd k" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1293 | proof (cases k) | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1294 | case 0 then show ?thesis by auto | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1295 | next | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1296 | case (Suc _) then have pos_k: "k > 0" by auto | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1297 | from assms dvd_pos_nat [OF this] have pos_mn: "m > 0" "n > 0" by auto | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1298 | with gcd_zero_nat [of m n] have pos_gcd: "gcd m n > 0" by simp | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1299 | from assms obtain p where k_m: "k = m * p" using dvd_def by blast | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1300 | from assms obtain q where k_n: "k = n * q" using dvd_def by blast | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1301 | from pos_k k_m have pos_p: "p > 0" by auto | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1302 | from pos_k k_n have pos_q: "q > 0" by auto | 
| 27556 | 1303 | have "k * k * gcd q p = k * gcd (k * q) (k * p)" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1304 | by (simp add: mult_ac gcd_mult_distrib_nat) | 
| 27556 | 1305 | also have "\<dots> = k * gcd (m * p * q) (n * q * p)" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1306 | by (simp add: k_m [symmetric] k_n [symmetric]) | 
| 27556 | 1307 | also have "\<dots> = k * p * q * gcd m n" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1308 | by (simp add: mult_ac gcd_mult_distrib_nat) | 
| 27556 | 1309 | finally have "(m * p) * (n * q) * gcd q p = k * p * q * gcd m n" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1310 | by (simp only: k_m [symmetric] k_n [symmetric]) | 
| 27556 | 1311 | then have "p * q * m * n * gcd q p = p * q * k * gcd m n" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1312 | by (simp add: mult_ac) | 
| 27556 | 1313 | with pos_p pos_q have "m * n * gcd q p = k * gcd m n" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1314 | by simp | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1315 | with prod_gcd_lcm_nat [of m n] | 
| 27556 | 1316 | have "lcm m n * gcd q p * gcd m n = k * gcd m n" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1317 | by (simp add: mult_ac) | 
| 31706 | 1318 | with pos_gcd have "lcm m n * gcd q p = k" by auto | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1319 | then show ?thesis using dvd_def by auto | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1320 | qed | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1321 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1322 | lemma lcm_least_int: | 
| 31798 | 1323 | "(m::int) dvd k \<Longrightarrow> n dvd k \<Longrightarrow> lcm m n dvd k" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1324 | apply (subst lcm_abs_int) | 
| 31798 | 1325 | apply (rule dvd_trans) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1326 | apply (rule lcm_least_nat [transferred, of _ "abs k" _]) | 
| 31798 | 1327 | apply auto | 
| 31706 | 1328 | done | 
| 1329 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1330 | lemma lcm_dvd1_nat: "(m::nat) dvd lcm m n" | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1331 | proof (cases m) | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1332 | case 0 then show ?thesis by simp | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1333 | next | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1334 | case (Suc _) | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1335 | then have mpos: "m > 0" by simp | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1336 | show ?thesis | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1337 | proof (cases n) | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1338 | case 0 then show ?thesis by simp | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1339 | next | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1340 | case (Suc _) | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1341 | then have npos: "n > 0" by simp | 
| 27556 | 1342 | have "gcd m n dvd n" by simp | 
| 1343 | then obtain k where "n = gcd m n * k" using dvd_def by auto | |
| 31706 | 1344 | then have "m * n div gcd m n = m * (gcd m n * k) div gcd m n" | 
| 1345 | by (simp add: mult_ac) | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1346 | also have "\<dots> = m * k" using mpos npos gcd_zero_nat by simp | 
| 31706 | 1347 | finally show ?thesis by (simp add: lcm_nat_def) | 
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1348 | qed | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1349 | qed | 
| 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1350 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1351 | lemma lcm_dvd1_int: "(m::int) dvd lcm m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1352 | apply (subst lcm_abs_int) | 
| 31706 | 1353 | apply (rule dvd_trans) | 
| 1354 | prefer 2 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1355 | apply (rule lcm_dvd1_nat [transferred]) | 
| 31706 | 1356 | apply auto | 
| 1357 | done | |
| 1358 | ||
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1359 | lemma lcm_dvd2_nat: "(n::nat) dvd lcm m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1360 | by (subst lcm_commute_nat, rule lcm_dvd1_nat) | 
| 31706 | 1361 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1362 | lemma lcm_dvd2_int: "(n::int) dvd lcm m n" | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1363 | by (subst lcm_commute_int, rule lcm_dvd1_int) | 
| 31706 | 1364 | |
| 31730 | 1365 | lemma dvd_lcm_I1_nat[simp]: "(k::nat) dvd m \<Longrightarrow> k dvd lcm m n" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1366 | by(metis lcm_dvd1_nat dvd_trans) | 
| 31729 | 1367 | |
| 31730 | 1368 | lemma dvd_lcm_I2_nat[simp]: "(k::nat) dvd n \<Longrightarrow> k dvd lcm m n" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1369 | by(metis lcm_dvd2_nat dvd_trans) | 
| 31729 | 1370 | |
| 31730 | 1371 | lemma dvd_lcm_I1_int[simp]: "(i::int) dvd m \<Longrightarrow> i dvd lcm m n" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1372 | by(metis lcm_dvd1_int dvd_trans) | 
| 31729 | 1373 | |
| 31730 | 1374 | lemma dvd_lcm_I2_int[simp]: "(i::int) dvd n \<Longrightarrow> i dvd lcm m n" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1375 | by(metis lcm_dvd2_int dvd_trans) | 
| 31729 | 1376 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1377 | lemma lcm_unique_nat: "(a::nat) dvd d \<and> b dvd d \<and> | 
| 31706 | 1378 | (\<forall>e. a dvd e \<and> b dvd e \<longrightarrow> d dvd e) \<longleftrightarrow> d = lcm a b" | 
| 33657 | 1379 | by (auto intro: dvd_antisym lcm_least_nat lcm_dvd1_nat lcm_dvd2_nat) | 
| 27568 
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
 chaieb parents: 
27556diff
changeset | 1380 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1381 | lemma lcm_unique_int: "d >= 0 \<and> (a::int) dvd d \<and> b dvd d \<and> | 
| 31706 | 1382 | (\<forall>e. a dvd e \<and> b dvd e \<longrightarrow> d dvd e) \<longleftrightarrow> d = lcm a b" | 
| 33657 | 1383 | by (auto intro: dvd_antisym [transferred] lcm_least_int) | 
| 31706 | 1384 | |
| 31798 | 1385 | lemma lcm_proj2_if_dvd_nat [simp]: "(x::nat) dvd y \<Longrightarrow> lcm x y = y" | 
| 31706 | 1386 | apply (rule sym) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1387 | apply (subst lcm_unique_nat [symmetric]) | 
| 31706 | 1388 | apply auto | 
| 1389 | done | |
| 1390 | ||
| 31798 | 1391 | lemma lcm_proj2_if_dvd_int [simp]: "(x::int) dvd y \<Longrightarrow> lcm x y = abs y" | 
| 31706 | 1392 | apply (rule sym) | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1393 | apply (subst lcm_unique_int [symmetric]) | 
| 31706 | 1394 | apply auto | 
| 1395 | done | |
| 1396 | ||
| 31798 | 1397 | lemma lcm_proj1_if_dvd_nat [simp]: "(x::nat) dvd y \<Longrightarrow> lcm y x = y" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1398 | by (subst lcm_commute_nat, erule lcm_proj2_if_dvd_nat) | 
| 31706 | 1399 | |
| 31798 | 1400 | lemma lcm_proj1_if_dvd_int [simp]: "(x::int) dvd y \<Longrightarrow> lcm y x = abs y" | 
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1401 | by (subst lcm_commute_int, erule lcm_proj2_if_dvd_int) | 
| 31706 | 1402 | |
| 31992 | 1403 | lemma lcm_proj1_iff_nat[simp]: "lcm m n = (m::nat) \<longleftrightarrow> n dvd m" | 
| 1404 | by (metis lcm_proj1_if_dvd_nat lcm_unique_nat) | |
| 1405 | ||
| 1406 | lemma lcm_proj2_iff_nat[simp]: "lcm m n = (n::nat) \<longleftrightarrow> m dvd n" | |
| 1407 | by (metis lcm_proj2_if_dvd_nat lcm_unique_nat) | |
| 1408 | ||
| 1409 | lemma lcm_proj1_iff_int[simp]: "lcm m n = abs(m::int) \<longleftrightarrow> n dvd m" | |
| 1410 | by (metis dvd_abs_iff lcm_proj1_if_dvd_int lcm_unique_int) | |
| 1411 | ||
| 1412 | lemma lcm_proj2_iff_int[simp]: "lcm m n = abs(n::int) \<longleftrightarrow> m dvd n" | |
| 1413 | by (metis dvd_abs_iff lcm_proj2_if_dvd_int lcm_unique_int) | |
| 27568 
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
 chaieb parents: 
27556diff
changeset | 1414 | |
| 31766 | 1415 | lemma lcm_assoc_nat: "lcm (lcm n m) (p::nat) = lcm n (lcm m p)" | 
| 31992 | 1416 | by(rule lcm_unique_nat[THEN iffD1])(metis dvd.order_trans lcm_unique_nat) | 
| 31766 | 1417 | |
| 1418 | lemma lcm_assoc_int: "lcm (lcm n m) (p::int) = lcm n (lcm m p)" | |
| 31992 | 1419 | by(rule lcm_unique_int[THEN iffD1])(metis dvd_trans lcm_unique_int) | 
| 31766 | 1420 | |
| 31992 | 1421 | lemmas lcm_left_commute_nat = mk_left_commute[of lcm, OF lcm_assoc_nat lcm_commute_nat] | 
| 1422 | lemmas lcm_left_commute_int = mk_left_commute[of lcm, OF lcm_assoc_int lcm_commute_int] | |
| 31766 | 1423 | |
| 31952 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1424 | lemmas lcm_ac_nat = lcm_assoc_nat lcm_commute_nat lcm_left_commute_nat | 
| 
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
 nipkow parents: 
31814diff
changeset | 1425 | lemmas lcm_ac_int = lcm_assoc_int lcm_commute_int lcm_left_commute_int | 
| 31766 | 1426 | |
| 31992 | 1427 | lemma fun_left_comm_idem_gcd_nat: "fun_left_comm_idem (gcd :: nat\<Rightarrow>nat\<Rightarrow>nat)" | 
| 1428 | proof qed (auto simp add: gcd_ac_nat) | |
| 1429 | ||
| 1430 | lemma fun_left_comm_idem_gcd_int: "fun_left_comm_idem (gcd :: int\<Rightarrow>int\<Rightarrow>int)" | |
| 1431 | proof qed (auto simp add: gcd_ac_int) | |
| 1432 | ||
| 1433 | lemma fun_left_comm_idem_lcm_nat: "fun_left_comm_idem (lcm :: nat\<Rightarrow>nat\<Rightarrow>nat)" | |
| 1434 | proof qed (auto simp add: lcm_ac_nat) | |
| 1435 | ||
| 1436 | lemma fun_left_comm_idem_lcm_int: "fun_left_comm_idem (lcm :: int\<Rightarrow>int\<Rightarrow>int)" | |
| 1437 | proof qed (auto simp add: lcm_ac_int) | |
| 1438 | ||
| 23687 
06884f7ffb18
extended - convers now basic lcm properties also
 haftmann parents: 
23431diff
changeset | 1439 | |
| 31995 | 1440 | (* FIXME introduce selimattice_bot/top and derive the following lemmas in there: *) | 
| 1441 | ||
| 1442 | lemma lcm_0_iff_nat[simp]: "lcm (m::nat) n = 0 \<longleftrightarrow> m=0 \<or> n=0" | |
| 1443 | by (metis lcm_0_left_nat lcm_0_nat mult_is_0 prod_gcd_lcm_nat) | |
| 1444 | ||
| 1445 | lemma lcm_0_iff_int[simp]: "lcm (m::int) n = 0 \<longleftrightarrow> m=0 \<or> n=0" | |
| 1446 | by (metis lcm_0_int lcm_0_left_int lcm_pos_int zless_le) | |
| 1447 | ||
| 1448 | lemma lcm_1_iff_nat[simp]: "lcm (m::nat) n = 1 \<longleftrightarrow> m=1 \<and> n=1" | |
| 1449 | by (metis gcd_1_nat lcm_unique_nat nat_mult_1 prod_gcd_lcm_nat) | |
| 1450 | ||
| 1451 | lemma lcm_1_iff_int[simp]: "lcm (m::int) n = 1 \<longleftrightarrow> (m=1 \<or> m = -1) \<and> (n=1 \<or> n = -1)" | |
| 31996 
1d93369079c4
Tuned proof of lcm_1_iff_int, because metis produced enormous proof term.
 berghofe parents: 
31995diff
changeset | 1452 | by (auto simp add: abs_mult_self trans [OF lcm_unique_int eq_commute, symmetric] zmult_eq_1_iff) | 
| 31995 | 1453 | |
| 32112 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1454 | subsubsection {* The complete divisibility lattice *}
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1455 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1456 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1457 | interpretation gcd_semilattice_nat: lower_semilattice "op dvd" "(%m n::nat. m dvd n & ~ n dvd m)" gcd | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1458 | proof | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1459 | case goal3 thus ?case by(metis gcd_unique_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1460 | qed auto | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1461 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1462 | interpretation lcm_semilattice_nat: upper_semilattice "op dvd" "(%m n::nat. m dvd n & ~ n dvd m)" lcm | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1463 | proof | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1464 | case goal3 thus ?case by(metis lcm_unique_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1465 | qed auto | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1466 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1467 | interpretation gcd_lcm_lattice_nat: lattice "op dvd" "(%m n::nat. m dvd n & ~ n dvd m)" gcd lcm .. | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1468 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1469 | text{* Lifting gcd and lcm to finite (Gcd/Lcm) and infinite sets (GCD/LCM).
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1470 | GCD is defined via LCM to facilitate the proof that we have a complete lattice. | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1471 | Later on we show that GCD and Gcd coincide on finite sets. | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1472 | *} | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1473 | context gcd | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1474 | begin | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1475 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1476 | definition Gcd :: "'a set \<Rightarrow> 'a" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1477 | where "Gcd = fold gcd 0" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1478 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1479 | definition Lcm :: "'a set \<Rightarrow> 'a" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1480 | where "Lcm = fold lcm 1" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1481 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1482 | definition LCM :: "'a set \<Rightarrow> 'a" where | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1483 | "LCM M = (if finite M then Lcm M else 0)" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1484 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1485 | definition GCD :: "'a set \<Rightarrow> 'a" where | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1486 | "GCD M = LCM(INT m:M. {d. d dvd m})"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1487 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1488 | end | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1489 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1490 | lemma Gcd_empty[simp]: "Gcd {} = 0"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1491 | by(simp add:Gcd_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1492 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1493 | lemma Lcm_empty[simp]: "Lcm {} = 1"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1494 | by(simp add:Lcm_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1495 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1496 | lemma GCD_empty_nat[simp]: "GCD {} = (0::nat)"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1497 | by(simp add:GCD_def LCM_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1498 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1499 | lemma LCM_eq_Lcm[simp]: "finite M \<Longrightarrow> LCM M = Lcm M" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1500 | by(simp add:LCM_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1501 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1502 | lemma Lcm_insert_nat [simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1503 | assumes "finite N" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1504 | shows "Lcm (insert (n::nat) N) = lcm n (Lcm N)" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1505 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1506 | interpret fun_left_comm_idem "lcm::nat\<Rightarrow>nat\<Rightarrow>nat" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1507 | by (rule fun_left_comm_idem_lcm_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1508 | from assms show ?thesis by(simp add: Lcm_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1509 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1510 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1511 | lemma Lcm_insert_int [simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1512 | assumes "finite N" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1513 | shows "Lcm (insert (n::int) N) = lcm n (Lcm N)" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1514 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1515 | interpret fun_left_comm_idem "lcm::int\<Rightarrow>int\<Rightarrow>int" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1516 | by (rule fun_left_comm_idem_lcm_int) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1517 | from assms show ?thesis by(simp add: Lcm_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1518 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1519 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1520 | lemma Gcd_insert_nat [simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1521 | assumes "finite N" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1522 | shows "Gcd (insert (n::nat) N) = gcd n (Gcd N)" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1523 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1524 | interpret fun_left_comm_idem "gcd::nat\<Rightarrow>nat\<Rightarrow>nat" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1525 | by (rule fun_left_comm_idem_gcd_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1526 | from assms show ?thesis by(simp add: Gcd_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1527 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1528 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1529 | lemma Gcd_insert_int [simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1530 | assumes "finite N" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1531 | shows "Gcd (insert (n::int) N) = gcd n (Gcd N)" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1532 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1533 | interpret fun_left_comm_idem "gcd::int\<Rightarrow>int\<Rightarrow>int" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1534 | by (rule fun_left_comm_idem_gcd_int) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1535 | from assms show ?thesis by(simp add: Gcd_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1536 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1537 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1538 | lemma Lcm0_iff[simp]: "finite (M::nat set) \<Longrightarrow> M \<noteq> {} \<Longrightarrow> Lcm M = 0 \<longleftrightarrow> 0 : M"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1539 | by(induct rule:finite_ne_induct) auto | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1540 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1541 | lemma Lcm_eq_0[simp]: "finite (M::nat set) \<Longrightarrow> 0 : M \<Longrightarrow> Lcm M = 0" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1542 | by (metis Lcm0_iff empty_iff) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1543 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1544 | lemma Gcd_dvd_nat [simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1545 | assumes "finite M" and "(m::nat) \<in> M" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1546 | shows "Gcd M dvd m" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1547 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1548 | show ?thesis using gcd_semilattice_nat.fold_inf_le_inf[OF assms, of 0] by (simp add: Gcd_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1549 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1550 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1551 | lemma dvd_Gcd_nat[simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1552 | assumes "finite M" and "ALL (m::nat) : M. n dvd m" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1553 | shows "n dvd Gcd M" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1554 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1555 | show ?thesis using gcd_semilattice_nat.inf_le_fold_inf[OF assms, of 0] by (simp add: Gcd_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1556 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1557 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1558 | lemma dvd_Lcm_nat [simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1559 | assumes "finite M" and "(m::nat) \<in> M" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1560 | shows "m dvd Lcm M" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1561 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1562 | show ?thesis using lcm_semilattice_nat.sup_le_fold_sup[OF assms, of 1] by (simp add: Lcm_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1563 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1564 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1565 | lemma Lcm_dvd_nat[simp]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1566 | assumes "finite M" and "ALL (m::nat) : M. m dvd n" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1567 | shows "Lcm M dvd n" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1568 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1569 | show ?thesis using lcm_semilattice_nat.fold_sup_le_sup[OF assms, of 1] by (simp add: Lcm_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1570 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1571 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1572 | interpretation gcd_lcm_complete_lattice_nat: | 
| 32879 | 1573 | complete_lattice GCD LCM "op dvd" "%m n::nat. m dvd n & ~ n dvd m" gcd lcm 1 0 | 
| 32112 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1574 | proof | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1575 | case goal1 show ?case by simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1576 | next | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1577 | case goal2 show ?case by simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1578 | next | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1579 | case goal5 thus ?case by (auto simp: LCM_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1580 | next | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1581 | case goal6 thus ?case | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1582 | by(auto simp: LCM_def)(metis finite_nat_set_iff_bounded_le gcd_proj2_if_dvd_nat gcd_le1_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1583 | next | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1584 | case goal3 thus ?case by (auto simp: GCD_def LCM_def)(metis finite_INT finite_divisors_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1585 | next | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1586 | case goal4 thus ?case by(auto simp: LCM_def GCD_def) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1587 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1588 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1589 | text{* Alternative characterizations of Gcd and GCD: *}
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1590 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1591 | lemma Gcd_eq_Max: "finite(M::nat set) \<Longrightarrow> M \<noteq> {} \<Longrightarrow> 0 \<notin> M \<Longrightarrow> Gcd M = Max(\<Inter>m\<in>M. {d. d dvd m})"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1592 | apply(rule antisym) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1593 | apply(rule Max_ge) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1594 | apply (metis all_not_in_conv finite_divisors_nat finite_INT) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1595 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1596 | apply (rule Max_le_iff[THEN iffD2]) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1597 | apply (metis all_not_in_conv finite_divisors_nat finite_INT) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1598 | apply fastsimp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1599 | apply clarsimp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1600 | apply (metis Gcd_dvd_nat Max_in dvd_0_left dvd_Gcd_nat dvd_imp_le linorder_antisym_conv3 not_less0) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1601 | done | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1602 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1603 | lemma Gcd_remove0_nat: "finite M \<Longrightarrow> Gcd M = Gcd (M - {0::nat})"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1604 | apply(induct pred:finite) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1605 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1606 | apply(case_tac "x=0") | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1607 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1608 | apply(subgoal_tac "insert x F - {0} = insert x (F - {0})")
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1609 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1610 | apply blast | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1611 | done | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1612 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1613 | lemma Lcm_in_lcm_closed_set_nat: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1614 |   "finite M \<Longrightarrow> M \<noteq> {} \<Longrightarrow> ALL m n :: nat. m:M \<longrightarrow> n:M \<longrightarrow> lcm m n : M \<Longrightarrow> Lcm M : M"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1615 | apply(induct rule:finite_linorder_min_induct) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1616 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1617 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1618 | apply(subgoal_tac "ALL m n :: nat. m:A \<longrightarrow> n:A \<longrightarrow> lcm m n : A") | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1619 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1620 |  apply(case_tac "A={}")
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1621 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1622 | apply simp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1623 | apply (metis lcm_pos_nat lcm_unique_nat linorder_neq_iff nat_dvd_not_less not_less0) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1624 | done | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1625 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1626 | lemma Lcm_eq_Max_nat: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1627 |   "finite M \<Longrightarrow> M \<noteq> {} \<Longrightarrow> 0 \<notin> M \<Longrightarrow> ALL m n :: nat. m:M \<longrightarrow> n:M \<longrightarrow> lcm m n : M \<Longrightarrow> Lcm M = Max M"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1628 | apply(rule antisym) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1629 | apply(rule Max_ge, assumption) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1630 | apply(erule (2) Lcm_in_lcm_closed_set_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1631 | apply clarsimp | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1632 | apply (metis Lcm0_iff dvd_Lcm_nat dvd_imp_le neq0_conv) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1633 | done | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1634 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1635 | text{* Finally GCD is Gcd: *}
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1636 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1637 | lemma GCD_eq_Gcd[simp]: assumes "finite(M::nat set)" shows "GCD M = Gcd M" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1638 | proof- | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1639 |   have divisors_remove0_nat: "(\<Inter>m\<in>M. {d::nat. d dvd m}) = (\<Inter>m\<in>M-{0}. {d::nat. d dvd m})" by auto
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1640 | show ?thesis | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1641 | proof cases | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1642 |     assume "M={}" thus ?thesis by simp
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1643 | next | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1644 |     assume "M\<noteq>{}"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1645 | show ?thesis | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1646 | proof cases | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1647 |       assume "M={0}" thus ?thesis by(simp add:GCD_def LCM_def)
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1648 | next | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1649 |       assume "M\<noteq>{0}"
 | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1650 |       with `M\<noteq>{}` assms show ?thesis
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1651 | apply(subst Gcd_remove0_nat[OF assms]) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1652 | apply(simp add:GCD_def) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1653 | apply(subst divisors_remove0_nat) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1654 | apply(simp add:LCM_def) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1655 | apply rule | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1656 | apply rule | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1657 | apply(subst Gcd_eq_Max) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1658 | apply simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1659 | apply blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1660 | apply blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1661 | apply(rule Lcm_eq_Max_nat) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1662 | apply simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1663 | apply blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1664 | apply fastsimp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1665 | apply clarsimp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1666 | apply(fastsimp intro: finite_divisors_nat intro!: finite_INT) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32879diff
changeset | 1667 | done | 
| 32112 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1668 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1669 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1670 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1671 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1672 | lemma Lcm_set_nat [code_unfold]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1673 | "Lcm (set ns) = foldl lcm (1::nat) ns" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1674 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1675 | interpret fun_left_comm_idem "lcm::nat\<Rightarrow>nat\<Rightarrow>nat" by (rule fun_left_comm_idem_lcm_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1676 | show ?thesis by(simp add: Lcm_def fold_set lcm_commute_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1677 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1678 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1679 | lemma Lcm_set_int [code_unfold]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1680 | "Lcm (set is) = foldl lcm (1::int) is" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1681 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1682 | interpret fun_left_comm_idem "lcm::int\<Rightarrow>int\<Rightarrow>int" by (rule fun_left_comm_idem_lcm_int) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1683 | show ?thesis by(simp add: Lcm_def fold_set lcm_commute_int) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1684 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1685 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1686 | lemma Gcd_set_nat [code_unfold]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1687 | "Gcd (set ns) = foldl gcd (0::nat) ns" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1688 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1689 | interpret fun_left_comm_idem "gcd::nat\<Rightarrow>nat\<Rightarrow>nat" by (rule fun_left_comm_idem_gcd_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1690 | show ?thesis by(simp add: Gcd_def fold_set gcd_commute_nat) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1691 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1692 | |
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1693 | lemma Gcd_set_int [code_unfold]: | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1694 | "Gcd (set ns) = foldl gcd (0::int) ns" | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1695 | proof - | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1696 | interpret fun_left_comm_idem "gcd::int\<Rightarrow>int\<Rightarrow>int" by (rule fun_left_comm_idem_gcd_int) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1697 | show ?thesis by(simp add: Gcd_def fold_set gcd_commute_int) | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1698 | qed | 
| 
6da9c2a49fed
Made dvd/gcd/lcm a complete lattice by introducing Gcd/GCD/Lcm/LCM
 nipkow parents: 
32111diff
changeset | 1699 | |
| 33197 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1700 | lemma gcd_eq_nitpick_gcd [nitpick_def]: "gcd x y \<equiv> Nitpick.nat_gcd x y" | 
| 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1701 | apply (rule eq_reflection) | 
| 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1702 | apply (induct x y rule: nat_gcd.induct) | 
| 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1703 | by (simp add: gcd_nat.simps Nitpick.nat_gcd.simps) | 
| 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1704 | |
| 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1705 | lemma lcm_eq_nitpick_lcm [nitpick_def]: "lcm x y \<equiv> Nitpick.nat_lcm x y" | 
| 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1706 | by (simp only: lcm_nat_def Nitpick.nat_lcm_def gcd_eq_nitpick_gcd) | 
| 
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
 blanchet parents: 
32960diff
changeset | 1707 | |
| 21256 | 1708 | end |