1 (* Title: HOL/Int.thy |
1 (* Title: HOL/Int.thy |
2 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
2 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 Author: Tobias Nipkow, Florian Haftmann, TU Muenchen |
3 Author: Tobias Nipkow, Florian Haftmann, TU Muenchen |
4 *) |
4 *) |
5 |
5 |
6 section {* The Integers as Equivalence Classes over Pairs of Natural Numbers *} |
6 section {* The Integers as Equivalence Classes over Pairs of Natural Numbers *} |
7 |
7 |
8 theory Int |
8 theory Int |
9 imports Equiv_Relations Power Quotient Fun_Def |
9 imports Equiv_Relations Power Quotient Fun_Def |
10 begin |
10 begin |
11 |
11 |
336 lemma nat_le_eq_zle: "0 < w | 0 \<le> z ==> (nat w \<le> nat z) = (w\<le>z)" |
336 lemma nat_le_eq_zle: "0 < w | 0 \<le> z ==> (nat w \<le> nat z) = (w\<le>z)" |
337 by transfer (clarsimp, arith) |
337 by transfer (clarsimp, arith) |
338 |
338 |
339 text{*An alternative condition is @{term "0 \<le> w"} *} |
339 text{*An alternative condition is @{term "0 \<le> w"} *} |
340 corollary nat_mono_iff: "0 < z ==> (nat w < nat z) = (w < z)" |
340 corollary nat_mono_iff: "0 < z ==> (nat w < nat z) = (w < z)" |
341 by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) |
341 by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) |
342 |
342 |
343 corollary nat_less_eq_zless: "0 \<le> w ==> (nat w < nat z) = (w<z)" |
343 corollary nat_less_eq_zless: "0 \<le> w ==> (nat w < nat z) = (w<z)" |
344 by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) |
344 by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) |
345 |
345 |
346 lemma zless_nat_conj [simp]: "(nat w < nat z) = (0 < z & w < z)" |
346 lemma zless_nat_conj [simp]: "(nat w < nat z) = (0 < z & w < z)" |
347 by transfer (clarsimp, arith) |
347 by transfer (clarsimp, arith) |
348 |
348 |
349 lemma nonneg_eq_int: |
349 lemma nonneg_eq_int: |
353 using assms by (blast dest: nat_0_le sym) |
353 using assms by (blast dest: nat_0_le sym) |
354 |
354 |
355 lemma nat_eq_iff: |
355 lemma nat_eq_iff: |
356 "nat w = m \<longleftrightarrow> (if 0 \<le> w then w = int m else m = 0)" |
356 "nat w = m \<longleftrightarrow> (if 0 \<le> w then w = int m else m = 0)" |
357 by transfer (clarsimp simp add: le_imp_diff_is_add) |
357 by transfer (clarsimp simp add: le_imp_diff_is_add) |
358 |
358 |
359 corollary nat_eq_iff2: |
359 corollary nat_eq_iff2: |
360 "m = nat w \<longleftrightarrow> (if 0 \<le> w then w = int m else m = 0)" |
360 "m = nat w \<longleftrightarrow> (if 0 \<le> w then w = int m else m = 0)" |
361 using nat_eq_iff [of w m] by auto |
361 using nat_eq_iff [of w m] by auto |
362 |
362 |
363 lemma nat_0 [simp]: |
363 lemma nat_0 [simp]: |
376 "nat (- numeral k) = 0" |
376 "nat (- numeral k) = 0" |
377 by simp |
377 by simp |
378 |
378 |
379 lemma nat_2: "nat 2 = Suc (Suc 0)" |
379 lemma nat_2: "nat 2 = Suc (Suc 0)" |
380 by simp |
380 by simp |
381 |
381 |
382 lemma nat_less_iff: "0 \<le> w ==> (nat w < m) = (w < of_nat m)" |
382 lemma nat_less_iff: "0 \<le> w ==> (nat w < m) = (w < of_nat m)" |
383 by transfer (clarsimp, arith) |
383 by transfer (clarsimp, arith) |
384 |
384 |
385 lemma nat_le_iff: "nat x \<le> n \<longleftrightarrow> x \<le> int n" |
385 lemma nat_le_iff: "nat x \<le> n \<longleftrightarrow> x \<le> int n" |
386 by transfer (clarsimp simp add: le_diff_conv) |
386 by transfer (clarsimp simp add: le_diff_conv) |
402 by transfer clarsimp |
402 by transfer clarsimp |
403 |
403 |
404 lemma nat_diff_distrib': |
404 lemma nat_diff_distrib': |
405 "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> nat (x - y) = nat x - nat y" |
405 "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> nat (x - y) = nat x - nat y" |
406 by transfer clarsimp |
406 by transfer clarsimp |
407 |
407 |
408 lemma nat_diff_distrib: |
408 lemma nat_diff_distrib: |
409 "0 \<le> z' \<Longrightarrow> z' \<le> z \<Longrightarrow> nat (z - z') = nat z - nat z'" |
409 "0 \<le> z' \<Longrightarrow> z' \<le> z \<Longrightarrow> nat (z - z') = nat z - nat z'" |
410 by (rule nat_diff_distrib') auto |
410 by (rule nat_diff_distrib') auto |
411 |
411 |
412 lemma nat_zminus_int [simp]: "nat (- int n) = 0" |
412 lemma nat_zminus_int [simp]: "nat (- int n) = 0" |
413 by transfer simp |
413 by transfer simp |
414 |
414 |
415 lemma le_nat_iff: |
415 lemma le_nat_iff: |
416 "k \<ge> 0 \<Longrightarrow> n \<le> nat k \<longleftrightarrow> int n \<le> k" |
416 "k \<ge> 0 \<Longrightarrow> n \<le> nat k \<longleftrightarrow> int n \<le> k" |
417 by transfer auto |
417 by transfer auto |
418 |
418 |
419 lemma zless_nat_eq_int_zless: "(m < nat z) = (int m < z)" |
419 lemma zless_nat_eq_int_zless: "(m < nat z) = (int m < z)" |
420 by transfer (clarsimp simp add: less_diff_conv) |
420 by transfer (clarsimp simp add: less_diff_conv) |
421 |
421 |
422 context ring_1 |
422 context ring_1 |
423 begin |
423 begin |
425 lemma of_nat_nat: "0 \<le> z \<Longrightarrow> of_nat (nat z) = of_int z" |
425 lemma of_nat_nat: "0 \<le> z \<Longrightarrow> of_nat (nat z) = of_int z" |
426 by transfer (clarsimp simp add: of_nat_diff) |
426 by transfer (clarsimp simp add: of_nat_diff) |
427 |
427 |
428 end |
428 end |
429 |
429 |
430 lemma diff_nat_numeral [simp]: |
430 lemma diff_nat_numeral [simp]: |
431 "(numeral v :: nat) - numeral v' = nat (numeral v - numeral v')" |
431 "(numeral v :: nat) - numeral v' = nat (numeral v - numeral v')" |
432 by (simp only: nat_diff_distrib' zero_le_numeral nat_numeral) |
432 by (simp only: nat_diff_distrib' zero_le_numeral nat_numeral) |
433 |
433 |
434 |
434 |
435 text {* For termination proofs: *} |
435 text {* For termination proofs: *} |
548 |
548 |
549 subsubsection {* Binary comparisons *} |
549 subsubsection {* Binary comparisons *} |
550 |
550 |
551 text {* Preliminaries *} |
551 text {* Preliminaries *} |
552 |
552 |
553 lemma le_imp_0_less: |
553 lemma le_imp_0_less: |
554 assumes le: "0 \<le> z" |
554 assumes le: "0 \<le> z" |
555 shows "(0::int) < 1 + z" |
555 shows "(0::int) < 1 + z" |
556 proof - |
556 proof - |
557 have "0 \<le> z" by fact |
557 have "0 \<le> z" by fact |
558 also have "... < z + 1" by (rule less_add_one) |
558 also have "... < z + 1" by (rule less_add_one) |
563 lemma odd_less_0_iff: |
563 lemma odd_less_0_iff: |
564 "(1 + z + z < 0) = (z < (0::int))" |
564 "(1 + z + z < 0) = (z < (0::int))" |
565 proof (cases z) |
565 proof (cases z) |
566 case (nonneg n) |
566 case (nonneg n) |
567 thus ?thesis by (simp add: linorder_not_less add.assoc add_increasing |
567 thus ?thesis by (simp add: linorder_not_less add.assoc add_increasing |
568 le_imp_0_less [THEN order_less_imp_le]) |
568 le_imp_0_less [THEN order_less_imp_le]) |
569 next |
569 next |
570 case (neg n) |
570 case (neg n) |
571 thus ?thesis by (simp del: of_nat_Suc of_nat_add of_nat_1 |
571 thus ?thesis by (simp del: of_nat_Suc of_nat_add of_nat_1 |
572 add: algebra_simps of_nat_1 [where 'a=int, symmetric] of_nat_add [symmetric]) |
572 add: algebra_simps of_nat_1 [where 'a=int, symmetric] of_nat_add [symmetric]) |
573 qed |
573 qed |
578 |
578 |
579 lemma odd_nonzero: |
579 lemma odd_nonzero: |
580 "1 + z + z \<noteq> (0::int)" |
580 "1 + z + z \<noteq> (0::int)" |
581 proof (cases z) |
581 proof (cases z) |
582 case (nonneg n) |
582 case (nonneg n) |
583 have le: "0 \<le> z+z" by (simp add: nonneg add_increasing) |
583 have le: "0 \<le> z+z" by (simp add: nonneg add_increasing) |
584 thus ?thesis using le_imp_0_less [OF le] |
584 thus ?thesis using le_imp_0_less [OF le] |
585 by (auto simp add: add.assoc) |
585 by (auto simp add: add.assoc) |
586 next |
586 next |
587 case (neg n) |
587 case (neg n) |
588 show ?thesis |
588 show ?thesis |
589 proof |
589 proof |
590 assume eq: "1 + z + z = 0" |
590 assume eq: "1 + z + z = 0" |
591 have "(0::int) < 1 + (int n + int n)" |
591 have "(0::int) < 1 + (int n + int n)" |
592 by (simp add: le_imp_0_less add_increasing) |
592 by (simp add: le_imp_0_less add_increasing) |
593 also have "... = - (1 + z + z)" |
593 also have "... = - (1 + z + z)" |
594 by (simp add: neg add.assoc [symmetric]) |
594 by (simp add: neg add.assoc [symmetric]) |
595 also have "... = 0" by (simp add: eq) |
595 also have "... = 0" by (simp add: eq) |
596 finally have "0<0" .. |
596 finally have "0<0" .. |
597 thus False by blast |
597 thus False by blast |
598 qed |
598 qed |
599 qed |
599 qed |
600 |
600 |
697 assume eq: "1 + a + a = 0" |
697 assume eq: "1 + a + a = 0" |
698 hence "of_int (1 + z + z) = (of_int 0 :: 'a)" by (simp add: a) |
698 hence "of_int (1 + z + z) = (of_int 0 :: 'a)" by (simp add: a) |
699 hence "1 + z + z = 0" by (simp only: of_int_eq_iff) |
699 hence "1 + z + z = 0" by (simp only: of_int_eq_iff) |
700 with odd_nonzero show False by blast |
700 with odd_nonzero show False by blast |
701 qed |
701 qed |
702 qed |
702 qed |
703 |
703 |
704 lemma Nats_numeral [simp]: "numeral w \<in> Nats" |
704 lemma Nats_numeral [simp]: "numeral w \<in> Nats" |
705 using of_nat_in_Nats [of "numeral w"] by simp |
705 using of_nat_in_Nats [of "numeral w"] by simp |
706 |
706 |
707 lemma Ints_odd_less_0: |
707 lemma Ints_odd_less_0: |
708 assumes in_Ints: "a \<in> Ints" |
708 assumes in_Ints: "a \<in> Ints" |
709 shows "(1 + a + a < 0) = (a < (0::'a::linordered_idom))" |
709 shows "(1 + a + a < 0) = (a < (0::'a::linordered_idom))" |
710 proof - |
710 proof - |
711 from in_Ints have "a \<in> range of_int" unfolding Ints_def [symmetric] . |
711 from in_Ints have "a \<in> range of_int" unfolding Ints_def [symmetric] . |
712 then obtain z where a: "a = of_int z" .. |
712 then obtain z where a: "a = of_int z" .. |
785 subsection{*The functions @{term nat} and @{term int}*} |
785 subsection{*The functions @{term nat} and @{term int}*} |
786 |
786 |
787 text{*Simplify the term @{term "w + - z"}*} |
787 text{*Simplify the term @{term "w + - z"}*} |
788 |
788 |
789 lemma one_less_nat_eq [simp]: "(Suc 0 < nat z) = (1 < z)" |
789 lemma one_less_nat_eq [simp]: "(Suc 0 < nat z) = (1 < z)" |
790 apply (insert zless_nat_conj [of 1 z]) |
790 using zless_nat_conj [of 1 z] by auto |
791 apply auto |
|
792 done |
|
793 |
791 |
794 text{*This simplifies expressions of the form @{term "int n = z"} where |
792 text{*This simplifies expressions of the form @{term "int n = z"} where |
795 z is an integer literal.*} |
793 z is an integer literal.*} |
796 lemmas int_eq_iff_numeral [simp] = int_eq_iff [of _ "numeral v"] for v |
794 lemmas int_eq_iff_numeral [simp] = int_eq_iff [of _ "numeral v"] for v |
797 |
795 |
855 apply (rule_tac [2] nat_mult_distrib, auto) |
853 apply (rule_tac [2] nat_mult_distrib, auto) |
856 done |
854 done |
857 |
855 |
858 lemma nat_abs_mult_distrib: "nat (abs (w * z)) = nat (abs w) * nat (abs z)" |
856 lemma nat_abs_mult_distrib: "nat (abs (w * z)) = nat (abs w) * nat (abs z)" |
859 apply (cases "z=0 | w=0") |
857 apply (cases "z=0 | w=0") |
860 apply (auto simp add: abs_if nat_mult_distrib [symmetric] |
858 apply (auto simp add: abs_if nat_mult_distrib [symmetric] |
861 nat_mult_distrib_neg [symmetric] mult_less_0_iff) |
859 nat_mult_distrib_neg [symmetric] mult_less_0_iff) |
862 done |
860 done |
863 |
861 |
864 lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" |
862 lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" |
865 apply (rule sym) |
863 apply (rule sym) |
866 apply (simp add: nat_eq_iff) |
864 apply (simp add: nat_eq_iff) |
867 done |
865 done |
868 |
866 |
869 lemma diff_nat_eq_if: |
867 lemma diff_nat_eq_if: |
870 "nat z - nat z' = |
868 "nat z - nat z' = |
871 (if z' < 0 then nat z |
869 (if z' < 0 then nat z |
872 else let d = z-z' in |
870 else let d = z-z' in |
873 if d < 0 then 0 else nat d)" |
871 if d < 0 then 0 else nat d)" |
874 by (simp add: Let_def nat_diff_distrib [symmetric]) |
872 by (simp add: Let_def nat_diff_distrib [symmetric]) |
875 |
873 |
876 lemma nat_numeral_diff_1 [simp]: |
874 lemma nat_numeral_diff_1 [simp]: |
877 "numeral v - (1::nat) = nat (numeral v - 1)" |
875 "numeral v - (1::nat) = nat (numeral v - 1)" |
889 |
887 |
890 theorem wf_int_ge_less_than: "wf (int_ge_less_than d)" |
888 theorem wf_int_ge_less_than: "wf (int_ge_less_than d)" |
891 proof - |
889 proof - |
892 have "int_ge_less_than d \<subseteq> measure (%z. nat (z-d))" |
890 have "int_ge_less_than d \<subseteq> measure (%z. nat (z-d))" |
893 by (auto simp add: int_ge_less_than_def) |
891 by (auto simp add: int_ge_less_than_def) |
894 thus ?thesis |
892 thus ?thesis |
895 by (rule wf_subset [OF wf_measure]) |
893 by (rule wf_subset [OF wf_measure]) |
896 qed |
894 qed |
897 |
895 |
898 text{*This variant looks odd, but is typical of the relations suggested |
896 text{*This variant looks odd, but is typical of the relations suggested |
899 by RankFinder.*} |
897 by RankFinder.*} |
900 |
898 |
903 where |
901 where |
904 "int_ge_less_than2 d = {(z',z). d \<le> z & z' < z}" |
902 "int_ge_less_than2 d = {(z',z). d \<le> z & z' < z}" |
905 |
903 |
906 theorem wf_int_ge_less_than2: "wf (int_ge_less_than2 d)" |
904 theorem wf_int_ge_less_than2: "wf (int_ge_less_than2 d)" |
907 proof - |
905 proof - |
908 have "int_ge_less_than2 d \<subseteq> measure (%z. nat (1+z-d))" |
906 have "int_ge_less_than2 d \<subseteq> measure (%z. nat (1+z-d))" |
909 by (auto simp add: int_ge_less_than2_def) |
907 by (auto simp add: int_ge_less_than2_def) |
910 thus ?thesis |
908 thus ?thesis |
911 by (rule wf_subset [OF wf_measure]) |
909 by (rule wf_subset [OF wf_measure]) |
912 qed |
910 qed |
913 |
911 |
914 (* `set:int': dummy construction *) |
912 (* `set:int': dummy construction *) |
915 theorem int_ge_induct [case_names base step, induct set: int]: |
913 theorem int_ge_induct [case_names base step, induct set: int]: |
916 fixes i :: int |
914 fixes i :: int |
1007 qed |
1005 qed |
1008 |
1006 |
1009 subsection{*Intermediate value theorems*} |
1007 subsection{*Intermediate value theorems*} |
1010 |
1008 |
1011 lemma int_val_lemma: |
1009 lemma int_val_lemma: |
1012 "(\<forall>i<n::nat. abs(f(i+1) - f i) \<le> 1) --> |
1010 "(\<forall>i<n::nat. abs(f(i+1) - f i) \<le> 1) --> |
1013 f 0 \<le> k --> k \<le> f n --> (\<exists>i \<le> n. f i = (k::int))" |
1011 f 0 \<le> k --> k \<le> f n --> (\<exists>i \<le> n. f i = (k::int))" |
1014 unfolding One_nat_def |
1012 unfolding One_nat_def |
1015 apply (induct n) |
1013 apply (induct n) |
1016 apply simp |
1014 apply simp |
1017 apply (intro strip) |
1015 apply (intro strip) |
1025 done |
1023 done |
1026 |
1024 |
1027 lemmas nat0_intermed_int_val = int_val_lemma [rule_format (no_asm)] |
1025 lemmas nat0_intermed_int_val = int_val_lemma [rule_format (no_asm)] |
1028 |
1026 |
1029 lemma nat_intermed_int_val: |
1027 lemma nat_intermed_int_val: |
1030 "[| \<forall>i. m \<le> i & i < n --> abs(f(i + 1::nat) - f i) \<le> 1; m < n; |
1028 "[| \<forall>i. m \<le> i & i < n --> abs(f(i + 1::nat) - f i) \<le> 1; m < n; |
1031 f m \<le> k; k \<le> f n |] ==> ? i. m \<le> i & i \<le> n & f i = (k::int)" |
1029 f m \<le> k; k \<le> f n |] ==> ? i. m \<le> i & i \<le> n & f i = (k::int)" |
1032 apply (cut_tac n = "n-m" and f = "%i. f (i+m) " and k = k |
1030 apply (cut_tac n = "n-m" and f = "%i. f (i+m) " and k = k |
1033 in int_val_lemma) |
1031 in int_val_lemma) |
1034 unfolding One_nat_def |
1032 unfolding One_nat_def |
1035 apply simp |
1033 apply simp |
1036 apply (erule exE) |
1034 apply (erule exE) |
1037 apply (rule_tac x = "i+m" in exI, arith) |
1035 apply (rule_tac x = "i+m" in exI, arith) |
1051 by auto |
1049 by auto |
1052 have "~ (2 \<le> \<bar>m\<bar>)" |
1050 have "~ (2 \<le> \<bar>m\<bar>)" |
1053 proof |
1051 proof |
1054 assume "2 \<le> \<bar>m\<bar>" |
1052 assume "2 \<le> \<bar>m\<bar>" |
1055 hence "2*\<bar>n\<bar> \<le> \<bar>m\<bar>*\<bar>n\<bar>" |
1053 hence "2*\<bar>n\<bar> \<le> \<bar>m\<bar>*\<bar>n\<bar>" |
1056 by (simp add: mult_mono 0) |
1054 by (simp add: mult_mono 0) |
1057 also have "... = \<bar>m*n\<bar>" |
1055 also have "... = \<bar>m*n\<bar>" |
1058 by (simp add: abs_mult) |
1056 by (simp add: abs_mult) |
1059 also have "... = 1" |
1057 also have "... = 1" |
1060 by (simp add: mn) |
1058 by (simp add: mn) |
1061 finally have "2*\<bar>n\<bar> \<le> 1" . |
1059 finally have "2*\<bar>n\<bar> \<le> 1" . |
1062 thus "False" using 0 |
1060 thus "False" using 0 |
1075 from assms have "m * n = 1 ==> m = 1" by (auto dest: pos_zmult_eq_1_iff_lemma) |
1073 from assms have "m * n = 1 ==> m = 1" by (auto dest: pos_zmult_eq_1_iff_lemma) |
1076 thus ?thesis by (auto dest: pos_zmult_eq_1_iff_lemma) |
1074 thus ?thesis by (auto dest: pos_zmult_eq_1_iff_lemma) |
1077 qed |
1075 qed |
1078 |
1076 |
1079 lemma zmult_eq_1_iff: "(m*n = (1::int)) = ((m = 1 & n = 1) | (m = -1 & n = -1))" |
1077 lemma zmult_eq_1_iff: "(m*n = (1::int)) = ((m = 1 & n = 1) | (m = -1 & n = -1))" |
1080 apply (rule iffI) |
1078 apply (rule iffI) |
1081 apply (frule pos_zmult_eq_1_iff_lemma) |
1079 apply (frule pos_zmult_eq_1_iff_lemma) |
1082 apply (simp add: mult.commute [of m]) |
1080 apply (simp add: mult.commute [of m]) |
1083 apply (frule pos_zmult_eq_1_iff_lemma, auto) |
1081 apply (frule pos_zmult_eq_1_iff_lemma, auto) |
1084 done |
1082 done |
1085 |
1083 |
1086 lemma infinite_UNIV_int: "\<not> finite (UNIV::int set)" |
1084 lemma infinite_UNIV_int: "\<not> finite (UNIV::int set)" |
1087 proof |
1085 proof |
1088 assume "finite (UNIV::int set)" |
1086 assume "finite (UNIV::int set)" |
1224 "0 <= m ==> 0 <= n ==> m dvd n ==> n dvd m ==> m = (n::int)" |
1222 "0 <= m ==> 0 <= n ==> m dvd n ==> n dvd m ==> m = (n::int)" |
1225 apply (simp add: dvd_def, auto) |
1223 apply (simp add: dvd_def, auto) |
1226 apply (auto simp add: mult.assoc zero_le_mult_iff zmult_eq_1_iff) |
1224 apply (auto simp add: mult.assoc zero_le_mult_iff zmult_eq_1_iff) |
1227 done |
1225 done |
1228 |
1226 |
1229 lemma zdvd_antisym_abs: assumes "(a::int) dvd b" and "b dvd a" |
1227 lemma zdvd_antisym_abs: assumes "(a::int) dvd b" and "b dvd a" |
1230 shows "\<bar>a\<bar> = \<bar>b\<bar>" |
1228 shows "\<bar>a\<bar> = \<bar>b\<bar>" |
1231 proof cases |
1229 proof cases |
1232 assume "a = 0" with assms show ?thesis by simp |
1230 assume "a = 0" with assms show ?thesis by simp |
1233 next |
1231 next |
1234 assume "a \<noteq> 0" |
1232 assume "a \<noteq> 0" |
1235 from `a dvd b` obtain k where k:"b = a*k" unfolding dvd_def by blast |
1233 from `a dvd b` obtain k where k:"b = a*k" unfolding dvd_def by blast |
1236 from `b dvd a` obtain k' where k':"a = b*k'" unfolding dvd_def by blast |
1234 from `b dvd a` obtain k' where k':"a = b*k'" unfolding dvd_def by blast |
1237 from k k' have "a = a*k*k'" by simp |
1235 from k k' have "a = a*k*k'" by simp |
1238 with mult_cancel_left1[where c="a" and b="k*k'"] |
1236 with mult_cancel_left1[where c="a" and b="k*k'"] |
1239 have kk':"k*k' = 1" using `a\<noteq>0` by (simp add: mult.assoc) |
1237 have kk':"k*k' = 1" using `a\<noteq>0` by (simp add: mult.assoc) |
1240 hence "k = 1 \<and> k' = 1 \<or> k = -1 \<and> k' = -1" by (simp add: zmult_eq_1_iff) |
1238 hence "k = 1 \<and> k' = 1 \<or> k = -1 \<and> k' = -1" by (simp add: zmult_eq_1_iff) |
1241 thus ?thesis using k k' by auto |
1239 thus ?thesis using k k' by auto |
1242 qed |
1240 qed |
1243 |
1241 |
1244 lemma zdvd_zdiffD: "k dvd m - n ==> k dvd n ==> k dvd (m::int)" |
1242 lemma zdvd_zdiffD: "k dvd m - n ==> k dvd n ==> k dvd (m::int)" |
1245 using dvd_add_right_iff [of k "- n" m] by simp |
1243 using dvd_add_right_iff [of k "- n" m] by simp |
1246 |
1244 |
1247 lemma zdvd_reduce: "(k dvd n + k * m) = (k dvd (n::int))" |
1245 lemma zdvd_reduce: "(k dvd n + k * m) = (k dvd (n::int))" |
1248 using dvd_add_times_triv_right_iff [of k n m] by (simp add: ac_simps) |
1246 using dvd_add_times_triv_right_iff [of k n m] by (simp add: ac_simps) |
1249 |
1247 |
1250 lemma dvd_imp_le_int: |
1248 lemma dvd_imp_le_int: |
1315 assume "\<bar>x\<bar>=1" |
1313 assume "\<bar>x\<bar>=1" |
1316 then have "x = 1 \<or> x = -1" by auto |
1314 then have "x = 1 \<or> x = -1" by auto |
1317 then show "x dvd 1" by (auto intro: dvdI) |
1315 then show "x dvd 1" by (auto intro: dvdI) |
1318 qed |
1316 qed |
1319 |
1317 |
1320 lemma zdvd_mult_cancel1: |
1318 lemma zdvd_mult_cancel1: |
1321 assumes mp:"m \<noteq>(0::int)" shows "(m * n dvd m) = (\<bar>n\<bar> = 1)" |
1319 assumes mp:"m \<noteq>(0::int)" shows "(m * n dvd m) = (\<bar>n\<bar> = 1)" |
1322 proof |
1320 proof |
1323 assume n1: "\<bar>n\<bar> = 1" thus "m * n dvd m" |
1321 assume n1: "\<bar>n\<bar> = 1" thus "m * n dvd m" |
1324 by (cases "n >0") (auto simp add: minus_equation_iff) |
1322 by (cases "n >0") (auto simp add: minus_equation_iff) |
1325 next |
1323 next |
1326 assume H: "m * n dvd m" hence H2: "m * n dvd m * 1" by simp |
1324 assume H: "m * n dvd m" hence H2: "m * n dvd m * 1" by simp |
1327 from zdvd_mult_cancel[OF H2 mp] show "\<bar>n\<bar> = 1" by (simp only: zdvd1_eq) |
1325 from zdvd_mult_cancel[OF H2 mp] show "\<bar>n\<bar> = 1" by (simp only: zdvd1_eq) |
1328 qed |
1326 qed |