| author | wenzelm | 
| Mon, 24 Jun 2019 16:26:25 +0200 | |
| changeset 70359 | 470d4f145e4c | 
| parent 70356 | 4a327c061870 | 
| child 70927 | cc204e10385c | 
| permissions | -rw-r--r-- | 
| 47108 | 1 | (* Title: HOL/Num.thy | 
| 2 | Author: Florian Haftmann | |
| 3 | Author: Brian Huffman | |
| 4 | *) | |
| 5 | ||
| 60758 | 6 | section \<open>Binary Numerals\<close> | 
| 47108 | 7 | |
| 8 | theory Num | |
| 64178 | 9 | imports BNF_Least_Fixpoint Transfer | 
| 47108 | 10 | begin | 
| 11 | ||
| 61799 | 12 | subsection \<open>The \<open>num\<close> type\<close> | 
| 47108 | 13 | |
| 58310 | 14 | datatype num = One | Bit0 num | Bit1 num | 
| 47108 | 15 | |
| 69593 | 16 | text \<open>Increment function for type \<^typ>\<open>num\<close>\<close> | 
| 47108 | 17 | |
| 63654 | 18 | primrec inc :: "num \<Rightarrow> num" | 
| 19 | where | |
| 20 | "inc One = Bit0 One" | |
| 21 | | "inc (Bit0 x) = Bit1 x" | |
| 22 | | "inc (Bit1 x) = Bit0 (inc x)" | |
| 47108 | 23 | |
| 69593 | 24 | text \<open>Converting between type \<^typ>\<open>num\<close> and type \<^typ>\<open>nat\<close>\<close> | 
| 47108 | 25 | |
| 63654 | 26 | primrec nat_of_num :: "num \<Rightarrow> nat" | 
| 27 | where | |
| 28 | "nat_of_num One = Suc 0" | |
| 29 | | "nat_of_num (Bit0 x) = nat_of_num x + nat_of_num x" | |
| 30 | | "nat_of_num (Bit1 x) = Suc (nat_of_num x + nat_of_num x)" | |
| 47108 | 31 | |
| 63654 | 32 | primrec num_of_nat :: "nat \<Rightarrow> num" | 
| 33 | where | |
| 34 | "num_of_nat 0 = One" | |
| 35 | | "num_of_nat (Suc n) = (if 0 < n then inc (num_of_nat n) else One)" | |
| 47108 | 36 | |
| 37 | lemma nat_of_num_pos: "0 < nat_of_num x" | |
| 38 | by (induct x) simp_all | |
| 39 | ||
| 40 | lemma nat_of_num_neq_0: " nat_of_num x \<noteq> 0" | |
| 41 | by (induct x) simp_all | |
| 42 | ||
| 43 | lemma nat_of_num_inc: "nat_of_num (inc x) = Suc (nat_of_num x)" | |
| 44 | by (induct x) simp_all | |
| 45 | ||
| 63654 | 46 | lemma num_of_nat_double: "0 < n \<Longrightarrow> num_of_nat (n + n) = Bit0 (num_of_nat n)" | 
| 47108 | 47 | by (induct n) simp_all | 
| 48 | ||
| 69593 | 49 | text \<open>Type \<^typ>\<open>num\<close> is isomorphic to the strictly positive natural numbers.\<close> | 
| 47108 | 50 | |
| 51 | lemma nat_of_num_inverse: "num_of_nat (nat_of_num x) = x" | |
| 52 | by (induct x) (simp_all add: num_of_nat_double nat_of_num_pos) | |
| 53 | ||
| 54 | lemma num_of_nat_inverse: "0 < n \<Longrightarrow> nat_of_num (num_of_nat n) = n" | |
| 55 | by (induct n) (simp_all add: nat_of_num_inc) | |
| 56 | ||
| 57 | lemma num_eq_iff: "x = y \<longleftrightarrow> nat_of_num x = nat_of_num y" | |
| 58 | apply safe | |
| 59 | apply (drule arg_cong [where f=num_of_nat]) | |
| 60 | apply (simp add: nat_of_num_inverse) | |
| 61 | done | |
| 62 | ||
| 63 | lemma num_induct [case_names One inc]: | |
| 64 | fixes P :: "num \<Rightarrow> bool" | |
| 65 | assumes One: "P One" | |
| 66 | and inc: "\<And>x. P x \<Longrightarrow> P (inc x)" | |
| 67 | shows "P x" | |
| 68 | proof - | |
| 69 | obtain n where n: "Suc n = nat_of_num x" | |
| 63654 | 70 | by (cases "nat_of_num x") (simp_all add: nat_of_num_neq_0) | 
| 47108 | 71 | have "P (num_of_nat (Suc n))" | 
| 72 | proof (induct n) | |
| 63654 | 73 | case 0 | 
| 74 | from One show ?case by simp | |
| 47108 | 75 | next | 
| 76 | case (Suc n) | |
| 77 | then have "P (inc (num_of_nat (Suc n)))" by (rule inc) | |
| 78 | then show "P (num_of_nat (Suc (Suc n)))" by simp | |
| 79 | qed | |
| 80 | with n show "P x" | |
| 81 | by (simp add: nat_of_num_inverse) | |
| 82 | qed | |
| 83 | ||
| 60758 | 84 | text \<open> | 
| 69593 | 85 | From now on, there are two possible models for \<^typ>\<open>num\<close>: as positive | 
| 63654 | 86 | naturals (rule \<open>num_induct\<close>) and as digit representation (rules | 
| 87 | \<open>num.induct\<close>, \<open>num.cases\<close>). | |
| 60758 | 88 | \<close> | 
| 47108 | 89 | |
| 90 | ||
| 60758 | 91 | subsection \<open>Numeral operations\<close> | 
| 47108 | 92 | |
| 93 | instantiation num :: "{plus,times,linorder}"
 | |
| 94 | begin | |
| 95 | ||
| 63654 | 96 | definition [code del]: "m + n = num_of_nat (nat_of_num m + nat_of_num n)" | 
| 47108 | 97 | |
| 63654 | 98 | definition [code del]: "m * n = num_of_nat (nat_of_num m * nat_of_num n)" | 
| 47108 | 99 | |
| 63654 | 100 | definition [code del]: "m \<le> n \<longleftrightarrow> nat_of_num m \<le> nat_of_num n" | 
| 47108 | 101 | |
| 63654 | 102 | definition [code del]: "m < n \<longleftrightarrow> nat_of_num m < nat_of_num n" | 
| 47108 | 103 | |
| 104 | instance | |
| 61169 | 105 | by standard (auto simp add: less_num_def less_eq_num_def num_eq_iff) | 
| 47108 | 106 | |
| 107 | end | |
| 108 | ||
| 109 | lemma nat_of_num_add: "nat_of_num (x + y) = nat_of_num x + nat_of_num y" | |
| 110 | unfolding plus_num_def | |
| 111 | by (intro num_of_nat_inverse add_pos_pos nat_of_num_pos) | |
| 112 | ||
| 113 | lemma nat_of_num_mult: "nat_of_num (x * y) = nat_of_num x * nat_of_num y" | |
| 114 | unfolding times_num_def | |
| 115 | by (intro num_of_nat_inverse mult_pos_pos nat_of_num_pos) | |
| 116 | ||
| 117 | lemma add_num_simps [simp, code]: | |
| 118 | "One + One = Bit0 One" | |
| 119 | "One + Bit0 n = Bit1 n" | |
| 120 | "One + Bit1 n = Bit0 (n + One)" | |
| 121 | "Bit0 m + One = Bit1 m" | |
| 122 | "Bit0 m + Bit0 n = Bit0 (m + n)" | |
| 123 | "Bit0 m + Bit1 n = Bit1 (m + n)" | |
| 124 | "Bit1 m + One = Bit0 (m + One)" | |
| 125 | "Bit1 m + Bit0 n = Bit1 (m + n)" | |
| 126 | "Bit1 m + Bit1 n = Bit0 (m + n + One)" | |
| 127 | by (simp_all add: num_eq_iff nat_of_num_add) | |
| 128 | ||
| 129 | lemma mult_num_simps [simp, code]: | |
| 130 | "m * One = m" | |
| 131 | "One * n = n" | |
| 132 | "Bit0 m * Bit0 n = Bit0 (Bit0 (m * n))" | |
| 133 | "Bit0 m * Bit1 n = Bit0 (m * Bit1 n)" | |
| 134 | "Bit1 m * Bit0 n = Bit0 (Bit1 m * n)" | |
| 135 | "Bit1 m * Bit1 n = Bit1 (m + n + Bit0 (m * n))" | |
| 63654 | 136 | by (simp_all add: num_eq_iff nat_of_num_add nat_of_num_mult distrib_right distrib_left) | 
| 47108 | 137 | |
| 138 | lemma eq_num_simps: | |
| 139 | "One = One \<longleftrightarrow> True" | |
| 140 | "One = Bit0 n \<longleftrightarrow> False" | |
| 141 | "One = Bit1 n \<longleftrightarrow> False" | |
| 142 | "Bit0 m = One \<longleftrightarrow> False" | |
| 143 | "Bit1 m = One \<longleftrightarrow> False" | |
| 144 | "Bit0 m = Bit0 n \<longleftrightarrow> m = n" | |
| 145 | "Bit0 m = Bit1 n \<longleftrightarrow> False" | |
| 146 | "Bit1 m = Bit0 n \<longleftrightarrow> False" | |
| 147 | "Bit1 m = Bit1 n \<longleftrightarrow> m = n" | |
| 148 | by simp_all | |
| 149 | ||
| 150 | lemma le_num_simps [simp, code]: | |
| 151 | "One \<le> n \<longleftrightarrow> True" | |
| 152 | "Bit0 m \<le> One \<longleftrightarrow> False" | |
| 153 | "Bit1 m \<le> One \<longleftrightarrow> False" | |
| 154 | "Bit0 m \<le> Bit0 n \<longleftrightarrow> m \<le> n" | |
| 155 | "Bit0 m \<le> Bit1 n \<longleftrightarrow> m \<le> n" | |
| 156 | "Bit1 m \<le> Bit1 n \<longleftrightarrow> m \<le> n" | |
| 157 | "Bit1 m \<le> Bit0 n \<longleftrightarrow> m < n" | |
| 158 | using nat_of_num_pos [of n] nat_of_num_pos [of m] | |
| 159 | by (auto simp add: less_eq_num_def less_num_def) | |
| 160 | ||
| 161 | lemma less_num_simps [simp, code]: | |
| 162 | "m < One \<longleftrightarrow> False" | |
| 163 | "One < Bit0 n \<longleftrightarrow> True" | |
| 164 | "One < Bit1 n \<longleftrightarrow> True" | |
| 165 | "Bit0 m < Bit0 n \<longleftrightarrow> m < n" | |
| 166 | "Bit0 m < Bit1 n \<longleftrightarrow> m \<le> n" | |
| 167 | "Bit1 m < Bit1 n \<longleftrightarrow> m < n" | |
| 168 | "Bit1 m < Bit0 n \<longleftrightarrow> m < n" | |
| 169 | using nat_of_num_pos [of n] nat_of_num_pos [of m] | |
| 170 | by (auto simp add: less_eq_num_def less_num_def) | |
| 171 | ||
| 61630 | 172 | lemma le_num_One_iff: "x \<le> num.One \<longleftrightarrow> x = num.One" | 
| 63654 | 173 | by (simp add: antisym_conv) | 
| 61630 | 174 | |
| 63654 | 175 | text \<open>Rules using \<open>One\<close> and \<open>inc\<close> as constructors.\<close> | 
| 47108 | 176 | |
| 177 | lemma add_One: "x + One = inc x" | |
| 178 | by (simp add: num_eq_iff nat_of_num_add nat_of_num_inc) | |
| 179 | ||
| 180 | lemma add_One_commute: "One + n = n + One" | |
| 181 | by (induct n) simp_all | |
| 182 | ||
| 183 | lemma add_inc: "x + inc y = inc (x + y)" | |
| 184 | by (simp add: num_eq_iff nat_of_num_add nat_of_num_inc) | |
| 185 | ||
| 186 | lemma mult_inc: "x * inc y = x * y + x" | |
| 187 | by (simp add: num_eq_iff nat_of_num_mult nat_of_num_add nat_of_num_inc) | |
| 188 | ||
| 69593 | 189 | text \<open>The \<^const>\<open>num_of_nat\<close> conversion.\<close> | 
| 47108 | 190 | |
| 63654 | 191 | lemma num_of_nat_One: "n \<le> 1 \<Longrightarrow> num_of_nat n = One" | 
| 47108 | 192 | by (cases n) simp_all | 
| 193 | ||
| 194 | lemma num_of_nat_plus_distrib: | |
| 195 | "0 < m \<Longrightarrow> 0 < n \<Longrightarrow> num_of_nat (m + n) = num_of_nat m + num_of_nat n" | |
| 196 | by (induct n) (auto simp add: add_One add_One_commute add_inc) | |
| 197 | ||
| 63654 | 198 | text \<open>A double-and-decrement function.\<close> | 
| 47108 | 199 | |
| 63654 | 200 | primrec BitM :: "num \<Rightarrow> num" | 
| 201 | where | |
| 202 | "BitM One = One" | |
| 203 | | "BitM (Bit0 n) = Bit1 (BitM n)" | |
| 204 | | "BitM (Bit1 n) = Bit1 (Bit0 n)" | |
| 47108 | 205 | |
| 206 | lemma BitM_plus_one: "BitM n + One = Bit0 n" | |
| 207 | by (induct n) simp_all | |
| 208 | ||
| 209 | lemma one_plus_BitM: "One + BitM n = Bit0 n" | |
| 210 | unfolding add_One_commute BitM_plus_one .. | |
| 211 | ||
| 63654 | 212 | text \<open>Squaring and exponentiation.\<close> | 
| 47108 | 213 | |
| 63654 | 214 | primrec sqr :: "num \<Rightarrow> num" | 
| 215 | where | |
| 216 | "sqr One = One" | |
| 217 | | "sqr (Bit0 n) = Bit0 (Bit0 (sqr n))" | |
| 218 | | "sqr (Bit1 n) = Bit1 (Bit0 (sqr n + n))" | |
| 47108 | 219 | |
| 63654 | 220 | primrec pow :: "num \<Rightarrow> num \<Rightarrow> num" | 
| 221 | where | |
| 222 | "pow x One = x" | |
| 223 | | "pow x (Bit0 y) = sqr (pow x y)" | |
| 224 | | "pow x (Bit1 y) = sqr (pow x y) * x" | |
| 47108 | 225 | |
| 226 | lemma nat_of_num_sqr: "nat_of_num (sqr x) = nat_of_num x * nat_of_num x" | |
| 63654 | 227 | by (induct x) (simp_all add: algebra_simps nat_of_num_add) | 
| 47108 | 228 | |
| 229 | lemma sqr_conv_mult: "sqr x = x * x" | |
| 230 | by (simp add: num_eq_iff nat_of_num_sqr nat_of_num_mult) | |
| 231 | ||
| 70226 | 232 | lemma num_double [simp]: | 
| 233 | "num.Bit0 num.One * n = num.Bit0 n" | |
| 234 | by (simp add: num_eq_iff nat_of_num_mult) | |
| 235 | ||
| 47108 | 236 | |
| 60758 | 237 | subsection \<open>Binary numerals\<close> | 
| 47108 | 238 | |
| 60758 | 239 | text \<open> | 
| 47211 | 240 | We embed binary representations into a generic algebraic | 
| 61799 | 241 | structure using \<open>numeral\<close>. | 
| 60758 | 242 | \<close> | 
| 47108 | 243 | |
| 244 | class numeral = one + semigroup_add | |
| 245 | begin | |
| 246 | ||
| 63654 | 247 | primrec numeral :: "num \<Rightarrow> 'a" | 
| 248 | where | |
| 249 | numeral_One: "numeral One = 1" | |
| 250 | | numeral_Bit0: "numeral (Bit0 n) = numeral n + numeral n" | |
| 251 | | numeral_Bit1: "numeral (Bit1 n) = numeral n + numeral n + 1" | |
| 47108 | 252 | |
| 50817 | 253 | lemma numeral_code [code]: | 
| 254 | "numeral One = 1" | |
| 255 | "numeral (Bit0 n) = (let m = numeral n in m + m)" | |
| 256 | "numeral (Bit1 n) = (let m = numeral n in m + m + 1)" | |
| 257 | by (simp_all add: Let_def) | |
| 63654 | 258 | |
| 47108 | 259 | lemma one_plus_numeral_commute: "1 + numeral x = numeral x + 1" | 
| 63654 | 260 | proof (induct x) | 
| 261 | case One | |
| 262 | then show ?case by simp | |
| 263 | next | |
| 264 | case Bit0 | |
| 265 | then show ?case by (simp add: add.assoc [symmetric]) (simp add: add.assoc) | |
| 266 | next | |
| 267 | case Bit1 | |
| 268 | then show ?case by (simp add: add.assoc [symmetric]) (simp add: add.assoc) | |
| 269 | qed | |
| 47108 | 270 | |
| 271 | lemma numeral_inc: "numeral (inc x) = numeral x + 1" | |
| 272 | proof (induct x) | |
| 63654 | 273 | case One | 
| 274 | then show ?case by simp | |
| 275 | next | |
| 276 | case Bit0 | |
| 277 | then show ?case by simp | |
| 278 | next | |
| 47108 | 279 | case (Bit1 x) | 
| 280 | have "numeral x + (1 + numeral x) + 1 = numeral x + (numeral x + 1) + 1" | |
| 281 | by (simp only: one_plus_numeral_commute) | |
| 282 | with Bit1 show ?case | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 283 | by (simp add: add.assoc) | 
| 63654 | 284 | qed | 
| 47108 | 285 | |
| 286 | declare numeral.simps [simp del] | |
| 287 | ||
| 288 | abbreviation "Numeral1 \<equiv> numeral One" | |
| 289 | ||
| 290 | declare numeral_One [code_post] | |
| 291 | ||
| 292 | end | |
| 293 | ||
| 60758 | 294 | text \<open>Numeral syntax.\<close> | 
| 47108 | 295 | |
| 296 | syntax | |
| 297 |   "_Numeral" :: "num_const \<Rightarrow> 'a"    ("_")
 | |
| 298 | ||
| 69605 | 299 | ML_file \<open>Tools/numeral.ML\<close> | 
| 58410 
6d46ad54a2ab
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
 haftmann parents: 
58310diff
changeset | 300 | |
| 60758 | 301 | parse_translation \<open> | 
| 52143 | 302 | let | 
| 69593 | 303 | fun numeral_tr [(c as Const (\<^syntax_const>\<open>_constrain\<close>, _)) $ t $ u] = | 
| 52143 | 304 | c $ numeral_tr [t] $ u | 
| 305 | | numeral_tr [Const (num, _)] = | |
| 58421 | 306 | (Numeral.mk_number_syntax o #value o Lexicon.read_num) num | 
| 52143 | 307 |       | numeral_tr ts = raise TERM ("numeral_tr", ts);
 | 
| 69593 | 308 | in [(\<^syntax_const>\<open>_Numeral\<close>, K numeral_tr)] end | 
| 60758 | 309 | \<close> | 
| 47108 | 310 | |
| 60758 | 311 | typed_print_translation \<open> | 
| 52143 | 312 | let | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 313 | fun num_tr' ctxt T [n] = | 
| 52143 | 314 | let | 
| 62597 | 315 | val k = Numeral.dest_num_syntax n; | 
| 52187 | 316 | val t' = | 
| 69593 | 317 | Syntax.const \<^syntax_const>\<open>_Numeral\<close> $ | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 318 | Syntax.free (string_of_int k); | 
| 52143 | 319 | in | 
| 320 | (case T of | |
| 69593 | 321 | Type (\<^type_name>\<open>fun\<close>, [_, T']) => | 
| 52210 
0226035df99d
more explicit Printer.type_emphasis, depending on show_type_emphasis;
 wenzelm parents: 
52187diff
changeset | 322 | if Printer.type_emphasis ctxt T' then | 
| 69593 | 323 | Syntax.const \<^syntax_const>\<open>_constrain\<close> $ t' $ | 
| 52210 
0226035df99d
more explicit Printer.type_emphasis, depending on show_type_emphasis;
 wenzelm parents: 
52187diff
changeset | 324 | Syntax_Phases.term_of_typ ctxt T' | 
| 
0226035df99d
more explicit Printer.type_emphasis, depending on show_type_emphasis;
 wenzelm parents: 
52187diff
changeset | 325 | else t' | 
| 52187 | 326 | | _ => if T = dummyT then t' else raise Match) | 
| 52143 | 327 | end; | 
| 328 | in | |
| 69593 | 329 | [(\<^const_syntax>\<open>numeral\<close>, num_tr')] | 
| 52143 | 330 | end | 
| 60758 | 331 | \<close> | 
| 47108 | 332 | |
| 47228 | 333 | |
| 60758 | 334 | subsection \<open>Class-specific numeral rules\<close> | 
| 47108 | 335 | |
| 69593 | 336 | text \<open>\<^const>\<open>numeral\<close> is a morphism.\<close> | 
| 63654 | 337 | |
| 47108 | 338 | |
| 61799 | 339 | subsubsection \<open>Structures with addition: class \<open>numeral\<close>\<close> | 
| 47108 | 340 | |
| 341 | context numeral | |
| 342 | begin | |
| 343 | ||
| 344 | lemma numeral_add: "numeral (m + n) = numeral m + numeral n" | |
| 345 | by (induct n rule: num_induct) | |
| 63654 | 346 | (simp_all only: numeral_One add_One add_inc numeral_inc add.assoc) | 
| 47108 | 347 | |
| 348 | lemma numeral_plus_numeral: "numeral m + numeral n = numeral (m + n)" | |
| 349 | by (rule numeral_add [symmetric]) | |
| 350 | ||
| 351 | lemma numeral_plus_one: "numeral n + 1 = numeral (n + One)" | |
| 352 | using numeral_add [of n One] by (simp add: numeral_One) | |
| 353 | ||
| 354 | lemma one_plus_numeral: "1 + numeral n = numeral (One + n)" | |
| 355 | using numeral_add [of One n] by (simp add: numeral_One) | |
| 356 | ||
| 357 | lemma one_add_one: "1 + 1 = 2" | |
| 358 | using numeral_add [of One One] by (simp add: numeral_One) | |
| 359 | ||
| 360 | lemmas add_numeral_special = | |
| 361 | numeral_plus_one one_plus_numeral one_add_one | |
| 362 | ||
| 363 | end | |
| 364 | ||
| 63654 | 365 | |
| 366 | subsubsection \<open>Structures with negation: class \<open>neg_numeral\<close>\<close> | |
| 47108 | 367 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 368 | class neg_numeral = numeral + group_add | 
| 47108 | 369 | begin | 
| 370 | ||
| 63654 | 371 | lemma uminus_numeral_One: "- Numeral1 = - 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 372 | by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 373 | |
| 60758 | 374 | text \<open>Numerals form an abelian subgroup.\<close> | 
| 47108 | 375 | |
| 63654 | 376 | inductive is_num :: "'a \<Rightarrow> bool" | 
| 377 | where | |
| 378 | "is_num 1" | |
| 379 | | "is_num x \<Longrightarrow> is_num (- x)" | |
| 380 | | "is_num x \<Longrightarrow> is_num y \<Longrightarrow> is_num (x + y)" | |
| 47108 | 381 | |
| 382 | lemma is_num_numeral: "is_num (numeral k)" | |
| 63654 | 383 | by (induct k) (simp_all add: numeral.simps is_num.intros) | 
| 47108 | 384 | |
| 63654 | 385 | lemma is_num_add_commute: "is_num x \<Longrightarrow> is_num y \<Longrightarrow> x + y = y + x" | 
| 47108 | 386 | apply (induct x rule: is_num.induct) | 
| 63654 | 387 | apply (induct y rule: is_num.induct) | 
| 388 | apply simp | |
| 389 | apply (rule_tac a=x in add_left_imp_eq) | |
| 390 | apply (rule_tac a=x in add_right_imp_eq) | |
| 391 | apply (simp add: add.assoc) | |
| 392 | apply (simp add: add.assoc [symmetric]) | |
| 393 | apply (simp add: add.assoc) | |
| 394 | apply (rule_tac a=x in add_left_imp_eq) | |
| 395 | apply (rule_tac a=x in add_right_imp_eq) | |
| 396 | apply (simp add: add.assoc) | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 397 | apply (simp add: add.assoc) | 
| 63654 | 398 | apply (simp add: add.assoc [symmetric]) | 
| 47108 | 399 | done | 
| 400 | ||
| 63654 | 401 | lemma is_num_add_left_commute: "is_num x \<Longrightarrow> is_num y \<Longrightarrow> x + (y + z) = y + (x + z)" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 402 | by (simp only: add.assoc [symmetric] is_num_add_commute) | 
| 47108 | 403 | |
| 404 | lemmas is_num_normalize = | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 405 | add.assoc is_num_add_commute is_num_add_left_commute | 
| 47108 | 406 | is_num.intros is_num_numeral | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53064diff
changeset | 407 | minus_add | 
| 47108 | 408 | |
| 63654 | 409 | definition dbl :: "'a \<Rightarrow> 'a" | 
| 410 | where "dbl x = x + x" | |
| 411 | ||
| 412 | definition dbl_inc :: "'a \<Rightarrow> 'a" | |
| 413 | where "dbl_inc x = x + x + 1" | |
| 47108 | 414 | |
| 63654 | 415 | definition dbl_dec :: "'a \<Rightarrow> 'a" | 
| 416 | where "dbl_dec x = x + x - 1" | |
| 417 | ||
| 418 | definition sub :: "num \<Rightarrow> num \<Rightarrow> 'a" | |
| 419 | where "sub k l = numeral k - numeral l" | |
| 47108 | 420 | |
| 421 | lemma numeral_BitM: "numeral (BitM n) = numeral (Bit0 n) - 1" | |
| 422 | by (simp only: BitM_plus_one [symmetric] numeral_add numeral_One eq_diff_eq) | |
| 423 | ||
| 424 | lemma dbl_simps [simp]: | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 425 | "dbl (- numeral k) = - dbl (numeral k)" | 
| 47108 | 426 | "dbl 0 = 0" | 
| 427 | "dbl 1 = 2" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 428 | "dbl (- 1) = - 2" | 
| 47108 | 429 | "dbl (numeral k) = numeral (Bit0 k)" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 430 | by (simp_all add: dbl_def numeral.simps minus_add) | 
| 47108 | 431 | |
| 432 | lemma dbl_inc_simps [simp]: | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 433 | "dbl_inc (- numeral k) = - dbl_dec (numeral k)" | 
| 47108 | 434 | "dbl_inc 0 = 1" | 
| 435 | "dbl_inc 1 = 3" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 436 | "dbl_inc (- 1) = - 1" | 
| 47108 | 437 | "dbl_inc (numeral k) = numeral (Bit1 k)" | 
| 63654 | 438 | by (simp_all add: dbl_inc_def dbl_dec_def numeral.simps numeral_BitM is_num_normalize algebra_simps | 
| 439 | del: add_uminus_conv_diff) | |
| 47108 | 440 | |
| 441 | lemma dbl_dec_simps [simp]: | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 442 | "dbl_dec (- numeral k) = - dbl_inc (numeral k)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 443 | "dbl_dec 0 = - 1" | 
| 47108 | 444 | "dbl_dec 1 = 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 445 | "dbl_dec (- 1) = - 3" | 
| 47108 | 446 | "dbl_dec (numeral k) = numeral (BitM k)" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 447 | by (simp_all add: dbl_dec_def dbl_inc_def numeral.simps numeral_BitM is_num_normalize) | 
| 47108 | 448 | |
| 449 | lemma sub_num_simps [simp]: | |
| 450 | "sub One One = 0" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 451 | "sub One (Bit0 l) = - numeral (BitM l)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 452 | "sub One (Bit1 l) = - numeral (Bit0 l)" | 
| 47108 | 453 | "sub (Bit0 k) One = numeral (BitM k)" | 
| 454 | "sub (Bit1 k) One = numeral (Bit0 k)" | |
| 455 | "sub (Bit0 k) (Bit0 l) = dbl (sub k l)" | |
| 456 | "sub (Bit0 k) (Bit1 l) = dbl_dec (sub k l)" | |
| 457 | "sub (Bit1 k) (Bit0 l) = dbl_inc (sub k l)" | |
| 458 | "sub (Bit1 k) (Bit1 l) = dbl (sub k l)" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 459 | by (simp_all add: dbl_def dbl_dec_def dbl_inc_def sub_def numeral.simps | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53064diff
changeset | 460 | numeral_BitM is_num_normalize del: add_uminus_conv_diff add: diff_conv_add_uminus) | 
| 47108 | 461 | |
| 462 | lemma add_neg_numeral_simps: | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 463 | "numeral m + - numeral n = sub m n" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 464 | "- numeral m + numeral n = sub n m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 465 | "- numeral m + - numeral n = - (numeral m + numeral n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 466 | by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize | 
| 63654 | 467 | del: add_uminus_conv_diff add: diff_conv_add_uminus) | 
| 47108 | 468 | |
| 469 | lemma add_neg_numeral_special: | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 470 | "1 + - numeral m = sub One m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 471 | "- numeral m + 1 = sub One m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 472 | "numeral m + - 1 = sub m One" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 473 | "- 1 + numeral n = sub n One" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 474 | "- 1 + - numeral n = - numeral (inc n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 475 | "- numeral m + - 1 = - numeral (inc m)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 476 | "1 + - 1 = 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 477 | "- 1 + 1 = 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 478 | "- 1 + - 1 = - 2" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 479 | by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize right_minus numeral_inc | 
| 63654 | 480 | del: add_uminus_conv_diff add: diff_conv_add_uminus) | 
| 47108 | 481 | |
| 482 | lemma diff_numeral_simps: | |
| 483 | "numeral m - numeral n = sub m n" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 484 | "numeral m - - numeral n = numeral (m + n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 485 | "- numeral m - numeral n = - numeral (m + n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 486 | "- numeral m - - numeral n = sub n m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 487 | by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize | 
| 63654 | 488 | del: add_uminus_conv_diff add: diff_conv_add_uminus) | 
| 47108 | 489 | |
| 490 | lemma diff_numeral_special: | |
| 491 | "1 - numeral n = sub One n" | |
| 492 | "numeral m - 1 = sub m One" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 493 | "1 - - numeral n = numeral (One + n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 494 | "- numeral m - 1 = - numeral (m + One)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 495 | "- 1 - numeral n = - numeral (inc n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 496 | "numeral m - - 1 = numeral (inc m)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 497 | "- 1 - - numeral n = sub n One" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 498 | "- numeral m - - 1 = sub One m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 499 | "1 - 1 = 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 500 | "- 1 - 1 = - 2" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 501 | "1 - - 1 = 2" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 502 | "- 1 - - 1 = 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 503 | by (simp_all add: sub_def numeral_add numeral.simps is_num_normalize numeral_inc | 
| 63654 | 504 | del: add_uminus_conv_diff add: diff_conv_add_uminus) | 
| 47108 | 505 | |
| 506 | end | |
| 507 | ||
| 63654 | 508 | |
| 509 | subsubsection \<open>Structures with multiplication: class \<open>semiring_numeral\<close>\<close> | |
| 47108 | 510 | |
| 511 | class semiring_numeral = semiring + monoid_mult | |
| 512 | begin | |
| 513 | ||
| 514 | subclass numeral .. | |
| 515 | ||
| 516 | lemma numeral_mult: "numeral (m * n) = numeral m * numeral n" | |
| 63654 | 517 | by (induct n rule: num_induct) | 
| 518 | (simp_all add: numeral_One mult_inc numeral_inc numeral_add distrib_left) | |
| 47108 | 519 | |
| 520 | lemma numeral_times_numeral: "numeral m * numeral n = numeral (m * n)" | |
| 521 | by (rule numeral_mult [symmetric]) | |
| 522 | ||
| 53064 | 523 | lemma mult_2: "2 * z = z + z" | 
| 63654 | 524 | by (simp add: one_add_one [symmetric] distrib_right) | 
| 53064 | 525 | |
| 526 | lemma mult_2_right: "z * 2 = z + z" | |
| 63654 | 527 | by (simp add: one_add_one [symmetric] distrib_left) | 
| 53064 | 528 | |
| 66936 | 529 | lemma left_add_twice: | 
| 530 | "a + (a + b) = 2 * a + b" | |
| 531 | by (simp add: mult_2 ac_simps) | |
| 532 | ||
| 47108 | 533 | end | 
| 534 | ||
| 63654 | 535 | |
| 536 | subsubsection \<open>Structures with a zero: class \<open>semiring_1\<close>\<close> | |
| 47108 | 537 | |
| 538 | context semiring_1 | |
| 539 | begin | |
| 540 | ||
| 541 | subclass semiring_numeral .. | |
| 542 | ||
| 543 | lemma of_nat_numeral [simp]: "of_nat (numeral n) = numeral n" | |
| 63654 | 544 | by (induct n) (simp_all only: numeral.simps numeral_class.numeral.simps of_nat_add of_nat_1) | 
| 47108 | 545 | |
| 64178 | 546 | lemma numeral_unfold_funpow: | 
| 67399 | 547 | "numeral k = ((+) 1 ^^ numeral k) 0" | 
| 64178 | 548 | unfolding of_nat_def [symmetric] by simp | 
| 549 | ||
| 47108 | 550 | end | 
| 551 | ||
| 64178 | 552 | lemma transfer_rule_numeral: | 
| 553 | fixes R :: "'a::semiring_1 \<Rightarrow> 'b::semiring_1 \<Rightarrow> bool" | |
| 554 | assumes [transfer_rule]: "R 0 0" "R 1 1" | |
| 555 | "rel_fun R (rel_fun R R) plus plus" | |
| 556 | shows "rel_fun HOL.eq R numeral numeral" | |
| 557 | apply (subst (2) numeral_unfold_funpow [abs_def]) | |
| 558 | apply (subst (1) numeral_unfold_funpow [abs_def]) | |
| 559 | apply transfer_prover | |
| 560 | done | |
| 561 | ||
| 63654 | 562 | lemma nat_of_num_numeral [code_abbrev]: "nat_of_num = numeral" | 
| 47108 | 563 | proof | 
| 564 | fix n | |
| 565 | have "numeral n = nat_of_num n" | |
| 566 | by (induct n) (simp_all add: numeral.simps) | |
| 63654 | 567 | then show "nat_of_num n = numeral n" | 
| 568 | by simp | |
| 47108 | 569 | qed | 
| 570 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
50817diff
changeset | 571 | lemma nat_of_num_code [code]: | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
50817diff
changeset | 572 | "nat_of_num One = 1" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
50817diff
changeset | 573 | "nat_of_num (Bit0 n) = (let m = nat_of_num n in m + m)" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
50817diff
changeset | 574 | "nat_of_num (Bit1 n) = (let m = nat_of_num n in Suc (m + m))" | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
50817diff
changeset | 575 | by (simp_all add: Let_def) | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
50817diff
changeset | 576 | |
| 63654 | 577 | |
| 578 | subsubsection \<open>Equality: class \<open>semiring_char_0\<close>\<close> | |
| 47108 | 579 | |
| 580 | context semiring_char_0 | |
| 581 | begin | |
| 582 | ||
| 583 | lemma numeral_eq_iff: "numeral m = numeral n \<longleftrightarrow> m = n" | |
| 63654 | 584 | by (simp only: of_nat_numeral [symmetric] nat_of_num_numeral [symmetric] | 
| 585 | of_nat_eq_iff num_eq_iff) | |
| 47108 | 586 | |
| 587 | lemma numeral_eq_one_iff: "numeral n = 1 \<longleftrightarrow> n = One" | |
| 588 | by (rule numeral_eq_iff [of n One, unfolded numeral_One]) | |
| 589 | ||
| 590 | lemma one_eq_numeral_iff: "1 = numeral n \<longleftrightarrow> One = n" | |
| 591 | by (rule numeral_eq_iff [of One n, unfolded numeral_One]) | |
| 592 | ||
| 593 | lemma numeral_neq_zero: "numeral n \<noteq> 0" | |
| 63654 | 594 | by (simp add: of_nat_numeral [symmetric] nat_of_num_numeral [symmetric] nat_of_num_pos) | 
| 47108 | 595 | |
| 596 | lemma zero_neq_numeral: "0 \<noteq> numeral n" | |
| 597 | unfolding eq_commute [of 0] by (rule numeral_neq_zero) | |
| 598 | ||
| 599 | lemmas eq_numeral_simps [simp] = | |
| 600 | numeral_eq_iff | |
| 601 | numeral_eq_one_iff | |
| 602 | one_eq_numeral_iff | |
| 603 | numeral_neq_zero | |
| 604 | zero_neq_numeral | |
| 605 | ||
| 606 | end | |
| 607 | ||
| 63654 | 608 | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 609 | subsubsection \<open>Comparisons: class \<open>linordered_nonzero_semiring\<close>\<close> | 
| 47108 | 610 | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 611 | context linordered_nonzero_semiring | 
| 47108 | 612 | begin | 
| 613 | ||
| 614 | lemma numeral_le_iff: "numeral m \<le> numeral n \<longleftrightarrow> m \<le> n" | |
| 615 | proof - | |
| 616 | have "of_nat (numeral m) \<le> of_nat (numeral n) \<longleftrightarrow> m \<le> n" | |
| 63654 | 617 | by (simp only: less_eq_num_def nat_of_num_numeral of_nat_le_iff) | 
| 47108 | 618 | then show ?thesis by simp | 
| 619 | qed | |
| 620 | ||
| 621 | lemma one_le_numeral: "1 \<le> numeral n" | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 622 | using numeral_le_iff [of num.One n] by (simp add: numeral_One) | 
| 47108 | 623 | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 624 | lemma numeral_le_one_iff: "numeral n \<le> 1 \<longleftrightarrow> n \<le> num.One" | 
| 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 625 | using numeral_le_iff [of n num.One] by (simp add: numeral_One) | 
| 47108 | 626 | |
| 627 | lemma numeral_less_iff: "numeral m < numeral n \<longleftrightarrow> m < n" | |
| 628 | proof - | |
| 629 | have "of_nat (numeral m) < of_nat (numeral n) \<longleftrightarrow> m < n" | |
| 630 | unfolding less_num_def nat_of_num_numeral of_nat_less_iff .. | |
| 631 | then show ?thesis by simp | |
| 632 | qed | |
| 633 | ||
| 634 | lemma not_numeral_less_one: "\<not> numeral n < 1" | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 635 | using numeral_less_iff [of n num.One] by (simp add: numeral_One) | 
| 47108 | 636 | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 637 | lemma one_less_numeral_iff: "1 < numeral n \<longleftrightarrow> num.One < n" | 
| 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 638 | using numeral_less_iff [of num.One n] by (simp add: numeral_One) | 
| 47108 | 639 | |
| 640 | lemma zero_le_numeral: "0 \<le> numeral n" | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 641 | using dual_order.trans one_le_numeral zero_le_one by blast | 
| 47108 | 642 | |
| 643 | lemma zero_less_numeral: "0 < numeral n" | |
| 70270 
4065e3b0e5bf
Generalisations involving numerals; comparisons should now work for ennreal
 paulson <lp15@cam.ac.uk> parents: 
70226diff
changeset | 644 | using less_linear not_numeral_less_one order.strict_trans zero_less_one by blast | 
| 47108 | 645 | |
| 646 | lemma not_numeral_le_zero: "\<not> numeral n \<le> 0" | |
| 647 | by (simp add: not_le zero_less_numeral) | |
| 648 | ||
| 649 | lemma not_numeral_less_zero: "\<not> numeral n < 0" | |
| 650 | by (simp add: not_less zero_le_numeral) | |
| 651 | ||
| 652 | lemmas le_numeral_extra = | |
| 653 | zero_le_one not_one_le_zero | |
| 654 | order_refl [of 0] order_refl [of 1] | |
| 655 | ||
| 656 | lemmas less_numeral_extra = | |
| 657 | zero_less_one not_one_less_zero | |
| 658 | less_irrefl [of 0] less_irrefl [of 1] | |
| 659 | ||
| 660 | lemmas le_numeral_simps [simp] = | |
| 661 | numeral_le_iff | |
| 662 | one_le_numeral | |
| 663 | numeral_le_one_iff | |
| 664 | zero_le_numeral | |
| 665 | not_numeral_le_zero | |
| 666 | ||
| 667 | lemmas less_numeral_simps [simp] = | |
| 668 | numeral_less_iff | |
| 669 | one_less_numeral_iff | |
| 670 | not_numeral_less_one | |
| 671 | zero_less_numeral | |
| 672 | not_numeral_less_zero | |
| 673 | ||
| 61630 | 674 | lemma min_0_1 [simp]: | 
| 63654 | 675 | fixes min' :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" | 
| 676 | defines "min' \<equiv> min" | |
| 677 | shows | |
| 678 | "min' 0 1 = 0" | |
| 679 | "min' 1 0 = 0" | |
| 680 | "min' 0 (numeral x) = 0" | |
| 681 | "min' (numeral x) 0 = 0" | |
| 682 | "min' 1 (numeral x) = 1" | |
| 683 | "min' (numeral x) 1 = 1" | |
| 684 | by (simp_all add: min'_def min_def le_num_One_iff) | |
| 61630 | 685 | |
| 63654 | 686 | lemma max_0_1 [simp]: | 
| 687 | fixes max' :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" | |
| 688 | defines "max' \<equiv> max" | |
| 689 | shows | |
| 690 | "max' 0 1 = 1" | |
| 691 | "max' 1 0 = 1" | |
| 692 | "max' 0 (numeral x) = numeral x" | |
| 693 | "max' (numeral x) 0 = numeral x" | |
| 694 | "max' 1 (numeral x) = numeral x" | |
| 695 | "max' (numeral x) 1 = numeral x" | |
| 696 | by (simp_all add: max'_def max_def le_num_One_iff) | |
| 61630 | 697 | |
| 47108 | 698 | end | 
| 699 | ||
| 67116 | 700 | text \<open>Unfold \<open>min\<close> and \<open>max\<close> on numerals.\<close> | 
| 701 | ||
| 702 | lemmas max_number_of [simp] = | |
| 703 | max_def [of "numeral u" "numeral v"] | |
| 704 | max_def [of "numeral u" "- numeral v"] | |
| 705 | max_def [of "- numeral u" "numeral v"] | |
| 706 | max_def [of "- numeral u" "- numeral v"] for u v | |
| 707 | ||
| 708 | lemmas min_number_of [simp] = | |
| 709 | min_def [of "numeral u" "numeral v"] | |
| 710 | min_def [of "numeral u" "- numeral v"] | |
| 711 | min_def [of "- numeral u" "numeral v"] | |
| 712 | min_def [of "- numeral u" "- numeral v"] for u v | |
| 713 | ||
| 63654 | 714 | |
| 715 | subsubsection \<open>Multiplication and negation: class \<open>ring_1\<close>\<close> | |
| 47108 | 716 | |
| 717 | context ring_1 | |
| 718 | begin | |
| 719 | ||
| 720 | subclass neg_numeral .. | |
| 721 | ||
| 722 | lemma mult_neg_numeral_simps: | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 723 | "- numeral m * - numeral n = numeral (m * n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 724 | "- numeral m * numeral n = - numeral (m * n)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 725 | "numeral m * - numeral n = - numeral (m * n)" | 
| 63654 | 726 | by (simp_all only: mult_minus_left mult_minus_right minus_minus numeral_mult) | 
| 47108 | 727 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 728 | lemma mult_minus1 [simp]: "- 1 * z = - z" | 
| 63654 | 729 | by (simp add: numeral.simps) | 
| 47108 | 730 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 731 | lemma mult_minus1_right [simp]: "z * - 1 = - z" | 
| 63654 | 732 | by (simp add: numeral.simps) | 
| 47108 | 733 | |
| 734 | end | |
| 735 | ||
| 63654 | 736 | |
| 737 | subsubsection \<open>Equality using \<open>iszero\<close> for rings with non-zero characteristic\<close> | |
| 47108 | 738 | |
| 739 | context ring_1 | |
| 740 | begin | |
| 741 | ||
| 742 | definition iszero :: "'a \<Rightarrow> bool" | |
| 743 | where "iszero z \<longleftrightarrow> z = 0" | |
| 744 | ||
| 745 | lemma iszero_0 [simp]: "iszero 0" | |
| 746 | by (simp add: iszero_def) | |
| 747 | ||
| 748 | lemma not_iszero_1 [simp]: "\<not> iszero 1" | |
| 749 | by (simp add: iszero_def) | |
| 750 | ||
| 751 | lemma not_iszero_Numeral1: "\<not> iszero Numeral1" | |
| 752 | by (simp add: numeral_One) | |
| 753 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 754 | lemma not_iszero_neg_1 [simp]: "\<not> iszero (- 1)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 755 | by (simp add: iszero_def) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 756 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 757 | lemma not_iszero_neg_Numeral1: "\<not> iszero (- Numeral1)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 758 | by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 759 | |
| 63654 | 760 | lemma iszero_neg_numeral [simp]: "iszero (- numeral w) \<longleftrightarrow> iszero (numeral w)" | 
| 761 | unfolding iszero_def by (rule neg_equal_0_iff_equal) | |
| 47108 | 762 | |
| 763 | lemma eq_iff_iszero_diff: "x = y \<longleftrightarrow> iszero (x - y)" | |
| 764 | unfolding iszero_def by (rule eq_iff_diff_eq_0) | |
| 765 | ||
| 63654 | 766 | text \<open> | 
| 767 | The \<open>eq_numeral_iff_iszero\<close> lemmas are not declared \<open>[simp]\<close> by default, | |
| 768 | because for rings of characteristic zero, better simp rules are possible. | |
| 769 | For a type like integers mod \<open>n\<close>, type-instantiated versions of these rules | |
| 770 | should be added to the simplifier, along with a type-specific rule for | |
| 771 | deciding propositions of the form \<open>iszero (numeral w)\<close>. | |
| 47108 | 772 | |
| 63654 | 773 | bh: Maybe it would not be so bad to just declare these as simp rules anyway? | 
| 774 | I should test whether these rules take precedence over the \<open>ring_char_0\<close> | |
| 775 | rules in the simplifier. | |
| 60758 | 776 | \<close> | 
| 47108 | 777 | |
| 778 | lemma eq_numeral_iff_iszero: | |
| 779 | "numeral x = numeral y \<longleftrightarrow> iszero (sub x y)" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 780 | "numeral x = - numeral y \<longleftrightarrow> iszero (numeral (x + y))" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 781 | "- numeral x = numeral y \<longleftrightarrow> iszero (numeral (x + y))" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 782 | "- numeral x = - numeral y \<longleftrightarrow> iszero (sub y x)" | 
| 47108 | 783 | "numeral x = 1 \<longleftrightarrow> iszero (sub x One)" | 
| 784 | "1 = numeral y \<longleftrightarrow> iszero (sub One y)" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 785 | "- numeral x = 1 \<longleftrightarrow> iszero (numeral (x + One))" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 786 | "1 = - numeral y \<longleftrightarrow> iszero (numeral (One + y))" | 
| 47108 | 787 | "numeral x = 0 \<longleftrightarrow> iszero (numeral x)" | 
| 788 | "0 = numeral y \<longleftrightarrow> iszero (numeral y)" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 789 | "- numeral x = 0 \<longleftrightarrow> iszero (numeral x)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 790 | "0 = - numeral y \<longleftrightarrow> iszero (numeral y)" | 
| 47108 | 791 | unfolding eq_iff_iszero_diff diff_numeral_simps diff_numeral_special | 
| 792 | by simp_all | |
| 793 | ||
| 794 | end | |
| 795 | ||
| 63654 | 796 | |
| 797 | subsubsection \<open>Equality and negation: class \<open>ring_char_0\<close>\<close> | |
| 47108 | 798 | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62348diff
changeset | 799 | context ring_char_0 | 
| 47108 | 800 | begin | 
| 801 | ||
| 802 | lemma not_iszero_numeral [simp]: "\<not> iszero (numeral w)" | |
| 803 | by (simp add: iszero_def) | |
| 804 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 805 | lemma neg_numeral_eq_iff: "- numeral m = - numeral n \<longleftrightarrow> m = n" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 806 | by simp | 
| 47108 | 807 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 808 | lemma numeral_neq_neg_numeral: "numeral m \<noteq> - numeral n" | 
| 63654 | 809 | by (simp add: eq_neg_iff_add_eq_0 numeral_plus_numeral) | 
| 47108 | 810 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 811 | lemma neg_numeral_neq_numeral: "- numeral m \<noteq> numeral n" | 
| 47108 | 812 | by (rule numeral_neq_neg_numeral [symmetric]) | 
| 813 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 814 | lemma zero_neq_neg_numeral: "0 \<noteq> - numeral n" | 
| 63654 | 815 | by simp | 
| 47108 | 816 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 817 | lemma neg_numeral_neq_zero: "- numeral n \<noteq> 0" | 
| 63654 | 818 | by simp | 
| 47108 | 819 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 820 | lemma one_neq_neg_numeral: "1 \<noteq> - numeral n" | 
| 47108 | 821 | using numeral_neq_neg_numeral [of One n] by (simp add: numeral_One) | 
| 822 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 823 | lemma neg_numeral_neq_one: "- numeral n \<noteq> 1" | 
| 47108 | 824 | using neg_numeral_neq_numeral [of n One] by (simp add: numeral_One) | 
| 825 | ||
| 63654 | 826 | lemma neg_one_neq_numeral: "- 1 \<noteq> numeral n" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 827 | using neg_numeral_neq_numeral [of One n] by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 828 | |
| 63654 | 829 | lemma numeral_neq_neg_one: "numeral n \<noteq> - 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 830 | using numeral_neq_neg_numeral [of n One] by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 831 | |
| 63654 | 832 | lemma neg_one_eq_numeral_iff: "- 1 = - numeral n \<longleftrightarrow> n = One" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 833 | using neg_numeral_eq_iff [of One n] by (auto simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 834 | |
| 63654 | 835 | lemma numeral_eq_neg_one_iff: "- numeral n = - 1 \<longleftrightarrow> n = One" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 836 | using neg_numeral_eq_iff [of n One] by (auto simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 837 | |
| 63654 | 838 | lemma neg_one_neq_zero: "- 1 \<noteq> 0" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 839 | by simp | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 840 | |
| 63654 | 841 | lemma zero_neq_neg_one: "0 \<noteq> - 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 842 | by simp | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 843 | |
| 63654 | 844 | lemma neg_one_neq_one: "- 1 \<noteq> 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 845 | using neg_numeral_neq_numeral [of One One] by (simp only: numeral_One not_False_eq_True) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 846 | |
| 63654 | 847 | lemma one_neq_neg_one: "1 \<noteq> - 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 848 | using numeral_neq_neg_numeral [of One One] by (simp only: numeral_One not_False_eq_True) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 849 | |
| 47108 | 850 | lemmas eq_neg_numeral_simps [simp] = | 
| 851 | neg_numeral_eq_iff | |
| 852 | numeral_neq_neg_numeral neg_numeral_neq_numeral | |
| 853 | one_neq_neg_numeral neg_numeral_neq_one | |
| 854 | zero_neq_neg_numeral neg_numeral_neq_zero | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 855 | neg_one_neq_numeral numeral_neq_neg_one | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 856 | neg_one_eq_numeral_iff numeral_eq_neg_one_iff | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 857 | neg_one_neq_zero zero_neq_neg_one | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 858 | neg_one_neq_one one_neq_neg_one | 
| 47108 | 859 | |
| 860 | end | |
| 861 | ||
| 62348 | 862 | |
| 63654 | 863 | subsubsection \<open>Structures with negation and order: class \<open>linordered_idom\<close>\<close> | 
| 47108 | 864 | |
| 865 | context linordered_idom | |
| 866 | begin | |
| 867 | ||
| 868 | subclass ring_char_0 .. | |
| 869 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 870 | lemma neg_numeral_le_iff: "- numeral m \<le> - numeral n \<longleftrightarrow> n \<le> m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 871 | by (simp only: neg_le_iff_le numeral_le_iff) | 
| 47108 | 872 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 873 | lemma neg_numeral_less_iff: "- numeral m < - numeral n \<longleftrightarrow> n < m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 874 | by (simp only: neg_less_iff_less numeral_less_iff) | 
| 47108 | 875 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 876 | lemma neg_numeral_less_zero: "- numeral n < 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 877 | by (simp only: neg_less_0_iff_less zero_less_numeral) | 
| 47108 | 878 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 879 | lemma neg_numeral_le_zero: "- numeral n \<le> 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 880 | by (simp only: neg_le_0_iff_le zero_le_numeral) | 
| 47108 | 881 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 882 | lemma not_zero_less_neg_numeral: "\<not> 0 < - numeral n" | 
| 47108 | 883 | by (simp only: not_less neg_numeral_le_zero) | 
| 884 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 885 | lemma not_zero_le_neg_numeral: "\<not> 0 \<le> - numeral n" | 
| 47108 | 886 | by (simp only: not_le neg_numeral_less_zero) | 
| 887 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 888 | lemma neg_numeral_less_numeral: "- numeral m < numeral n" | 
| 47108 | 889 | using neg_numeral_less_zero zero_less_numeral by (rule less_trans) | 
| 890 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 891 | lemma neg_numeral_le_numeral: "- numeral m \<le> numeral n" | 
| 47108 | 892 | by (simp only: less_imp_le neg_numeral_less_numeral) | 
| 893 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 894 | lemma not_numeral_less_neg_numeral: "\<not> numeral m < - numeral n" | 
| 47108 | 895 | by (simp only: not_less neg_numeral_le_numeral) | 
| 896 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 897 | lemma not_numeral_le_neg_numeral: "\<not> numeral m \<le> - numeral n" | 
| 47108 | 898 | by (simp only: not_le neg_numeral_less_numeral) | 
| 63654 | 899 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 900 | lemma neg_numeral_less_one: "- numeral m < 1" | 
| 47108 | 901 | by (rule neg_numeral_less_numeral [of m One, unfolded numeral_One]) | 
| 902 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 903 | lemma neg_numeral_le_one: "- numeral m \<le> 1" | 
| 47108 | 904 | by (rule neg_numeral_le_numeral [of m One, unfolded numeral_One]) | 
| 905 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 906 | lemma not_one_less_neg_numeral: "\<not> 1 < - numeral m" | 
| 47108 | 907 | by (simp only: not_less neg_numeral_le_one) | 
| 908 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 909 | lemma not_one_le_neg_numeral: "\<not> 1 \<le> - numeral m" | 
| 47108 | 910 | by (simp only: not_le neg_numeral_less_one) | 
| 911 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 912 | lemma not_numeral_less_neg_one: "\<not> numeral m < - 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 913 | using not_numeral_less_neg_numeral [of m One] by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 914 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 915 | lemma not_numeral_le_neg_one: "\<not> numeral m \<le> - 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 916 | using not_numeral_le_neg_numeral [of m One] by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 917 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 918 | lemma neg_one_less_numeral: "- 1 < numeral m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 919 | using neg_numeral_less_numeral [of One m] by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 920 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 921 | lemma neg_one_le_numeral: "- 1 \<le> numeral m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 922 | using neg_numeral_le_numeral [of One m] by (simp add: numeral_One) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 923 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 924 | lemma neg_numeral_less_neg_one_iff: "- numeral m < - 1 \<longleftrightarrow> m \<noteq> One" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 925 | by (cases m) simp_all | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 926 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 927 | lemma neg_numeral_le_neg_one: "- numeral m \<le> - 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 928 | by simp | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 929 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 930 | lemma not_neg_one_less_neg_numeral: "\<not> - 1 < - numeral m" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 931 | by simp | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 932 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 933 | lemma not_neg_one_le_neg_numeral_iff: "\<not> - 1 \<le> - numeral m \<longleftrightarrow> m \<noteq> One" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 934 | by (cases m) simp_all | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 935 | |
| 63654 | 936 | lemma sub_non_negative: "sub n m \<ge> 0 \<longleftrightarrow> n \<ge> m" | 
| 47108 | 937 | by (simp only: sub_def le_diff_eq) simp | 
| 938 | ||
| 63654 | 939 | lemma sub_positive: "sub n m > 0 \<longleftrightarrow> n > m" | 
| 47108 | 940 | by (simp only: sub_def less_diff_eq) simp | 
| 941 | ||
| 63654 | 942 | lemma sub_non_positive: "sub n m \<le> 0 \<longleftrightarrow> n \<le> m" | 
| 47108 | 943 | by (simp only: sub_def diff_le_eq) simp | 
| 944 | ||
| 63654 | 945 | lemma sub_negative: "sub n m < 0 \<longleftrightarrow> n < m" | 
| 47108 | 946 | by (simp only: sub_def diff_less_eq) simp | 
| 947 | ||
| 948 | lemmas le_neg_numeral_simps [simp] = | |
| 949 | neg_numeral_le_iff | |
| 950 | neg_numeral_le_numeral not_numeral_le_neg_numeral | |
| 951 | neg_numeral_le_zero not_zero_le_neg_numeral | |
| 952 | neg_numeral_le_one not_one_le_neg_numeral | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 953 | neg_one_le_numeral not_numeral_le_neg_one | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 954 | neg_numeral_le_neg_one not_neg_one_le_neg_numeral_iff | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 955 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 956 | lemma le_minus_one_simps [simp]: | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 957 | "- 1 \<le> 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 958 | "- 1 \<le> 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 959 | "\<not> 0 \<le> - 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 960 | "\<not> 1 \<le> - 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 961 | by simp_all | 
| 47108 | 962 | |
| 963 | lemmas less_neg_numeral_simps [simp] = | |
| 964 | neg_numeral_less_iff | |
| 965 | neg_numeral_less_numeral not_numeral_less_neg_numeral | |
| 966 | neg_numeral_less_zero not_zero_less_neg_numeral | |
| 967 | neg_numeral_less_one not_one_less_neg_numeral | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 968 | neg_one_less_numeral not_numeral_less_neg_one | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 969 | neg_numeral_less_neg_one_iff not_neg_one_less_neg_numeral | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 970 | |
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 971 | lemma less_minus_one_simps [simp]: | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 972 | "- 1 < 0" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 973 | "- 1 < 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 974 | "\<not> 0 < - 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 975 | "\<not> 1 < - 1" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 976 | by (simp_all add: less_le) | 
| 47108 | 977 | |
| 61944 | 978 | lemma abs_numeral [simp]: "\<bar>numeral n\<bar> = numeral n" | 
| 47108 | 979 | by simp | 
| 980 | ||
| 61944 | 981 | lemma abs_neg_numeral [simp]: "\<bar>- numeral n\<bar> = numeral n" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 982 | by (simp only: abs_minus_cancel abs_numeral) | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 983 | |
| 61944 | 984 | lemma abs_neg_one [simp]: "\<bar>- 1\<bar> = 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 985 | by simp | 
| 47108 | 986 | |
| 987 | end | |
| 988 | ||
| 63654 | 989 | |
| 990 | subsubsection \<open>Natural numbers\<close> | |
| 47108 | 991 | |
| 67959 | 992 | lemma numeral_num_of_nat: | 
| 993 | "numeral (num_of_nat n) = n" if "n > 0" | |
| 994 | using that nat_of_num_numeral num_of_nat_inverse by simp | |
| 995 | ||
| 47299 | 996 | lemma Suc_1 [simp]: "Suc 1 = 2" | 
| 997 | unfolding Suc_eq_plus1 by (rule one_add_one) | |
| 998 | ||
| 47108 | 999 | lemma Suc_numeral [simp]: "Suc (numeral n) = numeral (n + One)" | 
| 47299 | 1000 | unfolding Suc_eq_plus1 by (rule numeral_plus_one) | 
| 47108 | 1001 | |
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1002 | definition pred_numeral :: "num \<Rightarrow> nat" | 
| 67959 | 1003 | where "pred_numeral k = numeral k - 1" | 
| 1004 | ||
| 1005 | declare [[code drop: pred_numeral]] | |
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1006 | |
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1007 | lemma numeral_eq_Suc: "numeral k = Suc (pred_numeral k)" | 
| 63654 | 1008 | by (simp add: pred_numeral_def) | 
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1009 | |
| 47220 
52426c62b5d0
replace lemmas eval_nat_numeral with a simpler reformulation
 huffman parents: 
47218diff
changeset | 1010 | lemma eval_nat_numeral: | 
| 47108 | 1011 | "numeral One = Suc 0" | 
| 1012 | "numeral (Bit0 n) = Suc (numeral (BitM n))" | |
| 1013 | "numeral (Bit1 n) = Suc (numeral (Bit0 n))" | |
| 1014 | by (simp_all add: numeral.simps BitM_plus_one) | |
| 1015 | ||
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1016 | lemma pred_numeral_simps [simp]: | 
| 47300 | 1017 | "pred_numeral One = 0" | 
| 1018 | "pred_numeral (Bit0 k) = numeral (BitM k)" | |
| 1019 | "pred_numeral (Bit1 k) = numeral (Bit0 k)" | |
| 63654 | 1020 | by (simp_all only: pred_numeral_def eval_nat_numeral diff_Suc_Suc diff_0) | 
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1021 | |
| 67959 | 1022 | lemma pred_numeral_inc [simp]: | 
| 1023 | "pred_numeral (Num.inc k) = numeral k" | |
| 1024 | by (simp only: pred_numeral_def numeral_inc diff_add_inverse2) | |
| 1025 | ||
| 47192 
0c0501cb6da6
move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
 huffman parents: 
47191diff
changeset | 1026 | lemma numeral_2_eq_2: "2 = Suc (Suc 0)" | 
| 47220 
52426c62b5d0
replace lemmas eval_nat_numeral with a simpler reformulation
 huffman parents: 
47218diff
changeset | 1027 | by (simp add: eval_nat_numeral) | 
| 47192 
0c0501cb6da6
move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
 huffman parents: 
47191diff
changeset | 1028 | |
| 
0c0501cb6da6
move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
 huffman parents: 
47191diff
changeset | 1029 | lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))" | 
| 47220 
52426c62b5d0
replace lemmas eval_nat_numeral with a simpler reformulation
 huffman parents: 
47218diff
changeset | 1030 | by (simp add: eval_nat_numeral) | 
| 47192 
0c0501cb6da6
move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
 huffman parents: 
47191diff
changeset | 1031 | |
| 47207 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1032 | lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0" | 
| 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1033 | by (simp only: numeral_One One_nat_def) | 
| 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1034 | |
| 63654 | 1035 | lemma Suc_nat_number_of_add: "Suc (numeral v + n) = numeral (v + One) + n" | 
| 47207 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1036 | by simp | 
| 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1037 | |
| 63654 | 1038 | lemma numerals: "Numeral1 = (1::nat)" "2 = Suc (Suc 0)" | 
| 1039 | by (rule numeral_One) (rule numeral_2_eq_2) | |
| 47207 
9368aa814518
move lemmas from Nat_Numeral to Int.thy and Num.thy
 huffman parents: 
47192diff
changeset | 1040 | |
| 63913 | 1041 | lemmas numeral_nat = eval_nat_numeral BitM.simps One_nat_def | 
| 1042 | ||
| 69593 | 1043 | text \<open>Comparisons involving \<^term>\<open>Suc\<close>.\<close> | 
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1044 | |
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1045 | lemma eq_numeral_Suc [simp]: "numeral k = Suc n \<longleftrightarrow> pred_numeral k = n" | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1046 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1047 | |
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1048 | lemma Suc_eq_numeral [simp]: "Suc n = numeral k \<longleftrightarrow> n = pred_numeral k" | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1049 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1050 | |
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1051 | lemma less_numeral_Suc [simp]: "numeral k < Suc n \<longleftrightarrow> pred_numeral k < n" | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1052 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1053 | |
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1054 | lemma less_Suc_numeral [simp]: "Suc n < numeral k \<longleftrightarrow> n < pred_numeral k" | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1055 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1056 | |
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1057 | lemma le_numeral_Suc [simp]: "numeral k \<le> Suc n \<longleftrightarrow> pred_numeral k \<le> n" | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1058 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1059 | |
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1060 | lemma le_Suc_numeral [simp]: "Suc n \<le> numeral k \<longleftrightarrow> n \<le> pred_numeral k" | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1061 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1062 | |
| 47218 
2b652cbadde1
new lemmas for simplifying subtraction on nat numerals
 huffman parents: 
47216diff
changeset | 1063 | lemma diff_Suc_numeral [simp]: "Suc n - numeral k = n - pred_numeral k" | 
| 
2b652cbadde1
new lemmas for simplifying subtraction on nat numerals
 huffman parents: 
47216diff
changeset | 1064 | by (simp add: numeral_eq_Suc) | 
| 
2b652cbadde1
new lemmas for simplifying subtraction on nat numerals
 huffman parents: 
47216diff
changeset | 1065 | |
| 
2b652cbadde1
new lemmas for simplifying subtraction on nat numerals
 huffman parents: 
47216diff
changeset | 1066 | lemma diff_numeral_Suc [simp]: "numeral k - Suc n = pred_numeral k - n" | 
| 
2b652cbadde1
new lemmas for simplifying subtraction on nat numerals
 huffman parents: 
47216diff
changeset | 1067 | by (simp add: numeral_eq_Suc) | 
| 
2b652cbadde1
new lemmas for simplifying subtraction on nat numerals
 huffman parents: 
47216diff
changeset | 1068 | |
| 63654 | 1069 | lemma max_Suc_numeral [simp]: "max (Suc n) (numeral k) = Suc (max n (pred_numeral k))" | 
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1070 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1071 | |
| 63654 | 1072 | lemma max_numeral_Suc [simp]: "max (numeral k) (Suc n) = Suc (max (pred_numeral k) n)" | 
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1073 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1074 | |
| 63654 | 1075 | lemma min_Suc_numeral [simp]: "min (Suc n) (numeral k) = Suc (min n (pred_numeral k))" | 
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1076 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1077 | |
| 63654 | 1078 | lemma min_numeral_Suc [simp]: "min (numeral k) (Suc n) = Suc (min (pred_numeral k) n)" | 
| 47209 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1079 | by (simp add: numeral_eq_Suc) | 
| 
4893907fe872
add constant pred_numeral k = numeral k - (1::nat);
 huffman parents: 
47207diff
changeset | 1080 | |
| 69593 | 1081 | text \<open>For \<^term>\<open>case_nat\<close> and \<^term>\<open>rec_nat\<close>.\<close> | 
| 47216 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1082 | |
| 63654 | 1083 | lemma case_nat_numeral [simp]: "case_nat a f (numeral v) = (let pv = pred_numeral v in f pv)" | 
| 47216 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1084 | by (simp add: numeral_eq_Suc) | 
| 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1085 | |
| 55415 | 1086 | lemma case_nat_add_eq_if [simp]: | 
| 1087 | "case_nat a f ((numeral v) + n) = (let pv = pred_numeral v in f (pv + n))" | |
| 47216 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1088 | by (simp add: numeral_eq_Suc) | 
| 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1089 | |
| 55415 | 1090 | lemma rec_nat_numeral [simp]: | 
| 63654 | 1091 | "rec_nat a f (numeral v) = (let pv = pred_numeral v in f pv (rec_nat a f pv))" | 
| 47216 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1092 | by (simp add: numeral_eq_Suc Let_def) | 
| 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1093 | |
| 55415 | 1094 | lemma rec_nat_add_eq_if [simp]: | 
| 63654 | 1095 | "rec_nat a f (numeral v + n) = (let pv = pred_numeral v in f (pv + n) (rec_nat a f (pv + n)))" | 
| 47216 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1096 | by (simp add: numeral_eq_Suc Let_def) | 
| 
4d0878d54ca5
move more theorems from Nat_Numeral.thy to Num.thy
 huffman parents: 
47211diff
changeset | 1097 | |
| 69593 | 1098 | text \<open>Case analysis on \<^term>\<open>n < 2\<close>.\<close> | 
| 47255 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1099 | lemma less_2_cases: "n < 2 \<Longrightarrow> n = 0 \<or> n = Suc 0" | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1100 | by (auto simp add: numeral_2_eq_2) | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1101 | |
| 63654 | 1102 | text \<open>Removal of Small Numerals: 0, 1 and (in additive positions) 2.\<close> | 
| 60758 | 1103 | text \<open>bh: Are these rules really a good idea?\<close> | 
| 47255 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1104 | |
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1105 | lemma add_2_eq_Suc [simp]: "2 + n = Suc (Suc n)" | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1106 | by simp | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1107 | |
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1108 | lemma add_2_eq_Suc' [simp]: "n + 2 = Suc (Suc n)" | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1109 | by simp | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1110 | |
| 60758 | 1111 | text \<open>Can be used to eliminate long strings of Sucs, but not by default.\<close> | 
| 47255 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1112 | lemma Suc3_eq_add_3: "Suc (Suc (Suc n)) = 3 + n" | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1113 | by simp | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1114 | |
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1115 | lemmas nat_1_add_1 = one_add_one [where 'a=nat] (* legacy *) | 
| 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
 huffman parents: 
47228diff
changeset | 1116 | |
| 47108 | 1117 | |
| 69593 | 1118 | subsection \<open>Particular lemmas concerning \<^term>\<open>2\<close>\<close> | 
| 58512 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1119 | |
| 59867 
58043346ca64
given up separate type classes demanding `inverse 0 = 0`
 haftmann parents: 
59621diff
changeset | 1120 | context linordered_field | 
| 58512 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1121 | begin | 
| 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1122 | |
| 62348 | 1123 | subclass field_char_0 .. | 
| 1124 | ||
| 63654 | 1125 | lemma half_gt_zero_iff: "0 < a / 2 \<longleftrightarrow> 0 < a" | 
| 58512 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1126 | by (auto simp add: field_simps) | 
| 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1127 | |
| 63654 | 1128 | lemma half_gt_zero [simp]: "0 < a \<Longrightarrow> 0 < a / 2" | 
| 58512 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1129 | by (simp add: half_gt_zero_iff) | 
| 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1130 | |
| 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1131 | end | 
| 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1132 | |
| 
dc4d76dfa8f0
moved lemmas out of Int.thy which have nothing to do with int
 haftmann parents: 
58421diff
changeset | 1133 | |
| 60758 | 1134 | subsection \<open>Numeral equations as default simplification rules\<close> | 
| 47108 | 1135 | |
| 1136 | declare (in numeral) numeral_One [simp] | |
| 1137 | declare (in numeral) numeral_plus_numeral [simp] | |
| 1138 | declare (in numeral) add_numeral_special [simp] | |
| 1139 | declare (in neg_numeral) add_neg_numeral_simps [simp] | |
| 1140 | declare (in neg_numeral) add_neg_numeral_special [simp] | |
| 1141 | declare (in neg_numeral) diff_numeral_simps [simp] | |
| 1142 | declare (in neg_numeral) diff_numeral_special [simp] | |
| 1143 | declare (in semiring_numeral) numeral_times_numeral [simp] | |
| 1144 | declare (in ring_1) mult_neg_numeral_simps [simp] | |
| 1145 | ||
| 67116 | 1146 | |
| 1147 | subsubsection \<open>Special Simplification for Constants\<close> | |
| 1148 | ||
| 1149 | text \<open>These distributive laws move literals inside sums and differences.\<close> | |
| 1150 | ||
| 1151 | lemmas distrib_right_numeral [simp] = distrib_right [of _ _ "numeral v"] for v | |
| 1152 | lemmas distrib_left_numeral [simp] = distrib_left [of "numeral v"] for v | |
| 1153 | lemmas left_diff_distrib_numeral [simp] = left_diff_distrib [of _ _ "numeral v"] for v | |
| 1154 | lemmas right_diff_distrib_numeral [simp] = right_diff_distrib [of "numeral v"] for v | |
| 1155 | ||
| 1156 | text \<open>These are actually for fields, like real\<close> | |
| 1157 | ||
| 1158 | lemmas zero_less_divide_iff_numeral [simp, no_atp] = zero_less_divide_iff [of "numeral w"] for w | |
| 1159 | lemmas divide_less_0_iff_numeral [simp, no_atp] = divide_less_0_iff [of "numeral w"] for w | |
| 1160 | lemmas zero_le_divide_iff_numeral [simp, no_atp] = zero_le_divide_iff [of "numeral w"] for w | |
| 1161 | lemmas divide_le_0_iff_numeral [simp, no_atp] = divide_le_0_iff [of "numeral w"] for w | |
| 1162 | ||
| 1163 | text \<open>Replaces \<open>inverse #nn\<close> by \<open>1/#nn\<close>. It looks | |
| 1164 | strange, but then other simprocs simplify the quotient.\<close> | |
| 1165 | ||
| 1166 | lemmas inverse_eq_divide_numeral [simp] = | |
| 1167 | inverse_eq_divide [of "numeral w"] for w | |
| 1168 | ||
| 1169 | lemmas inverse_eq_divide_neg_numeral [simp] = | |
| 1170 | inverse_eq_divide [of "- numeral w"] for w | |
| 1171 | ||
| 1172 | text \<open>These laws simplify inequalities, moving unary minus from a term | |
| 1173 | into the literal.\<close> | |
| 1174 | ||
| 1175 | lemmas equation_minus_iff_numeral [no_atp] = | |
| 1176 | equation_minus_iff [of "numeral v"] for v | |
| 1177 | ||
| 1178 | lemmas minus_equation_iff_numeral [no_atp] = | |
| 1179 | minus_equation_iff [of _ "numeral v"] for v | |
| 1180 | ||
| 1181 | lemmas le_minus_iff_numeral [no_atp] = | |
| 1182 | le_minus_iff [of "numeral v"] for v | |
| 1183 | ||
| 1184 | lemmas minus_le_iff_numeral [no_atp] = | |
| 1185 | minus_le_iff [of _ "numeral v"] for v | |
| 1186 | ||
| 1187 | lemmas less_minus_iff_numeral [no_atp] = | |
| 1188 | less_minus_iff [of "numeral v"] for v | |
| 1189 | ||
| 1190 | lemmas minus_less_iff_numeral [no_atp] = | |
| 1191 | minus_less_iff [of _ "numeral v"] for v | |
| 1192 | ||
| 1193 | (* FIXME maybe simproc *) | |
| 1194 | ||
| 1195 | text \<open>Cancellation of constant factors in comparisons (\<open><\<close> and \<open>\<le>\<close>)\<close> | |
| 1196 | ||
| 1197 | lemmas mult_less_cancel_left_numeral [simp, no_atp] = mult_less_cancel_left [of "numeral v"] for v | |
| 1198 | lemmas mult_less_cancel_right_numeral [simp, no_atp] = mult_less_cancel_right [of _ "numeral v"] for v | |
| 1199 | lemmas mult_le_cancel_left_numeral [simp, no_atp] = mult_le_cancel_left [of "numeral v"] for v | |
| 1200 | lemmas mult_le_cancel_right_numeral [simp, no_atp] = mult_le_cancel_right [of _ "numeral v"] for v | |
| 1201 | ||
| 1202 | text \<open>Multiplying out constant divisors in comparisons (\<open><\<close>, \<open>\<le>\<close> and \<open>=\<close>)\<close> | |
| 1203 | ||
| 1204 | named_theorems divide_const_simps "simplification rules to simplify comparisons involving constant divisors" | |
| 1205 | ||
| 1206 | lemmas le_divide_eq_numeral1 [simp,divide_const_simps] = | |
| 1207 | pos_le_divide_eq [of "numeral w", OF zero_less_numeral] | |
| 1208 | neg_le_divide_eq [of "- numeral w", OF neg_numeral_less_zero] for w | |
| 1209 | ||
| 1210 | lemmas divide_le_eq_numeral1 [simp,divide_const_simps] = | |
| 1211 | pos_divide_le_eq [of "numeral w", OF zero_less_numeral] | |
| 1212 | neg_divide_le_eq [of "- numeral w", OF neg_numeral_less_zero] for w | |
| 1213 | ||
| 1214 | lemmas less_divide_eq_numeral1 [simp,divide_const_simps] = | |
| 1215 | pos_less_divide_eq [of "numeral w", OF zero_less_numeral] | |
| 1216 | neg_less_divide_eq [of "- numeral w", OF neg_numeral_less_zero] for w | |
| 1217 | ||
| 1218 | lemmas divide_less_eq_numeral1 [simp,divide_const_simps] = | |
| 1219 | pos_divide_less_eq [of "numeral w", OF zero_less_numeral] | |
| 1220 | neg_divide_less_eq [of "- numeral w", OF neg_numeral_less_zero] for w | |
| 1221 | ||
| 1222 | lemmas eq_divide_eq_numeral1 [simp,divide_const_simps] = | |
| 1223 | eq_divide_eq [of _ _ "numeral w"] | |
| 1224 | eq_divide_eq [of _ _ "- numeral w"] for w | |
| 1225 | ||
| 1226 | lemmas divide_eq_eq_numeral1 [simp,divide_const_simps] = | |
| 1227 | divide_eq_eq [of _ "numeral w"] | |
| 1228 | divide_eq_eq [of _ "- numeral w"] for w | |
| 1229 | ||
| 1230 | ||
| 1231 | subsubsection \<open>Optional Simplification Rules Involving Constants\<close> | |
| 1232 | ||
| 1233 | text \<open>Simplify quotients that are compared with a literal constant.\<close> | |
| 1234 | ||
| 1235 | lemmas le_divide_eq_numeral [divide_const_simps] = | |
| 1236 | le_divide_eq [of "numeral w"] | |
| 1237 | le_divide_eq [of "- numeral w"] for w | |
| 1238 | ||
| 1239 | lemmas divide_le_eq_numeral [divide_const_simps] = | |
| 1240 | divide_le_eq [of _ _ "numeral w"] | |
| 1241 | divide_le_eq [of _ _ "- numeral w"] for w | |
| 1242 | ||
| 1243 | lemmas less_divide_eq_numeral [divide_const_simps] = | |
| 1244 | less_divide_eq [of "numeral w"] | |
| 1245 | less_divide_eq [of "- numeral w"] for w | |
| 1246 | ||
| 1247 | lemmas divide_less_eq_numeral [divide_const_simps] = | |
| 1248 | divide_less_eq [of _ _ "numeral w"] | |
| 1249 | divide_less_eq [of _ _ "- numeral w"] for w | |
| 1250 | ||
| 1251 | lemmas eq_divide_eq_numeral [divide_const_simps] = | |
| 1252 | eq_divide_eq [of "numeral w"] | |
| 1253 | eq_divide_eq [of "- numeral w"] for w | |
| 1254 | ||
| 1255 | lemmas divide_eq_eq_numeral [divide_const_simps] = | |
| 1256 | divide_eq_eq [of _ _ "numeral w"] | |
| 1257 | divide_eq_eq [of _ _ "- numeral w"] for w | |
| 1258 | ||
| 1259 | text \<open>Not good as automatic simprules because they cause case splits.\<close> | |
| 1260 | ||
| 1261 | lemmas [divide_const_simps] = | |
| 1262 | le_divide_eq_1 divide_le_eq_1 less_divide_eq_1 divide_less_eq_1 | |
| 1263 | ||
| 1264 | ||
| 60758 | 1265 | subsection \<open>Setting up simprocs\<close> | 
| 47108 | 1266 | |
| 63654 | 1267 | lemma mult_numeral_1: "Numeral1 * a = a" | 
| 1268 | for a :: "'a::semiring_numeral" | |
| 47108 | 1269 | by simp | 
| 1270 | ||
| 63654 | 1271 | lemma mult_numeral_1_right: "a * Numeral1 = a" | 
| 1272 | for a :: "'a::semiring_numeral" | |
| 47108 | 1273 | by simp | 
| 1274 | ||
| 63654 | 1275 | lemma divide_numeral_1: "a / Numeral1 = a" | 
| 1276 | for a :: "'a::field" | |
| 47108 | 1277 | by simp | 
| 1278 | ||
| 63654 | 1279 | lemma inverse_numeral_1: "inverse Numeral1 = (Numeral1::'a::division_ring)" | 
| 47108 | 1280 | by simp | 
| 1281 | ||
| 63654 | 1282 | text \<open> | 
| 1283 | Theorem lists for the cancellation simprocs. The use of a binary | |
| 1284 | numeral for 1 reduces the number of special cases. | |
| 1285 | \<close> | |
| 47108 | 1286 | |
| 68536 | 1287 | lemma mult_1s_semiring_numeral: | 
| 63654 | 1288 | "Numeral1 * a = a" | 
| 1289 | "a * Numeral1 = a" | |
| 68536 | 1290 | for a :: "'a::semiring_numeral" | 
| 1291 | by simp_all | |
| 1292 | ||
| 1293 | lemma mult_1s_ring_1: | |
| 63654 | 1294 | "- Numeral1 * b = - b" | 
| 1295 | "b * - Numeral1 = - b" | |
| 68536 | 1296 | for b :: "'a::ring_1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1297 | by simp_all | 
| 47108 | 1298 | |
| 68536 | 1299 | lemmas mult_1s = mult_1s_semiring_numeral mult_1s_ring_1 | 
| 1300 | ||
| 60758 | 1301 | setup \<open> | 
| 47226 | 1302 | Reorient_Proc.add | 
| 69593 | 1303 | (fn Const (\<^const_name>\<open>numeral\<close>, _) $ _ => true | 
| 1304 | | Const (\<^const_name>\<open>uminus\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ _) => true | |
| 63654 | 1305 | | _ => false) | 
| 60758 | 1306 | \<close> | 
| 47226 | 1307 | |
| 63654 | 1308 | simproc_setup reorient_numeral ("numeral w = x" | "- numeral w = y") =
 | 
| 1309 | Reorient_Proc.proc | |
| 47226 | 1310 | |
| 47108 | 1311 | |
| 63654 | 1312 | subsubsection \<open>Simplification of arithmetic operations on integer constants\<close> | 
| 47108 | 1313 | |
| 1314 | lemmas arith_special = (* already declared simp above *) | |
| 1315 | add_numeral_special add_neg_numeral_special | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1316 | diff_numeral_special | 
| 47108 | 1317 | |
| 63654 | 1318 | lemmas arith_extra_simps = (* rules already in simpset *) | 
| 47108 | 1319 | numeral_plus_numeral add_neg_numeral_simps add_0_left add_0_right | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1320 | minus_zero | 
| 47108 | 1321 | diff_numeral_simps diff_0 diff_0_right | 
| 1322 | numeral_times_numeral mult_neg_numeral_simps | |
| 1323 | mult_zero_left mult_zero_right | |
| 1324 | abs_numeral abs_neg_numeral | |
| 1325 | ||
| 60758 | 1326 | text \<open> | 
| 47108 | 1327 | For making a minimal simpset, one must include these default simprules. | 
| 61799 | 1328 | Also include \<open>simp_thms\<close>. | 
| 60758 | 1329 | \<close> | 
| 47108 | 1330 | |
| 1331 | lemmas arith_simps = | |
| 1332 | add_num_simps mult_num_simps sub_num_simps | |
| 1333 | BitM.simps dbl_simps dbl_inc_simps dbl_dec_simps | |
| 1334 | abs_zero abs_one arith_extra_simps | |
| 1335 | ||
| 54249 | 1336 | lemmas more_arith_simps = | 
| 1337 | neg_le_iff_le | |
| 1338 | minus_zero left_minus right_minus | |
| 1339 | mult_1_left mult_1_right | |
| 1340 | mult_minus_left mult_minus_right | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 1341 | minus_add_distrib minus_minus mult.assoc | 
| 54249 | 1342 | |
| 1343 | lemmas of_nat_simps = | |
| 1344 | of_nat_0 of_nat_1 of_nat_Suc of_nat_add of_nat_mult | |
| 1345 | ||
| 63654 | 1346 | text \<open>Simplification of relational operations.\<close> | 
| 47108 | 1347 | |
| 1348 | lemmas eq_numeral_extra = | |
| 1349 | zero_neq_one one_neq_zero | |
| 1350 | ||
| 1351 | lemmas rel_simps = | |
| 1352 | le_num_simps less_num_simps eq_num_simps | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1353 | le_numeral_simps le_neg_numeral_simps le_minus_one_simps le_numeral_extra | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1354 | less_numeral_simps less_neg_numeral_simps less_minus_one_simps less_numeral_extra | 
| 47108 | 1355 | eq_numeral_simps eq_neg_numeral_simps eq_numeral_extra | 
| 1356 | ||
| 54249 | 1357 | lemma Let_numeral [simp]: "Let (numeral v) f = f (numeral v)" | 
| 61799 | 1358 | \<comment> \<open>Unfold all \<open>let\<close>s involving constants\<close> | 
| 54249 | 1359 | unfolding Let_def .. | 
| 1360 | ||
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1361 | lemma Let_neg_numeral [simp]: "Let (- numeral v) f = f (- numeral v)" | 
| 61799 | 1362 | \<comment> \<open>Unfold all \<open>let\<close>s involving constants\<close> | 
| 54249 | 1363 | unfolding Let_def .. | 
| 1364 | ||
| 60758 | 1365 | declaration \<open> | 
| 63654 | 1366 | let | 
| 59996 | 1367 | fun number_of ctxt T n = | 
| 69593 | 1368 | if not (Sign.of_sort (Proof_Context.theory_of ctxt) (T, \<^sort>\<open>numeral\<close>)) | 
| 54249 | 1369 |     then raise CTERM ("number_of", [])
 | 
| 59996 | 1370 | else Numeral.mk_cnumber (Thm.ctyp_of ctxt T) n; | 
| 54249 | 1371 | in | 
| 1372 | K ( | |
| 70356 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70270diff
changeset | 1373 | Lin_Arith.set_number_of number_of | 
| 63654 | 1374 | #> Lin_Arith.add_simps | 
| 70356 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70270diff
changeset | 1375 |       @{thms arith_simps more_arith_simps rel_simps pred_numeral_simps
 | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70270diff
changeset | 1376 | arith_special numeral_One of_nat_simps uminus_numeral_One | 
| 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70270diff
changeset | 1377 | Suc_numeral Let_numeral Let_neg_numeral Let_0 Let_1 | 
| 63654 | 1378 | le_Suc_numeral le_numeral_Suc less_Suc_numeral less_numeral_Suc | 
| 70356 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70270diff
changeset | 1379 | Suc_eq_numeral eq_numeral_Suc mult_Suc mult_Suc_right of_nat_numeral}) | 
| 54249 | 1380 | end | 
| 60758 | 1381 | \<close> | 
| 54249 | 1382 | |
| 47108 | 1383 | |
| 63654 | 1384 | subsubsection \<open>Simplification of arithmetic when nested to the right\<close> | 
| 47108 | 1385 | |
| 63654 | 1386 | lemma add_numeral_left [simp]: "numeral v + (numeral w + z) = (numeral(v + w) + z)" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 1387 | by (simp_all add: add.assoc [symmetric]) | 
| 47108 | 1388 | |
| 1389 | lemma add_neg_numeral_left [simp]: | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1390 | "numeral v + (- numeral w + y) = (sub v w + y)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1391 | "- numeral v + (numeral w + y) = (sub w v + y)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54249diff
changeset | 1392 | "- numeral v + (- numeral w + y) = (- numeral(v + w) + y)" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 1393 | by (simp_all add: add.assoc [symmetric]) | 
| 47108 | 1394 | |
| 68536 | 1395 | lemma mult_numeral_left_semiring_numeral: | 
| 47108 | 1396 | "numeral v * (numeral w * z) = (numeral(v * w) * z :: 'a::semiring_numeral)" | 
| 68536 | 1397 | by (simp add: mult.assoc [symmetric]) | 
| 1398 | ||
| 1399 | lemma mult_numeral_left_ring_1: | |
| 1400 | "- numeral v * (numeral w * y) = (- numeral(v * w) * y :: 'a::ring_1)" | |
| 1401 | "numeral v * (- numeral w * y) = (- numeral(v * w) * y :: 'a::ring_1)" | |
| 1402 | "- numeral v * (- numeral w * y) = (numeral(v * w) * y :: 'a::ring_1)" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
55974diff
changeset | 1403 | by (simp_all add: mult.assoc [symmetric]) | 
| 47108 | 1404 | |
| 68536 | 1405 | lemmas mult_numeral_left [simp] = | 
| 1406 | mult_numeral_left_semiring_numeral | |
| 1407 | mult_numeral_left_ring_1 | |
| 1408 | ||
| 47108 | 1409 | hide_const (open) One Bit0 Bit1 BitM inc pow sqr sub dbl dbl_inc dbl_dec | 
| 1410 | ||
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
50817diff
changeset | 1411 | |
| 63654 | 1412 | subsection \<open>Code module namespace\<close> | 
| 47108 | 1413 | |
| 52435 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52210diff
changeset | 1414 | code_identifier | 
| 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 haftmann parents: 
52210diff
changeset | 1415 | code_module Num \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith | 
| 47108 | 1416 | |
| 66283 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1417 | subsection \<open>Printing of evaluated natural numbers as numerals\<close> | 
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1418 | |
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1419 | lemma [code_post]: | 
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1420 | "Suc 0 = 1" | 
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1421 | "Suc 1 = 2" | 
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1422 | "Suc (numeral n) = numeral (Num.inc n)" | 
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1423 | by (simp_all add: numeral_inc) | 
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1424 | |
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1425 | lemmas [code_post] = Num.inc.simps | 
| 
adf3155c57e2
Printing natural numbers as numerals in evaluation
 eberlm <eberlm@in.tum.de> parents: 
64238diff
changeset | 1426 | |
| 47108 | 1427 | end |