1236 apply (erule conjE) |
1236 apply (erule conjE) |
1237 apply (erule_tac x = "nat x" in allE) |
1237 apply (erule_tac x = "nat x" in allE) |
1238 apply simp |
1238 apply simp |
1239 done |
1239 done |
1240 |
1240 |
1241 theorem zdvd_int: "(x dvd y) = (int x dvd int y)" |
1241 theorem zdvd_int_of_nat: "(x dvd y) = (int_of_nat x dvd int_of_nat y)" |
1242 apply (simp only: dvd_def ex_nat int_int_eq [symmetric] zmult_int [symmetric] |
1242 unfolding dvd_def |
1243 nat_0_le cong add: conj_cong) |
1243 apply (rule_tac s="\<exists>k. int_of_nat y = int_of_nat x * int_of_nat k" in trans) |
|
1244 apply (simp only: of_nat_mult [symmetric] of_nat_eq_iff) |
|
1245 apply (simp add: ex_nat cong add: conj_cong) |
1244 apply (rule iffI) |
1246 apply (rule iffI) |
1245 apply iprover |
1247 apply iprover |
1246 apply (erule exE) |
1248 apply (erule exE) |
1247 apply (case_tac "x=0") |
1249 apply (case_tac "x=0") |
1248 apply (rule_tac x=0 in exI) |
1250 apply (rule_tac x=0 in exI) |
1249 apply simp |
1251 apply simp |
1250 apply (case_tac "0 \<le> k") |
1252 apply (case_tac "0 \<le> k") |
1251 apply iprover |
1253 apply iprover |
1252 apply (simp add: linorder_not_le) |
1254 apply (simp add: linorder_not_le) |
1253 apply (drule mult_strict_left_mono_neg [OF iffD2 [OF zero_less_int_conv]]) |
1255 apply (drule mult_strict_left_mono_neg [OF iffD2 [OF of_nat_0_less_iff]]) |
1254 apply assumption |
1256 apply assumption |
1255 apply (simp add: mult_ac) |
1257 apply (simp add: mult_ac) |
1256 done |
1258 done |
|
1259 |
|
1260 theorem zdvd_int: "(x dvd y) = (int x dvd int y)" |
|
1261 unfolding int_eq_of_nat by (rule zdvd_int_of_nat) |
1257 |
1262 |
1258 lemma zdvd1_eq[simp]: "(x::int) dvd 1 = ( \<bar>x\<bar> = 1)" |
1263 lemma zdvd1_eq[simp]: "(x::int) dvd 1 = ( \<bar>x\<bar> = 1)" |
1259 proof |
1264 proof |
1260 assume d: "x dvd 1" hence "int (nat \<bar>x\<bar>) dvd int (nat 1)" by (simp add: zdvd_abs1) |
1265 assume d: "x dvd 1" hence "int (nat \<bar>x\<bar>) dvd int (nat 1)" by (simp add: zdvd_abs1) |
1261 hence "nat \<bar>x\<bar> dvd 1" by (simp add: zdvd_int) |
1266 hence "nat \<bar>x\<bar> dvd 1" by (simp add: zdvd_int) |
1273 next |
1278 next |
1274 assume H: "m * n dvd m" hence H2: "m * n dvd m * 1" by simp |
1279 assume H: "m * n dvd m" hence H2: "m * n dvd m * 1" by simp |
1275 from zdvd_mult_cancel[OF H2 mp] show "\<bar>n\<bar> = 1" by (simp only: zdvd1_eq) |
1280 from zdvd_mult_cancel[OF H2 mp] show "\<bar>n\<bar> = 1" by (simp only: zdvd1_eq) |
1276 qed |
1281 qed |
1277 |
1282 |
|
1283 lemma int_of_nat_dvd_iff: "(int_of_nat m dvd z) = (m dvd nat (abs z))" |
|
1284 apply (auto simp add: dvd_def nat_abs_mult_distrib) |
|
1285 apply (auto simp add: nat_eq_iff' abs_if split add: split_if_asm) |
|
1286 apply (rule_tac x = "-(int_of_nat k)" in exI) |
|
1287 apply auto |
|
1288 done |
|
1289 |
1278 lemma int_dvd_iff: "(int m dvd z) = (m dvd nat (abs z))" |
1290 lemma int_dvd_iff: "(int m dvd z) = (m dvd nat (abs z))" |
1279 apply (auto simp add: dvd_def nat_abs_mult_distrib) |
1291 unfolding int_eq_of_nat by (rule int_of_nat_dvd_iff) |
1280 apply (auto simp add: nat_eq_iff abs_if split add: split_if_asm) |
1292 |
1281 apply (rule_tac x = "-(int k)" in exI) |
1293 lemma dvd_int_of_nat_iff: "(z dvd int_of_nat m) = (nat (abs z) dvd m)" |
1282 apply (auto simp add: int_mult) |
1294 apply (auto simp add: dvd_def abs_if) |
|
1295 apply (rule_tac [3] x = "nat k" in exI) |
|
1296 apply (rule_tac [2] x = "-(int_of_nat k)" in exI) |
|
1297 apply (rule_tac x = "nat (-k)" in exI) |
|
1298 apply (cut_tac [3] m = m and 'a=int in of_nat_less_0_iff) |
|
1299 apply (cut_tac m = m and 'a=int in of_nat_less_0_iff) |
|
1300 apply (auto simp add: zero_le_mult_iff mult_less_0_iff |
|
1301 nat_mult_distrib [symmetric] nat_eq_iff2') |
1283 done |
1302 done |
1284 |
1303 |
1285 lemma dvd_int_iff: "(z dvd int m) = (nat (abs z) dvd m)" |
1304 lemma dvd_int_iff: "(z dvd int m) = (nat (abs z) dvd m)" |
1286 apply (auto simp add: dvd_def abs_if int_mult) |
1305 unfolding int_eq_of_nat by (rule dvd_int_of_nat_iff) |
1287 apply (rule_tac [3] x = "nat k" in exI) |
1306 |
1288 apply (rule_tac [2] x = "-(int k)" in exI) |
1307 lemma nat_dvd_iff': "(nat z dvd m) = (if 0 \<le> z then (z dvd int_of_nat m) else m = 0)" |
1289 apply (rule_tac x = "nat (-k)" in exI) |
1308 apply (auto simp add: dvd_def) |
1290 apply (cut_tac [3] k = m in int_less_0_conv) |
1309 apply (rule_tac x = "nat k" in exI) |
1291 apply (cut_tac k = m in int_less_0_conv) |
1310 apply (cut_tac m = m and 'a=int in of_nat_less_0_iff) |
1292 apply (auto simp add: zero_le_mult_iff mult_less_0_iff |
1311 apply (auto simp add: zero_le_mult_iff mult_less_0_iff |
1293 nat_mult_distrib [symmetric] nat_eq_iff2) |
1312 nat_mult_distrib [symmetric] nat_eq_iff2') |
1294 done |
1313 done |
1295 |
1314 |
1296 lemma nat_dvd_iff: "(nat z dvd m) = (if 0 \<le> z then (z dvd int m) else m = 0)" |
1315 lemma nat_dvd_iff: "(nat z dvd m) = (if 0 \<le> z then (z dvd int m) else m = 0)" |
1297 apply (auto simp add: dvd_def int_mult) |
1316 unfolding int_eq_of_nat by (rule nat_dvd_iff') |
1298 apply (rule_tac x = "nat k" in exI) |
|
1299 apply (cut_tac k = m in int_less_0_conv) |
|
1300 apply (auto simp add: zero_le_mult_iff mult_less_0_iff |
|
1301 nat_mult_distrib [symmetric] nat_eq_iff2) |
|
1302 done |
|
1303 |
1317 |
1304 lemma zminus_dvd_iff [iff]: "(-z dvd w) = (z dvd (w::int))" |
1318 lemma zminus_dvd_iff [iff]: "(-z dvd w) = (z dvd (w::int))" |
1305 apply (auto simp add: dvd_def) |
1319 apply (auto simp add: dvd_def) |
1306 apply (rule_tac [!] x = "-k" in exI, auto) |
1320 apply (rule_tac [!] x = "-k" in exI, auto) |
1307 done |
1321 done |
1366 by (induct n, simp_all add: int_mult) |
1380 by (induct n, simp_all add: int_mult) |
1367 |
1381 |
1368 text{*Compatibility binding*} |
1382 text{*Compatibility binding*} |
1369 lemmas zpower_int = int_power [symmetric] |
1383 lemmas zpower_int = int_power [symmetric] |
1370 |
1384 |
1371 lemma zdiv_int: "int (a div b) = (int a) div (int b)" |
1385 lemma int_of_nat_div: |
|
1386 "int_of_nat (a div b) = (int_of_nat a) div (int_of_nat b)" |
1372 apply (subst split_div, auto) |
1387 apply (subst split_div, auto) |
1373 apply (subst split_zdiv, auto) |
1388 apply (subst split_zdiv, auto) |
1374 apply (rule_tac a="int (b * i) + int j" and b="int b" and r="int j" and r'=ja in IntDiv.unique_quotient) |
1389 apply (rule_tac a="int_of_nat (b * i) + int_of_nat j" and b="int_of_nat b" and r="int_of_nat j" and r'=ja in IntDiv.unique_quotient) |
1375 apply (auto simp add: IntDiv.quorem_def int_eq_of_nat) |
1390 apply (auto simp add: IntDiv.quorem_def) |
1376 done |
1391 done |
1377 |
1392 |
1378 lemma zmod_int: "int (a mod b) = (int a) mod (int b)" |
1393 lemma zdiv_int: "int (a div b) = (int a) div (int b)" |
|
1394 unfolding int_eq_of_nat by (rule int_of_nat_div) |
|
1395 |
|
1396 lemma int_of_nat_mod: |
|
1397 "int_of_nat (a mod b) = (int_of_nat a) mod (int_of_nat b)" |
1379 apply (subst split_mod, auto) |
1398 apply (subst split_mod, auto) |
1380 apply (subst split_zmod, auto) |
1399 apply (subst split_zmod, auto) |
1381 apply (rule_tac a="int (b * i) + int j" and b="int b" and q="int i" and q'=ia |
1400 apply (rule_tac a="int_of_nat (b * i) + int_of_nat j" and b="int_of_nat b" and q="int_of_nat i" and q'=ia |
1382 in unique_remainder) |
1401 in unique_remainder) |
1383 apply (auto simp add: IntDiv.quorem_def int_eq_of_nat) |
1402 apply (auto simp add: IntDiv.quorem_def) |
1384 done |
1403 done |
|
1404 |
|
1405 lemma zmod_int: "int (a mod b) = (int a) mod (int b)" |
|
1406 unfolding int_eq_of_nat by (rule int_of_nat_mod) |
1385 |
1407 |
1386 text{*Suggested by Matthias Daum*} |
1408 text{*Suggested by Matthias Daum*} |
1387 lemma int_power_div_base: |
1409 lemma int_power_div_base: |
1388 "\<lbrakk>0 < m; 0 < k\<rbrakk> \<Longrightarrow> k ^ m div k = (k::int) ^ (m - Suc 0)" |
1410 "\<lbrakk>0 < m; 0 < k\<rbrakk> \<Longrightarrow> k ^ m div k = (k::int) ^ (m - Suc 0)" |
1389 apply (subgoal_tac "k ^ m = k ^ ((m - 1) + 1)") |
1411 apply (subgoal_tac "k ^ m = k ^ ((m - 1) + 1)") |