| author | wenzelm | 
| Mon, 24 Jun 2019 16:26:25 +0200 | |
| changeset 70359 | 470d4f145e4c | 
| parent 70356 | 4a327c061870 | 
| child 70365 | 4df0628e8545 | 
| permissions | -rw-r--r-- | 
| 41959 | 1 | (* Title: HOL/Int.thy | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 2 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | 
| 41959 | 3 | Author: Tobias Nipkow, Florian Haftmann, TU Muenchen | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 4 | *) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 5 | |
| 60758 | 6 | section \<open>The Integers as Equivalence Classes over Pairs of Natural Numbers\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 7 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 8 | theory Int | 
| 63652 | 9 | imports Equiv_Relations Power Quotient Fun_Def | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 10 | begin | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 11 | |
| 60758 | 12 | subsection \<open>Definition of integers as a quotient type\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 13 | |
| 63652 | 14 | definition intrel :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" | 
| 15 | where "intrel = (\<lambda>(x, y) (u, v). x + v = u + y)" | |
| 48045 | 16 | |
| 17 | lemma intrel_iff [simp]: "intrel (x, y) (u, v) \<longleftrightarrow> x + v = u + y" | |
| 18 | by (simp add: intrel_def) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 19 | |
| 48045 | 20 | quotient_type int = "nat \<times> nat" / "intrel" | 
| 45694 
4a8743618257
prefer typedef without extra definition and alternative name;
 wenzelm parents: 
45607diff
changeset | 21 | morphisms Rep_Integ Abs_Integ | 
| 48045 | 22 | proof (rule equivpI) | 
| 63652 | 23 | show "reflp intrel" by (auto simp: reflp_def) | 
| 24 | show "symp intrel" by (auto simp: symp_def) | |
| 25 | show "transp intrel" by (auto simp: transp_def) | |
| 48045 | 26 | qed | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 27 | |
| 48045 | 28 | lemma eq_Abs_Integ [case_names Abs_Integ, cases type: int]: | 
| 63652 | 29 | "(\<And>x y. z = Abs_Integ (x, y) \<Longrightarrow> P) \<Longrightarrow> P" | 
| 30 | by (induct z) auto | |
| 31 | ||
| 48045 | 32 | |
| 60758 | 33 | subsection \<open>Integers form a commutative ring\<close> | 
| 48045 | 34 | |
| 35 | instantiation int :: comm_ring_1 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 36 | begin | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 37 | |
| 51994 | 38 | lift_definition zero_int :: "int" is "(0, 0)" . | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 39 | |
| 51994 | 40 | lift_definition one_int :: "int" is "(1, 0)" . | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 41 | |
| 48045 | 42 | lift_definition plus_int :: "int \<Rightarrow> int \<Rightarrow> int" | 
| 43 | is "\<lambda>(x, y) (u, v). (x + u, y + v)" | |
| 44 | by clarsimp | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 45 | |
| 48045 | 46 | lift_definition uminus_int :: "int \<Rightarrow> int" | 
| 47 | is "\<lambda>(x, y). (y, x)" | |
| 48 | by clarsimp | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 49 | |
| 48045 | 50 | lift_definition minus_int :: "int \<Rightarrow> int \<Rightarrow> int" | 
| 51 | is "\<lambda>(x, y) (u, v). (x + v, y + u)" | |
| 52 | by clarsimp | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 53 | |
| 48045 | 54 | lift_definition times_int :: "int \<Rightarrow> int \<Rightarrow> int" | 
| 55 | is "\<lambda>(x, y) (u, v). (x*u + y*v, x*v + y*u)" | |
| 56 | proof (clarsimp) | |
| 57 | fix s t u v w x y z :: nat | |
| 58 | assume "s + v = u + t" and "w + z = y + x" | |
| 63652 | 59 | then have "(s + v) * w + (u + t) * x + u * (w + z) + v * (y + x) = | 
| 60 | (u + t) * w + (s + v) * x + u * (y + x) + v * (w + z)" | |
| 48045 | 61 | by simp | 
| 63652 | 62 | then show "(s * w + t * x) + (u * z + v * y) = (u * y + v * z) + (s * x + t * w)" | 
| 48045 | 63 | by (simp add: algebra_simps) | 
| 64 | qed | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 65 | |
| 48045 | 66 | instance | 
| 63652 | 67 | by standard (transfer; clarsimp simp: algebra_simps)+ | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 68 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 69 | end | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 70 | |
| 63652 | 71 | abbreviation int :: "nat \<Rightarrow> int" | 
| 72 | where "int \<equiv> of_nat" | |
| 44709 | 73 | |
| 48045 | 74 | lemma int_def: "int n = Abs_Integ (n, 0)" | 
| 63652 | 75 | by (induct n) (simp add: zero_int.abs_eq, simp add: one_int.abs_eq plus_int.abs_eq) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 76 | |
| 67399 | 77 | lemma int_transfer [transfer_rule]: "(rel_fun (=) pcr_int) (\<lambda>n. (n, 0)) int" | 
| 63652 | 78 | by (simp add: rel_fun_def int.pcr_cr_eq cr_int_def int_def) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 79 | |
| 63652 | 80 | lemma int_diff_cases: obtains (diff) m n where "z = int m - int n" | 
| 48045 | 81 | by transfer clarsimp | 
| 82 | ||
| 63652 | 83 | |
| 60758 | 84 | subsection \<open>Integers are totally ordered\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 85 | |
| 48045 | 86 | instantiation int :: linorder | 
| 87 | begin | |
| 88 | ||
| 89 | lift_definition less_eq_int :: "int \<Rightarrow> int \<Rightarrow> bool" | |
| 90 | is "\<lambda>(x, y) (u, v). x + v \<le> u + y" | |
| 91 | by auto | |
| 92 | ||
| 93 | lift_definition less_int :: "int \<Rightarrow> int \<Rightarrow> bool" | |
| 94 | is "\<lambda>(x, y) (u, v). x + v < u + y" | |
| 95 | by auto | |
| 96 | ||
| 97 | instance | |
| 61169 | 98 | by standard (transfer, force)+ | 
| 48045 | 99 | |
| 100 | end | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 101 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 102 | instantiation int :: distrib_lattice | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 103 | begin | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 104 | |
| 63652 | 105 | definition "(inf :: int \<Rightarrow> int \<Rightarrow> int) = min" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 106 | |
| 63652 | 107 | definition "(sup :: int \<Rightarrow> int \<Rightarrow> int) = max" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 108 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 109 | instance | 
| 63652 | 110 | by standard (auto simp add: inf_int_def sup_int_def max_min_distrib2) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 111 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 112 | end | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 113 | |
| 60758 | 114 | subsection \<open>Ordering properties of arithmetic operations\<close> | 
| 48045 | 115 | |
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34055diff
changeset | 116 | instance int :: ordered_cancel_ab_semigroup_add | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 117 | proof | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 118 | fix i j k :: int | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 119 | show "i \<le> j \<Longrightarrow> k + i \<le> k + j" | 
| 48045 | 120 | by transfer clarsimp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 121 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 122 | |
| 63652 | 123 | text \<open>Strict Monotonicity of Multiplication.\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 124 | |
| 63652 | 125 | text \<open>Strict, in 1st argument; proof is by induction on \<open>k > 0\<close>.\<close> | 
| 126 | lemma zmult_zless_mono2_lemma: "i < j \<Longrightarrow> 0 < k \<Longrightarrow> int k * i < int k * j" | |
| 127 | for i j :: int | |
| 128 | proof (induct k) | |
| 129 | case 0 | |
| 130 | then show ?case by simp | |
| 131 | next | |
| 132 | case (Suc k) | |
| 133 | then show ?case | |
| 134 | by (cases "k = 0") (simp_all add: distrib_right add_strict_mono) | |
| 135 | qed | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 136 | |
| 63652 | 137 | lemma zero_le_imp_eq_int: "0 \<le> k \<Longrightarrow> \<exists>n. k = int n" | 
| 138 | for k :: int | |
| 139 | apply transfer | |
| 140 | apply clarsimp | |
| 141 | apply (rule_tac x="a - b" in exI) | |
| 142 | apply simp | |
| 143 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 144 | |
| 63652 | 145 | lemma zero_less_imp_eq_int: "0 < k \<Longrightarrow> \<exists>n>0. k = int n" | 
| 146 | for k :: int | |
| 147 | apply transfer | |
| 148 | apply clarsimp | |
| 149 | apply (rule_tac x="a - b" in exI) | |
| 150 | apply simp | |
| 151 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 152 | |
| 63652 | 153 | lemma zmult_zless_mono2: "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j" | 
| 154 | for i j k :: int | |
| 155 | by (drule zero_less_imp_eq_int) (auto simp add: zmult_zless_mono2_lemma) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 156 | |
| 63652 | 157 | |
| 158 | text \<open>The integers form an ordered integral domain.\<close> | |
| 159 | ||
| 48045 | 160 | instantiation int :: linordered_idom | 
| 161 | begin | |
| 162 | ||
| 63652 | 163 | definition zabs_def: "\<bar>i::int\<bar> = (if i < 0 then - i else i)" | 
| 48045 | 164 | |
| 63652 | 165 | definition zsgn_def: "sgn (i::int) = (if i = 0 then 0 else if 0 < i then 1 else - 1)" | 
| 48045 | 166 | |
| 63652 | 167 | instance | 
| 168 | proof | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 169 | fix i j k :: int | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 170 | show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 171 | by (rule zmult_zless_mono2) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 172 | show "\<bar>i\<bar> = (if i < 0 then -i else i)" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 173 | by (simp only: zabs_def) | 
| 61076 | 174 | show "sgn (i::int) = (if i=0 then 0 else if 0<i then 1 else - 1)" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 175 | by (simp only: zsgn_def) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 176 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 177 | |
| 48045 | 178 | end | 
| 179 | ||
| 63652 | 180 | lemma zless_imp_add1_zle: "w < z \<Longrightarrow> w + 1 \<le> z" | 
| 181 | for w z :: int | |
| 48045 | 182 | by transfer clarsimp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 183 | |
| 63652 | 184 | lemma zless_iff_Suc_zadd: "w < z \<longleftrightarrow> (\<exists>n. z = w + int (Suc n))" | 
| 185 | for w z :: int | |
| 186 | apply transfer | |
| 187 | apply auto | |
| 188 | apply (rename_tac a b c d) | |
| 189 | apply (rule_tac x="c+b - Suc(a+d)" in exI) | |
| 190 | apply arith | |
| 191 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 192 | |
| 63652 | 193 | lemma zabs_less_one_iff [simp]: "\<bar>z\<bar> < 1 \<longleftrightarrow> z = 0" (is "?lhs \<longleftrightarrow> ?rhs") | 
| 194 | for z :: int | |
| 62347 | 195 | proof | 
| 63652 | 196 | assume ?rhs | 
| 197 | then show ?lhs by simp | |
| 62347 | 198 | next | 
| 63652 | 199 | assume ?lhs | 
| 200 | with zless_imp_add1_zle [of "\<bar>z\<bar>" 1] have "\<bar>z\<bar> + 1 \<le> 1" by simp | |
| 201 | then have "\<bar>z\<bar> \<le> 0" by simp | |
| 202 | then show ?rhs by simp | |
| 62347 | 203 | qed | 
| 204 | ||
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 205 | |
| 61799 | 206 | subsection \<open>Embedding of the Integers into any \<open>ring_1\<close>: \<open>of_int\<close>\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 207 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 208 | context ring_1 | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 209 | begin | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 210 | |
| 63652 | 211 | lift_definition of_int :: "int \<Rightarrow> 'a" | 
| 212 | is "\<lambda>(i, j). of_nat i - of_nat j" | |
| 48045 | 213 | by (clarsimp simp add: diff_eq_eq eq_diff_eq diff_add_eq | 
| 63652 | 214 | of_nat_add [symmetric] simp del: of_nat_add) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 215 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 216 | lemma of_int_0 [simp]: "of_int 0 = 0" | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48045diff
changeset | 217 | by transfer simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 218 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 219 | lemma of_int_1 [simp]: "of_int 1 = 1" | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48045diff
changeset | 220 | by transfer simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 221 | |
| 63652 | 222 | lemma of_int_add [simp]: "of_int (w + z) = of_int w + of_int z" | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48045diff
changeset | 223 | by transfer (clarsimp simp add: algebra_simps) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 224 | |
| 63652 | 225 | lemma of_int_minus [simp]: "of_int (- z) = - (of_int z)" | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48045diff
changeset | 226 | by (transfer fixing: uminus) clarsimp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 227 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 228 | lemma of_int_diff [simp]: "of_int (w - z) = of_int w - of_int z" | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
54223diff
changeset | 229 | using of_int_add [of w "- z"] by simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 230 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 231 | lemma of_int_mult [simp]: "of_int (w*z) = of_int w * of_int z" | 
| 63652 | 232 | by (transfer fixing: times) (clarsimp simp add: algebra_simps) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 233 | |
| 61531 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61524diff
changeset | 234 | lemma mult_of_int_commute: "of_int x * y = y * of_int x" | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61524diff
changeset | 235 | by (transfer fixing: times) (auto simp: algebra_simps mult_of_nat_commute) | 
| 
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
 eberlm parents: 
61524diff
changeset | 236 | |
| 63652 | 237 | text \<open>Collapse nested embeddings.\<close> | 
| 44709 | 238 | lemma of_int_of_nat_eq [simp]: "of_int (int n) = of_nat n" | 
| 63652 | 239 | by (induct n) auto | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 240 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 241 | lemma of_int_numeral [simp, code_post]: "of_int (numeral k) = numeral k" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 242 | by (simp add: of_nat_numeral [symmetric] of_int_of_nat_eq [symmetric]) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 243 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 244 | lemma of_int_neg_numeral [code_post]: "of_int (- numeral k) = - numeral k" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 245 | by simp | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 246 | |
| 63652 | 247 | lemma of_int_power [simp]: "of_int (z ^ n) = of_int z ^ n" | 
| 31015 | 248 | by (induct n) simp_all | 
| 249 | ||
| 66816 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 250 | lemma of_int_of_bool [simp]: | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 251 | "of_int (of_bool P) = of_bool P" | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 252 | by auto | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 253 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 254 | end | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 255 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 256 | context ring_char_0 | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 257 | begin | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 258 | |
| 63652 | 259 | lemma of_int_eq_iff [simp]: "of_int w = of_int z \<longleftrightarrow> w = z" | 
| 260 | by transfer (clarsimp simp add: algebra_simps of_nat_add [symmetric] simp del: of_nat_add) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 261 | |
| 63652 | 262 | text \<open>Special cases where either operand is zero.\<close> | 
| 263 | lemma of_int_eq_0_iff [simp]: "of_int z = 0 \<longleftrightarrow> z = 0" | |
| 36424 | 264 | using of_int_eq_iff [of z 0] by simp | 
| 265 | ||
| 63652 | 266 | lemma of_int_0_eq_iff [simp]: "0 = of_int z \<longleftrightarrow> z = 0" | 
| 36424 | 267 | using of_int_eq_iff [of 0 z] by simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 268 | |
| 63652 | 269 | lemma of_int_eq_1_iff [iff]: "of_int z = 1 \<longleftrightarrow> z = 1" | 
| 61234 | 270 | using of_int_eq_iff [of z 1] by simp | 
| 271 | ||
| 66912 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 272 | lemma numeral_power_eq_of_int_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 273 | "numeral x ^ n = of_int y \<longleftrightarrow> numeral x ^ n = y" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 274 | using of_int_eq_iff[of "numeral x ^ n" y, unfolded of_int_numeral of_int_power] . | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 275 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 276 | lemma of_int_eq_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 277 | "of_int y = numeral x ^ n \<longleftrightarrow> y = numeral x ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 278 | using numeral_power_eq_of_int_cancel_iff [of x n y] by (metis (mono_tags)) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 279 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 280 | lemma neg_numeral_power_eq_of_int_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 281 | "(- numeral x) ^ n = of_int y \<longleftrightarrow> (- numeral x) ^ n = y" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 282 | using of_int_eq_iff[of "(- numeral x) ^ n" y] | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 283 | by simp | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 284 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 285 | lemma of_int_eq_neg_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 286 | "of_int y = (- numeral x) ^ n \<longleftrightarrow> y = (- numeral x) ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 287 | using neg_numeral_power_eq_of_int_cancel_iff[of x n y] by (metis (mono_tags)) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 288 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 289 | lemma of_int_eq_of_int_power_cancel_iff[simp]: "(of_int b) ^ w = of_int x \<longleftrightarrow> b ^ w = x" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 290 | by (metis of_int_power of_int_eq_iff) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 291 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 292 | lemma of_int_power_eq_of_int_cancel_iff[simp]: "of_int x = (of_int b) ^ w \<longleftrightarrow> x = b ^ w" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 293 | by (metis of_int_eq_of_int_power_cancel_iff) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 294 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 295 | end | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 296 | |
| 36424 | 297 | context linordered_idom | 
| 298 | begin | |
| 299 | ||
| 63652 | 300 | text \<open>Every \<open>linordered_idom\<close> has characteristic zero.\<close> | 
| 36424 | 301 | subclass ring_char_0 .. | 
| 302 | ||
| 63652 | 303 | lemma of_int_le_iff [simp]: "of_int w \<le> of_int z \<longleftrightarrow> w \<le> z" | 
| 304 | by (transfer fixing: less_eq) | |
| 305 | (clarsimp simp add: algebra_simps of_nat_add [symmetric] simp del: of_nat_add) | |
| 36424 | 306 | |
| 63652 | 307 | lemma of_int_less_iff [simp]: "of_int w < of_int z \<longleftrightarrow> w < z" | 
| 36424 | 308 | by (simp add: less_le order_less_le) | 
| 309 | ||
| 63652 | 310 | lemma of_int_0_le_iff [simp]: "0 \<le> of_int z \<longleftrightarrow> 0 \<le> z" | 
| 36424 | 311 | using of_int_le_iff [of 0 z] by simp | 
| 312 | ||
| 63652 | 313 | lemma of_int_le_0_iff [simp]: "of_int z \<le> 0 \<longleftrightarrow> z \<le> 0" | 
| 36424 | 314 | using of_int_le_iff [of z 0] by simp | 
| 315 | ||
| 63652 | 316 | lemma of_int_0_less_iff [simp]: "0 < of_int z \<longleftrightarrow> 0 < z" | 
| 36424 | 317 | using of_int_less_iff [of 0 z] by simp | 
| 318 | ||
| 63652 | 319 | lemma of_int_less_0_iff [simp]: "of_int z < 0 \<longleftrightarrow> z < 0" | 
| 36424 | 320 | using of_int_less_iff [of z 0] by simp | 
| 321 | ||
| 63652 | 322 | lemma of_int_1_le_iff [simp]: "1 \<le> of_int z \<longleftrightarrow> 1 \<le> z" | 
| 61234 | 323 | using of_int_le_iff [of 1 z] by simp | 
| 324 | ||
| 63652 | 325 | lemma of_int_le_1_iff [simp]: "of_int z \<le> 1 \<longleftrightarrow> z \<le> 1" | 
| 61234 | 326 | using of_int_le_iff [of z 1] by simp | 
| 327 | ||
| 63652 | 328 | lemma of_int_1_less_iff [simp]: "1 < of_int z \<longleftrightarrow> 1 < z" | 
| 61234 | 329 | using of_int_less_iff [of 1 z] by simp | 
| 330 | ||
| 63652 | 331 | lemma of_int_less_1_iff [simp]: "of_int z < 1 \<longleftrightarrow> z < 1" | 
| 61234 | 332 | using of_int_less_iff [of z 1] by simp | 
| 333 | ||
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61944diff
changeset | 334 | lemma of_int_pos: "z > 0 \<Longrightarrow> of_int z > 0" | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61944diff
changeset | 335 | by simp | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61944diff
changeset | 336 | |
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61944diff
changeset | 337 | lemma of_int_nonneg: "z \<ge> 0 \<Longrightarrow> of_int z \<ge> 0" | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61944diff
changeset | 338 | by simp | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61944diff
changeset | 339 | |
| 63652 | 340 | lemma of_int_abs [simp]: "of_int \<bar>x\<bar> = \<bar>of_int x\<bar>" | 
| 62347 | 341 | by (auto simp add: abs_if) | 
| 342 | ||
| 343 | lemma of_int_lessD: | |
| 344 | assumes "\<bar>of_int n\<bar> < x" | |
| 345 | shows "n = 0 \<or> x > 1" | |
| 346 | proof (cases "n = 0") | |
| 63652 | 347 | case True | 
| 348 | then show ?thesis by simp | |
| 62347 | 349 | next | 
| 350 | case False | |
| 351 | then have "\<bar>n\<bar> \<noteq> 0" by simp | |
| 352 | then have "\<bar>n\<bar> > 0" by simp | |
| 353 | then have "\<bar>n\<bar> \<ge> 1" | |
| 354 | using zless_imp_add1_zle [of 0 "\<bar>n\<bar>"] by simp | |
| 355 | then have "\<bar>of_int n\<bar> \<ge> 1" | |
| 356 | unfolding of_int_1_le_iff [of "\<bar>n\<bar>", symmetric] by simp | |
| 357 | then have "1 < x" using assms by (rule le_less_trans) | |
| 358 | then show ?thesis .. | |
| 359 | qed | |
| 360 | ||
| 361 | lemma of_int_leD: | |
| 362 | assumes "\<bar>of_int n\<bar> \<le> x" | |
| 363 | shows "n = 0 \<or> 1 \<le> x" | |
| 364 | proof (cases "n = 0") | |
| 63652 | 365 | case True | 
| 366 | then show ?thesis by simp | |
| 62347 | 367 | next | 
| 368 | case False | |
| 369 | then have "\<bar>n\<bar> \<noteq> 0" by simp | |
| 370 | then have "\<bar>n\<bar> > 0" by simp | |
| 371 | then have "\<bar>n\<bar> \<ge> 1" | |
| 372 | using zless_imp_add1_zle [of 0 "\<bar>n\<bar>"] by simp | |
| 373 | then have "\<bar>of_int n\<bar> \<ge> 1" | |
| 374 | unfolding of_int_1_le_iff [of "\<bar>n\<bar>", symmetric] by simp | |
| 375 | then have "1 \<le> x" using assms by (rule order_trans) | |
| 376 | then show ?thesis .. | |
| 377 | qed | |
| 378 | ||
| 66912 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 379 | lemma numeral_power_le_of_int_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 380 | "numeral x ^ n \<le> of_int a \<longleftrightarrow> numeral x ^ n \<le> a" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 381 | by (metis (mono_tags) local.of_int_eq_numeral_power_cancel_iff of_int_le_iff) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 382 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 383 | lemma of_int_le_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 384 | "of_int a \<le> numeral x ^ n \<longleftrightarrow> a \<le> numeral x ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 385 | by (metis (mono_tags) local.numeral_power_eq_of_int_cancel_iff of_int_le_iff) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 386 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 387 | lemma numeral_power_less_of_int_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 388 | "numeral x ^ n < of_int a \<longleftrightarrow> numeral x ^ n < a" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 389 | by (metis (mono_tags) local.of_int_eq_numeral_power_cancel_iff of_int_less_iff) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 390 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 391 | lemma of_int_less_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 392 | "of_int a < numeral x ^ n \<longleftrightarrow> a < numeral x ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 393 | by (metis (mono_tags) local.of_int_eq_numeral_power_cancel_iff of_int_less_iff) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 394 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 395 | lemma neg_numeral_power_le_of_int_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 396 | "(- numeral x) ^ n \<le> of_int a \<longleftrightarrow> (- numeral x) ^ n \<le> a" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 397 | by (metis (mono_tags) of_int_le_iff of_int_neg_numeral of_int_power) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 398 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 399 | lemma of_int_le_neg_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 400 | "of_int a \<le> (- numeral x) ^ n \<longleftrightarrow> a \<le> (- numeral x) ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 401 | by (metis (mono_tags) of_int_le_iff of_int_neg_numeral of_int_power) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 402 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 403 | lemma neg_numeral_power_less_of_int_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 404 | "(- numeral x) ^ n < of_int a \<longleftrightarrow> (- numeral x) ^ n < a" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 405 | using of_int_less_iff[of "(- numeral x) ^ n" a] | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 406 | by simp | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 407 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 408 | lemma of_int_less_neg_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 409 | "of_int a < (- numeral x) ^ n \<longleftrightarrow> a < (- numeral x::int) ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 410 | using of_int_less_iff[of a "(- numeral x) ^ n"] | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 411 | by simp | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 412 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 413 | lemma of_int_le_of_int_power_cancel_iff[simp]: "(of_int b) ^ w \<le> of_int x \<longleftrightarrow> b ^ w \<le> x" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 414 | by (metis (mono_tags) of_int_le_iff of_int_power) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 415 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 416 | lemma of_int_power_le_of_int_cancel_iff[simp]: "of_int x \<le> (of_int b) ^ w\<longleftrightarrow> x \<le> b ^ w" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 417 | by (metis (mono_tags) of_int_le_iff of_int_power) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 418 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 419 | lemma of_int_less_of_int_power_cancel_iff[simp]: "(of_int b) ^ w < of_int x \<longleftrightarrow> b ^ w < x" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 420 | by (metis (mono_tags) of_int_less_iff of_int_power) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 421 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 422 | lemma of_int_power_less_of_int_cancel_iff[simp]: "of_int x < (of_int b) ^ w\<longleftrightarrow> x < b ^ w" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 423 | by (metis (mono_tags) of_int_less_iff of_int_power) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 424 | |
| 67969 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67399diff
changeset | 425 | lemma of_int_max: "of_int (max x y) = max (of_int x) (of_int y)" | 
| 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67399diff
changeset | 426 | by (auto simp: max_def) | 
| 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67399diff
changeset | 427 | |
| 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67399diff
changeset | 428 | lemma of_int_min: "of_int (min x y) = min (of_int x) (of_int y)" | 
| 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67399diff
changeset | 429 | by (auto simp: min_def) | 
| 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67399diff
changeset | 430 | |
| 36424 | 431 | end | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 432 | |
| 69791 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 433 | context division_ring | 
| 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 434 | begin | 
| 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 435 | |
| 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 436 | lemmas mult_inverse_of_int_commute = | 
| 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 437 | mult_commute_imp_mult_inverse_commute[OF mult_of_int_commute] | 
| 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 438 | |
| 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 439 | end | 
| 
195aeee8b30a
Formal Laurent series and overhaul of Formal power series (due to Jeremy Sylvestre)
 Manuel Eberl <eberlm@in.tum.de> parents: 
69700diff
changeset | 440 | |
| 69593 | 441 | text \<open>Comparisons involving \<^term>\<open>of_int\<close>.\<close> | 
| 61234 | 442 | |
| 63652 | 443 | lemma of_int_eq_numeral_iff [iff]: "of_int z = (numeral n :: 'a::ring_char_0) \<longleftrightarrow> z = numeral n" | 
| 61234 | 444 | using of_int_eq_iff by fastforce | 
| 445 | ||
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 446 | lemma of_int_le_numeral_iff [simp]: | 
| 63652 | 447 | "of_int z \<le> (numeral n :: 'a::linordered_idom) \<longleftrightarrow> z \<le> numeral n" | 
| 61234 | 448 | using of_int_le_iff [of z "numeral n"] by simp | 
| 449 | ||
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 450 | lemma of_int_numeral_le_iff [simp]: | 
| 63652 | 451 | "(numeral n :: 'a::linordered_idom) \<le> of_int z \<longleftrightarrow> numeral n \<le> z" | 
| 61234 | 452 | using of_int_le_iff [of "numeral n"] by simp | 
| 453 | ||
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 454 | lemma of_int_less_numeral_iff [simp]: | 
| 63652 | 455 | "of_int z < (numeral n :: 'a::linordered_idom) \<longleftrightarrow> z < numeral n" | 
| 61234 | 456 | using of_int_less_iff [of z "numeral n"] by simp | 
| 457 | ||
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 458 | lemma of_int_numeral_less_iff [simp]: | 
| 63652 | 459 | "(numeral n :: 'a::linordered_idom) < of_int z \<longleftrightarrow> numeral n < z" | 
| 61234 | 460 | using of_int_less_iff [of "numeral n" z] by simp | 
| 461 | ||
| 63652 | 462 | lemma of_nat_less_of_int_iff: "(of_nat n::'a::linordered_idom) < of_int x \<longleftrightarrow> int n < x" | 
| 56889 
48a745e1bde7
avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
 hoelzl parents: 
56525diff
changeset | 463 | by (metis of_int_of_nat_eq of_int_less_iff) | 
| 
48a745e1bde7
avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
 hoelzl parents: 
56525diff
changeset | 464 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 465 | lemma of_int_eq_id [simp]: "of_int = id" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 466 | proof | 
| 63652 | 467 | show "of_int z = id z" for z | 
| 468 | by (cases z rule: int_diff_cases) simp | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 469 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 470 | |
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 471 | instance int :: no_top | 
| 61169 | 472 | apply standard | 
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 473 | apply (rule_tac x="x + 1" in exI) | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 474 | apply simp | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 475 | done | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 476 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 477 | instance int :: no_bot | 
| 61169 | 478 | apply standard | 
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 479 | apply (rule_tac x="x - 1" in exI) | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 480 | apply simp | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 481 | done | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51185diff
changeset | 482 | |
| 63652 | 483 | |
| 61799 | 484 | subsection \<open>Magnitude of an Integer, as a Natural Number: \<open>nat\<close>\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 485 | |
| 48045 | 486 | lift_definition nat :: "int \<Rightarrow> nat" is "\<lambda>(x, y). x - y" | 
| 487 | by auto | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 488 | |
| 44709 | 489 | lemma nat_int [simp]: "nat (int n) = n" | 
| 48045 | 490 | by transfer simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 491 | |
| 44709 | 492 | lemma int_nat_eq [simp]: "int (nat z) = (if 0 \<le> z then z else 0)" | 
| 48045 | 493 | by transfer clarsimp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 494 | |
| 63652 | 495 | lemma nat_0_le: "0 \<le> z \<Longrightarrow> int (nat z) = z" | 
| 496 | by simp | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 497 | |
| 63652 | 498 | lemma nat_le_0 [simp]: "z \<le> 0 \<Longrightarrow> nat z = 0" | 
| 48045 | 499 | by transfer clarsimp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 500 | |
| 63652 | 501 | lemma nat_le_eq_zle: "0 < w \<or> 0 \<le> z \<Longrightarrow> nat w \<le> nat z \<longleftrightarrow> w \<le> z" | 
| 48045 | 502 | by transfer (clarsimp, arith) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 503 | |
| 69593 | 504 | text \<open>An alternative condition is \<^term>\<open>0 \<le> w\<close>.\<close> | 
| 63652 | 505 | lemma nat_mono_iff: "0 < z \<Longrightarrow> nat w < nat z \<longleftrightarrow> w < z" | 
| 506 | by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 507 | |
| 63652 | 508 | lemma nat_less_eq_zless: "0 \<le> w \<Longrightarrow> nat w < nat z \<longleftrightarrow> w < z" | 
| 509 | by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 510 | |
| 63652 | 511 | lemma zless_nat_conj [simp]: "nat w < nat z \<longleftrightarrow> 0 < z \<and> w < z" | 
| 48045 | 512 | by transfer (clarsimp, arith) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 513 | |
| 64714 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 514 | lemma nonneg_int_cases: | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 515 | assumes "0 \<le> k" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 516 | obtains n where "k = int n" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 517 | proof - | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 518 | from assms have "k = int (nat k)" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 519 | by simp | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 520 | then show thesis | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 521 | by (rule that) | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 522 | qed | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 523 | |
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 524 | lemma pos_int_cases: | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 525 | assumes "0 < k" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 526 | obtains n where "k = int n" and "n > 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 527 | proof - | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 528 | from assms have "0 \<le> k" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 529 | by simp | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 530 | then obtain n where "k = int n" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 531 | by (rule nonneg_int_cases) | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 532 | moreover have "n > 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 533 | using \<open>k = int n\<close> assms by simp | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 534 | ultimately show thesis | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 535 | by (rule that) | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 536 | qed | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 537 | |
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 538 | lemma nonpos_int_cases: | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 539 | assumes "k \<le> 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 540 | obtains n where "k = - int n" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 541 | proof - | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 542 | from assms have "- k \<ge> 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 543 | by simp | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 544 | then obtain n where "- k = int n" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 545 | by (rule nonneg_int_cases) | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 546 | then have "k = - int n" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 547 | by simp | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 548 | then show thesis | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 549 | by (rule that) | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 550 | qed | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 551 | |
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 552 | lemma neg_int_cases: | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 553 | assumes "k < 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 554 | obtains n where "k = - int n" and "n > 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 555 | proof - | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 556 | from assms have "- k > 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 557 | by simp | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 558 | then obtain n where "- k = int n" and "- k > 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 559 | by (blast elim: pos_int_cases) | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 560 | then have "k = - int n" and "n > 0" | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 561 | by simp_all | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 562 | then show thesis | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 563 | by (rule that) | 
| 
53bab28983f1
complete set of cases rules for integers known to be (non-)positive/negative;
 haftmann parents: 
64272diff
changeset | 564 | qed | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 565 | |
| 63652 | 566 | lemma nat_eq_iff: "nat w = m \<longleftrightarrow> (if 0 \<le> w then w = int m else m = 0)" | 
| 48045 | 567 | by transfer (clarsimp simp add: le_imp_diff_is_add) | 
| 60162 | 568 | |
| 63652 | 569 | lemma nat_eq_iff2: "m = nat w \<longleftrightarrow> (if 0 \<le> w then w = int m else m = 0)" | 
| 54223 | 570 | using nat_eq_iff [of w m] by auto | 
| 571 | ||
| 63652 | 572 | lemma nat_0 [simp]: "nat 0 = 0" | 
| 54223 | 573 | by (simp add: nat_eq_iff) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 574 | |
| 63652 | 575 | lemma nat_1 [simp]: "nat 1 = Suc 0" | 
| 54223 | 576 | by (simp add: nat_eq_iff) | 
| 577 | ||
| 63652 | 578 | lemma nat_numeral [simp]: "nat (numeral k) = numeral k" | 
| 54223 | 579 | by (simp add: nat_eq_iff) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 580 | |
| 63652 | 581 | lemma nat_neg_numeral [simp]: "nat (- numeral k) = 0" | 
| 54223 | 582 | by simp | 
| 583 | ||
| 584 | lemma nat_2: "nat 2 = Suc (Suc 0)" | |
| 585 | by simp | |
| 60162 | 586 | |
| 63652 | 587 | lemma nat_less_iff: "0 \<le> w \<Longrightarrow> nat w < m \<longleftrightarrow> w < of_nat m" | 
| 48045 | 588 | by transfer (clarsimp, arith) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 589 | |
| 44709 | 590 | lemma nat_le_iff: "nat x \<le> n \<longleftrightarrow> x \<le> int n" | 
| 48045 | 591 | by transfer (clarsimp simp add: le_diff_conv) | 
| 44707 | 592 | |
| 593 | lemma nat_mono: "x \<le> y \<Longrightarrow> nat x \<le> nat y" | |
| 48045 | 594 | by transfer auto | 
| 44707 | 595 | |
| 63652 | 596 | lemma nat_0_iff[simp]: "nat i = 0 \<longleftrightarrow> i \<le> 0" | 
| 597 | for i :: int | |
| 48045 | 598 | by transfer clarsimp | 
| 29700 | 599 | |
| 63652 | 600 | lemma int_eq_iff: "of_nat m = z \<longleftrightarrow> m = nat z \<and> 0 \<le> z" | 
| 601 | by (auto simp add: nat_eq_iff2) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 602 | |
| 63652 | 603 | lemma zero_less_nat_eq [simp]: "0 < nat z \<longleftrightarrow> 0 < z" | 
| 604 | using zless_nat_conj [of 0] by auto | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 605 | |
| 63652 | 606 | lemma nat_add_distrib: "0 \<le> z \<Longrightarrow> 0 \<le> z' \<Longrightarrow> nat (z + z') = nat z + nat z'" | 
| 48045 | 607 | by transfer clarsimp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 608 | |
| 63652 | 609 | lemma nat_diff_distrib': "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> nat (x - y) = nat x - nat y" | 
| 54223 | 610 | by transfer clarsimp | 
| 60162 | 611 | |
| 63652 | 612 | lemma nat_diff_distrib: "0 \<le> z' \<Longrightarrow> z' \<le> z \<Longrightarrow> nat (z - z') = nat z - nat z'" | 
| 54223 | 613 | by (rule nat_diff_distrib') auto | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 614 | |
| 44709 | 615 | lemma nat_zminus_int [simp]: "nat (- int n) = 0" | 
| 48045 | 616 | by transfer simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 617 | |
| 63652 | 618 | lemma le_nat_iff: "k \<ge> 0 \<Longrightarrow> n \<le> nat k \<longleftrightarrow> int n \<le> k" | 
| 53065 | 619 | by transfer auto | 
| 60162 | 620 | |
| 63652 | 621 | lemma zless_nat_eq_int_zless: "m < nat z \<longleftrightarrow> int m < z" | 
| 48045 | 622 | by transfer (clarsimp simp add: less_diff_conv) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 623 | |
| 63652 | 624 | lemma (in ring_1) of_nat_nat [simp]: "0 \<le> z \<Longrightarrow> of_nat (nat z) = of_int z" | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48045diff
changeset | 625 | by transfer (clarsimp simp add: of_nat_diff) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 626 | |
| 63652 | 627 | lemma diff_nat_numeral [simp]: "(numeral v :: nat) - numeral v' = nat (numeral v - numeral v')" | 
| 54249 | 628 | by (simp only: nat_diff_distrib' zero_le_numeral nat_numeral) | 
| 629 | ||
| 66886 | 630 | lemma nat_abs_triangle_ineq: | 
| 631 | "nat \<bar>k + l\<bar> \<le> nat \<bar>k\<bar> + nat \<bar>l\<bar>" | |
| 632 | by (simp add: nat_add_distrib [symmetric] nat_le_eq_zle abs_triangle_ineq) | |
| 633 | ||
| 66816 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 634 | lemma nat_of_bool [simp]: | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 635 | "nat (of_bool P) = of_bool P" | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 636 | by auto | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 637 | |
| 66836 | 638 | lemma split_nat [arith_split]: "P (nat i) \<longleftrightarrow> ((\<forall>n. i = int n \<longrightarrow> P n) \<and> (i < 0 \<longrightarrow> P 0))" | 
| 639 | (is "?P = (?L \<and> ?R)") | |
| 640 | for i :: int | |
| 641 | proof (cases "i < 0") | |
| 642 | case True | |
| 643 | then show ?thesis | |
| 644 | by auto | |
| 645 | next | |
| 646 | case False | |
| 647 | have "?P = ?L" | |
| 648 | proof | |
| 649 | assume ?P | |
| 650 | then show ?L using False by auto | |
| 651 | next | |
| 652 | assume ?L | |
| 653 | moreover from False have "int (nat i) = i" | |
| 654 | by (simp add: not_less) | |
| 655 | ultimately show ?P | |
| 656 | by simp | |
| 657 | qed | |
| 658 | with False show ?thesis by simp | |
| 659 | qed | |
| 660 | ||
| 661 | lemma all_nat: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x\<ge>0. P (nat x))" | |
| 662 | by (auto split: split_nat) | |
| 663 | ||
| 664 | lemma ex_nat: "(\<exists>x. P x) \<longleftrightarrow> (\<exists>x. 0 \<le> x \<and> P (nat x))" | |
| 665 | proof | |
| 666 | assume "\<exists>x. P x" | |
| 667 | then obtain x where "P x" .. | |
| 668 | then have "int x \<ge> 0 \<and> P (nat (int x))" by simp | |
| 669 | then show "\<exists>x\<ge>0. P (nat x)" .. | |
| 670 | next | |
| 671 | assume "\<exists>x\<ge>0. P (nat x)" | |
| 672 | then show "\<exists>x. P x" by auto | |
| 673 | qed | |
| 674 | ||
| 54249 | 675 | |
| 60758 | 676 | text \<open>For termination proofs:\<close> | 
| 63652 | 677 | lemma measure_function_int[measure_function]: "is_measure (nat \<circ> abs)" .. | 
| 29779 | 678 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 679 | |
| 69593 | 680 | subsection \<open>Lemmas about the Function \<^term>\<open>of_nat\<close> and Orderings\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 681 | |
| 61076 | 682 | lemma negative_zless_0: "- (int (Suc n)) < (0 :: int)" | 
| 63652 | 683 | by (simp add: order_less_le del: of_nat_Suc) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 684 | |
| 44709 | 685 | lemma negative_zless [iff]: "- (int (Suc n)) < int m" | 
| 63652 | 686 | by (rule negative_zless_0 [THEN order_less_le_trans], simp) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 687 | |
| 44709 | 688 | lemma negative_zle_0: "- int n \<le> 0" | 
| 63652 | 689 | by (simp add: minus_le_iff) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 690 | |
| 44709 | 691 | lemma negative_zle [iff]: "- int n \<le> int m" | 
| 63652 | 692 | by (rule order_trans [OF negative_zle_0 of_nat_0_le_iff]) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 693 | |
| 63652 | 694 | lemma not_zle_0_negative [simp]: "\<not> 0 \<le> - int (Suc n)" | 
| 695 | by (subst le_minus_iff) (simp del: of_nat_Suc) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 696 | |
| 63652 | 697 | lemma int_zle_neg: "int n \<le> - int m \<longleftrightarrow> n = 0 \<and> m = 0" | 
| 48045 | 698 | by transfer simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 699 | |
| 63652 | 700 | lemma not_int_zless_negative [simp]: "\<not> int n < - int m" | 
| 701 | by (simp add: linorder_not_less) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 702 | |
| 63652 | 703 | lemma negative_eq_positive [simp]: "- int n = of_nat m \<longleftrightarrow> n = 0 \<and> m = 0" | 
| 704 | by (force simp add: order_eq_iff [of "- of_nat n"] int_zle_neg) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 705 | |
| 63652 | 706 | lemma zle_iff_zadd: "w \<le> z \<longleftrightarrow> (\<exists>n. z = w + int n)" | 
| 707 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 62348 | 708 | proof | 
| 63652 | 709 | assume ?rhs | 
| 710 | then show ?lhs by auto | |
| 62348 | 711 | next | 
| 63652 | 712 | assume ?lhs | 
| 62348 | 713 | then have "0 \<le> z - w" by simp | 
| 714 | then obtain n where "z - w = int n" | |
| 715 | using zero_le_imp_eq_int [of "z - w"] by blast | |
| 63652 | 716 | then have "z = w + int n" by simp | 
| 717 | then show ?rhs .. | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 718 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 719 | |
| 44709 | 720 | lemma zadd_int_left: "int m + (int n + z) = int (m + n) + z" | 
| 63652 | 721 | by simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 722 | |
| 63652 | 723 | text \<open> | 
| 724 | This version is proved for all ordered rings, not just integers! | |
| 725 | It is proved here because attribute \<open>arith_split\<close> is not available | |
| 726 | in theory \<open>Rings\<close>. | |
| 727 | But is it really better than just rewriting with \<open>abs_if\<close>? | |
| 728 | \<close> | |
| 729 | lemma abs_split [arith_split, no_atp]: "P \<bar>a\<bar> \<longleftrightarrow> (0 \<le> a \<longrightarrow> P a) \<and> (a < 0 \<longrightarrow> P (- a))" | |
| 730 | for a :: "'a::linordered_idom" | |
| 731 | by (force dest: order_less_le_trans simp add: abs_if linorder_not_less) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 732 | |
| 44709 | 733 | lemma negD: "x < 0 \<Longrightarrow> \<exists>n. x = - (int (Suc n))" | 
| 63652 | 734 | apply transfer | 
| 735 | apply clarsimp | |
| 736 | apply (rule_tac x="b - Suc a" in exI) | |
| 737 | apply arith | |
| 738 | done | |
| 739 | ||
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 740 | |
| 60758 | 741 | subsection \<open>Cases and induction\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 742 | |
| 63652 | 743 | text \<open> | 
| 744 | Now we replace the case analysis rule by a more conventional one: | |
| 745 | whether an integer is negative or not. | |
| 746 | \<close> | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 747 | |
| 63652 | 748 | text \<open>This version is symmetric in the two subgoals.\<close> | 
| 749 | lemma int_cases2 [case_names nonneg nonpos, cases type: int]: | |
| 750 | "(\<And>n. z = int n \<Longrightarrow> P) \<Longrightarrow> (\<And>n. z = - (int n) \<Longrightarrow> P) \<Longrightarrow> P" | |
| 751 | by (cases "z < 0") (auto simp add: linorder_not_less dest!: negD nat_0_le [THEN sym]) | |
| 59613 
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
 paulson <lp15@cam.ac.uk> parents: 
59582diff
changeset | 752 | |
| 63652 | 753 | text \<open>This is the default, with a negative case.\<close> | 
| 754 | lemma int_cases [case_names nonneg neg, cases type: int]: | |
| 755 | "(\<And>n. z = int n \<Longrightarrow> P) \<Longrightarrow> (\<And>n. z = - (int (Suc n)) \<Longrightarrow> P) \<Longrightarrow> P" | |
| 756 | apply (cases "z < 0") | |
| 757 | apply (blast dest!: negD) | |
| 758 | apply (simp add: linorder_not_less del: of_nat_Suc) | |
| 759 | apply auto | |
| 760 | apply (blast dest: nat_0_le [THEN sym]) | |
| 761 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 762 | |
| 60868 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 763 | lemma int_cases3 [case_names zero pos neg]: | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 764 | fixes k :: int | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 765 | assumes "k = 0 \<Longrightarrow> P" and "\<And>n. k = int n \<Longrightarrow> n > 0 \<Longrightarrow> P" | 
| 61204 | 766 | and "\<And>n. k = - int n \<Longrightarrow> n > 0 \<Longrightarrow> P" | 
| 60868 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 767 | shows "P" | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 768 | proof (cases k "0::int" rule: linorder_cases) | 
| 63652 | 769 | case equal | 
| 770 | with assms(1) show P by simp | |
| 60868 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 771 | next | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 772 | case greater | 
| 63539 | 773 | then have *: "nat k > 0" by simp | 
| 774 | moreover from * have "k = int (nat k)" by auto | |
| 60868 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 775 | ultimately show P using assms(2) by blast | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 776 | next | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 777 | case less | 
| 63539 | 778 | then have *: "nat (- k) > 0" by simp | 
| 779 | moreover from * have "k = - int (nat (- k))" by auto | |
| 60868 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 780 | ultimately show P using assms(3) by blast | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 781 | qed | 
| 
dd18c33c001e
direct bootstrap of integer division from natural division
 haftmann parents: 
60758diff
changeset | 782 | |
| 63652 | 783 | lemma int_of_nat_induct [case_names nonneg neg, induct type: int]: | 
| 784 | "(\<And>n. P (int n)) \<Longrightarrow> (\<And>n. P (- (int (Suc n)))) \<Longrightarrow> P z" | |
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 785 | by (cases z) auto | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 786 | |
| 66816 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 787 | lemma sgn_mult_dvd_iff [simp]: | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 788 | "sgn r * l dvd k \<longleftrightarrow> l dvd k \<and> (r = 0 \<longrightarrow> k = 0)" for k l r :: int | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 789 | by (cases r rule: int_cases3) auto | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 790 | |
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 791 | lemma mult_sgn_dvd_iff [simp]: | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 792 | "l * sgn r dvd k \<longleftrightarrow> l dvd k \<and> (r = 0 \<longrightarrow> k = 0)" for k l r :: int | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 793 | using sgn_mult_dvd_iff [of r l k] by (simp add: ac_simps) | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 794 | |
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 795 | lemma dvd_sgn_mult_iff [simp]: | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 796 | "l dvd sgn r * k \<longleftrightarrow> l dvd k \<or> r = 0" for k l r :: int | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 797 | by (cases r rule: int_cases3) simp_all | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 798 | |
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 799 | lemma dvd_mult_sgn_iff [simp]: | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 800 | "l dvd k * sgn r \<longleftrightarrow> l dvd k \<or> r = 0" for k l r :: int | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 801 | using dvd_sgn_mult_iff [of l r k] by (simp add: ac_simps) | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 802 | |
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 803 | lemma int_sgnE: | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 804 | fixes k :: int | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 805 | obtains n and l where "k = sgn l * int n" | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 806 | proof - | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 807 | have "k = sgn k * int (nat \<bar>k\<bar>)" | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 808 | by (simp add: sgn_mult_abs) | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 809 | then show ?thesis .. | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 810 | qed | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 811 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 812 | |
| 60758 | 813 | subsubsection \<open>Binary comparisons\<close> | 
| 28958 | 814 | |
| 60758 | 815 | text \<open>Preliminaries\<close> | 
| 28958 | 816 | |
| 60162 | 817 | lemma le_imp_0_less: | 
| 63652 | 818 | fixes z :: int | 
| 28958 | 819 | assumes le: "0 \<le> z" | 
| 63652 | 820 | shows "0 < 1 + z" | 
| 28958 | 821 | proof - | 
| 822 | have "0 \<le> z" by fact | |
| 63652 | 823 | also have "\<dots> < z + 1" by (rule less_add_one) | 
| 824 | also have "\<dots> = 1 + z" by (simp add: ac_simps) | |
| 28958 | 825 | finally show "0 < 1 + z" . | 
| 826 | qed | |
| 827 | ||
| 63652 | 828 | lemma odd_less_0_iff: "1 + z + z < 0 \<longleftrightarrow> z < 0" | 
| 829 | for z :: int | |
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 830 | proof (cases z) | 
| 28958 | 831 | case (nonneg n) | 
| 63652 | 832 | then show ?thesis | 
| 833 | by (simp add: linorder_not_less add.assoc add_increasing le_imp_0_less [THEN order_less_imp_le]) | |
| 28958 | 834 | next | 
| 835 | case (neg n) | |
| 63652 | 836 | then show ?thesis | 
| 837 | by (simp del: of_nat_Suc of_nat_add of_nat_1 | |
| 838 | add: algebra_simps of_nat_1 [where 'a=int, symmetric] of_nat_add [symmetric]) | |
| 28958 | 839 | qed | 
| 840 | ||
| 63652 | 841 | |
| 60758 | 842 | subsubsection \<open>Comparisons, for Ordered Rings\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 843 | |
| 63652 | 844 | lemma odd_nonzero: "1 + z + z \<noteq> 0" | 
| 845 | for z :: int | |
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 846 | proof (cases z) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 847 | case (nonneg n) | 
| 63652 | 848 | have le: "0 \<le> z + z" | 
| 849 | by (simp add: nonneg add_increasing) | |
| 850 | then show ?thesis | |
| 67116 | 851 | using le_imp_0_less [OF le] by (auto simp: ac_simps) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 852 | next | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 853 | case (neg n) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 854 | show ?thesis | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 855 | proof | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 856 | assume eq: "1 + z + z = 0" | 
| 63652 | 857 | have "0 < 1 + (int n + int n)" | 
| 60162 | 858 | by (simp add: le_imp_0_less add_increasing) | 
| 63652 | 859 | also have "\<dots> = - (1 + z + z)" | 
| 60162 | 860 | by (simp add: neg add.assoc [symmetric]) | 
| 63652 | 861 | also have "\<dots> = 0" by (simp add: eq) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 862 | finally have "0<0" .. | 
| 63652 | 863 | then show False by blast | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 864 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 865 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 866 | |
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30496diff
changeset | 867 | |
| 60758 | 868 | subsection \<open>The Set of Integers\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 869 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 870 | context ring_1 | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 871 | begin | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 872 | |
| 61070 | 873 | definition Ints :: "'a set"  ("\<int>")
 | 
| 874 | where "\<int> = range of_int" | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 875 | |
| 35634 | 876 | lemma Ints_of_int [simp]: "of_int z \<in> \<int>" | 
| 877 | by (simp add: Ints_def) | |
| 878 | ||
| 879 | lemma Ints_of_nat [simp]: "of_nat n \<in> \<int>" | |
| 45533 | 880 | using Ints_of_int [of "of_nat n"] by simp | 
| 35634 | 881 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 882 | lemma Ints_0 [simp]: "0 \<in> \<int>" | 
| 45533 | 883 | using Ints_of_int [of "0"] by simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 884 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 885 | lemma Ints_1 [simp]: "1 \<in> \<int>" | 
| 45533 | 886 | using Ints_of_int [of "1"] by simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 887 | |
| 61552 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
61531diff
changeset | 888 | lemma Ints_numeral [simp]: "numeral n \<in> \<int>" | 
| 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
61531diff
changeset | 889 | by (subst of_nat_numeral [symmetric], rule Ints_of_nat) | 
| 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
61531diff
changeset | 890 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 891 | lemma Ints_add [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a + b \<in> \<int>" | 
| 63652 | 892 | apply (auto simp add: Ints_def) | 
| 893 | apply (rule range_eqI) | |
| 894 | apply (rule of_int_add [symmetric]) | |
| 895 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 896 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 897 | lemma Ints_minus [simp]: "a \<in> \<int> \<Longrightarrow> -a \<in> \<int>" | 
| 63652 | 898 | apply (auto simp add: Ints_def) | 
| 899 | apply (rule range_eqI) | |
| 900 | apply (rule of_int_minus [symmetric]) | |
| 901 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 902 | |
| 68721 | 903 | lemma minus_in_Ints_iff: "-x \<in> \<int> \<longleftrightarrow> x \<in> \<int>" | 
| 904 | using Ints_minus[of x] Ints_minus[of "-x"] by auto | |
| 905 | ||
| 35634 | 906 | lemma Ints_diff [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a - b \<in> \<int>" | 
| 63652 | 907 | apply (auto simp add: Ints_def) | 
| 908 | apply (rule range_eqI) | |
| 909 | apply (rule of_int_diff [symmetric]) | |
| 910 | done | |
| 35634 | 911 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 912 | lemma Ints_mult [simp]: "a \<in> \<int> \<Longrightarrow> b \<in> \<int> \<Longrightarrow> a * b \<in> \<int>" | 
| 63652 | 913 | apply (auto simp add: Ints_def) | 
| 914 | apply (rule range_eqI) | |
| 915 | apply (rule of_int_mult [symmetric]) | |
| 916 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 917 | |
| 35634 | 918 | lemma Ints_power [simp]: "a \<in> \<int> \<Longrightarrow> a ^ n \<in> \<int>" | 
| 63652 | 919 | by (induct n) simp_all | 
| 35634 | 920 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 921 | lemma Ints_cases [cases set: Ints]: | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 922 | assumes "q \<in> \<int>" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 923 | obtains (of_int) z where "q = of_int z" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 924 | unfolding Ints_def | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 925 | proof - | 
| 60758 | 926 | from \<open>q \<in> \<int>\<close> have "q \<in> range of_int" unfolding Ints_def . | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 927 | then obtain z where "q = of_int z" .. | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 928 | then show thesis .. | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 929 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 930 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 931 | lemma Ints_induct [case_names of_int, induct set: Ints]: | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 932 | "q \<in> \<int> \<Longrightarrow> (\<And>z. P (of_int z)) \<Longrightarrow> P q" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 933 | by (rule Ints_cases) auto | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 934 | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 935 | lemma Nats_subset_Ints: "\<nat> \<subseteq> \<int>" | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 936 | unfolding Nats_def Ints_def | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 937 | by (rule subsetI, elim imageE, hypsubst, subst of_int_of_nat_eq[symmetric], rule imageI) simp_all | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 938 | |
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 939 | lemma Nats_altdef1: "\<nat> = {of_int n |n. n \<ge> 0}"
 | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 940 | proof (intro subsetI equalityI) | 
| 63652 | 941 | fix x :: 'a | 
| 942 |   assume "x \<in> {of_int n |n. n \<ge> 0}"
 | |
| 943 | then obtain n where "x = of_int n" "n \<ge> 0" | |
| 944 | by (auto elim!: Ints_cases) | |
| 945 | then have "x = of_nat (nat n)" | |
| 946 | by (subst of_nat_nat) simp_all | |
| 947 | then show "x \<in> \<nat>" | |
| 948 | by simp | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 949 | next | 
| 63652 | 950 | fix x :: 'a | 
| 951 | assume "x \<in> \<nat>" | |
| 952 | then obtain n where "x = of_nat n" | |
| 953 | by (auto elim!: Nats_cases) | |
| 954 | then have "x = of_int (int n)" by simp | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 955 | also have "int n \<ge> 0" by simp | 
| 63652 | 956 |   then have "of_int (int n) \<in> {of_int n |n. n \<ge> 0}" by blast
 | 
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 957 |   finally show "x \<in> {of_int n |n. n \<ge> 0}" .
 | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 958 | qed | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 959 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 960 | end | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 961 | |
| 64758 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 962 | lemma (in linordered_idom) Ints_abs [simp]: | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 963 | shows "a \<in> \<int> \<Longrightarrow> abs a \<in> \<int>" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 964 | by (auto simp: abs_if) | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 965 | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 966 | lemma (in linordered_idom) Nats_altdef2: "\<nat> = {n \<in> \<int>. n \<ge> 0}"
 | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 967 | proof (intro subsetI equalityI) | 
| 63652 | 968 | fix x :: 'a | 
| 969 |   assume "x \<in> {n \<in> \<int>. n \<ge> 0}"
 | |
| 970 | then obtain n where "x = of_int n" "n \<ge> 0" | |
| 971 | by (auto elim!: Ints_cases) | |
| 972 | then have "x = of_nat (nat n)" | |
| 973 | by (subst of_nat_nat) simp_all | |
| 974 | then show "x \<in> \<nat>" | |
| 975 | by simp | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 976 | qed (auto elim!: Nats_cases) | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 977 | |
| 64849 | 978 | lemma (in idom_divide) of_int_divide_in_Ints: | 
| 979 | "of_int a div of_int b \<in> \<int>" if "b dvd a" | |
| 980 | proof - | |
| 981 | from that obtain c where "a = b * c" .. | |
| 982 | then show ?thesis | |
| 983 | by (cases "of_int b = 0") simp_all | |
| 984 | qed | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61234diff
changeset | 985 | |
| 69593 | 986 | text \<open>The premise involving \<^term>\<open>Ints\<close> prevents \<^term>\<open>a = 1/2\<close>.\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 987 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 988 | lemma Ints_double_eq_0_iff: | 
| 63652 | 989 | fixes a :: "'a::ring_char_0" | 
| 61070 | 990 | assumes in_Ints: "a \<in> \<int>" | 
| 63652 | 991 | shows "a + a = 0 \<longleftrightarrow> a = 0" | 
| 992 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 993 | proof - | 
| 63652 | 994 | from in_Ints have "a \<in> range of_int" | 
| 995 | unfolding Ints_def [symmetric] . | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 996 | then obtain z where a: "a = of_int z" .. | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 997 | show ?thesis | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 998 | proof | 
| 63652 | 999 | assume ?rhs | 
| 1000 | then show ?lhs by simp | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1001 | next | 
| 63652 | 1002 | assume ?lhs | 
| 1003 | with a have "of_int (z + z) = (of_int 0 :: 'a)" by simp | |
| 1004 | then have "z + z = 0" by (simp only: of_int_eq_iff) | |
| 67116 | 1005 | then have "z = 0" by (simp only: double_zero) | 
| 63652 | 1006 | with a show ?rhs by simp | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1007 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1008 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1009 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1010 | lemma Ints_odd_nonzero: | 
| 63652 | 1011 | fixes a :: "'a::ring_char_0" | 
| 61070 | 1012 | assumes in_Ints: "a \<in> \<int>" | 
| 63652 | 1013 | shows "1 + a + a \<noteq> 0" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1014 | proof - | 
| 63652 | 1015 | from in_Ints have "a \<in> range of_int" | 
| 1016 | unfolding Ints_def [symmetric] . | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1017 | then obtain z where a: "a = of_int z" .. | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1018 | show ?thesis | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1019 | proof | 
| 63652 | 1020 | assume "1 + a + a = 0" | 
| 1021 | with a have "of_int (1 + z + z) = (of_int 0 :: 'a)" by simp | |
| 1022 | then have "1 + z + z = 0" by (simp only: of_int_eq_iff) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1023 | with odd_nonzero show False by blast | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1024 | qed | 
| 60162 | 1025 | qed | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1026 | |
| 61070 | 1027 | lemma Nats_numeral [simp]: "numeral w \<in> \<nat>" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1028 | using of_nat_in_Nats [of "numeral w"] by simp | 
| 35634 | 1029 | |
| 60162 | 1030 | lemma Ints_odd_less_0: | 
| 63652 | 1031 | fixes a :: "'a::linordered_idom" | 
| 61070 | 1032 | assumes in_Ints: "a \<in> \<int>" | 
| 63652 | 1033 | shows "1 + a + a < 0 \<longleftrightarrow> a < 0" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1034 | proof - | 
| 63652 | 1035 | from in_Ints have "a \<in> range of_int" | 
| 1036 | unfolding Ints_def [symmetric] . | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1037 | then obtain z where a: "a = of_int z" .. | 
| 63652 | 1038 | with a have "1 + a + a < 0 \<longleftrightarrow> of_int (1 + z + z) < (of_int 0 :: 'a)" | 
| 1039 | by simp | |
| 1040 | also have "\<dots> \<longleftrightarrow> z < 0" | |
| 1041 | by (simp only: of_int_less_iff odd_less_0_iff) | |
| 1042 | also have "\<dots> \<longleftrightarrow> a < 0" | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1043 | by (simp add: a) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1044 | finally show ?thesis . | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1045 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1046 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1047 | |
| 69593 | 1048 | subsection \<open>\<^term>\<open>sum\<close> and \<^term>\<open>prod\<close>\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1049 | |
| 69182 | 1050 | context semiring_1 | 
| 1051 | begin | |
| 1052 | ||
| 1053 | lemma of_nat_sum [simp]: | |
| 1054 | "of_nat (sum f A) = (\<Sum>x\<in>A. of_nat (f x))" | |
| 1055 | by (induction A rule: infinite_finite_induct) auto | |
| 1056 | ||
| 1057 | end | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1058 | |
| 69182 | 1059 | context ring_1 | 
| 1060 | begin | |
| 1061 | ||
| 1062 | lemma of_int_sum [simp]: | |
| 1063 | "of_int (sum f A) = (\<Sum>x\<in>A. of_int (f x))" | |
| 1064 | by (induction A rule: infinite_finite_induct) auto | |
| 1065 | ||
| 1066 | end | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1067 | |
| 69182 | 1068 | context comm_semiring_1 | 
| 1069 | begin | |
| 1070 | ||
| 1071 | lemma of_nat_prod [simp]: | |
| 1072 | "of_nat (prod f A) = (\<Prod>x\<in>A. of_nat (f x))" | |
| 1073 | by (induction A rule: infinite_finite_induct) auto | |
| 1074 | ||
| 1075 | end | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1076 | |
| 69182 | 1077 | context comm_ring_1 | 
| 1078 | begin | |
| 1079 | ||
| 1080 | lemma of_int_prod [simp]: | |
| 1081 | "of_int (prod f A) = (\<Prod>x\<in>A. of_int (f x))" | |
| 1082 | by (induction A rule: infinite_finite_induct) auto | |
| 1083 | ||
| 1084 | end | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1085 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1086 | |
| 60758 | 1087 | subsection \<open>Setting up simplification procedures\<close> | 
| 30802 | 1088 | |
| 70356 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1089 | ML_file \<open>Tools/int_arith.ML\<close> | 
| 54249 | 1090 | |
| 70356 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1091 | declaration \<open>K ( | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1092 | Lin_Arith.add_discrete_type \<^type_name>\<open>Int.int\<close> | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1093 |   #> Lin_Arith.add_lessD @{thm zless_imp_add1_zle}
 | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1094 |   #> Lin_Arith.add_inj_thms @{thms of_nat_le_iff [THEN iffD2] of_nat_eq_iff [THEN iffD2]}
 | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1095 | #> Lin_Arith.add_inj_const (\<^const_name>\<open>of_nat\<close>, \<^typ>\<open>nat \<Rightarrow> int\<close>) | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1096 | #> Lin_Arith.add_simps | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1097 |       @{thms of_int_0 of_int_1 of_int_add of_int_mult of_int_numeral of_int_neg_numeral nat_0 nat_1 diff_nat_numeral nat_numeral
 | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1098 | neg_less_iff_less | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1099 | True_implies_equals | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1100 | distrib_left [where a = "numeral v" for v] | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1101 | distrib_left [where a = "- numeral v" for v] | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1102 | div_by_1 div_0 | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1103 | times_divide_eq_right times_divide_eq_left | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1104 | minus_divide_left [THEN sym] minus_divide_right [THEN sym] | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1105 | add_divide_distrib diff_divide_distrib | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1106 | of_int_minus of_int_diff | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1107 | of_int_of_nat_eq} | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1108 | #> Lin_Arith.add_simprocs [Int_Arith.zero_one_idom_simproc] | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70354diff
changeset | 1109 | )\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1110 | |
| 63652 | 1111 | simproc_setup fast_arith | 
| 1112 |   ("(m::'a::linordered_idom) < n" |
 | |
| 1113 | "(m::'a::linordered_idom) \<le> n" | | |
| 1114 | "(m::'a::linordered_idom) = n") = | |
| 61144 | 1115 | \<open>K Lin_Arith.simproc\<close> | 
| 43595 | 1116 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1117 | |
| 60758 | 1118 | subsection\<open>More Inequality Reasoning\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1119 | |
| 63652 | 1120 | lemma zless_add1_eq: "w < z + 1 \<longleftrightarrow> w < z \<or> w = z" | 
| 1121 | for w z :: int | |
| 1122 | by arith | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1123 | |
| 63652 | 1124 | lemma add1_zle_eq: "w + 1 \<le> z \<longleftrightarrow> w < z" | 
| 1125 | for w z :: int | |
| 1126 | by arith | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1127 | |
| 63652 | 1128 | lemma zle_diff1_eq [simp]: "w \<le> z - 1 \<longleftrightarrow> w < z" | 
| 1129 | for w z :: int | |
| 1130 | by arith | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1131 | |
| 63652 | 1132 | lemma zle_add1_eq_le [simp]: "w < z + 1 \<longleftrightarrow> w \<le> z" | 
| 1133 | for w z :: int | |
| 1134 | by arith | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1135 | |
| 63652 | 1136 | lemma int_one_le_iff_zero_less: "1 \<le> z \<longleftrightarrow> 0 < z" | 
| 1137 | for z :: int | |
| 1138 | by arith | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1139 | |
| 64758 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1140 | lemma Ints_nonzero_abs_ge1: | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1141 | fixes x:: "'a :: linordered_idom" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1142 | assumes "x \<in> Ints" "x \<noteq> 0" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1143 | shows "1 \<le> abs x" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1144 | proof (rule Ints_cases [OF \<open>x \<in> Ints\<close>]) | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1145 | fix z::int | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1146 | assume "x = of_int z" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1147 | with \<open>x \<noteq> 0\<close> | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1148 | show "1 \<le> \<bar>x\<bar>" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1149 | apply (auto simp add: abs_if) | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1150 | by (metis diff_0 of_int_1 of_int_le_iff of_int_minus zle_diff1_eq) | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1151 | qed | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1152 | |
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1153 | lemma Ints_nonzero_abs_less1: | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1154 | fixes x:: "'a :: linordered_idom" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1155 | shows "\<lbrakk>x \<in> Ints; abs x < 1\<rbrakk> \<Longrightarrow> x = 0" | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1156 | using Ints_nonzero_abs_ge1 [of x] by auto | 
| 
3b33d2fc5fc0
A few new lemmas and needed adaptations
 paulson <lp15@cam.ac.uk> parents: 
64714diff
changeset | 1157 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1158 | |
| 69593 | 1159 | subsection \<open>The functions \<^term>\<open>nat\<close> and \<^term>\<open>int\<close>\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1160 | |
| 69593 | 1161 | text \<open>Simplify the term \<^term>\<open>w + - z\<close>.\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1162 | |
| 63652 | 1163 | lemma one_less_nat_eq [simp]: "Suc 0 < nat z \<longleftrightarrow> 1 < z" | 
| 60162 | 1164 | using zless_nat_conj [of 1 z] by auto | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1165 | |
| 67116 | 1166 | lemma int_eq_iff_numeral [simp]: | 
| 1167 | "int m = numeral v \<longleftrightarrow> m = numeral v" | |
| 1168 | by (simp add: int_eq_iff) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1169 | |
| 67116 | 1170 | lemma nat_abs_int_diff: | 
| 1171 | "nat \<bar>int a - int b\<bar> = (if a \<le> b then b - a else a - b)" | |
| 59000 | 1172 | by auto | 
| 1173 | ||
| 1174 | lemma nat_int_add: "nat (int a + int b) = a + b" | |
| 1175 | by auto | |
| 1176 | ||
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1177 | context ring_1 | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1178 | begin | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1179 | |
| 33056 
791a4655cae3
renamed "nitpick_const_xxx" attributes to "nitpick_xxx" and "nitpick_ind_intros" to "nitpick_intros"
 blanchet parents: 
32437diff
changeset | 1180 | lemma of_int_of_nat [nitpick_simp]: | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1181 | "of_int k = (if k < 0 then - of_nat (nat (- k)) else of_nat (nat k))" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1182 | proof (cases "k < 0") | 
| 63652 | 1183 | case True | 
| 1184 | then have "0 \<le> - k" by simp | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1185 | then have "of_nat (nat (- k)) = of_int (- k)" by (rule of_nat_nat) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1186 | with True show ?thesis by simp | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1187 | next | 
| 63652 | 1188 | case False | 
| 1189 | then show ?thesis by (simp add: not_less) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1190 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1191 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1192 | end | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1193 | |
| 64014 | 1194 | lemma transfer_rule_of_int: | 
| 1195 | fixes R :: "'a::ring_1 \<Rightarrow> 'b::ring_1 \<Rightarrow> bool" | |
| 1196 | assumes [transfer_rule]: "R 0 0" "R 1 1" | |
| 1197 | "rel_fun R (rel_fun R R) plus plus" | |
| 1198 | "rel_fun R R uminus uminus" | |
| 1199 | shows "rel_fun HOL.eq R of_int of_int" | |
| 1200 | proof - | |
| 1201 | note transfer_rule_of_nat [transfer_rule] | |
| 1202 | have [transfer_rule]: "rel_fun HOL.eq R of_nat of_nat" | |
| 1203 | by transfer_prover | |
| 1204 | show ?thesis | |
| 1205 | by (unfold of_int_of_nat [abs_def]) transfer_prover | |
| 1206 | qed | |
| 1207 | ||
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1208 | lemma nat_mult_distrib: | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1209 | fixes z z' :: int | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1210 | assumes "0 \<le> z" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1211 | shows "nat (z * z') = nat z * nat z'" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1212 | proof (cases "0 \<le> z'") | 
| 63652 | 1213 | case False | 
| 1214 | with assms have "z * z' \<le> 0" | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1215 | by (simp add: not_le mult_le_0_iff) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1216 | then have "nat (z * z') = 0" by simp | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1217 | moreover from False have "nat z' = 0" by simp | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1218 | ultimately show ?thesis by simp | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1219 | next | 
| 63652 | 1220 | case True | 
| 1221 | with assms have ge_0: "z * z' \<ge> 0" by (simp add: zero_le_mult_iff) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1222 | show ?thesis | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1223 | by (rule injD [of "of_nat :: nat \<Rightarrow> int", OF inj_of_nat]) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1224 | (simp only: of_nat_mult of_nat_nat [OF True] | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1225 | of_nat_nat [OF assms] of_nat_nat [OF ge_0], simp) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1226 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1227 | |
| 63652 | 1228 | lemma nat_mult_distrib_neg: "z \<le> 0 \<Longrightarrow> nat (z * z') = nat (- z) * nat (- z')" | 
| 1229 | for z z' :: int | |
| 1230 | apply (rule trans) | |
| 1231 | apply (rule_tac [2] nat_mult_distrib) | |
| 1232 | apply auto | |
| 1233 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1234 | |
| 61944 | 1235 | lemma nat_abs_mult_distrib: "nat \<bar>w * z\<bar> = nat \<bar>w\<bar> * nat \<bar>z\<bar>" | 
| 63652 | 1236 | by (cases "z = 0 \<or> w = 0") | 
| 1237 | (auto simp add: abs_if nat_mult_distrib [symmetric] | |
| 1238 | nat_mult_distrib_neg [symmetric] mult_less_0_iff) | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1239 | |
| 63652 | 1240 | lemma int_in_range_abs [simp]: "int n \<in> range abs" | 
| 60570 | 1241 | proof (rule range_eqI) | 
| 63652 | 1242 | show "int n = \<bar>int n\<bar>" by simp | 
| 60570 | 1243 | qed | 
| 1244 | ||
| 63652 | 1245 | lemma range_abs_Nats [simp]: "range abs = (\<nat> :: int set)" | 
| 60570 | 1246 | proof - | 
| 1247 | have "\<bar>k\<bar> \<in> \<nat>" for k :: int | |
| 1248 | by (cases k) simp_all | |
| 1249 | moreover have "k \<in> range abs" if "k \<in> \<nat>" for k :: int | |
| 1250 | using that by induct simp | |
| 1251 | ultimately show ?thesis by blast | |
| 61204 | 1252 | qed | 
| 60570 | 1253 | |
| 63652 | 1254 | lemma Suc_nat_eq_nat_zadd1: "0 \<le> z \<Longrightarrow> Suc (nat z) = nat (1 + z)" | 
| 1255 | for z :: int | |
| 1256 | by (rule sym) (simp add: nat_eq_iff) | |
| 47207 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1257 | |
| 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1258 | lemma diff_nat_eq_if: | 
| 63652 | 1259 | "nat z - nat z' = | 
| 1260 | (if z' < 0 then nat z | |
| 1261 | else | |
| 1262 | let d = z - z' | |
| 1263 | in if d < 0 then 0 else nat d)" | |
| 1264 | by (simp add: Let_def nat_diff_distrib [symmetric]) | |
| 47207 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1265 | |
| 63652 | 1266 | lemma nat_numeral_diff_1 [simp]: "numeral v - (1::nat) = nat (numeral v - 1)" | 
| 47207 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1267 | using diff_nat_numeral [of v Num.One] by simp | 
| 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1268 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1269 | |
| 63652 | 1270 | subsection \<open>Induction principles for int\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1271 | |
| 63652 | 1272 | text \<open>Well-founded segments of the integers.\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1273 | |
| 63652 | 1274 | definition int_ge_less_than :: "int \<Rightarrow> (int \<times> int) set" | 
| 1275 |   where "int_ge_less_than d = {(z', z). d \<le> z' \<and> z' < z}"
 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1276 | |
| 63652 | 1277 | lemma wf_int_ge_less_than: "wf (int_ge_less_than d)" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1278 | proof - | 
| 63652 | 1279 | have "int_ge_less_than d \<subseteq> measure (\<lambda>z. nat (z - d))" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1280 | by (auto simp add: int_ge_less_than_def) | 
| 63652 | 1281 | then show ?thesis | 
| 60162 | 1282 | by (rule wf_subset [OF wf_measure]) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1283 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1284 | |
| 63652 | 1285 | text \<open> | 
| 1286 | This variant looks odd, but is typical of the relations suggested | |
| 1287 | by RankFinder.\<close> | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1288 | |
| 63652 | 1289 | definition int_ge_less_than2 :: "int \<Rightarrow> (int \<times> int) set" | 
| 1290 |   where "int_ge_less_than2 d = {(z',z). d \<le> z \<and> z' < z}"
 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1291 | |
| 63652 | 1292 | lemma wf_int_ge_less_than2: "wf (int_ge_less_than2 d)" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1293 | proof - | 
| 63652 | 1294 | have "int_ge_less_than2 d \<subseteq> measure (\<lambda>z. nat (1 + z - d))" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1295 | by (auto simp add: int_ge_less_than2_def) | 
| 63652 | 1296 | then show ?thesis | 
| 60162 | 1297 | by (rule wf_subset [OF wf_measure]) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1298 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1299 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1300 | (* `set:int': dummy construction *) | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1301 | theorem int_ge_induct [case_names base step, induct set: int]: | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1302 | fixes i :: int | 
| 63652 | 1303 | assumes ge: "k \<le> i" | 
| 1304 | and base: "P k" | |
| 1305 | and step: "\<And>i. k \<le> i \<Longrightarrow> P i \<Longrightarrow> P (i + 1)" | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1306 | shows "P i" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1307 | proof - | 
| 63652 | 1308 | have "\<And>i::int. n = nat (i - k) \<Longrightarrow> k \<le> i \<Longrightarrow> P i" for n | 
| 1309 | proof (induct n) | |
| 1310 | case 0 | |
| 1311 | then have "i = k" by arith | |
| 1312 | with base show "P i" by simp | |
| 1313 | next | |
| 1314 | case (Suc n) | |
| 1315 | then have "n = nat ((i - 1) - k)" by arith | |
| 1316 | moreover have k: "k \<le> i - 1" using Suc.prems by arith | |
| 1317 | ultimately have "P (i - 1)" by (rule Suc.hyps) | |
| 1318 | from step [OF k this] show ?case by simp | |
| 1319 | qed | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1320 | with ge show ?thesis by fast | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1321 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1322 | |
| 25928 | 1323 | (* `set:int': dummy construction *) | 
| 1324 | theorem int_gr_induct [case_names base step, induct set: int]: | |
| 63652 | 1325 | fixes i k :: int | 
| 1326 | assumes gr: "k < i" | |
| 1327 | and base: "P (k + 1)" | |
| 1328 | and step: "\<And>i. k < i \<Longrightarrow> P i \<Longrightarrow> P (i + 1)" | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1329 | shows "P i" | 
| 63652 | 1330 | apply (rule int_ge_induct[of "k + 1"]) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1331 | using gr apply arith | 
| 63652 | 1332 | apply (rule base) | 
| 1333 | apply (rule step) | |
| 1334 | apply simp_all | |
| 1335 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1336 | |
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1337 | theorem int_le_induct [consumes 1, case_names base step]: | 
| 63652 | 1338 | fixes i k :: int | 
| 1339 | assumes le: "i \<le> k" | |
| 1340 | and base: "P k" | |
| 1341 | and step: "\<And>i. i \<le> k \<Longrightarrow> P i \<Longrightarrow> P (i - 1)" | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1342 | shows "P i" | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1343 | proof - | 
| 63652 | 1344 | have "\<And>i::int. n = nat(k-i) \<Longrightarrow> i \<le> k \<Longrightarrow> P i" for n | 
| 1345 | proof (induct n) | |
| 1346 | case 0 | |
| 1347 | then have "i = k" by arith | |
| 1348 | with base show "P i" by simp | |
| 1349 | next | |
| 1350 | case (Suc n) | |
| 1351 | then have "n = nat (k - (i + 1))" by arith | |
| 1352 | moreover have k: "i + 1 \<le> k" using Suc.prems by arith | |
| 1353 | ultimately have "P (i + 1)" by (rule Suc.hyps) | |
| 1354 | from step[OF k this] show ?case by simp | |
| 1355 | qed | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1356 | with le show ?thesis by fast | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1357 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1358 | |
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1359 | theorem int_less_induct [consumes 1, case_names base step]: | 
| 63652 | 1360 | fixes i k :: int | 
| 1361 | assumes less: "i < k" | |
| 1362 | and base: "P (k - 1)" | |
| 1363 | and step: "\<And>i. i < k \<Longrightarrow> P i \<Longrightarrow> P (i - 1)" | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1364 | shows "P i" | 
| 63652 | 1365 | apply (rule int_le_induct[of _ "k - 1"]) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1366 | using less apply arith | 
| 63652 | 1367 | apply (rule base) | 
| 1368 | apply (rule step) | |
| 1369 | apply simp_all | |
| 1370 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1371 | |
| 36811 
4ab4aa5bee1c
renamed former Int.int_induct to Int.int_of_nat_induct, former Presburger.int_induct to Int.int_induct: is more conservative and more natural than the intermediate solution
 haftmann parents: 
36801diff
changeset | 1372 | theorem int_induct [case_names base step1 step2]: | 
| 36801 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1373 | fixes k :: int | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1374 | assumes base: "P k" | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1375 | and step1: "\<And>i. k \<le> i \<Longrightarrow> P i \<Longrightarrow> P (i + 1)" | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1376 | and step2: "\<And>i. k \<ge> i \<Longrightarrow> P i \<Longrightarrow> P (i - 1)" | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1377 | shows "P i" | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1378 | proof - | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1379 | have "i \<le> k \<or> i \<ge> k" by arith | 
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1380 | then show ?thesis | 
| 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1381 | proof | 
| 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1382 | assume "i \<ge> k" | 
| 63652 | 1383 | then show ?thesis | 
| 1384 | using base by (rule int_ge_induct) (fact step1) | |
| 36801 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1385 | next | 
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1386 | assume "i \<le> k" | 
| 63652 | 1387 | then show ?thesis | 
| 1388 | using base by (rule int_le_induct) (fact step2) | |
| 36801 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1389 | qed | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1390 | qed | 
| 
3560de0fe851
moved int induction lemma to theory Int as int_bidirectional_induct
 haftmann parents: 
36749diff
changeset | 1391 | |
| 63652 | 1392 | |
| 1393 | subsection \<open>Intermediate value theorems\<close> | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1394 | |
| 67116 | 1395 | lemma nat_intermed_int_val: | 
| 1396 | "\<exists>i. m \<le> i \<and> i \<le> n \<and> f i = k" | |
| 1397 | if "\<forall>i. m \<le> i \<and> i < n \<longrightarrow> \<bar>f (Suc i) - f i\<bar> \<le> 1" | |
| 1398 | "m \<le> n" "f m \<le> k" "k \<le> f n" | |
| 1399 | for m n :: nat and k :: int | |
| 1400 | proof - | |
| 1401 | have "(\<forall>i<n. \<bar>f (Suc i) - f i\<bar> \<le> 1) \<Longrightarrow> f 0 \<le> k \<Longrightarrow> k \<le> f n | |
| 1402 | \<Longrightarrow> (\<exists>i \<le> n. f i = k)" | |
| 1403 | for n :: nat and f | |
| 1404 | apply (induct n) | |
| 1405 | apply auto | |
| 1406 | apply (erule_tac x = n in allE) | |
| 1407 | apply (case_tac "k = f (Suc n)") | |
| 1408 | apply (auto simp add: abs_if split: if_split_asm intro: le_SucI) | |
| 1409 | done | |
| 1410 | from this [of "n - m" "f \<circ> plus m"] that show ?thesis | |
| 1411 | apply auto | |
| 1412 | apply (rule_tac x = "m + i" in exI) | |
| 1413 | apply auto | |
| 1414 | done | |
| 1415 | qed | |
| 1416 | ||
| 1417 | lemma nat0_intermed_int_val: | |
| 1418 | "\<exists>i\<le>n. f i = k" | |
| 1419 | if "\<forall>i<n. \<bar>f (i + 1) - f i\<bar> \<le> 1" "f 0 \<le> k" "k \<le> f n" | |
| 63652 | 1420 | for n :: nat and k :: int | 
| 67116 | 1421 | using nat_intermed_int_val [of 0 n f k] that by auto | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1422 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1423 | |
| 63652 | 1424 | subsection \<open>Products and 1, by T. M. Rasmussen\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1425 | |
| 34055 | 1426 | lemma abs_zmult_eq_1: | 
| 63652 | 1427 | fixes m n :: int | 
| 34055 | 1428 | assumes mn: "\<bar>m * n\<bar> = 1" | 
| 63652 | 1429 | shows "\<bar>m\<bar> = 1" | 
| 34055 | 1430 | proof - | 
| 63652 | 1431 | from mn have 0: "m \<noteq> 0" "n \<noteq> 0" by auto | 
| 1432 | have "\<not> 2 \<le> \<bar>m\<bar>" | |
| 34055 | 1433 | proof | 
| 1434 | assume "2 \<le> \<bar>m\<bar>" | |
| 63652 | 1435 | then have "2 * \<bar>n\<bar> \<le> \<bar>m\<bar> * \<bar>n\<bar>" by (simp add: mult_mono 0) | 
| 1436 | also have "\<dots> = \<bar>m * n\<bar>" by (simp add: abs_mult) | |
| 1437 | also from mn have "\<dots> = 1" by simp | |
| 1438 | finally have "2 * \<bar>n\<bar> \<le> 1" . | |
| 1439 | with 0 show "False" by arith | |
| 34055 | 1440 | qed | 
| 63652 | 1441 | with 0 show ?thesis by auto | 
| 34055 | 1442 | qed | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1443 | |
| 63652 | 1444 | lemma pos_zmult_eq_1_iff_lemma: "m * n = 1 \<Longrightarrow> m = 1 \<or> m = - 1" | 
| 1445 | for m n :: int | |
| 1446 | using abs_zmult_eq_1 [of m n] by arith | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1447 | |
| 35815 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35634diff
changeset | 1448 | lemma pos_zmult_eq_1_iff: | 
| 63652 | 1449 | fixes m n :: int | 
| 1450 | assumes "0 < m" | |
| 1451 | shows "m * n = 1 \<longleftrightarrow> m = 1 \<and> n = 1" | |
| 35815 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35634diff
changeset | 1452 | proof - | 
| 63652 | 1453 | from assms have "m * n = 1 \<Longrightarrow> m = 1" | 
| 1454 | by (auto dest: pos_zmult_eq_1_iff_lemma) | |
| 1455 | then show ?thesis | |
| 1456 | by (auto dest: pos_zmult_eq_1_iff_lemma) | |
| 35815 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35634diff
changeset | 1457 | qed | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1458 | |
| 63652 | 1459 | lemma zmult_eq_1_iff: "m * n = 1 \<longleftrightarrow> (m = 1 \<and> n = 1) \<or> (m = - 1 \<and> n = - 1)" | 
| 1460 | for m n :: int | |
| 1461 | apply (rule iffI) | |
| 1462 | apply (frule pos_zmult_eq_1_iff_lemma) | |
| 1463 | apply (simp add: mult.commute [of m]) | |
| 1464 | apply (frule pos_zmult_eq_1_iff_lemma) | |
| 1465 | apply auto | |
| 1466 | done | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1467 | |
| 69700 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69605diff
changeset | 1468 | lemma infinite_UNIV_int [simp]: "\<not> finite (UNIV::int set)" | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1469 | proof | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
33056diff
changeset | 1470 | assume "finite (UNIV::int set)" | 
| 61076 | 1471 | moreover have "inj (\<lambda>i::int. 2 * i)" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
33056diff
changeset | 1472 | by (rule injI) simp | 
| 61076 | 1473 | ultimately have "surj (\<lambda>i::int. 2 * i)" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
33056diff
changeset | 1474 | by (rule finite_UNIV_inj_surj) | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
33056diff
changeset | 1475 | then obtain i :: int where "1 = 2 * i" by (rule surjE) | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
33056diff
changeset | 1476 | then show False by (simp add: pos_zmult_eq_1_iff) | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1477 | qed | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1478 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1479 | |
| 60758 | 1480 | subsection \<open>The divides relation\<close> | 
| 33320 | 1481 | |
| 63652 | 1482 | lemma zdvd_antisym_nonneg: "0 \<le> m \<Longrightarrow> 0 \<le> n \<Longrightarrow> m dvd n \<Longrightarrow> n dvd m \<Longrightarrow> m = n" | 
| 1483 | for m n :: int | |
| 1484 | by (auto simp add: dvd_def mult.assoc zero_le_mult_iff zmult_eq_1_iff) | |
| 33320 | 1485 | |
| 63652 | 1486 | lemma zdvd_antisym_abs: | 
| 1487 | fixes a b :: int | |
| 1488 | assumes "a dvd b" and "b dvd a" | |
| 33320 | 1489 | shows "\<bar>a\<bar> = \<bar>b\<bar>" | 
| 63652 | 1490 | proof (cases "a = 0") | 
| 1491 | case True | |
| 1492 | with assms show ?thesis by simp | |
| 33657 | 1493 | next | 
| 63652 | 1494 | case False | 
| 1495 | from \<open>a dvd b\<close> obtain k where k: "b = a * k" | |
| 1496 | unfolding dvd_def by blast | |
| 1497 | from \<open>b dvd a\<close> obtain k' where k': "a = b * k'" | |
| 1498 | unfolding dvd_def by blast | |
| 1499 | from k k' have "a = a * k * k'" by simp | |
| 1500 | with mult_cancel_left1[where c="a" and b="k*k'"] have kk': "k * k' = 1" | |
| 1501 | using \<open>a \<noteq> 0\<close> by (simp add: mult.assoc) | |
| 1502 | then have "k = 1 \<and> k' = 1 \<or> k = -1 \<and> k' = -1" | |
| 1503 | by (simp add: zmult_eq_1_iff) | |
| 1504 | with k k' show ?thesis by auto | |
| 33320 | 1505 | qed | 
| 1506 | ||
| 63652 | 1507 | lemma zdvd_zdiffD: "k dvd m - n \<Longrightarrow> k dvd n \<Longrightarrow> k dvd m" | 
| 1508 | for k m n :: int | |
| 60162 | 1509 | using dvd_add_right_iff [of k "- n" m] by simp | 
| 33320 | 1510 | |
| 63652 | 1511 | lemma zdvd_reduce: "k dvd n + k * m \<longleftrightarrow> k dvd n" | 
| 1512 | for k m n :: int | |
| 58649 
a62065b5e1e2
generalized and consolidated some theorems concerning divisibility
 haftmann parents: 
58512diff
changeset | 1513 | using dvd_add_times_triv_right_iff [of k n m] by (simp add: ac_simps) | 
| 33320 | 1514 | |
| 1515 | lemma dvd_imp_le_int: | |
| 1516 | fixes d i :: int | |
| 1517 | assumes "i \<noteq> 0" and "d dvd i" | |
| 1518 | shows "\<bar>d\<bar> \<le> \<bar>i\<bar>" | |
| 1519 | proof - | |
| 60758 | 1520 | from \<open>d dvd i\<close> obtain k where "i = d * k" .. | 
| 1521 | with \<open>i \<noteq> 0\<close> have "k \<noteq> 0" by auto | |
| 33320 | 1522 | then have "1 \<le> \<bar>k\<bar>" and "0 \<le> \<bar>d\<bar>" by auto | 
| 1523 | then have "\<bar>d\<bar> * 1 \<le> \<bar>d\<bar> * \<bar>k\<bar>" by (rule mult_left_mono) | |
| 60758 | 1524 | with \<open>i = d * k\<close> show ?thesis by (simp add: abs_mult) | 
| 33320 | 1525 | qed | 
| 1526 | ||
| 1527 | lemma zdvd_not_zless: | |
| 1528 | fixes m n :: int | |
| 1529 | assumes "0 < m" and "m < n" | |
| 1530 | shows "\<not> n dvd m" | |
| 1531 | proof | |
| 1532 | from assms have "0 < n" by auto | |
| 1533 | assume "n dvd m" then obtain k where k: "m = n * k" .. | |
| 60758 | 1534 | with \<open>0 < m\<close> have "0 < n * k" by auto | 
| 1535 | with \<open>0 < n\<close> have "0 < k" by (simp add: zero_less_mult_iff) | |
| 1536 | with k \<open>0 < n\<close> \<open>m < n\<close> have "n * k < n * 1" by simp | |
| 1537 | with \<open>0 < n\<close> \<open>0 < k\<close> show False unfolding mult_less_cancel_left by auto | |
| 33320 | 1538 | qed | 
| 1539 | ||
| 63652 | 1540 | lemma zdvd_mult_cancel: | 
| 1541 | fixes k m n :: int | |
| 1542 | assumes d: "k * m dvd k * n" | |
| 1543 | and "k \<noteq> 0" | |
| 33320 | 1544 | shows "m dvd n" | 
| 63652 | 1545 | proof - | 
| 1546 | from d obtain h where h: "k * n = k * m * h" | |
| 1547 | unfolding dvd_def by blast | |
| 1548 | have "n = m * h" | |
| 1549 | proof (rule ccontr) | |
| 1550 | assume "\<not> ?thesis" | |
| 1551 | with \<open>k \<noteq> 0\<close> have "k * n \<noteq> k * (m * h)" by simp | |
| 1552 | with h show False | |
| 1553 | by (simp add: mult.assoc) | |
| 1554 | qed | |
| 1555 | then show ?thesis by simp | |
| 33320 | 1556 | qed | 
| 1557 | ||
| 67118 | 1558 | lemma int_dvd_int_iff [simp]: | 
| 1559 | "int m dvd int n \<longleftrightarrow> m dvd n" | |
| 33320 | 1560 | proof - | 
| 67118 | 1561 | have "m dvd n" if "int n = int m * k" for k | 
| 63652 | 1562 | proof (cases k) | 
| 67118 | 1563 | case (nonneg q) | 
| 1564 | with that have "n = m * q" | |
| 63652 | 1565 | by (simp del: of_nat_mult add: of_nat_mult [symmetric]) | 
| 1566 | then show ?thesis .. | |
| 1567 | next | |
| 67118 | 1568 | case (neg q) | 
| 1569 | with that have "int n = int m * (- int (Suc q))" | |
| 63652 | 1570 | by simp | 
| 67118 | 1571 | also have "\<dots> = - (int m * int (Suc q))" | 
| 63652 | 1572 | by (simp only: mult_minus_right) | 
| 67118 | 1573 | also have "\<dots> = - int (m * Suc q)" | 
| 63652 | 1574 | by (simp only: of_nat_mult [symmetric]) | 
| 67118 | 1575 | finally have "- int (m * Suc q) = int n" .. | 
| 63652 | 1576 | then show ?thesis | 
| 1577 | by (simp only: negative_eq_positive) auto | |
| 33320 | 1578 | qed | 
| 67118 | 1579 | then show ?thesis by (auto simp add: dvd_def) | 
| 33320 | 1580 | qed | 
| 1581 | ||
| 67118 | 1582 | lemma dvd_nat_abs_iff [simp]: | 
| 1583 | "n dvd nat \<bar>k\<bar> \<longleftrightarrow> int n dvd k" | |
| 1584 | proof - | |
| 1585 | have "n dvd nat \<bar>k\<bar> \<longleftrightarrow> int n dvd int (nat \<bar>k\<bar>)" | |
| 1586 | by (simp only: int_dvd_int_iff) | |
| 1587 | then show ?thesis | |
| 1588 | by simp | |
| 1589 | qed | |
| 1590 | ||
| 1591 | lemma nat_abs_dvd_iff [simp]: | |
| 1592 | "nat \<bar>k\<bar> dvd n \<longleftrightarrow> k dvd int n" | |
| 1593 | proof - | |
| 1594 | have "nat \<bar>k\<bar> dvd n \<longleftrightarrow> int (nat \<bar>k\<bar>) dvd int n" | |
| 1595 | by (simp only: int_dvd_int_iff) | |
| 1596 | then show ?thesis | |
| 1597 | by simp | |
| 1598 | qed | |
| 1599 | ||
| 1600 | lemma zdvd1_eq [simp]: "x dvd 1 \<longleftrightarrow> \<bar>x\<bar> = 1" (is "?lhs \<longleftrightarrow> ?rhs") | |
| 63652 | 1601 | for x :: int | 
| 33320 | 1602 | proof | 
| 63652 | 1603 | assume ?lhs | 
| 67118 | 1604 | then have "nat \<bar>x\<bar> dvd nat \<bar>1\<bar>" | 
| 1605 | by (simp only: nat_abs_dvd_iff) simp | |
| 1606 | then have "nat \<bar>x\<bar> = 1" | |
| 1607 | by simp | |
| 1608 | then show ?rhs | |
| 1609 | by (cases "x < 0") simp_all | |
| 33320 | 1610 | next | 
| 63652 | 1611 | assume ?rhs | 
| 67118 | 1612 | then have "x = 1 \<or> x = - 1" | 
| 1613 | by auto | |
| 1614 | then show ?lhs | |
| 1615 | by (auto intro: dvdI) | |
| 33320 | 1616 | qed | 
| 1617 | ||
| 60162 | 1618 | lemma zdvd_mult_cancel1: | 
| 63652 | 1619 | fixes m :: int | 
| 1620 | assumes mp: "m \<noteq> 0" | |
| 1621 | shows "m * n dvd m \<longleftrightarrow> \<bar>n\<bar> = 1" | |
| 1622 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 33320 | 1623 | proof | 
| 63652 | 1624 | assume ?rhs | 
| 1625 | then show ?lhs | |
| 1626 | by (cases "n > 0") (auto simp add: minus_equation_iff) | |
| 33320 | 1627 | next | 
| 63652 | 1628 | assume ?lhs | 
| 1629 | then have "m * n dvd m * 1" by simp | |
| 1630 | from zdvd_mult_cancel[OF this mp] show ?rhs | |
| 1631 | by (simp only: zdvd1_eq) | |
| 33320 | 1632 | qed | 
| 1633 | ||
| 63652 | 1634 | lemma nat_dvd_iff: "nat z dvd m \<longleftrightarrow> (if 0 \<le> z then z dvd int m else m = 0)" | 
| 67118 | 1635 | using nat_abs_dvd_iff [of z m] by (cases "z \<ge> 0") auto | 
| 33320 | 1636 | |
| 63652 | 1637 | lemma eq_nat_nat_iff: "0 \<le> z \<Longrightarrow> 0 \<le> z' \<Longrightarrow> nat z = nat z' \<longleftrightarrow> z = z'" | 
| 67116 | 1638 | by (auto elim: nonneg_int_cases) | 
| 33341 | 1639 | |
| 63652 | 1640 | lemma nat_power_eq: "0 \<le> z \<Longrightarrow> nat (z ^ n) = nat z ^ n" | 
| 33341 | 1641 | by (induct n) (simp_all add: nat_mult_distrib) | 
| 1642 | ||
| 66912 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1643 | lemma numeral_power_eq_nat_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1644 | "numeral x ^ n = nat y \<longleftrightarrow> numeral x ^ n = y" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1645 | using nat_eq_iff2 by auto | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1646 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1647 | lemma nat_eq_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1648 | "nat y = numeral x ^ n \<longleftrightarrow> y = numeral x ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1649 | using numeral_power_eq_nat_cancel_iff[of x n y] | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1650 | by (metis (mono_tags)) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1651 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1652 | lemma numeral_power_le_nat_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1653 | "numeral x ^ n \<le> nat a \<longleftrightarrow> numeral x ^ n \<le> a" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1654 | using nat_le_eq_zle[of "numeral x ^ n" a] | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1655 | by (auto simp: nat_power_eq) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1656 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1657 | lemma nat_le_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1658 | "nat a \<le> numeral x ^ n \<longleftrightarrow> a \<le> numeral x ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1659 | by (simp add: nat_le_iff) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1660 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1661 | lemma numeral_power_less_nat_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1662 | "numeral x ^ n < nat a \<longleftrightarrow> numeral x ^ n < a" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1663 | using nat_less_eq_zless[of "numeral x ^ n" a] | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1664 | by (auto simp: nat_power_eq) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1665 | |
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1666 | lemma nat_less_numeral_power_cancel_iff [simp]: | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1667 | "nat a < numeral x ^ n \<longleftrightarrow> a < numeral x ^ n" | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1668 | using nat_less_eq_zless[of a "numeral x ^ n"] | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1669 | by (cases "a < 0") (auto simp: nat_power_eq less_le_trans[where y=0]) | 
| 
a99a7cbf0fb5
generalized lemmas cancelling real_of_int/real in (in)equalities with power; completed set of related simp rules; lemmas about floorlog/bitlen
 immler parents: 
66886diff
changeset | 1670 | |
| 63652 | 1671 | lemma zdvd_imp_le: "z dvd n \<Longrightarrow> 0 < n \<Longrightarrow> z \<le> n" | 
| 1672 | for n z :: int | |
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1673 | apply (cases n) | 
| 67118 | 1674 | apply auto | 
| 42676 
8724f20bf69c
proper case_names for int_cases, int_of_nat_induct;
 wenzelm parents: 
42411diff
changeset | 1675 | apply (cases z) | 
| 63652 | 1676 | apply (auto simp add: dvd_imp_le) | 
| 33320 | 1677 | done | 
| 1678 | ||
| 36749 | 1679 | lemma zdvd_period: | 
| 1680 | fixes a d :: int | |
| 1681 | assumes "a dvd d" | |
| 1682 | shows "a dvd (x + t) \<longleftrightarrow> a dvd ((x + c * d) + t)" | |
| 63652 | 1683 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 36749 | 1684 | proof - | 
| 66816 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 1685 | from assms have "a dvd (x + t) \<longleftrightarrow> a dvd ((x + t) + c * d)" | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 1686 | by (simp add: dvd_add_left_iff) | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 1687 | then show ?thesis | 
| 
212a3334e7da
more fundamental definition of div and mod on int
 haftmann parents: 
66035diff
changeset | 1688 | by (simp add: ac_simps) | 
| 36749 | 1689 | qed | 
| 1690 | ||
| 33320 | 1691 | |
| 60758 | 1692 | subsection \<open>Finiteness of intervals\<close> | 
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1693 | |
| 63652 | 1694 | lemma finite_interval_int1 [iff]: "finite {i :: int. a \<le> i \<and> i \<le> b}"
 | 
| 1695 | proof (cases "a \<le> b") | |
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1696 | case True | 
| 63652 | 1697 | then show ?thesis | 
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1698 | proof (induct b rule: int_ge_induct) | 
| 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1699 | case base | 
| 63652 | 1700 |     have "{i. a \<le> i \<and> i \<le> a} = {a}" by auto
 | 
| 1701 | then show ?case by simp | |
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1702 | next | 
| 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1703 | case (step b) | 
| 63652 | 1704 |     then have "{i. a \<le> i \<and> i \<le> b + 1} = {i. a \<le> i \<and> i \<le> b} \<union> {b + 1}" by auto
 | 
| 1705 | with step show ?case by simp | |
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1706 | qed | 
| 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1707 | next | 
| 63652 | 1708 | case False | 
| 1709 | then show ?thesis | |
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1710 | by (metis (lifting, no_types) Collect_empty_eq finite.emptyI order_trans) | 
| 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1711 | qed | 
| 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1712 | |
| 63652 | 1713 | lemma finite_interval_int2 [iff]: "finite {i :: int. a \<le> i \<and> i < b}"
 | 
| 1714 | by (rule rev_finite_subset[OF finite_interval_int1[of "a" "b"]]) auto | |
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1715 | |
| 63652 | 1716 | lemma finite_interval_int3 [iff]: "finite {i :: int. a < i \<and> i \<le> b}"
 | 
| 1717 | by (rule rev_finite_subset[OF finite_interval_int1[of "a" "b"]]) auto | |
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1718 | |
| 63652 | 1719 | lemma finite_interval_int4 [iff]: "finite {i :: int. a < i \<and> i < b}"
 | 
| 1720 | by (rule rev_finite_subset[OF finite_interval_int1[of "a" "b"]]) auto | |
| 46756 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1721 | |
| 
faf62905cd53
adding finiteness of intervals on integer sets; adding another finiteness theorem for multisets
 bulwahn parents: 
46027diff
changeset | 1722 | |
| 60758 | 1723 | subsection \<open>Configuration of the code generator\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1724 | |
| 60758 | 1725 | text \<open>Constructors\<close> | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1726 | |
| 63652 | 1727 | definition Pos :: "num \<Rightarrow> int" | 
| 1728 | where [simp, code_abbrev]: "Pos = numeral" | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1729 | |
| 63652 | 1730 | definition Neg :: "num \<Rightarrow> int" | 
| 1731 | where [simp, code_abbrev]: "Neg n = - (Pos n)" | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1732 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1733 | code_datatype "0::int" Pos Neg | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1734 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1735 | |
| 63652 | 1736 | text \<open>Auxiliary operations.\<close> | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1737 | |
| 63652 | 1738 | definition dup :: "int \<Rightarrow> int" | 
| 1739 | where [simp]: "dup k = k + k" | |
| 26507 | 1740 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1741 | lemma dup_code [code]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1742 | "dup 0 = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1743 | "dup (Pos n) = Pos (Num.Bit0 n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1744 | "dup (Neg n) = Neg (Num.Bit0 n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1745 | by (simp_all add: numeral_Bit0) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1746 | |
| 63652 | 1747 | definition sub :: "num \<Rightarrow> num \<Rightarrow> int" | 
| 1748 | where [simp]: "sub m n = numeral m - numeral n" | |
| 26507 | 1749 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1750 | lemma sub_code [code]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1751 | "sub Num.One Num.One = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1752 | "sub (Num.Bit0 m) Num.One = Pos (Num.BitM m)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1753 | "sub (Num.Bit1 m) Num.One = Pos (Num.Bit0 m)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1754 | "sub Num.One (Num.Bit0 n) = Neg (Num.BitM n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1755 | "sub Num.One (Num.Bit1 n) = Neg (Num.Bit0 n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1756 | "sub (Num.Bit0 m) (Num.Bit0 n) = dup (sub m n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1757 | "sub (Num.Bit1 m) (Num.Bit1 n) = dup (sub m n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1758 | "sub (Num.Bit1 m) (Num.Bit0 n) = dup (sub m n) + 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1759 | "sub (Num.Bit0 m) (Num.Bit1 n) = dup (sub m n) - 1" | 
| 66035 
de6cd60b1226
replace non-arithmetic terms by fresh variables before replaying linear-arithmetic proofs: avoid failed proof replays due to an overambitious simpset which may cause proof replay to diverge from the pre-computed proof trace
 boehmes parents: 
64996diff
changeset | 1760 | by (simp_all only: sub_def dup_def numeral.simps Pos_def Neg_def numeral_BitM) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1761 | |
| 63652 | 1762 | text \<open>Implementations.\<close> | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1763 | |
| 64996 | 1764 | lemma one_int_code [code]: "1 = Pos Num.One" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1765 | by simp | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1766 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1767 | lemma plus_int_code [code]: | 
| 63652 | 1768 | "k + 0 = k" | 
| 1769 | "0 + l = l" | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1770 | "Pos m + Pos n = Pos (m + n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1771 | "Pos m + Neg n = sub m n" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1772 | "Neg m + Pos n = sub n m" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1773 | "Neg m + Neg n = Neg (m + n)" | 
| 63652 | 1774 | for k l :: int | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1775 | by simp_all | 
| 26507 | 1776 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1777 | lemma uminus_int_code [code]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1778 | "uminus 0 = (0::int)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1779 | "uminus (Pos m) = Neg m" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1780 | "uminus (Neg m) = Pos m" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1781 | by simp_all | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1782 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1783 | lemma minus_int_code [code]: | 
| 63652 | 1784 | "k - 0 = k" | 
| 1785 | "0 - l = uminus l" | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1786 | "Pos m - Pos n = sub m n" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1787 | "Pos m - Neg n = Pos (m + n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1788 | "Neg m - Pos n = Neg (m + n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1789 | "Neg m - Neg n = sub n m" | 
| 63652 | 1790 | for k l :: int | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1791 | by simp_all | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1792 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1793 | lemma times_int_code [code]: | 
| 63652 | 1794 | "k * 0 = 0" | 
| 1795 | "0 * l = 0" | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1796 | "Pos m * Pos n = Pos (m * n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1797 | "Pos m * Neg n = Neg (m * n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1798 | "Neg m * Pos n = Neg (m * n)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1799 | "Neg m * Neg n = Pos (m * n)" | 
| 63652 | 1800 | for k l :: int | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1801 | by simp_all | 
| 26507 | 1802 | |
| 38857 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
 haftmann parents: 
37887diff
changeset | 1803 | instantiation int :: equal | 
| 26507 | 1804 | begin | 
| 1805 | ||
| 63652 | 1806 | definition "HOL.equal k l \<longleftrightarrow> k = (l::int)" | 
| 38857 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
 haftmann parents: 
37887diff
changeset | 1807 | |
| 61169 | 1808 | instance | 
| 1809 | by standard (rule equal_int_def) | |
| 26507 | 1810 | |
| 1811 | end | |
| 1812 | ||
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1813 | lemma equal_int_code [code]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1814 | "HOL.equal 0 (0::int) \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1815 | "HOL.equal 0 (Pos l) \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1816 | "HOL.equal 0 (Neg l) \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1817 | "HOL.equal (Pos k) 0 \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1818 | "HOL.equal (Pos k) (Pos l) \<longleftrightarrow> HOL.equal k l" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1819 | "HOL.equal (Pos k) (Neg l) \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1820 | "HOL.equal (Neg k) 0 \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1821 | "HOL.equal (Neg k) (Pos l) \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1822 | "HOL.equal (Neg k) (Neg l) \<longleftrightarrow> HOL.equal k l" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1823 | by (auto simp add: equal) | 
| 26507 | 1824 | |
| 63652 | 1825 | lemma equal_int_refl [code nbe]: "HOL.equal k k \<longleftrightarrow> True" | 
| 1826 | for k :: int | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1827 | by (fact equal_refl) | 
| 26507 | 1828 | |
| 28562 | 1829 | lemma less_eq_int_code [code]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1830 | "0 \<le> (0::int) \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1831 | "0 \<le> Pos l \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1832 | "0 \<le> Neg l \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1833 | "Pos k \<le> 0 \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1834 | "Pos k \<le> Pos l \<longleftrightarrow> k \<le> l" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1835 | "Pos k \<le> Neg l \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1836 | "Neg k \<le> 0 \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1837 | "Neg k \<le> Pos l \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1838 | "Neg k \<le> Neg l \<longleftrightarrow> l \<le> k" | 
| 28958 | 1839 | by simp_all | 
| 26507 | 1840 | |
| 28562 | 1841 | lemma less_int_code [code]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1842 | "0 < (0::int) \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1843 | "0 < Pos l \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1844 | "0 < Neg l \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1845 | "Pos k < 0 \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1846 | "Pos k < Pos l \<longleftrightarrow> k < l" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1847 | "Pos k < Neg l \<longleftrightarrow> False" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1848 | "Neg k < 0 \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1849 | "Neg k < Pos l \<longleftrightarrow> True" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1850 | "Neg k < Neg l \<longleftrightarrow> l < k" | 
| 28958 | 1851 | by simp_all | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1852 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1853 | lemma nat_code [code]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1854 | "nat (Int.Neg k) = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1855 | "nat 0 = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1856 | "nat (Int.Pos k) = nat_of_num k" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1857 | by (simp_all add: nat_of_num_numeral) | 
| 25928 | 1858 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1859 | lemma (in ring_1) of_int_code [code]: | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1860 | "of_int (Int.Neg k) = - numeral k" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1861 | "of_int 0 = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1862 | "of_int (Int.Pos k) = numeral k" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1863 | by simp_all | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1864 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1865 | |
| 63652 | 1866 | text \<open>Serializer setup.\<close> | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1867 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51994diff
changeset | 1868 | code_identifier | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
51994diff
changeset | 1869 | code_module Int \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1870 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1871 | quickcheck_params [default_type = int] | 
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1872 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46756diff
changeset | 1873 | hide_const (open) Pos Neg sub dup | 
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1874 | |
| 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1875 | |
| 61799 | 1876 | text \<open>De-register \<open>int\<close> as a quotient type:\<close> | 
| 48045 | 1877 | |
| 53652 
18fbca265e2e
use lifting_forget for deregistering numeric types as a quotient type
 kuncar parents: 
53065diff
changeset | 1878 | lifting_update int.lifting | 
| 
18fbca265e2e
use lifting_forget for deregistering numeric types as a quotient type
 kuncar parents: 
53065diff
changeset | 1879 | lifting_forget int.lifting | 
| 48045 | 1880 | |
| 67116 | 1881 | |
| 1882 | subsection \<open>Duplicates\<close> | |
| 1883 | ||
| 1884 | lemmas int_sum = of_nat_sum [where 'a=int] | |
| 1885 | lemmas int_prod = of_nat_prod [where 'a=int] | |
| 1886 | lemmas zle_int = of_nat_le_iff [where 'a=int] | |
| 1887 | lemmas int_int_eq = of_nat_eq_iff [where 'a=int] | |
| 1888 | lemmas nonneg_eq_int = nonneg_int_cases | |
| 1889 | lemmas double_eq_0_iff = double_zero | |
| 1890 | ||
| 1891 | lemmas int_distrib = | |
| 1892 | distrib_right [of z1 z2 w] | |
| 1893 | distrib_left [of w z1 z2] | |
| 1894 | left_diff_distrib [of z1 z2 w] | |
| 1895 | right_diff_distrib [of w z1 z2] | |
| 1896 | for z1 z2 w :: int | |
| 1897 | ||
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: diff
changeset | 1898 | end | 
| 67116 | 1899 |