| author | haftmann | 
| Mon, 26 Apr 2010 11:34:15 +0200 | |
| changeset 36348 | 89c54f51f55a | 
| parent 35815 | 10e723e54076 | 
| child 36699 | 816da1023508 | 
| permissions | -rw-r--r-- | 
| 30925 | 1 | (* Title: HOL/Nat_Numeral.thy | 
| 23164 | 2 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | 
| 3 | Copyright 1999 University of Cambridge | |
| 4 | *) | |
| 5 | ||
| 30925 | 6 | header {* Binary numerals for the natural numbers *}
 | 
| 23164 | 7 | |
| 30925 | 8 | theory Nat_Numeral | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 9 | imports Int | 
| 23164 | 10 | begin | 
| 11 | ||
| 31014 | 12 | subsection {* Numerals for natural numbers *}
 | 
| 13 | ||
| 23164 | 14 | text {*
 | 
| 15 | Arithmetic for naturals is reduced to that for the non-negative integers. | |
| 16 | *} | |
| 17 | ||
| 25571 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 18 | instantiation nat :: number | 
| 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 19 | begin | 
| 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 20 | |
| 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 21 | definition | 
| 32069 
6d28bbd33e2c
prefer code_inline over code_unfold; use code_unfold_post where appropriate
 haftmann parents: 
31998diff
changeset | 22 | nat_number_of_def [code_unfold, code del]: "number_of v = nat (number_of v)" | 
| 25571 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 23 | |
| 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 24 | instance .. | 
| 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 25 | |
| 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25481diff
changeset | 26 | end | 
| 23164 | 27 | |
| 31998 
2c7a24f74db9
code attributes use common underscore convention
 haftmann parents: 
31790diff
changeset | 28 | lemma [code_post]: | 
| 25965 | 29 | "nat (number_of v) = number_of v" | 
| 30 | unfolding nat_number_of_def .. | |
| 31 | ||
| 31014 | 32 | |
| 33 | subsection {* Special case: squares and cubes *}
 | |
| 34 | ||
| 35 | lemma numeral_2_eq_2: "2 = Suc (Suc 0)" | |
| 36 | by (simp add: nat_number_of_def) | |
| 37 | ||
| 38 | lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))" | |
| 39 | by (simp add: nat_number_of_def) | |
| 40 | ||
| 41 | context power | |
| 30960 | 42 | begin | 
| 43 | ||
| 23164 | 44 | abbreviation (xsymbols) | 
| 30960 | 45 |   power2 :: "'a \<Rightarrow> 'a"  ("(_\<twosuperior>)" [1000] 999) where
 | 
| 46 | "x\<twosuperior> \<equiv> x ^ 2" | |
| 23164 | 47 | |
| 48 | notation (latex output) | |
| 29401 
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
 huffman parents: 
29045diff
changeset | 49 |   power2  ("(_\<twosuperior>)" [1000] 999)
 | 
| 23164 | 50 | |
| 51 | notation (HTML output) | |
| 29401 
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
 huffman parents: 
29045diff
changeset | 52 |   power2  ("(_\<twosuperior>)" [1000] 999)
 | 
| 23164 | 53 | |
| 30960 | 54 | end | 
| 55 | ||
| 31014 | 56 | context monoid_mult | 
| 57 | begin | |
| 58 | ||
| 59 | lemma power2_eq_square: "a\<twosuperior> = a * a" | |
| 60 | by (simp add: numeral_2_eq_2) | |
| 61 | ||
| 62 | lemma power3_eq_cube: "a ^ 3 = a * a * a" | |
| 63 | by (simp add: numeral_3_eq_3 mult_assoc) | |
| 64 | ||
| 65 | lemma power_even_eq: | |
| 66 | "a ^ (2*n) = (a ^ n) ^ 2" | |
| 35047 
1b2bae06c796
hide fact Nat.add_0_right; make add_0_right from Groups priority
 haftmann parents: 
35043diff
changeset | 67 | by (subst mult_commute) (simp add: power_mult) | 
| 31014 | 68 | |
| 69 | lemma power_odd_eq: | |
| 70 | "a ^ Suc (2*n) = a * (a ^ n) ^ 2" | |
| 71 | by (simp add: power_even_eq) | |
| 72 | ||
| 73 | end | |
| 74 | ||
| 75 | context semiring_1 | |
| 76 | begin | |
| 77 | ||
| 78 | lemma zero_power2 [simp]: "0\<twosuperior> = 0" | |
| 79 | by (simp add: power2_eq_square) | |
| 80 | ||
| 81 | lemma one_power2 [simp]: "1\<twosuperior> = 1" | |
| 82 | by (simp add: power2_eq_square) | |
| 83 | ||
| 84 | end | |
| 85 | ||
| 86 | context comm_ring_1 | |
| 87 | begin | |
| 88 | ||
| 89 | lemma power2_minus [simp]: | |
| 90 | "(- a)\<twosuperior> = a\<twosuperior>" | |
| 91 | by (simp add: power2_eq_square) | |
| 92 | ||
| 93 | text{*
 | |
| 94 |   We cannot prove general results about the numeral @{term "-1"},
 | |
| 95 |   so we have to use @{term "- 1"} instead.
 | |
| 96 | *} | |
| 97 | ||
| 98 | lemma power_minus1_even [simp]: | |
| 99 | "(- 1) ^ (2*n) = 1" | |
| 100 | proof (induct n) | |
| 101 | case 0 show ?case by simp | |
| 102 | next | |
| 103 | case (Suc n) then show ?case by (simp add: power_add) | |
| 104 | qed | |
| 105 | ||
| 106 | lemma power_minus1_odd: | |
| 107 | "(- 1) ^ Suc (2*n) = - 1" | |
| 108 | by simp | |
| 109 | ||
| 110 | lemma power_minus_even [simp]: | |
| 111 | "(-a) ^ (2*n) = a ^ (2*n)" | |
| 112 | by (simp add: power_minus [of a]) | |
| 113 | ||
| 114 | end | |
| 115 | ||
| 35631 
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
 huffman parents: 
35216diff
changeset | 116 | context linordered_ring | 
| 31014 | 117 | begin | 
| 118 | ||
| 119 | lemma sum_squares_ge_zero: | |
| 120 | "0 \<le> x * x + y * y" | |
| 121 | by (intro add_nonneg_nonneg zero_le_square) | |
| 122 | ||
| 123 | lemma not_sum_squares_lt_zero: | |
| 124 | "\<not> x * x + y * y < 0" | |
| 125 | by (simp add: not_less sum_squares_ge_zero) | |
| 126 | ||
| 35631 
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
 huffman parents: 
35216diff
changeset | 127 | end | 
| 
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
 huffman parents: 
35216diff
changeset | 128 | |
| 
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
 huffman parents: 
35216diff
changeset | 129 | context linordered_ring_strict | 
| 
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
 huffman parents: 
35216diff
changeset | 130 | begin | 
| 
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
 huffman parents: 
35216diff
changeset | 131 | |
| 31014 | 132 | lemma sum_squares_eq_zero_iff: | 
| 133 | "x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 31034 | 134 | by (simp add: add_nonneg_eq_0_iff) | 
| 31014 | 135 | |
| 136 | lemma sum_squares_le_zero_iff: | |
| 137 | "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 138 | by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff) | |
| 139 | ||
| 140 | lemma sum_squares_gt_zero_iff: | |
| 141 | "0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" | |
| 35631 
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
 huffman parents: 
35216diff
changeset | 142 | by (simp add: not_le [symmetric] sum_squares_le_zero_iff) | 
| 31014 | 143 | |
| 144 | end | |
| 145 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
33342diff
changeset | 146 | context linordered_semidom | 
| 31014 | 147 | begin | 
| 148 | ||
| 149 | lemma power2_le_imp_le: | |
| 150 | "x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y" | |
| 151 | unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) | |
| 152 | ||
| 153 | lemma power2_less_imp_less: | |
| 154 | "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y" | |
| 155 | by (rule power_less_imp_less_base) | |
| 156 | ||
| 157 | lemma power2_eq_imp_eq: | |
| 158 | "x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y" | |
| 159 | unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp | |
| 160 | ||
| 161 | end | |
| 162 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
33342diff
changeset | 163 | context linordered_idom | 
| 31014 | 164 | begin | 
| 165 | ||
| 166 | lemma zero_eq_power2 [simp]: | |
| 167 | "a\<twosuperior> = 0 \<longleftrightarrow> a = 0" | |
| 168 | by (force simp add: power2_eq_square) | |
| 169 | ||
| 170 | lemma zero_le_power2 [simp]: | |
| 171 | "0 \<le> a\<twosuperior>" | |
| 172 | by (simp add: power2_eq_square) | |
| 173 | ||
| 174 | lemma zero_less_power2 [simp]: | |
| 175 | "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0" | |
| 176 | by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) | |
| 177 | ||
| 178 | lemma power2_less_0 [simp]: | |
| 179 | "\<not> a\<twosuperior> < 0" | |
| 180 | by (force simp add: power2_eq_square mult_less_0_iff) | |
| 181 | ||
| 182 | lemma abs_power2 [simp]: | |
| 183 | "abs (a\<twosuperior>) = a\<twosuperior>" | |
| 184 | by (simp add: power2_eq_square abs_mult abs_mult_self) | |
| 185 | ||
| 186 | lemma power2_abs [simp]: | |
| 187 | "(abs a)\<twosuperior> = a\<twosuperior>" | |
| 188 | by (simp add: power2_eq_square abs_mult_self) | |
| 189 | ||
| 190 | lemma odd_power_less_zero: | |
| 191 | "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0" | |
| 192 | proof (induct n) | |
| 193 | case 0 | |
| 194 | then show ?case by simp | |
| 195 | next | |
| 196 | case (Suc n) | |
| 197 | have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" | |
| 198 | by (simp add: mult_ac power_add power2_eq_square) | |
| 199 | thus ?case | |
| 200 | by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg) | |
| 201 | qed | |
| 202 | ||
| 203 | lemma odd_0_le_power_imp_0_le: | |
| 204 | "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a" | |
| 205 | using odd_power_less_zero [of a n] | |
| 206 | by (force simp add: linorder_not_less [symmetric]) | |
| 207 | ||
| 208 | lemma zero_le_even_power'[simp]: | |
| 209 | "0 \<le> a ^ (2*n)" | |
| 210 | proof (induct n) | |
| 211 | case 0 | |
| 35216 | 212 | show ?case by simp | 
| 31014 | 213 | next | 
| 214 | case (Suc n) | |
| 215 | have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" | |
| 216 | by (simp add: mult_ac power_add power2_eq_square) | |
| 217 | thus ?case | |
| 218 | by (simp add: Suc zero_le_mult_iff) | |
| 219 | qed | |
| 220 | ||
| 221 | lemma sum_power2_ge_zero: | |
| 222 | "0 \<le> x\<twosuperior> + y\<twosuperior>" | |
| 223 | unfolding power2_eq_square by (rule sum_squares_ge_zero) | |
| 224 | ||
| 225 | lemma not_sum_power2_lt_zero: | |
| 226 | "\<not> x\<twosuperior> + y\<twosuperior> < 0" | |
| 227 | unfolding power2_eq_square by (rule not_sum_squares_lt_zero) | |
| 228 | ||
| 229 | lemma sum_power2_eq_zero_iff: | |
| 230 | "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 231 | unfolding power2_eq_square by (rule sum_squares_eq_zero_iff) | |
| 232 | ||
| 233 | lemma sum_power2_le_zero_iff: | |
| 234 | "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 235 | unfolding power2_eq_square by (rule sum_squares_le_zero_iff) | |
| 236 | ||
| 237 | lemma sum_power2_gt_zero_iff: | |
| 238 | "0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" | |
| 239 | unfolding power2_eq_square by (rule sum_squares_gt_zero_iff) | |
| 240 | ||
| 241 | end | |
| 242 | ||
| 243 | lemma power2_sum: | |
| 244 | fixes x y :: "'a::number_ring" | |
| 245 | shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y" | |
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 246 | by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute) | 
| 31014 | 247 | |
| 248 | lemma power2_diff: | |
| 249 | fixes x y :: "'a::number_ring" | |
| 250 | shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y" | |
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 251 | by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute) | 
| 31014 | 252 | |
| 23164 | 253 | |
| 29040 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 254 | subsection {* Predicate for negative binary numbers *}
 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 255 | |
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 256 | definition neg :: "int \<Rightarrow> bool" where | 
| 29040 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 257 | "neg Z \<longleftrightarrow> Z < 0" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 258 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 259 | lemma not_neg_int [simp]: "~ neg (of_nat n)" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 260 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 261 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 262 | lemma neg_zminus_int [simp]: "neg (- (of_nat (Suc n)))" | 
| 35216 | 263 | by (simp add: neg_def del: of_nat_Suc) | 
| 29040 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 264 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 265 | lemmas neg_eq_less_0 = neg_def | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 266 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 267 | lemma not_neg_eq_ge_0: "(~neg x) = (0 \<le> x)" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 268 | by (simp add: neg_def linorder_not_less) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 269 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 270 | text{*To simplify inequalities when Numeral1 can get simplified to 1*}
 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 271 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 272 | lemma not_neg_0: "~ neg 0" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 273 | by (simp add: One_int_def neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 274 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 275 | lemma not_neg_1: "~ neg 1" | 
| 35216 | 276 | by (simp add: neg_def linorder_not_less) | 
| 29040 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 277 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 278 | lemma neg_nat: "neg z ==> nat z = 0" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 279 | by (simp add: neg_def order_less_imp_le) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 280 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 281 | lemma not_neg_nat: "~ neg z ==> of_nat (nat z) = z" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 282 | by (simp add: linorder_not_less neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 283 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 284 | text {*
 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 285 |   If @{term Numeral0} is rewritten to 0 then this rule can't be applied:
 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 286 |   @{term Numeral0} IS @{term "number_of Pls"}
 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 287 | *} | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 288 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 289 | lemma not_neg_number_of_Pls: "~ neg (number_of Int.Pls)" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 290 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 291 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 292 | lemma neg_number_of_Min: "neg (number_of Int.Min)" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 293 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 294 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 295 | lemma neg_number_of_Bit0: | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 296 | "neg (number_of (Int.Bit0 w)) = neg (number_of w)" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 297 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 298 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 299 | lemma neg_number_of_Bit1: | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 300 | "neg (number_of (Int.Bit1 w)) = neg (number_of w)" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 301 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 302 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 303 | lemmas neg_simps [simp] = | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 304 | not_neg_0 not_neg_1 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 305 | not_neg_number_of_Pls neg_number_of_Min | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 306 | neg_number_of_Bit0 neg_number_of_Bit1 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 307 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 308 | |
| 23164 | 309 | subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
 | 
| 310 | ||
| 35216 | 311 | declare nat_1 [simp] | 
| 23164 | 312 | |
| 313 | lemma nat_number_of [simp]: "nat (number_of w) = number_of w" | |
| 314 | by (simp add: nat_number_of_def) | |
| 315 | ||
| 31998 
2c7a24f74db9
code attributes use common underscore convention
 haftmann parents: 
31790diff
changeset | 316 | lemma nat_numeral_0_eq_0 [simp, code_post]: "Numeral0 = (0::nat)" | 
| 23164 | 317 | by (simp add: nat_number_of_def) | 
| 318 | ||
| 319 | lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)" | |
| 35216 | 320 | by (simp add: nat_number_of_def) | 
| 23164 | 321 | |
| 31998 
2c7a24f74db9
code attributes use common underscore convention
 haftmann parents: 
31790diff
changeset | 322 | lemma numeral_1_eq_Suc_0 [code_post]: "Numeral1 = Suc 0" | 
| 35216 | 323 | by (simp only: nat_numeral_1_eq_1 One_nat_def) | 
| 23164 | 324 | |
| 325 | ||
| 326 | subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
 | |
| 327 | ||
| 328 | lemma int_nat_number_of [simp]: | |
| 23365 | 329 | "int (number_of v) = | 
| 23307 
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
 huffman parents: 
23294diff
changeset | 330 | (if neg (number_of v :: int) then 0 | 
| 
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
 huffman parents: 
23294diff
changeset | 331 | else (number_of v :: int))" | 
| 28984 | 332 | unfolding nat_number_of_def number_of_is_id neg_def | 
| 333 | by simp | |
| 23307 
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
 huffman parents: 
23294diff
changeset | 334 | |
| 23164 | 335 | |
| 336 | subsubsection{*Successor *}
 | |
| 337 | ||
| 338 | lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" | |
| 339 | apply (rule sym) | |
| 340 | apply (simp add: nat_eq_iff int_Suc) | |
| 341 | done | |
| 342 | ||
| 343 | lemma Suc_nat_number_of_add: | |
| 344 | "Suc (number_of v + n) = | |
| 28984 | 345 | (if neg (number_of v :: int) then 1+n else number_of (Int.succ v) + n)" | 
| 346 | unfolding nat_number_of_def number_of_is_id neg_def numeral_simps | |
| 347 | by (simp add: Suc_nat_eq_nat_zadd1 add_ac) | |
| 23164 | 348 | |
| 349 | lemma Suc_nat_number_of [simp]: | |
| 350 | "Suc (number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 351 | (if neg (number_of v :: int) then 1 else number_of (Int.succ v))" | 
| 23164 | 352 | apply (cut_tac n = 0 in Suc_nat_number_of_add) | 
| 353 | apply (simp cong del: if_weak_cong) | |
| 354 | done | |
| 355 | ||
| 356 | ||
| 357 | subsubsection{*Addition *}
 | |
| 358 | ||
| 359 | lemma add_nat_number_of [simp]: | |
| 360 | "(number_of v :: nat) + number_of v' = | |
| 29012 | 361 | (if v < Int.Pls then number_of v' | 
| 362 | else if v' < Int.Pls then number_of v | |
| 23164 | 363 | else number_of (v + v'))" | 
| 29012 | 364 | unfolding nat_number_of_def number_of_is_id numeral_simps | 
| 28984 | 365 | by (simp add: nat_add_distrib) | 
| 23164 | 366 | |
| 30081 | 367 | lemma nat_number_of_add_1 [simp]: | 
| 368 | "number_of v + (1::nat) = | |
| 369 | (if v < Int.Pls then 1 else number_of (Int.succ v))" | |
| 370 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 371 | by (simp add: nat_add_distrib) | |
| 372 | ||
| 373 | lemma nat_1_add_number_of [simp]: | |
| 374 | "(1::nat) + number_of v = | |
| 375 | (if v < Int.Pls then 1 else number_of (Int.succ v))" | |
| 376 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 377 | by (simp add: nat_add_distrib) | |
| 378 | ||
| 379 | lemma nat_1_add_1 [simp]: "1 + 1 = (2::nat)" | |
| 380 | by (rule int_int_eq [THEN iffD1]) simp | |
| 381 | ||
| 23164 | 382 | |
| 383 | subsubsection{*Subtraction *}
 | |
| 384 | ||
| 385 | lemma diff_nat_eq_if: | |
| 386 | "nat z - nat z' = | |
| 387 | (if neg z' then nat z | |
| 388 | else let d = z-z' in | |
| 389 | if neg d then 0 else nat d)" | |
| 27651 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 haftmann parents: 
26342diff
changeset | 390 | by (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0) | 
| 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 haftmann parents: 
26342diff
changeset | 391 | |
| 23164 | 392 | |
| 393 | lemma diff_nat_number_of [simp]: | |
| 394 | "(number_of v :: nat) - number_of v' = | |
| 29012 | 395 | (if v' < Int.Pls then number_of v | 
| 23164 | 396 | else let d = number_of (v + uminus v') in | 
| 397 | if neg d then 0 else nat d)" | |
| 29012 | 398 | unfolding nat_number_of_def number_of_is_id numeral_simps neg_def | 
| 399 | by auto | |
| 23164 | 400 | |
| 30081 | 401 | lemma nat_number_of_diff_1 [simp]: | 
| 402 | "number_of v - (1::nat) = | |
| 403 | (if v \<le> Int.Pls then 0 else number_of (Int.pred v))" | |
| 404 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 405 | by auto | |
| 406 | ||
| 23164 | 407 | |
| 408 | subsubsection{*Multiplication *}
 | |
| 409 | ||
| 410 | lemma mult_nat_number_of [simp]: | |
| 411 | "(number_of v :: nat) * number_of v' = | |
| 29012 | 412 | (if v < Int.Pls then 0 else number_of (v * v'))" | 
| 413 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 28984 | 414 | by (simp add: nat_mult_distrib) | 
| 23164 | 415 | |
| 416 | ||
| 417 | subsection{*Comparisons*}
 | |
| 418 | ||
| 419 | subsubsection{*Equals (=) *}
 | |
| 420 | ||
| 421 | lemma eq_nat_number_of [simp]: | |
| 422 | "((number_of v :: nat) = number_of v') = | |
| 28969 | 423 | (if neg (number_of v :: int) then (number_of v' :: int) \<le> 0 | 
| 424 | else if neg (number_of v' :: int) then (number_of v :: int) = 0 | |
| 425 | else v = v')" | |
| 426 | unfolding nat_number_of_def number_of_is_id neg_def | |
| 427 | by auto | |
| 23164 | 428 | |
| 429 | ||
| 430 | subsubsection{*Less-than (<) *}
 | |
| 431 | ||
| 432 | lemma less_nat_number_of [simp]: | |
| 29011 | 433 | "(number_of v :: nat) < number_of v' \<longleftrightarrow> | 
| 434 | (if v < v' then Int.Pls < v' else False)" | |
| 435 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 28961 | 436 | by auto | 
| 23164 | 437 | |
| 438 | ||
| 29010 | 439 | subsubsection{*Less-than-or-equal *}
 | 
| 440 | ||
| 441 | lemma le_nat_number_of [simp]: | |
| 442 | "(number_of v :: nat) \<le> number_of v' \<longleftrightarrow> | |
| 443 | (if v \<le> v' then True else v \<le> Int.Pls)" | |
| 444 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 445 | by auto | |
| 446 | ||
| 23164 | 447 | (*Maps #n to n for n = 0, 1, 2*) | 
| 448 | lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 | |
| 449 | ||
| 450 | ||
| 451 | subsection{*Powers with Numeric Exponents*}
 | |
| 452 | ||
| 453 | text{*Squares of literal numerals will be evaluated.*}
 | |
| 31014 | 454 | lemmas power2_eq_square_number_of [simp] = | 
| 23164 | 455 | power2_eq_square [of "number_of w", standard] | 
| 456 | ||
| 457 | ||
| 458 | text{*Simprules for comparisons where common factors can be cancelled.*}
 | |
| 459 | lemmas zero_compare_simps = | |
| 460 | add_strict_increasing add_strict_increasing2 add_increasing | |
| 461 | zero_le_mult_iff zero_le_divide_iff | |
| 462 | zero_less_mult_iff zero_less_divide_iff | |
| 463 | mult_le_0_iff divide_le_0_iff | |
| 464 | mult_less_0_iff divide_less_0_iff | |
| 465 | zero_le_power2 power2_less_0 | |
| 466 | ||
| 467 | subsubsection{*Nat *}
 | |
| 468 | ||
| 469 | lemma Suc_pred': "0 < n ==> n = Suc(n - 1)" | |
| 35216 | 470 | by simp | 
| 23164 | 471 | |
| 472 | (*Expresses a natural number constant as the Suc of another one. | |
| 473 | NOT suitable for rewriting because n recurs in the condition.*) | |
| 474 | lemmas expand_Suc = Suc_pred' [of "number_of v", standard] | |
| 475 | ||
| 476 | subsubsection{*Arith *}
 | |
| 477 | ||
| 31790 | 478 | lemma Suc_eq_plus1: "Suc n = n + 1" | 
| 35216 | 479 | unfolding One_nat_def by simp | 
| 23164 | 480 | |
| 31790 | 481 | lemma Suc_eq_plus1_left: "Suc n = 1 + n" | 
| 35216 | 482 | unfolding One_nat_def by simp | 
| 23164 | 483 | |
| 484 | (* These two can be useful when m = number_of... *) | |
| 485 | ||
| 486 | lemma add_eq_if: "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))" | |
| 30079 
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
 huffman parents: 
29958diff
changeset | 487 | unfolding One_nat_def by (cases m) simp_all | 
| 23164 | 488 | |
| 489 | lemma mult_eq_if: "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))" | |
| 30079 
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
 huffman parents: 
29958diff
changeset | 490 | unfolding One_nat_def by (cases m) simp_all | 
| 23164 | 491 | |
| 492 | lemma power_eq_if: "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))" | |
| 30079 
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
 huffman parents: 
29958diff
changeset | 493 | unfolding One_nat_def by (cases m) simp_all | 
| 23164 | 494 | |
| 495 | ||
| 496 | subsection{*Comparisons involving (0::nat) *}
 | |
| 497 | ||
| 498 | text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*}
 | |
| 499 | ||
| 500 | lemma eq_number_of_0 [simp]: | |
| 29012 | 501 | "number_of v = (0::nat) \<longleftrightarrow> v \<le> Int.Pls" | 
| 502 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 503 | by auto | |
| 23164 | 504 | |
| 505 | lemma eq_0_number_of [simp]: | |
| 29012 | 506 | "(0::nat) = number_of v \<longleftrightarrow> v \<le> Int.Pls" | 
| 23164 | 507 | by (rule trans [OF eq_sym_conv eq_number_of_0]) | 
| 508 | ||
| 509 | lemma less_0_number_of [simp]: | |
| 29012 | 510 | "(0::nat) < number_of v \<longleftrightarrow> Int.Pls < v" | 
| 511 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 512 | by simp | |
| 23164 | 513 | |
| 514 | lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)" | |
| 28969 | 515 | by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric]) | 
| 23164 | 516 | |
| 517 | ||
| 518 | ||
| 519 | subsection{*Comparisons involving  @{term Suc} *}
 | |
| 520 | ||
| 521 | lemma eq_number_of_Suc [simp]: | |
| 522 | "(number_of v = Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 523 | (let pv = number_of (Int.pred v) in | 
| 23164 | 524 | if neg pv then False else nat pv = n)" | 
| 525 | apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less | |
| 526 | number_of_pred nat_number_of_def | |
| 527 | split add: split_if) | |
| 528 | apply (rule_tac x = "number_of v" in spec) | |
| 529 | apply (auto simp add: nat_eq_iff) | |
| 530 | done | |
| 531 | ||
| 532 | lemma Suc_eq_number_of [simp]: | |
| 533 | "(Suc n = number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 534 | (let pv = number_of (Int.pred v) in | 
| 23164 | 535 | if neg pv then False else nat pv = n)" | 
| 536 | by (rule trans [OF eq_sym_conv eq_number_of_Suc]) | |
| 537 | ||
| 538 | lemma less_number_of_Suc [simp]: | |
| 539 | "(number_of v < Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 540 | (let pv = number_of (Int.pred v) in | 
| 23164 | 541 | if neg pv then True else nat pv < n)" | 
| 542 | apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less | |
| 543 | number_of_pred nat_number_of_def | |
| 544 | split add: split_if) | |
| 545 | apply (rule_tac x = "number_of v" in spec) | |
| 546 | apply (auto simp add: nat_less_iff) | |
| 547 | done | |
| 548 | ||
| 549 | lemma less_Suc_number_of [simp]: | |
| 550 | "(Suc n < number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 551 | (let pv = number_of (Int.pred v) in | 
| 23164 | 552 | if neg pv then False else n < nat pv)" | 
| 553 | apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less | |
| 554 | number_of_pred nat_number_of_def | |
| 555 | split add: split_if) | |
| 556 | apply (rule_tac x = "number_of v" in spec) | |
| 557 | apply (auto simp add: zless_nat_eq_int_zless) | |
| 558 | done | |
| 559 | ||
| 560 | lemma le_number_of_Suc [simp]: | |
| 561 | "(number_of v <= Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 562 | (let pv = number_of (Int.pred v) in | 
| 23164 | 563 | if neg pv then True else nat pv <= n)" | 
| 35216 | 564 | by (simp add: Let_def linorder_not_less [symmetric]) | 
| 23164 | 565 | |
| 566 | lemma le_Suc_number_of [simp]: | |
| 567 | "(Suc n <= number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 568 | (let pv = number_of (Int.pred v) in | 
| 23164 | 569 | if neg pv then False else n <= nat pv)" | 
| 35216 | 570 | by (simp add: Let_def linorder_not_less [symmetric]) | 
| 23164 | 571 | |
| 572 | ||
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 573 | lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min" | 
| 23164 | 574 | by auto | 
| 575 | ||
| 576 | ||
| 577 | ||
| 578 | subsection{*Max and Min Combined with @{term Suc} *}
 | |
| 579 | ||
| 580 | lemma max_number_of_Suc [simp]: | |
| 581 | "max (Suc n) (number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 582 | (let pv = number_of (Int.pred v) in | 
| 23164 | 583 | if neg pv then Suc n else Suc(max n (nat pv)))" | 
| 584 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 585 | split add: split_if nat.split) | |
| 586 | apply (rule_tac x = "number_of v" in spec) | |
| 587 | apply auto | |
| 588 | done | |
| 589 | ||
| 590 | lemma max_Suc_number_of [simp]: | |
| 591 | "max (number_of v) (Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 592 | (let pv = number_of (Int.pred v) in | 
| 23164 | 593 | if neg pv then Suc n else Suc(max (nat pv) n))" | 
| 594 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 595 | split add: split_if nat.split) | |
| 596 | apply (rule_tac x = "number_of v" in spec) | |
| 597 | apply auto | |
| 598 | done | |
| 599 | ||
| 600 | lemma min_number_of_Suc [simp]: | |
| 601 | "min (Suc n) (number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 602 | (let pv = number_of (Int.pred v) in | 
| 23164 | 603 | if neg pv then 0 else Suc(min n (nat pv)))" | 
| 604 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 605 | split add: split_if nat.split) | |
| 606 | apply (rule_tac x = "number_of v" in spec) | |
| 607 | apply auto | |
| 608 | done | |
| 609 | ||
| 610 | lemma min_Suc_number_of [simp]: | |
| 611 | "min (number_of v) (Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 612 | (let pv = number_of (Int.pred v) in | 
| 23164 | 613 | if neg pv then 0 else Suc(min (nat pv) n))" | 
| 614 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 615 | split add: split_if nat.split) | |
| 616 | apply (rule_tac x = "number_of v" in spec) | |
| 617 | apply auto | |
| 618 | done | |
| 619 | ||
| 620 | subsection{*Literal arithmetic involving powers*}
 | |
| 621 | ||
| 622 | lemma power_nat_number_of: | |
| 623 | "(number_of v :: nat) ^ n = | |
| 624 | (if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))" | |
| 625 | by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq | |
| 626 | split add: split_if cong: imp_cong) | |
| 627 | ||
| 628 | ||
| 629 | lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard] | |
| 630 | declare power_nat_number_of_number_of [simp] | |
| 631 | ||
| 632 | ||
| 633 | ||
| 23294 | 634 | text{*For arbitrary rings*}
 | 
| 23164 | 635 | |
| 23294 | 636 | lemma power_number_of_even: | 
| 31014 | 637 | fixes z :: "'a::number_ring" | 
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 638 | shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 639 | by (cases "w \<ge> 0") (auto simp add: Let_def Bit0_def nat_number_of_def number_of_is_id | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 640 | nat_add_distrib power_add simp del: nat_number_of) | 
| 23164 | 641 | |
| 23294 | 642 | lemma power_number_of_odd: | 
| 31014 | 643 | fixes z :: "'a::number_ring" | 
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 644 | shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w | 
| 23164 | 645 | then (let w = z ^ (number_of w) in z * w * w) else 1)" | 
| 35815 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35631diff
changeset | 646 | unfolding Let_def Bit1_def nat_number_of_def number_of_is_id | 
| 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35631diff
changeset | 647 | apply (cases "0 <= w") | 
| 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35631diff
changeset | 648 | apply (simp only: mult_assoc nat_add_distrib power_add, simp) | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 649 | apply (simp add: not_le mult_2 [symmetric] add_assoc) | 
| 23164 | 650 | done | 
| 651 | ||
| 23294 | 652 | lemmas zpower_number_of_even = power_number_of_even [where 'a=int] | 
| 653 | lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int] | |
| 23164 | 654 | |
| 23294 | 655 | lemmas power_number_of_even_number_of [simp] = | 
| 656 | power_number_of_even [of "number_of v", standard] | |
| 23164 | 657 | |
| 23294 | 658 | lemmas power_number_of_odd_number_of [simp] = | 
| 659 | power_number_of_odd [of "number_of v", standard] | |
| 23164 | 660 | |
| 661 | lemma nat_number_of_Pls: "Numeral0 = (0::nat)" | |
| 35216 | 662 | by (simp add: nat_number_of_def) | 
| 23164 | 663 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 664 | lemma nat_number_of_Min: "number_of Int.Min = (0::nat)" | 
| 23164 | 665 | apply (simp only: number_of_Min nat_number_of_def nat_zminus_int) | 
| 666 | done | |
| 667 | ||
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 668 | lemma nat_number_of_Bit0: | 
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 669 | "number_of (Int.Bit0 w) = (let n::nat = number_of w in n + n)" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 670 | by (cases "w \<ge> 0") (auto simp add: Let_def Bit0_def nat_number_of_def number_of_is_id | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 671 | nat_add_distrib simp del: nat_number_of) | 
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 672 | |
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 673 | lemma nat_number_of_Bit1: | 
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 674 | "number_of (Int.Bit1 w) = | 
| 23164 | 675 | (if neg (number_of w :: int) then 0 | 
| 676 | else let n = number_of w in Suc (n + n))" | |
| 35815 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35631diff
changeset | 677 | unfolding Let_def Bit1_def nat_number_of_def number_of_is_id neg_def | 
| 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35631diff
changeset | 678 | apply (cases "w < 0") | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 679 | apply (simp add: mult_2 [symmetric] add_assoc) | 
| 35815 
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
 boehmes parents: 
35631diff
changeset | 680 | apply (simp only: nat_add_distrib, simp) | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 681 | done | 
| 23164 | 682 | |
| 683 | lemmas nat_number = | |
| 684 | nat_number_of_Pls nat_number_of_Min | |
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 685 | nat_number_of_Bit0 nat_number_of_Bit1 | 
| 23164 | 686 | |
| 35216 | 687 | lemmas nat_number' = | 
| 688 | nat_number_of_Bit0 nat_number_of_Bit1 | |
| 689 | ||
| 23164 | 690 | lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 691 | by (fact Let_def) | 
| 23164 | 692 | |
| 31014 | 693 | lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring})"
 | 
| 694 | by (simp only: number_of_Min power_minus1_even) | |
| 23164 | 695 | |
| 31014 | 696 | lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring})"
 | 
| 697 | by (simp only: number_of_Min power_minus1_odd) | |
| 23164 | 698 | |
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 699 | lemma nat_number_of_add_left: | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 700 | "number_of v + (number_of v' + (k::nat)) = | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 701 | (if neg (number_of v :: int) then number_of v' + k | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 702 | else if neg (number_of v' :: int) then number_of v + k | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 703 | else number_of (v + v') + k)" | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 704 | by (auto simp add: neg_def) | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 705 | |
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 706 | lemma nat_number_of_mult_left: | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 707 | "number_of v * (number_of v' * (k::nat)) = | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 708 | (if v < Int.Pls then 0 | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 709 | else number_of (v * v') * k)" | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 710 | by (auto simp add: not_less Pls_def nat_number_of_def number_of_is_id | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 711 | nat_mult_distrib simp del: nat_number_of) | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 712 | |
| 23164 | 713 | |
| 714 | subsection{*Literal arithmetic and @{term of_nat}*}
 | |
| 715 | ||
| 716 | lemma of_nat_double: | |
| 717 | "0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)" | |
| 718 | by (simp only: mult_2 nat_add_distrib of_nat_add) | |
| 719 | ||
| 720 | lemma nat_numeral_m1_eq_0: "-1 = (0::nat)" | |
| 721 | by (simp only: nat_number_of_def) | |
| 722 | ||
| 723 | lemma of_nat_number_of_lemma: | |
| 724 | "of_nat (number_of v :: nat) = | |
| 725 | (if 0 \<le> (number_of v :: int) | |
| 726 | then (number_of v :: 'a :: number_ring) | |
| 727 | else 0)" | |
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 728 | by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat) | 
| 23164 | 729 | |
| 730 | lemma of_nat_number_of_eq [simp]: | |
| 731 | "of_nat (number_of v :: nat) = | |
| 732 | (if neg (number_of v :: int) then 0 | |
| 733 | else (number_of v :: 'a :: number_ring))" | |
| 734 | by (simp only: of_nat_number_of_lemma neg_def, simp) | |
| 735 | ||
| 736 | ||
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 737 | subsubsection{*For simplifying @{term "Suc m - K"} and  @{term "K - Suc m"}*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 738 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 739 | text{*Where K above is a literal*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 740 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 741 | lemma Suc_diff_eq_diff_pred: "Numeral0 < n ==> Suc m - n = m - (n - Numeral1)" | 
| 35216 | 742 | by (simp split: nat_diff_split) | 
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 743 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 744 | text {*Now just instantiating @{text n} to @{text "number_of v"} does
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 745 | the right simplification, but with some redundant inequality | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 746 | tests.*} | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 747 | lemma neg_number_of_pred_iff_0: | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 748 | "neg (number_of (Int.pred v)::int) = (number_of v = (0::nat))" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 749 | apply (subgoal_tac "neg (number_of (Int.pred v)) = (number_of v < Suc 0) ") | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 750 | apply (simp only: less_Suc_eq_le le_0_eq) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 751 | apply (subst less_number_of_Suc, simp) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 752 | done | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 753 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 754 | text{*No longer required as a simprule because of the @{text inverse_fold}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 755 | simproc*} | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 756 | lemma Suc_diff_number_of: | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 757 | "Int.Pls < v ==> | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 758 | Suc m - (number_of v) = m - (number_of (Int.pred v))" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 759 | apply (subst Suc_diff_eq_diff_pred) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 760 | apply simp | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 761 | apply (simp del: nat_numeral_1_eq_1) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 762 | apply (auto simp only: diff_nat_number_of less_0_number_of [symmetric] | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 763 | neg_number_of_pred_iff_0) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 764 | done | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 765 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 766 | lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n" | 
| 35216 | 767 | by (simp split: nat_diff_split) | 
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 768 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 769 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 770 | subsubsection{*For @{term nat_case} and @{term nat_rec}*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 771 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 772 | lemma nat_case_number_of [simp]: | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 773 | "nat_case a f (number_of v) = | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 774 | (let pv = number_of (Int.pred v) in | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 775 | if neg pv then a else f (nat pv))" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 776 | by (simp split add: nat.split add: Let_def neg_number_of_pred_iff_0) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 777 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 778 | lemma nat_case_add_eq_if [simp]: | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 779 | "nat_case a f ((number_of v) + n) = | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 780 | (let pv = number_of (Int.pred v) in | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 781 | if neg pv then nat_case a f n else f (nat pv + n))" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 782 | apply (subst add_eq_if) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 783 | apply (simp split add: nat.split | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 784 | del: nat_numeral_1_eq_1 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 785 | add: nat_numeral_1_eq_1 [symmetric] | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 786 | numeral_1_eq_Suc_0 [symmetric] | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 787 | neg_number_of_pred_iff_0) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 788 | done | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 789 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 790 | lemma nat_rec_number_of [simp]: | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 791 | "nat_rec a f (number_of v) = | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 792 | (let pv = number_of (Int.pred v) in | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 793 | if neg pv then a else f (nat pv) (nat_rec a f (nat pv)))" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 794 | apply (case_tac " (number_of v) ::nat") | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 795 | apply (simp_all (no_asm_simp) add: Let_def neg_number_of_pred_iff_0) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 796 | apply (simp split add: split_if_asm) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 797 | done | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 798 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 799 | lemma nat_rec_add_eq_if [simp]: | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 800 | "nat_rec a f (number_of v + n) = | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 801 | (let pv = number_of (Int.pred v) in | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 802 | if neg pv then nat_rec a f n | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 803 | else f (nat pv + n) (nat_rec a f (nat pv + n)))" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 804 | apply (subst add_eq_if) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 805 | apply (simp split add: nat.split | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 806 | del: nat_numeral_1_eq_1 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 807 | add: nat_numeral_1_eq_1 [symmetric] | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 808 | numeral_1_eq_Suc_0 [symmetric] | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 809 | neg_number_of_pred_iff_0) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 810 | done | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 811 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 812 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 813 | subsubsection{*Various Other Lemmas*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 814 | |
| 31080 | 815 | lemma card_UNIV_bool[simp]: "card (UNIV :: bool set) = 2" | 
| 816 | by(simp add: UNIV_bool) | |
| 817 | ||
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 818 | text {*Evens and Odds, for Mutilated Chess Board*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 819 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 820 | text{*Lemmas for specialist use, NOT as default simprules*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 821 | lemma nat_mult_2: "2 * z = (z+z::nat)" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 822 | unfolding nat_1_add_1 [symmetric] left_distrib by simp | 
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 823 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 824 | lemma nat_mult_2_right: "z * 2 = (z+z::nat)" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 825 | by (subst mult_commute, rule nat_mult_2) | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 826 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 827 | text{*Case analysis on @{term "n<2"}*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 828 | lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 829 | by (auto simp add: nat_1_add_1 [symmetric]) | 
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 830 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 831 | text{*Removal of Small Numerals: 0, 1 and (in additive positions) 2*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 832 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 833 | lemma add_2_eq_Suc [simp]: "2 + n = Suc (Suc n)" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 834 | by simp | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 835 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 836 | lemma add_2_eq_Suc' [simp]: "n + 2 = Suc (Suc n)" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 837 | by simp | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 838 | |
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 839 | text{*Can be used to eliminate long strings of Sucs, but not by default*}
 | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 840 | lemma Suc3_eq_add_3: "Suc (Suc (Suc n)) = 3 + n" | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 841 | by simp | 
| 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 842 | |
| 31096 | 843 | end |