| author | blanchet | 
| Wed, 24 Feb 2010 11:35:39 +0100 | |
| changeset 35341 | c6bbfa9c4eca | 
| parent 35216 | 7641e8d831d2 | 
| child 35631 | 0b8a5fd339ab | 
| 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 | ||
| 35043 
07dbdf60d5ad
dropped accidental duplication of "lin" prefix from cs. 108662d50512
 haftmann parents: 
35028diff
changeset | 116 | context linordered_ring_strict | 
| 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 | ||
| 127 | lemma sum_squares_eq_zero_iff: | |
| 128 | "x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 31034 | 129 | by (simp add: add_nonneg_eq_0_iff) | 
| 31014 | 130 | |
| 131 | lemma sum_squares_le_zero_iff: | |
| 132 | "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 133 | by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff) | |
| 134 | ||
| 135 | lemma sum_squares_gt_zero_iff: | |
| 136 | "0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" | |
| 137 | proof - | |
| 138 | have "x * x + y * y \<noteq> 0 \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" | |
| 139 | by (simp add: sum_squares_eq_zero_iff) | |
| 140 | then have "0 \<noteq> x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" | |
| 141 | by auto | |
| 142 | then show ?thesis | |
| 143 | by (simp add: less_le sum_squares_ge_zero) | |
| 144 | qed | |
| 145 | ||
| 146 | end | |
| 147 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
33342diff
changeset | 148 | context linordered_semidom | 
| 31014 | 149 | begin | 
| 150 | ||
| 151 | lemma power2_le_imp_le: | |
| 152 | "x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y" | |
| 153 | unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) | |
| 154 | ||
| 155 | lemma power2_less_imp_less: | |
| 156 | "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y" | |
| 157 | by (rule power_less_imp_less_base) | |
| 158 | ||
| 159 | lemma power2_eq_imp_eq: | |
| 160 | "x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y" | |
| 161 | unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp | |
| 162 | ||
| 163 | end | |
| 164 | ||
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
33342diff
changeset | 165 | context linordered_idom | 
| 31014 | 166 | begin | 
| 167 | ||
| 168 | lemma zero_eq_power2 [simp]: | |
| 169 | "a\<twosuperior> = 0 \<longleftrightarrow> a = 0" | |
| 170 | by (force simp add: power2_eq_square) | |
| 171 | ||
| 172 | lemma zero_le_power2 [simp]: | |
| 173 | "0 \<le> a\<twosuperior>" | |
| 174 | by (simp add: power2_eq_square) | |
| 175 | ||
| 176 | lemma zero_less_power2 [simp]: | |
| 177 | "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0" | |
| 178 | by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) | |
| 179 | ||
| 180 | lemma power2_less_0 [simp]: | |
| 181 | "\<not> a\<twosuperior> < 0" | |
| 182 | by (force simp add: power2_eq_square mult_less_0_iff) | |
| 183 | ||
| 184 | lemma abs_power2 [simp]: | |
| 185 | "abs (a\<twosuperior>) = a\<twosuperior>" | |
| 186 | by (simp add: power2_eq_square abs_mult abs_mult_self) | |
| 187 | ||
| 188 | lemma power2_abs [simp]: | |
| 189 | "(abs a)\<twosuperior> = a\<twosuperior>" | |
| 190 | by (simp add: power2_eq_square abs_mult_self) | |
| 191 | ||
| 192 | lemma odd_power_less_zero: | |
| 193 | "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0" | |
| 194 | proof (induct n) | |
| 195 | case 0 | |
| 196 | then show ?case by simp | |
| 197 | next | |
| 198 | case (Suc n) | |
| 199 | have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" | |
| 200 | by (simp add: mult_ac power_add power2_eq_square) | |
| 201 | thus ?case | |
| 202 | by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg) | |
| 203 | qed | |
| 204 | ||
| 205 | lemma odd_0_le_power_imp_0_le: | |
| 206 | "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a" | |
| 207 | using odd_power_less_zero [of a n] | |
| 208 | by (force simp add: linorder_not_less [symmetric]) | |
| 209 | ||
| 210 | lemma zero_le_even_power'[simp]: | |
| 211 | "0 \<le> a ^ (2*n)" | |
| 212 | proof (induct n) | |
| 213 | case 0 | |
| 35216 | 214 | show ?case by simp | 
| 31014 | 215 | next | 
| 216 | case (Suc n) | |
| 217 | have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" | |
| 218 | by (simp add: mult_ac power_add power2_eq_square) | |
| 219 | thus ?case | |
| 220 | by (simp add: Suc zero_le_mult_iff) | |
| 221 | qed | |
| 222 | ||
| 223 | lemma sum_power2_ge_zero: | |
| 224 | "0 \<le> x\<twosuperior> + y\<twosuperior>" | |
| 225 | unfolding power2_eq_square by (rule sum_squares_ge_zero) | |
| 226 | ||
| 227 | lemma not_sum_power2_lt_zero: | |
| 228 | "\<not> x\<twosuperior> + y\<twosuperior> < 0" | |
| 229 | unfolding power2_eq_square by (rule not_sum_squares_lt_zero) | |
| 230 | ||
| 231 | lemma sum_power2_eq_zero_iff: | |
| 232 | "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 233 | unfolding power2_eq_square by (rule sum_squares_eq_zero_iff) | |
| 234 | ||
| 235 | lemma sum_power2_le_zero_iff: | |
| 236 | "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" | |
| 237 | unfolding power2_eq_square by (rule sum_squares_le_zero_iff) | |
| 238 | ||
| 239 | lemma sum_power2_gt_zero_iff: | |
| 240 | "0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" | |
| 241 | unfolding power2_eq_square by (rule sum_squares_gt_zero_iff) | |
| 242 | ||
| 243 | end | |
| 244 | ||
| 245 | lemma power2_sum: | |
| 246 | fixes x y :: "'a::number_ring" | |
| 247 | 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 | 248 | by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute) | 
| 31014 | 249 | |
| 250 | lemma power2_diff: | |
| 251 | fixes x y :: "'a::number_ring" | |
| 252 | 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 | 253 | by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute) | 
| 31014 | 254 | |
| 23164 | 255 | |
| 29040 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 256 | 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 | 257 | |
| 30652 
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
 haftmann parents: 
30497diff
changeset | 258 | 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 | 259 | "neg Z \<longleftrightarrow> Z < 0" | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 260 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 261 | 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 | 262 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 263 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 264 | lemma neg_zminus_int [simp]: "neg (- (of_nat (Suc n)))" | 
| 35216 | 265 | 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 | 266 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 267 | 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 | 268 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 269 | 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 | 270 | 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 | 271 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 272 | 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 | 273 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 274 | 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 | 275 | 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 | 276 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 277 | lemma not_neg_1: "~ neg 1" | 
| 35216 | 278 | 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 | 279 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 280 | 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 | 281 | 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 | 282 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 283 | 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 | 284 | 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 | 285 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 286 | text {*
 | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 287 |   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 | 288 |   @{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 | 289 | *} | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 290 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 291 | 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 | 292 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 293 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 294 | 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 | 295 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 296 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 297 | lemma neg_number_of_Bit0: | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 298 | "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 | 299 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 300 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 301 | lemma neg_number_of_Bit1: | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 302 | "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 | 303 | by (simp add: neg_def) | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 304 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 305 | lemmas neg_simps [simp] = | 
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 306 | 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 | 307 | 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 | 308 | 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 | 309 | |
| 
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
 huffman parents: 
29039diff
changeset | 310 | |
| 23164 | 311 | subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
 | 
| 312 | ||
| 35216 | 313 | declare nat_1 [simp] | 
| 23164 | 314 | |
| 315 | lemma nat_number_of [simp]: "nat (number_of w) = number_of w" | |
| 316 | by (simp add: nat_number_of_def) | |
| 317 | ||
| 31998 
2c7a24f74db9
code attributes use common underscore convention
 haftmann parents: 
31790diff
changeset | 318 | lemma nat_numeral_0_eq_0 [simp, code_post]: "Numeral0 = (0::nat)" | 
| 23164 | 319 | by (simp add: nat_number_of_def) | 
| 320 | ||
| 321 | lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)" | |
| 35216 | 322 | by (simp add: nat_number_of_def) | 
| 23164 | 323 | |
| 31998 
2c7a24f74db9
code attributes use common underscore convention
 haftmann parents: 
31790diff
changeset | 324 | lemma numeral_1_eq_Suc_0 [code_post]: "Numeral1 = Suc 0" | 
| 35216 | 325 | by (simp only: nat_numeral_1_eq_1 One_nat_def) | 
| 23164 | 326 | |
| 327 | ||
| 328 | subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
 | |
| 329 | ||
| 330 | lemma int_nat_number_of [simp]: | |
| 23365 | 331 | "int (number_of v) = | 
| 23307 
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
 huffman parents: 
23294diff
changeset | 332 | (if neg (number_of v :: int) then 0 | 
| 
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
 huffman parents: 
23294diff
changeset | 333 | else (number_of v :: int))" | 
| 28984 | 334 | unfolding nat_number_of_def number_of_is_id neg_def | 
| 335 | by simp | |
| 23307 
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
 huffman parents: 
23294diff
changeset | 336 | |
| 23164 | 337 | |
| 338 | subsubsection{*Successor *}
 | |
| 339 | ||
| 340 | lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" | |
| 341 | apply (rule sym) | |
| 342 | apply (simp add: nat_eq_iff int_Suc) | |
| 343 | done | |
| 344 | ||
| 345 | lemma Suc_nat_number_of_add: | |
| 346 | "Suc (number_of v + n) = | |
| 28984 | 347 | (if neg (number_of v :: int) then 1+n else number_of (Int.succ v) + n)" | 
| 348 | unfolding nat_number_of_def number_of_is_id neg_def numeral_simps | |
| 349 | by (simp add: Suc_nat_eq_nat_zadd1 add_ac) | |
| 23164 | 350 | |
| 351 | lemma Suc_nat_number_of [simp]: | |
| 352 | "Suc (number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 353 | (if neg (number_of v :: int) then 1 else number_of (Int.succ v))" | 
| 23164 | 354 | apply (cut_tac n = 0 in Suc_nat_number_of_add) | 
| 355 | apply (simp cong del: if_weak_cong) | |
| 356 | done | |
| 357 | ||
| 358 | ||
| 359 | subsubsection{*Addition *}
 | |
| 360 | ||
| 361 | lemma add_nat_number_of [simp]: | |
| 362 | "(number_of v :: nat) + number_of v' = | |
| 29012 | 363 | (if v < Int.Pls then number_of v' | 
| 364 | else if v' < Int.Pls then number_of v | |
| 23164 | 365 | else number_of (v + v'))" | 
| 29012 | 366 | unfolding nat_number_of_def number_of_is_id numeral_simps | 
| 28984 | 367 | by (simp add: nat_add_distrib) | 
| 23164 | 368 | |
| 30081 | 369 | lemma nat_number_of_add_1 [simp]: | 
| 370 | "number_of v + (1::nat) = | |
| 371 | (if v < Int.Pls then 1 else number_of (Int.succ v))" | |
| 372 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 373 | by (simp add: nat_add_distrib) | |
| 374 | ||
| 375 | lemma nat_1_add_number_of [simp]: | |
| 376 | "(1::nat) + number_of v = | |
| 377 | (if v < Int.Pls then 1 else number_of (Int.succ v))" | |
| 378 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 379 | by (simp add: nat_add_distrib) | |
| 380 | ||
| 381 | lemma nat_1_add_1 [simp]: "1 + 1 = (2::nat)" | |
| 382 | by (rule int_int_eq [THEN iffD1]) simp | |
| 383 | ||
| 23164 | 384 | |
| 385 | subsubsection{*Subtraction *}
 | |
| 386 | ||
| 387 | lemma diff_nat_eq_if: | |
| 388 | "nat z - nat z' = | |
| 389 | (if neg z' then nat z | |
| 390 | else let d = z-z' in | |
| 391 | 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 | 392 | 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 | 393 | |
| 23164 | 394 | |
| 395 | lemma diff_nat_number_of [simp]: | |
| 396 | "(number_of v :: nat) - number_of v' = | |
| 29012 | 397 | (if v' < Int.Pls then number_of v | 
| 23164 | 398 | else let d = number_of (v + uminus v') in | 
| 399 | if neg d then 0 else nat d)" | |
| 29012 | 400 | unfolding nat_number_of_def number_of_is_id numeral_simps neg_def | 
| 401 | by auto | |
| 23164 | 402 | |
| 30081 | 403 | lemma nat_number_of_diff_1 [simp]: | 
| 404 | "number_of v - (1::nat) = | |
| 405 | (if v \<le> Int.Pls then 0 else number_of (Int.pred v))" | |
| 406 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 407 | by auto | |
| 408 | ||
| 23164 | 409 | |
| 410 | subsubsection{*Multiplication *}
 | |
| 411 | ||
| 412 | lemma mult_nat_number_of [simp]: | |
| 413 | "(number_of v :: nat) * number_of v' = | |
| 29012 | 414 | (if v < Int.Pls then 0 else number_of (v * v'))" | 
| 415 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 28984 | 416 | by (simp add: nat_mult_distrib) | 
| 23164 | 417 | |
| 418 | ||
| 419 | subsection{*Comparisons*}
 | |
| 420 | ||
| 421 | subsubsection{*Equals (=) *}
 | |
| 422 | ||
| 423 | lemma eq_nat_number_of [simp]: | |
| 424 | "((number_of v :: nat) = number_of v') = | |
| 28969 | 425 | (if neg (number_of v :: int) then (number_of v' :: int) \<le> 0 | 
| 426 | else if neg (number_of v' :: int) then (number_of v :: int) = 0 | |
| 427 | else v = v')" | |
| 428 | unfolding nat_number_of_def number_of_is_id neg_def | |
| 429 | by auto | |
| 23164 | 430 | |
| 431 | ||
| 432 | subsubsection{*Less-than (<) *}
 | |
| 433 | ||
| 434 | lemma less_nat_number_of [simp]: | |
| 29011 | 435 | "(number_of v :: nat) < number_of v' \<longleftrightarrow> | 
| 436 | (if v < v' then Int.Pls < v' else False)" | |
| 437 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 28961 | 438 | by auto | 
| 23164 | 439 | |
| 440 | ||
| 29010 | 441 | subsubsection{*Less-than-or-equal *}
 | 
| 442 | ||
| 443 | lemma le_nat_number_of [simp]: | |
| 444 | "(number_of v :: nat) \<le> number_of v' \<longleftrightarrow> | |
| 445 | (if v \<le> v' then True else v \<le> Int.Pls)" | |
| 446 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 447 | by auto | |
| 448 | ||
| 23164 | 449 | (*Maps #n to n for n = 0, 1, 2*) | 
| 450 | lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 | |
| 451 | ||
| 452 | ||
| 453 | subsection{*Powers with Numeric Exponents*}
 | |
| 454 | ||
| 455 | text{*Squares of literal numerals will be evaluated.*}
 | |
| 31014 | 456 | lemmas power2_eq_square_number_of [simp] = | 
| 23164 | 457 | power2_eq_square [of "number_of w", standard] | 
| 458 | ||
| 459 | ||
| 460 | text{*Simprules for comparisons where common factors can be cancelled.*}
 | |
| 461 | lemmas zero_compare_simps = | |
| 462 | add_strict_increasing add_strict_increasing2 add_increasing | |
| 463 | zero_le_mult_iff zero_le_divide_iff | |
| 464 | zero_less_mult_iff zero_less_divide_iff | |
| 465 | mult_le_0_iff divide_le_0_iff | |
| 466 | mult_less_0_iff divide_less_0_iff | |
| 467 | zero_le_power2 power2_less_0 | |
| 468 | ||
| 469 | subsubsection{*Nat *}
 | |
| 470 | ||
| 471 | lemma Suc_pred': "0 < n ==> n = Suc(n - 1)" | |
| 35216 | 472 | by simp | 
| 23164 | 473 | |
| 474 | (*Expresses a natural number constant as the Suc of another one. | |
| 475 | NOT suitable for rewriting because n recurs in the condition.*) | |
| 476 | lemmas expand_Suc = Suc_pred' [of "number_of v", standard] | |
| 477 | ||
| 478 | subsubsection{*Arith *}
 | |
| 479 | ||
| 31790 | 480 | lemma Suc_eq_plus1: "Suc n = n + 1" | 
| 35216 | 481 | unfolding One_nat_def by simp | 
| 23164 | 482 | |
| 31790 | 483 | lemma Suc_eq_plus1_left: "Suc n = 1 + n" | 
| 35216 | 484 | unfolding One_nat_def by simp | 
| 23164 | 485 | |
| 486 | (* These two can be useful when m = number_of... *) | |
| 487 | ||
| 488 | 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 | 489 | unfolding One_nat_def by (cases m) simp_all | 
| 23164 | 490 | |
| 491 | 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 | 492 | unfolding One_nat_def by (cases m) simp_all | 
| 23164 | 493 | |
| 494 | 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 | 495 | unfolding One_nat_def by (cases m) simp_all | 
| 23164 | 496 | |
| 497 | ||
| 498 | subsection{*Comparisons involving (0::nat) *}
 | |
| 499 | ||
| 500 | text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*}
 | |
| 501 | ||
| 502 | lemma eq_number_of_0 [simp]: | |
| 29012 | 503 | "number_of v = (0::nat) \<longleftrightarrow> v \<le> Int.Pls" | 
| 504 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 505 | by auto | |
| 23164 | 506 | |
| 507 | lemma eq_0_number_of [simp]: | |
| 29012 | 508 | "(0::nat) = number_of v \<longleftrightarrow> v \<le> Int.Pls" | 
| 23164 | 509 | by (rule trans [OF eq_sym_conv eq_number_of_0]) | 
| 510 | ||
| 511 | lemma less_0_number_of [simp]: | |
| 29012 | 512 | "(0::nat) < number_of v \<longleftrightarrow> Int.Pls < v" | 
| 513 | unfolding nat_number_of_def number_of_is_id numeral_simps | |
| 514 | by simp | |
| 23164 | 515 | |
| 516 | lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)" | |
| 28969 | 517 | by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric]) | 
| 23164 | 518 | |
| 519 | ||
| 520 | ||
| 521 | subsection{*Comparisons involving  @{term Suc} *}
 | |
| 522 | ||
| 523 | lemma eq_number_of_Suc [simp]: | |
| 524 | "(number_of v = Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 525 | (let pv = number_of (Int.pred v) in | 
| 23164 | 526 | if neg pv then False else nat pv = n)" | 
| 527 | apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less | |
| 528 | number_of_pred nat_number_of_def | |
| 529 | split add: split_if) | |
| 530 | apply (rule_tac x = "number_of v" in spec) | |
| 531 | apply (auto simp add: nat_eq_iff) | |
| 532 | done | |
| 533 | ||
| 534 | lemma Suc_eq_number_of [simp]: | |
| 535 | "(Suc n = number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 536 | (let pv = number_of (Int.pred v) in | 
| 23164 | 537 | if neg pv then False else nat pv = n)" | 
| 538 | by (rule trans [OF eq_sym_conv eq_number_of_Suc]) | |
| 539 | ||
| 540 | lemma less_number_of_Suc [simp]: | |
| 541 | "(number_of v < Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 542 | (let pv = number_of (Int.pred v) in | 
| 23164 | 543 | if neg pv then True else nat pv < n)" | 
| 544 | apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less | |
| 545 | number_of_pred nat_number_of_def | |
| 546 | split add: split_if) | |
| 547 | apply (rule_tac x = "number_of v" in spec) | |
| 548 | apply (auto simp add: nat_less_iff) | |
| 549 | done | |
| 550 | ||
| 551 | lemma less_Suc_number_of [simp]: | |
| 552 | "(Suc n < number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 553 | (let pv = number_of (Int.pred v) in | 
| 23164 | 554 | if neg pv then False else n < nat pv)" | 
| 555 | apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less | |
| 556 | number_of_pred nat_number_of_def | |
| 557 | split add: split_if) | |
| 558 | apply (rule_tac x = "number_of v" in spec) | |
| 559 | apply (auto simp add: zless_nat_eq_int_zless) | |
| 560 | done | |
| 561 | ||
| 562 | lemma le_number_of_Suc [simp]: | |
| 563 | "(number_of v <= Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 564 | (let pv = number_of (Int.pred v) in | 
| 23164 | 565 | if neg pv then True else nat pv <= n)" | 
| 35216 | 566 | by (simp add: Let_def linorder_not_less [symmetric]) | 
| 23164 | 567 | |
| 568 | lemma le_Suc_number_of [simp]: | |
| 569 | "(Suc n <= number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 570 | (let pv = number_of (Int.pred v) in | 
| 23164 | 571 | if neg pv then False else n <= nat pv)" | 
| 35216 | 572 | by (simp add: Let_def linorder_not_less [symmetric]) | 
| 23164 | 573 | |
| 574 | ||
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 575 | lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min" | 
| 23164 | 576 | by auto | 
| 577 | ||
| 578 | ||
| 579 | ||
| 580 | subsection{*Max and Min Combined with @{term Suc} *}
 | |
| 581 | ||
| 582 | lemma max_number_of_Suc [simp]: | |
| 583 | "max (Suc n) (number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 584 | (let pv = number_of (Int.pred v) in | 
| 23164 | 585 | if neg pv then Suc n else Suc(max n (nat pv)))" | 
| 586 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 587 | split add: split_if nat.split) | |
| 588 | apply (rule_tac x = "number_of v" in spec) | |
| 589 | apply auto | |
| 590 | done | |
| 591 | ||
| 592 | lemma max_Suc_number_of [simp]: | |
| 593 | "max (number_of v) (Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 594 | (let pv = number_of (Int.pred v) in | 
| 23164 | 595 | if neg pv then Suc n else Suc(max (nat pv) n))" | 
| 596 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 597 | split add: split_if nat.split) | |
| 598 | apply (rule_tac x = "number_of v" in spec) | |
| 599 | apply auto | |
| 600 | done | |
| 601 | ||
| 602 | lemma min_number_of_Suc [simp]: | |
| 603 | "min (Suc n) (number_of v) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 604 | (let pv = number_of (Int.pred v) in | 
| 23164 | 605 | if neg pv then 0 else Suc(min n (nat pv)))" | 
| 606 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 607 | split add: split_if nat.split) | |
| 608 | apply (rule_tac x = "number_of v" in spec) | |
| 609 | apply auto | |
| 610 | done | |
| 611 | ||
| 612 | lemma min_Suc_number_of [simp]: | |
| 613 | "min (number_of v) (Suc n) = | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 614 | (let pv = number_of (Int.pred v) in | 
| 23164 | 615 | if neg pv then 0 else Suc(min (nat pv) n))" | 
| 616 | apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def | |
| 617 | split add: split_if nat.split) | |
| 618 | apply (rule_tac x = "number_of v" in spec) | |
| 619 | apply auto | |
| 620 | done | |
| 621 | ||
| 622 | subsection{*Literal arithmetic involving powers*}
 | |
| 623 | ||
| 624 | lemma power_nat_number_of: | |
| 625 | "(number_of v :: nat) ^ n = | |
| 626 | (if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))" | |
| 627 | by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq | |
| 628 | split add: split_if cong: imp_cong) | |
| 629 | ||
| 630 | ||
| 631 | lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard] | |
| 632 | declare power_nat_number_of_number_of [simp] | |
| 633 | ||
| 634 | ||
| 635 | ||
| 23294 | 636 | text{*For arbitrary rings*}
 | 
| 23164 | 637 | |
| 23294 | 638 | lemma power_number_of_even: | 
| 31014 | 639 | 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 | 640 | 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 | 641 | 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 | 642 | nat_add_distrib power_add simp del: nat_number_of) | 
| 23164 | 643 | |
| 23294 | 644 | lemma power_number_of_odd: | 
| 31014 | 645 | 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 | 646 | shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w | 
| 23164 | 647 | then (let w = z ^ (number_of w) in z * w * w) else 1)" | 
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 648 | apply (auto simp add: Let_def Bit1_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 | 649 | mult_assoc nat_add_distrib power_add not_le simp del: nat_number_of) | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 650 | apply (simp add: not_le mult_2 [symmetric] add_assoc) | 
| 23164 | 651 | done | 
| 652 | ||
| 23294 | 653 | lemmas zpower_number_of_even = power_number_of_even [where 'a=int] | 
| 654 | lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int] | |
| 23164 | 655 | |
| 23294 | 656 | lemmas power_number_of_even_number_of [simp] = | 
| 657 | power_number_of_even [of "number_of v", standard] | |
| 23164 | 658 | |
| 23294 | 659 | lemmas power_number_of_odd_number_of [simp] = | 
| 660 | power_number_of_odd [of "number_of v", standard] | |
| 23164 | 661 | |
| 662 | lemma nat_number_of_Pls: "Numeral0 = (0::nat)" | |
| 35216 | 663 | by (simp add: nat_number_of_def) | 
| 23164 | 664 | |
| 25919 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
 haftmann parents: 
25571diff
changeset | 665 | lemma nat_number_of_Min: "number_of Int.Min = (0::nat)" | 
| 23164 | 666 | apply (simp only: number_of_Min nat_number_of_def nat_zminus_int) | 
| 667 | done | |
| 668 | ||
| 26086 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 669 | 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 | 670 | "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 | 671 | 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 | 672 | 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 | 673 | |
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
25965diff
changeset | 674 | 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 | 675 | "number_of (Int.Bit1 w) = | 
| 23164 | 676 | (if neg (number_of w :: int) then 0 | 
| 677 | else let n = number_of w in Suc (n + n))" | |
| 33296 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 678 | apply (auto simp add: Let_def Bit1_def nat_number_of_def number_of_is_id neg_def | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 679 | nat_add_distrib simp del: nat_number_of) | 
| 
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
 haftmann parents: 
32069diff
changeset | 680 | apply (simp add: mult_2 [symmetric] add_assoc) | 
| 
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 |