author | wenzelm |
Fri, 17 Nov 2006 02:20:03 +0100 | |
changeset 21404 | eb85850d3eb7 |
parent 20900 | c1ba49ade6a5 |
child 21779 | 6d44dbae4bfa |
permissions | -rw-r--r-- |
20485 | 1 |
(* Title: HOL/Integ/Numeral.thy |
15013 | 2 |
ID: $Id$ |
20485 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
4 |
Copyright 1994 University of Cambridge |
|
15013 | 5 |
*) |
6 |
||
20485 | 7 |
header {* Arithmetic on Binary Integers *} |
15013 | 8 |
|
15131 | 9 |
theory Numeral |
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15140
diff
changeset
|
10 |
imports IntDef Datatype |
16417 | 11 |
uses "../Tools/numeral_syntax.ML" |
15131 | 12 |
begin |
15013 | 13 |
|
20485 | 14 |
text {* |
15 |
This formalization defines binary arithmetic in terms of the integers |
|
16 |
rather than using a datatype. This avoids multiple representations (leading |
|
17 |
zeroes, etc.) See @{text "ZF/Integ/twos-compl.ML"}, function @{text |
|
18 |
int_of_binary}, for the numerical interpretation. |
|
15013 | 19 |
|
20485 | 20 |
The representation expects that @{text "(m mod 2)"} is 0 or 1, |
21 |
even if m is negative; |
|
22 |
For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus |
|
23 |
@{text "-5 = (-3)*2 + 1"}. |
|
15013 | 24 |
*} |
25 |
||
20485 | 26 |
text{* |
27 |
This datatype avoids the use of type @{typ bool}, which would make |
|
28 |
all of the rewrite rules higher-order. |
|
29 |
*} |
|
15013 | 30 |
|
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15140
diff
changeset
|
31 |
datatype bit = B0 | B1 |
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15140
diff
changeset
|
32 |
|
15013 | 33 |
constdefs |
20485 | 34 |
Pls :: int |
35 |
"Pls == 0" |
|
36 |
Min :: int |
|
37 |
"Min == - 1" |
|
38 |
Bit :: "int \<Rightarrow> bit \<Rightarrow> int" (infixl "BIT" 90) |
|
39 |
"k BIT b == (case b of B0 \<Rightarrow> 0 | B1 \<Rightarrow> 1) + k + k" |
|
15013 | 40 |
|
41 |
axclass |
|
42 |
number < type -- {* for numeric types: nat, int, real, \dots *} |
|
43 |
||
44 |
consts |
|
20485 | 45 |
number_of :: "int \<Rightarrow> 'a::number" |
15013 | 46 |
|
47 |
syntax |
|
20485 | 48 |
"_Numeral" :: "num_const \<Rightarrow> 'a" ("_") |
15013 | 49 |
|
50 |
setup NumeralSyntax.setup |
|
51 |
||
19380 | 52 |
abbreviation |
20485 | 53 |
"Numeral0 \<equiv> number_of Pls" |
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
20900
diff
changeset
|
54 |
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
20900
diff
changeset
|
55 |
abbreviation |
20485 | 56 |
"Numeral1 \<equiv> number_of (Pls BIT B1)" |
15013 | 57 |
|
20485 | 58 |
lemma Let_number_of [simp]: "Let (number_of v) f = f (number_of v)" |
15013 | 59 |
-- {* Unfold all @{text let}s involving constants *} |
20485 | 60 |
unfolding Let_def .. |
61 |
||
62 |
lemma Let_0 [simp]: "Let 0 f = f 0" |
|
63 |
unfolding Let_def .. |
|
64 |
||
65 |
lemma Let_1 [simp]: "Let 1 f = f 1" |
|
66 |
unfolding Let_def .. |
|
15013 | 67 |
|
20485 | 68 |
definition |
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
20900
diff
changeset
|
69 |
succ :: "int \<Rightarrow> int" where |
20485 | 70 |
"succ k = k + 1" |
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
20900
diff
changeset
|
71 |
|
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
20900
diff
changeset
|
72 |
definition |
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
20900
diff
changeset
|
73 |
pred :: "int \<Rightarrow> int" where |
20485 | 74 |
"pred k = k - 1" |
75 |
||
76 |
lemmas numeral_simps = |
|
77 |
succ_def pred_def Pls_def Min_def Bit_def |
|
15013 | 78 |
|
20485 | 79 |
text {* Removal of leading zeroes *} |
80 |
||
20699 | 81 |
lemma Pls_0_eq [simp, code func]: |
20485 | 82 |
"Pls BIT B0 = Pls" |
83 |
unfolding numeral_simps by simp |
|
84 |
||
20699 | 85 |
lemma Min_1_eq [simp, code func]: |
20485 | 86 |
"Min BIT B1 = Min" |
87 |
unfolding numeral_simps by simp |
|
15013 | 88 |
|
89 |
||
20485 | 90 |
subsection {* The Functions @{term succ}, @{term pred} and @{term uminus} *} |
15013 | 91 |
|
20485 | 92 |
lemma succ_Pls [simp]: |
93 |
"succ Pls = Pls BIT B1" |
|
94 |
unfolding numeral_simps by simp |
|
15013 | 95 |
|
20485 | 96 |
lemma succ_Min [simp]: |
97 |
"succ Min = Pls" |
|
98 |
unfolding numeral_simps by simp |
|
15013 | 99 |
|
20485 | 100 |
lemma succ_1 [simp]: |
101 |
"succ (k BIT B1) = succ k BIT B0" |
|
102 |
unfolding numeral_simps by simp |
|
15013 | 103 |
|
20485 | 104 |
lemma succ_0 [simp]: |
105 |
"succ (k BIT B0) = k BIT B1" |
|
106 |
unfolding numeral_simps by simp |
|
15013 | 107 |
|
20485 | 108 |
lemma pred_Pls [simp]: |
109 |
"pred Pls = Min" |
|
110 |
unfolding numeral_simps by simp |
|
15013 | 111 |
|
20485 | 112 |
lemma pred_Min [simp]: |
113 |
"pred Min = Min BIT B0" |
|
114 |
unfolding numeral_simps by simp |
|
15013 | 115 |
|
20485 | 116 |
lemma pred_1 [simp]: |
117 |
"pred (k BIT B1) = k BIT B0" |
|
118 |
unfolding numeral_simps by simp |
|
15013 | 119 |
|
20485 | 120 |
lemma pred_0 [simp]: |
121 |
"pred (k BIT B0) = pred k BIT B1" |
|
122 |
unfolding numeral_simps by simp |
|
15013 | 123 |
|
20485 | 124 |
lemma minus_Pls [simp]: |
125 |
"- Pls = Pls" |
|
126 |
unfolding numeral_simps by simp |
|
15013 | 127 |
|
20485 | 128 |
lemma minus_Min [simp]: |
129 |
"- Min = Pls BIT B1" |
|
130 |
unfolding numeral_simps by simp |
|
15013 | 131 |
|
20485 | 132 |
lemma minus_1 [simp]: |
133 |
"- (k BIT B1) = pred (- k) BIT B1" |
|
134 |
unfolding numeral_simps by simp |
|
15013 | 135 |
|
20485 | 136 |
lemma minus_0 [simp]: |
137 |
"- (k BIT B0) = (- k) BIT B0" |
|
138 |
unfolding numeral_simps by simp |
|
15013 | 139 |
|
140 |
||
20485 | 141 |
subsection {* |
142 |
Binary Addition and Multiplication: @{term "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"} |
|
143 |
and @{term "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"} |
|
144 |
*} |
|
15013 | 145 |
|
20485 | 146 |
lemma add_Pls [simp]: |
147 |
"Pls + k = k" |
|
148 |
unfolding numeral_simps by simp |
|
15013 | 149 |
|
20485 | 150 |
lemma add_Min [simp]: |
151 |
"Min + k = pred k" |
|
152 |
unfolding numeral_simps by simp |
|
15013 | 153 |
|
20485 | 154 |
lemma add_BIT_11 [simp]: |
155 |
"(k BIT B1) + (l BIT B1) = (k + succ l) BIT B0" |
|
156 |
unfolding numeral_simps by simp |
|
15013 | 157 |
|
20485 | 158 |
lemma add_BIT_10 [simp]: |
159 |
"(k BIT B1) + (l BIT B0) = (k + l) BIT B1" |
|
160 |
unfolding numeral_simps by simp |
|
15013 | 161 |
|
20485 | 162 |
lemma add_BIT_0 [simp]: |
163 |
"(k BIT B0) + (l BIT b) = (k + l) BIT b" |
|
164 |
unfolding numeral_simps by simp |
|
15013 | 165 |
|
20485 | 166 |
lemma add_Pls_right [simp]: |
167 |
"k + Pls = k" |
|
168 |
unfolding numeral_simps by simp |
|
15013 | 169 |
|
20485 | 170 |
lemma add_Min_right [simp]: |
171 |
"k + Min = pred k" |
|
172 |
unfolding numeral_simps by simp |
|
15013 | 173 |
|
20485 | 174 |
lemma mult_Pls [simp]: |
175 |
"Pls * w = Pls" |
|
176 |
unfolding numeral_simps by simp |
|
15013 | 177 |
|
20485 | 178 |
lemma mult_Min [simp]: |
179 |
"Min * k = - k" |
|
180 |
unfolding numeral_simps by simp |
|
15013 | 181 |
|
20485 | 182 |
lemma mult_num1 [simp]: |
183 |
"(k BIT B1) * l = ((k * l) BIT B0) + l" |
|
184 |
unfolding numeral_simps int_distrib by simp |
|
15013 | 185 |
|
20485 | 186 |
lemma mult_num0 [simp]: |
187 |
"(k BIT B0) * l = (k * l) BIT B0" |
|
188 |
unfolding numeral_simps int_distrib by simp |
|
15013 | 189 |
|
190 |
||
191 |
||
20485 | 192 |
subsection {* Converting Numerals to Rings: @{term number_of} *} |
15013 | 193 |
|
194 |
axclass number_ring \<subseteq> number, comm_ring_1 |
|
20485 | 195 |
number_of_eq: "number_of k = of_int k" |
15013 | 196 |
|
197 |
lemma number_of_succ: |
|
20485 | 198 |
"number_of (succ k) = (1 + number_of k ::'a::number_ring)" |
199 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 200 |
|
201 |
lemma number_of_pred: |
|
20485 | 202 |
"number_of (pred w) = (- 1 + number_of w ::'a::number_ring)" |
203 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 204 |
|
205 |
lemma number_of_minus: |
|
20485 | 206 |
"number_of (uminus w) = (- (number_of w)::'a::number_ring)" |
207 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 208 |
|
209 |
lemma number_of_add: |
|
20485 | 210 |
"number_of (v + w) = (number_of v + number_of w::'a::number_ring)" |
211 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 212 |
|
213 |
lemma number_of_mult: |
|
20485 | 214 |
"number_of (v * w) = (number_of v * number_of w::'a::number_ring)" |
215 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 216 |
|
20485 | 217 |
text {* |
218 |
The correctness of shifting. |
|
219 |
But it doesn't seem to give a measurable speed-up. |
|
220 |
*} |
|
221 |
||
15013 | 222 |
lemma double_number_of_BIT: |
20485 | 223 |
"(1 + 1) * number_of w = (number_of (w BIT B0) ::'a::number_ring)" |
224 |
unfolding number_of_eq numeral_simps left_distrib by simp |
|
15013 | 225 |
|
20485 | 226 |
text {* |
227 |
Converting numerals 0 and 1 to their abstract versions. |
|
228 |
*} |
|
229 |
||
230 |
lemma numeral_0_eq_0 [simp]: |
|
231 |
"Numeral0 = (0::'a::number_ring)" |
|
232 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 233 |
|
20485 | 234 |
lemma numeral_1_eq_1 [simp]: |
235 |
"Numeral1 = (1::'a::number_ring)" |
|
236 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 237 |
|
20485 | 238 |
text {* |
239 |
Special-case simplification for small constants. |
|
240 |
*} |
|
15013 | 241 |
|
20485 | 242 |
text{* |
243 |
Unary minus for the abstract constant 1. Cannot be inserted |
|
244 |
as a simprule until later: it is @{text number_of_Min} re-oriented! |
|
245 |
*} |
|
15013 | 246 |
|
20485 | 247 |
lemma numeral_m1_eq_minus_1: |
248 |
"(-1::'a::number_ring) = - 1" |
|
249 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 250 |
|
20485 | 251 |
lemma mult_minus1 [simp]: |
252 |
"-1 * z = -(z::'a::number_ring)" |
|
253 |
unfolding number_of_eq numeral_simps by simp |
|
254 |
||
255 |
lemma mult_minus1_right [simp]: |
|
256 |
"z * -1 = -(z::'a::number_ring)" |
|
257 |
unfolding number_of_eq numeral_simps by simp |
|
15013 | 258 |
|
259 |
(*Negation of a coefficient*) |
|
260 |
lemma minus_number_of_mult [simp]: |
|
20485 | 261 |
"- (number_of w) * z = number_of (uminus w) * (z::'a::number_ring)" |
262 |
unfolding number_of_eq by simp |
|
263 |
||
264 |
text {* Subtraction *} |
|
265 |
||
266 |
lemma diff_number_of_eq: |
|
267 |
"number_of v - number_of w = |
|
268 |
(number_of (v + uminus w)::'a::number_ring)" |
|
269 |
unfolding number_of_eq by simp |
|
15013 | 270 |
|
20485 | 271 |
lemma number_of_Pls: |
272 |
"number_of Pls = (0::'a::number_ring)" |
|
273 |
unfolding number_of_eq numeral_simps by simp |
|
274 |
||
275 |
lemma number_of_Min: |
|
276 |
"number_of Min = (- 1::'a::number_ring)" |
|
277 |
unfolding number_of_eq numeral_simps by simp |
|
278 |
||
279 |
lemma number_of_BIT: |
|
280 |
"number_of(w BIT x) = (case x of B0 => 0 | B1 => (1::'a::number_ring)) |
|
281 |
+ (number_of w) + (number_of w)" |
|
282 |
unfolding number_of_eq numeral_simps by (simp split: bit.split) |
|
15013 | 283 |
|
284 |
||
20485 | 285 |
subsection {* Equality of Binary Numbers *} |
15013 | 286 |
|
20485 | 287 |
text {* First version by Norbert Voelker *} |
15013 | 288 |
|
289 |
lemma eq_number_of_eq: |
|
290 |
"((number_of x::'a::number_ring) = number_of y) = |
|
20485 | 291 |
iszero (number_of (x + uminus y) :: 'a)" |
292 |
unfolding iszero_def number_of_add number_of_minus |
|
293 |
by (simp add: compare_rls) |
|
15013 | 294 |
|
20485 | 295 |
lemma iszero_number_of_Pls: |
296 |
"iszero ((number_of Pls)::'a::number_ring)" |
|
297 |
unfolding iszero_def numeral_0_eq_0 .. |
|
15013 | 298 |
|
20485 | 299 |
lemma nonzero_number_of_Min: |
300 |
"~ iszero ((number_of Min)::'a::number_ring)" |
|
301 |
unfolding iszero_def numeral_m1_eq_minus_1 by simp |
|
15013 | 302 |
|
303 |
||
20485 | 304 |
subsection {* Comparisons, for Ordered Rings *} |
15013 | 305 |
|
20485 | 306 |
lemma double_eq_0_iff: |
307 |
"(a + a = 0) = (a = (0::'a::ordered_idom))" |
|
15013 | 308 |
proof - |
20485 | 309 |
have "a + a = (1 + 1) * a" unfolding left_distrib by simp |
15013 | 310 |
with zero_less_two [where 'a = 'a] |
311 |
show ?thesis by force |
|
312 |
qed |
|
313 |
||
314 |
lemma le_imp_0_less: |
|
20485 | 315 |
assumes le: "0 \<le> z" |
316 |
shows "(0::int) < 1 + z" |
|
15013 | 317 |
proof - |
318 |
have "0 \<le> z" . |
|
319 |
also have "... < z + 1" by (rule less_add_one) |
|
320 |
also have "... = 1 + z" by (simp add: add_ac) |
|
321 |
finally show "0 < 1 + z" . |
|
322 |
qed |
|
323 |
||
20485 | 324 |
lemma odd_nonzero: |
325 |
"1 + z + z \<noteq> (0::int)"; |
|
15013 | 326 |
proof (cases z rule: int_cases) |
327 |
case (nonneg n) |
|
328 |
have le: "0 \<le> z+z" by (simp add: nonneg add_increasing) |
|
329 |
thus ?thesis using le_imp_0_less [OF le] |
|
330 |
by (auto simp add: add_assoc) |
|
331 |
next |
|
332 |
case (neg n) |
|
333 |
show ?thesis |
|
334 |
proof |
|
335 |
assume eq: "1 + z + z = 0" |
|
336 |
have "0 < 1 + (int n + int n)" |
|
337 |
by (simp add: le_imp_0_less add_increasing) |
|
338 |
also have "... = - (1 + z + z)" |
|
339 |
by (simp add: neg add_assoc [symmetric]) |
|
340 |
also have "... = 0" by (simp add: eq) |
|
341 |
finally have "0<0" .. |
|
342 |
thus False by blast |
|
343 |
qed |
|
344 |
qed |
|
345 |
||
20485 | 346 |
text {* The premise involving @{term Ints} prevents @{term "a = 1/2"}. *} |
15013 | 347 |
|
20485 | 348 |
lemma Ints_odd_nonzero: |
349 |
assumes in_Ints: "a \<in> Ints" |
|
350 |
shows "1 + a + a \<noteq> (0::'a::ordered_idom)" |
|
351 |
proof - |
|
352 |
from in_Ints have "a \<in> range of_int" unfolding Ints_def [symmetric] . |
|
15013 | 353 |
then obtain z where a: "a = of_int z" .. |
354 |
show ?thesis |
|
355 |
proof |
|
356 |
assume eq: "1 + a + a = 0" |
|
357 |
hence "of_int (1 + z + z) = (of_int 0 :: 'a)" by (simp add: a) |
|
358 |
hence "1 + z + z = 0" by (simp only: of_int_eq_iff) |
|
359 |
with odd_nonzero show False by blast |
|
360 |
qed |
|
361 |
qed |
|
362 |
||
20485 | 363 |
lemma Ints_number_of: |
364 |
"(number_of w :: 'a::number_ring) \<in> Ints" |
|
365 |
unfolding number_of_eq Ints_def by simp |
|
15013 | 366 |
|
367 |
lemma iszero_number_of_BIT: |
|
20485 | 368 |
"iszero (number_of (w BIT x)::'a) = |
369 |
(x = B0 \<and> iszero (number_of w::'a::{ordered_idom,number_ring}))" |
|
370 |
by (simp add: iszero_def number_of_eq numeral_simps double_eq_0_iff |
|
371 |
Ints_odd_nonzero Ints_def split: bit.split) |
|
15013 | 372 |
|
373 |
lemma iszero_number_of_0: |
|
20485 | 374 |
"iszero (number_of (w BIT B0) :: 'a::{ordered_idom,number_ring}) = |
375 |
iszero (number_of w :: 'a)" |
|
376 |
by (simp only: iszero_number_of_BIT simp_thms) |
|
15013 | 377 |
|
378 |
lemma iszero_number_of_1: |
|
20485 | 379 |
"~ iszero (number_of (w BIT B1)::'a::{ordered_idom,number_ring})" |
380 |
by (simp add: iszero_number_of_BIT) |
|
15013 | 381 |
|
382 |
||
20485 | 383 |
subsection {* The Less-Than Relation *} |
15013 | 384 |
|
385 |
lemma less_number_of_eq_neg: |
|
20485 | 386 |
"((number_of x::'a::{ordered_idom,number_ring}) < number_of y) |
387 |
= neg (number_of (x + uminus y) :: 'a)" |
|
15013 | 388 |
apply (subst less_iff_diff_less_0) |
389 |
apply (simp add: neg_def diff_minus number_of_add number_of_minus) |
|
390 |
done |
|
391 |
||
20485 | 392 |
text {* |
393 |
If @{term Numeral0} is rewritten to 0 then this rule can't be applied: |
|
394 |
@{term Numeral0} IS @{term "number_of Pls"} |
|
395 |
*} |
|
396 |
||
15013 | 397 |
lemma not_neg_number_of_Pls: |
20485 | 398 |
"~ neg (number_of Pls ::'a::{ordered_idom,number_ring})" |
399 |
by (simp add: neg_def numeral_0_eq_0) |
|
15013 | 400 |
|
401 |
lemma neg_number_of_Min: |
|
20485 | 402 |
"neg (number_of Min ::'a::{ordered_idom,number_ring})" |
403 |
by (simp add: neg_def zero_less_one numeral_m1_eq_minus_1) |
|
15013 | 404 |
|
20485 | 405 |
lemma double_less_0_iff: |
406 |
"(a + a < 0) = (a < (0::'a::ordered_idom))" |
|
15013 | 407 |
proof - |
408 |
have "(a + a < 0) = ((1+1)*a < 0)" by (simp add: left_distrib) |
|
409 |
also have "... = (a < 0)" |
|
410 |
by (simp add: mult_less_0_iff zero_less_two |
|
411 |
order_less_not_sym [OF zero_less_two]) |
|
412 |
finally show ?thesis . |
|
413 |
qed |
|
414 |
||
20485 | 415 |
lemma odd_less_0: |
416 |
"(1 + z + z < 0) = (z < (0::int))"; |
|
15013 | 417 |
proof (cases z rule: int_cases) |
418 |
case (nonneg n) |
|
419 |
thus ?thesis by (simp add: linorder_not_less add_assoc add_increasing |
|
420 |
le_imp_0_less [THEN order_less_imp_le]) |
|
421 |
next |
|
422 |
case (neg n) |
|
423 |
thus ?thesis by (simp del: int_Suc |
|
20485 | 424 |
add: int_Suc0_eq_1 [symmetric] zadd_int compare_rls) |
15013 | 425 |
qed |
426 |
||
20485 | 427 |
text {* The premise involving @{term Ints} prevents @{term "a = 1/2"}. *} |
428 |
||
15013 | 429 |
lemma Ints_odd_less_0: |
20485 | 430 |
assumes in_Ints: "a \<in> Ints" |
431 |
shows "(1 + a + a < 0) = (a < (0::'a::ordered_idom))"; |
|
432 |
proof - |
|
433 |
from in_Ints have "a \<in> range of_int" unfolding Ints_def [symmetric] . |
|
15013 | 434 |
then obtain z where a: "a = of_int z" .. |
435 |
hence "((1::'a) + a + a < 0) = (of_int (1 + z + z) < (of_int 0 :: 'a))" |
|
436 |
by (simp add: a) |
|
437 |
also have "... = (z < 0)" by (simp only: of_int_less_iff odd_less_0) |
|
438 |
also have "... = (a < 0)" by (simp add: a) |
|
439 |
finally show ?thesis . |
|
440 |
qed |
|
441 |
||
442 |
lemma neg_number_of_BIT: |
|
20485 | 443 |
"neg (number_of (w BIT x)::'a) = |
444 |
neg (number_of w :: 'a::{ordered_idom,number_ring})" |
|
445 |
by (simp add: neg_def number_of_eq numeral_simps double_less_0_iff |
|
446 |
Ints_odd_less_0 Ints_def split: bit.split) |
|
15013 | 447 |
|
20596 | 448 |
|
20485 | 449 |
text {* Less-Than or Equals *} |
450 |
||
451 |
text {* Reduces @{term "a\<le>b"} to @{term "~ (b<a)"} for ALL numerals. *} |
|
15013 | 452 |
|
453 |
lemmas le_number_of_eq_not_less = |
|
20485 | 454 |
linorder_not_less [of "number_of w" "number_of v", symmetric, |
455 |
standard] |
|
15013 | 456 |
|
457 |
lemma le_number_of_eq: |
|
458 |
"((number_of x::'a::{ordered_idom,number_ring}) \<le> number_of y) |
|
20485 | 459 |
= (~ (neg (number_of (y + uminus x) :: 'a)))" |
15013 | 460 |
by (simp add: le_number_of_eq_not_less less_number_of_eq_neg) |
461 |
||
462 |
||
20485 | 463 |
text {* Absolute value (@{term abs}) *} |
15013 | 464 |
|
465 |
lemma abs_number_of: |
|
20485 | 466 |
"abs(number_of x::'a::{ordered_idom,number_ring}) = |
467 |
(if number_of x < (0::'a) then -number_of x else number_of x)" |
|
468 |
by (simp add: abs_if) |
|
15013 | 469 |
|
470 |
||
20485 | 471 |
text {* Re-orientation of the equation nnn=x *} |
15013 | 472 |
|
20485 | 473 |
lemma number_of_reorient: |
474 |
"(number_of w = x) = (x = number_of w)" |
|
475 |
by auto |
|
15013 | 476 |
|
477 |
||
20485 | 478 |
subsection {* Simplification of arithmetic operations on integer constants. *} |
15013 | 479 |
|
20900 | 480 |
lemmas arith_extra_simps [standard] = |
20485 | 481 |
number_of_add [symmetric] |
482 |
number_of_minus [symmetric] numeral_m1_eq_minus_1 [symmetric] |
|
483 |
number_of_mult [symmetric] |
|
484 |
diff_number_of_eq abs_number_of |
|
485 |
||
486 |
text {* |
|
487 |
For making a minimal simpset, one must include these default simprules. |
|
488 |
Also include @{text simp_thms}. |
|
489 |
*} |
|
15013 | 490 |
|
20485 | 491 |
lemmas arith_simps = |
492 |
bit.distinct |
|
493 |
Pls_0_eq Min_1_eq |
|
494 |
pred_Pls pred_Min pred_1 pred_0 |
|
495 |
succ_Pls succ_Min succ_1 succ_0 |
|
496 |
add_Pls add_Min add_BIT_0 add_BIT_10 add_BIT_11 |
|
497 |
minus_Pls minus_Min minus_1 minus_0 |
|
498 |
mult_Pls mult_Min mult_num1 mult_num0 |
|
499 |
add_Pls_right add_Min_right |
|
500 |
abs_zero abs_one arith_extra_simps |
|
15013 | 501 |
|
20485 | 502 |
text {* Simplification of relational operations *} |
15013 | 503 |
|
20485 | 504 |
lemmas rel_simps = |
505 |
eq_number_of_eq iszero_number_of_Pls nonzero_number_of_Min |
|
506 |
iszero_number_of_0 iszero_number_of_1 |
|
507 |
less_number_of_eq_neg |
|
508 |
not_neg_number_of_Pls not_neg_0 not_neg_1 not_iszero_1 |
|
509 |
neg_number_of_Min neg_number_of_BIT |
|
510 |
le_number_of_eq |
|
511 |
||
512 |
declare arith_extra_simps [simp] |
|
513 |
declare rel_simps [simp] |
|
15013 | 514 |
|
515 |
||
20485 | 516 |
subsection {* Simplification of arithmetic when nested to the right. *} |
15013 | 517 |
|
518 |
lemma add_number_of_left [simp]: |
|
20485 | 519 |
"number_of v + (number_of w + z) = |
520 |
(number_of(v + w) + z::'a::number_ring)" |
|
521 |
by (simp add: add_assoc [symmetric]) |
|
15013 | 522 |
|
523 |
lemma mult_number_of_left [simp]: |
|
20485 | 524 |
"number_of v * (number_of w * z) = |
525 |
(number_of(v * w) * z::'a::number_ring)" |
|
526 |
by (simp add: mult_assoc [symmetric]) |
|
15013 | 527 |
|
528 |
lemma add_number_of_diff1: |
|
20485 | 529 |
"number_of v + (number_of w - c) = |
530 |
number_of(v + w) - (c::'a::number_ring)" |
|
531 |
by (simp add: diff_minus add_number_of_left) |
|
15013 | 532 |
|
20485 | 533 |
lemma add_number_of_diff2 [simp]: |
534 |
"number_of v + (c - number_of w) = |
|
535 |
number_of (v + uminus w) + (c::'a::number_ring)" |
|
15013 | 536 |
apply (subst diff_number_of_eq [symmetric]) |
537 |
apply (simp only: compare_rls) |
|
538 |
done |
|
539 |
||
19380 | 540 |
|
20500 | 541 |
hide (open) const Pls Min B0 B1 succ pred |
19380 | 542 |
|
15013 | 543 |
end |