author | paulson |
Tue, 28 Sep 1999 15:31:54 +0200 | |
changeset 7625 | 94b2a50e69a5 |
parent 7519 | 8e4a21d1ba4f |
child 8028 | 5357e8eb09c8 |
permissions | -rw-r--r-- |
7032 | 1 |
(* Title: HOL/NatBin.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
||
6 |
Binary arithmetic for the natural numbers |
|
7 |
*) |
|
8 |
||
9 |
(** nat (coercion from int to nat) **) |
|
10 |
||
11 |
Goal "nat (number_of w) = number_of w"; |
|
12 |
by (simp_tac (simpset() addsimps [nat_number_of_def]) 1); |
|
13 |
qed "nat_number_of"; |
|
14 |
Addsimps [nat_number_of]; |
|
15 |
||
16 |
(*These rewrites should one day be re-oriented...*) |
|
17 |
||
18 |
Goal "#0 = 0"; |
|
19 |
by (simp_tac (simpset_of Int.thy addsimps [nat_0, nat_number_of_def]) 1); |
|
20 |
qed "numeral_0_eq_0"; |
|
21 |
||
22 |
Goal "#1 = 1"; |
|
23 |
by (simp_tac (simpset_of Int.thy addsimps [nat_1, nat_number_of_def]) 1); |
|
24 |
qed "numeral_1_eq_1"; |
|
25 |
||
26 |
Goal "#2 = 2"; |
|
27 |
by (simp_tac (simpset_of Int.thy addsimps [nat_2, nat_number_of_def]) 1); |
|
28 |
qed "numeral_2_eq_2"; |
|
29 |
||
30 |
||
31 |
(** int (coercion from nat to int) **) |
|
32 |
||
33 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
34 |
Goal "int (number_of v :: nat) = \ |
|
35 |
\ (if neg (number_of v) then #0 \ |
|
36 |
\ else (number_of v :: int))"; |
|
37 |
by (simp_tac |
|
38 |
(simpset_of Int.thy addsimps [neg_nat, nat_number_of_def, |
|
39 |
not_neg_nat, int_0]) 1); |
|
40 |
qed "int_nat_number_of"; |
|
41 |
Addsimps [int_nat_number_of]; |
|
42 |
||
43 |
||
44 |
(** Successor **) |
|
45 |
||
46 |
Goal "(#0::int) <= z ==> Suc (nat z) = nat (#1 + z)"; |
|
7086 | 47 |
by (rtac sym 1); |
7032 | 48 |
by (asm_simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
49 |
qed "Suc_nat_eq_nat_zadd1"; |
|
50 |
||
51 |
Goal "Suc (number_of v) = \ |
|
52 |
\ (if neg (number_of v) then #1 else number_of (bin_succ v))"; |
|
53 |
by (simp_tac |
|
54 |
(simpset_of Int.thy addsimps [neg_nat, nat_1, not_neg_eq_ge_0, |
|
55 |
nat_number_of_def, int_Suc, |
|
56 |
Suc_nat_eq_nat_zadd1, number_of_succ]) 1); |
|
57 |
qed "Suc_nat_number_of"; |
|
58 |
||
59 |
Goal "Suc #0 = #1"; |
|
60 |
by (simp_tac (simpset() addsimps [Suc_nat_number_of]) 1); |
|
61 |
qed "Suc_numeral_0_eq_1"; |
|
62 |
||
63 |
Goal "Suc #1 = #2"; |
|
64 |
by (simp_tac (simpset() addsimps [Suc_nat_number_of]) 1); |
|
65 |
qed "Suc_numeral_1_eq_2"; |
|
66 |
||
67 |
(** Addition **) |
|
68 |
||
69 |
Goal "[| (#0::int) <= z; #0 <= z' |] ==> nat z + nat z' = nat (z+z')"; |
|
70 |
by (rtac (inj_int RS injD) 1); |
|
71 |
by (asm_simp_tac (simpset() addsimps [zadd_int RS sym]) 1); |
|
72 |
qed "add_nat_eq_nat_zadd"; |
|
73 |
||
74 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
75 |
Goal "(number_of v :: nat) + number_of v' = \ |
|
76 |
\ (if neg (number_of v) then number_of v' \ |
|
77 |
\ else if neg (number_of v') then number_of v \ |
|
78 |
\ else number_of (bin_add v v'))"; |
|
79 |
by (simp_tac |
|
80 |
(simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, |
|
81 |
add_nat_eq_nat_zadd, number_of_add]) 1); |
|
82 |
qed "add_nat_number_of"; |
|
83 |
||
84 |
Addsimps [add_nat_number_of]; |
|
85 |
||
86 |
||
87 |
(** Subtraction **) |
|
88 |
||
89 |
Goal "[| (#0::int) <= z'; z' <= z |] ==> nat z - nat z' = nat (z-z')"; |
|
90 |
by (rtac (inj_int RS injD) 1); |
|
91 |
by (asm_simp_tac (simpset() addsimps [zdiff_int RS sym, nat_le_eq_zle]) 1); |
|
92 |
qed "diff_nat_eq_nat_zdiff"; |
|
93 |
||
94 |
||
95 |
Goal "nat z - nat z' = \ |
|
96 |
\ (if neg z' then nat z \ |
|
97 |
\ else let d = z-z' in \ |
|
98 |
\ if neg d then 0 else nat d)"; |
|
99 |
by (simp_tac (simpset() addsimps [Let_def, diff_nat_eq_nat_zdiff, |
|
100 |
neg_eq_less_0, not_neg_eq_ge_0]) 1); |
|
101 |
by (simp_tac (simpset() addsimps zcompare_rls@ |
|
102 |
[diff_is_0_eq, nat_le_eq_zle]) 1); |
|
103 |
qed "diff_nat_eq_if"; |
|
104 |
||
105 |
Goalw [nat_number_of_def] |
|
106 |
"(number_of v :: nat) - number_of v' = \ |
|
107 |
\ (if neg (number_of v') then number_of v \ |
|
108 |
\ else let d = number_of (bin_add v (bin_minus v')) in \ |
|
109 |
\ if neg d then #0 else nat d)"; |
|
110 |
by (simp_tac |
|
111 |
(simpset_of Int.thy delcongs [if_weak_cong] |
|
112 |
addsimps [not_neg_eq_ge_0, nat_0, |
|
113 |
diff_nat_eq_if, diff_number_of_eq]) 1); |
|
114 |
qed "diff_nat_number_of"; |
|
115 |
||
116 |
Addsimps [diff_nat_number_of]; |
|
117 |
||
118 |
||
119 |
(** Multiplication **) |
|
120 |
||
121 |
Goal "(#0::int) <= z ==> nat z * nat z' = nat (z*z')"; |
|
122 |
by (case_tac "#0 <= z'" 1); |
|
123 |
by (subgoal_tac "z'*z <= #0" 2); |
|
124 |
by (rtac (neg_imp_zmult_nonpos_iff RS iffD2) 3); |
|
7075 | 125 |
by (auto_tac (claset(), |
126 |
simpset() addsimps [zmult_commute])); |
|
7032 | 127 |
by (subgoal_tac "#0 <= z*z'" 1); |
128 |
by (force_tac (claset() addDs [zmult_zle_mono1], simpset()) 2); |
|
129 |
by (rtac (inj_int RS injD) 1); |
|
130 |
by (asm_simp_tac (simpset() addsimps [zmult_int RS sym]) 1); |
|
131 |
qed "mult_nat_eq_nat_zmult"; |
|
132 |
||
133 |
Goal "(number_of v :: nat) * number_of v' = \ |
|
134 |
\ (if neg (number_of v) then #0 else number_of (bin_mult v v'))"; |
|
135 |
by (simp_tac |
|
136 |
(simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, |
|
137 |
mult_nat_eq_nat_zmult, number_of_mult, |
|
138 |
nat_0]) 1); |
|
139 |
qed "mult_nat_number_of"; |
|
140 |
||
141 |
Addsimps [mult_nat_number_of]; |
|
142 |
||
143 |
||
144 |
(** Quotient **) |
|
145 |
||
146 |
Goal "(#0::int) <= z ==> nat z div nat z' = nat (z div z')"; |
|
147 |
by (case_tac "#0 <= z'" 1); |
|
148 |
by (auto_tac (claset(), |
|
7127
48e235179ffb
added parentheses to cope with a possible reduction of the precedence of unary
paulson
parents:
7086
diff
changeset
|
149 |
simpset() addsimps [div_nonneg_neg_le0, DIVISION_BY_ZERO_DIV])); |
7032 | 150 |
by (zdiv_undefined_case_tac "z' = #0" 1); |
151 |
by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_DIV]) 1); |
|
152 |
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset())); |
|
153 |
by (rename_tac "m m'" 1); |
|
154 |
by (subgoal_tac "#0 <= int m div int m'" 1); |
|
155 |
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, numeral_0_eq_0, |
|
156 |
pos_imp_zdiv_nonneg_iff]) 2); |
|
157 |
by (rtac (inj_int RS injD) 1); |
|
158 |
by (Asm_simp_tac 1); |
|
159 |
by (rtac sym 1); |
|
160 |
by (res_inst_tac [("r", "int (m mod m')")] quorem_div 1); |
|
161 |
by (Force_tac 2); |
|
162 |
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, quorem_def, |
|
163 |
numeral_0_eq_0, zadd_int, zmult_int, |
|
164 |
mod_less_divisor]) 1); |
|
165 |
by (rtac (mod_div_equality RS sym RS trans) 1); |
|
166 |
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1); |
|
167 |
qed "div_nat_eq_nat_zdiv"; |
|
168 |
||
169 |
Goal "(number_of v :: nat) div number_of v' = \ |
|
170 |
\ (if neg (number_of v) then #0 \ |
|
171 |
\ else nat (number_of v div number_of v'))"; |
|
172 |
by (simp_tac |
|
173 |
(simpset_of Int.thy addsimps [not_neg_eq_ge_0, nat_number_of_def, neg_nat, |
|
174 |
div_nat_eq_nat_zdiv, nat_0]) 1); |
|
175 |
qed "div_nat_number_of"; |
|
176 |
||
177 |
Addsimps [div_nat_number_of]; |
|
178 |
||
179 |
||
180 |
(** Remainder **) |
|
181 |
||
182 |
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*) |
|
183 |
Goal "[| (#0::int) <= z; #0 <= z' |] ==> nat z mod nat z' = nat (z mod z')"; |
|
184 |
by (zdiv_undefined_case_tac "z' = #0" 1); |
|
185 |
by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_MOD]) 1); |
|
186 |
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset())); |
|
187 |
by (rename_tac "m m'" 1); |
|
188 |
by (subgoal_tac "#0 <= int m mod int m'" 1); |
|
189 |
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, numeral_0_eq_0, |
|
190 |
pos_mod_sign]) 2); |
|
191 |
by (rtac (inj_int RS injD) 1); |
|
192 |
by (Asm_simp_tac 1); |
|
193 |
by (rtac sym 1); |
|
194 |
by (res_inst_tac [("q", "int (m div m')")] quorem_mod 1); |
|
195 |
by (Force_tac 2); |
|
196 |
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, quorem_def, |
|
197 |
numeral_0_eq_0, zadd_int, zmult_int, |
|
198 |
mod_less_divisor]) 1); |
|
199 |
by (rtac (mod_div_equality RS sym RS trans) 1); |
|
200 |
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1); |
|
201 |
qed "mod_nat_eq_nat_zmod"; |
|
202 |
||
203 |
Goal "(number_of v :: nat) mod number_of v' = \ |
|
204 |
\ (if neg (number_of v) then #0 \ |
|
205 |
\ else if neg (number_of v') then number_of v \ |
|
206 |
\ else nat (number_of v mod number_of v'))"; |
|
207 |
by (simp_tac |
|
208 |
(simpset_of Int.thy addsimps [not_neg_eq_ge_0, nat_number_of_def, |
|
209 |
neg_nat, nat_0, DIVISION_BY_ZERO_MOD, |
|
210 |
mod_nat_eq_nat_zmod]) 1); |
|
211 |
qed "mod_nat_number_of"; |
|
212 |
||
213 |
Addsimps [mod_nat_number_of]; |
|
214 |
||
215 |
||
216 |
(*** Comparisons ***) |
|
217 |
||
218 |
(** Equals (=) **) |
|
219 |
||
220 |
Goal "[| (#0::int) <= z; #0 <= z' |] ==> (nat z = nat z') = (z=z')"; |
|
221 |
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset())); |
|
222 |
qed "eq_nat_nat_iff"; |
|
223 |
||
224 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
225 |
Goal "((number_of v :: nat) = number_of v') = \ |
|
226 |
\ (if neg (number_of v) then ((#0::nat) = number_of v') \ |
|
227 |
\ else if neg (number_of v') then iszero (number_of v) \ |
|
228 |
\ else iszero (number_of (bin_add v (bin_minus v'))))"; |
|
229 |
by (simp_tac |
|
230 |
(simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, |
|
231 |
eq_nat_nat_iff, eq_number_of_eq, nat_0]) 1); |
|
232 |
by (simp_tac (simpset_of Int.thy addsimps [nat_eq_iff, iszero_def]) 1); |
|
233 |
qed "eq_nat_number_of"; |
|
234 |
||
235 |
Addsimps [eq_nat_number_of]; |
|
236 |
||
237 |
(** Less-than (<) **) |
|
238 |
||
239 |
(*"neg" is used in rewrite rules for binary comparisons*) |
|
240 |
Goal "((number_of v :: nat) < number_of v') = \ |
|
241 |
\ (if neg (number_of v) then neg (number_of (bin_minus v')) \ |
|
242 |
\ else neg (number_of (bin_add v (bin_minus v'))))"; |
|
243 |
by (simp_tac |
|
244 |
(simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, |
|
245 |
nat_less_eq_zless, less_number_of_eq_neg, |
|
246 |
nat_0]) 1); |
|
247 |
by (simp_tac (simpset_of Int.thy addsimps [neg_eq_less_int0, zminus_zless, |
|
7519
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
248 |
number_of_minus, zless_nat_eq_int_zless]) 1); |
7032 | 249 |
qed "less_nat_number_of"; |
250 |
||
251 |
Addsimps [less_nat_number_of]; |
|
252 |
||
253 |
||
254 |
(** Less-than-or-equals (<=) **) |
|
255 |
||
256 |
Goal "(number_of x <= (number_of y::nat)) = \ |
|
257 |
\ (~ number_of y < (number_of x::nat))"; |
|
258 |
by (rtac (linorder_not_less RS sym) 1); |
|
259 |
qed "le_nat_number_of_eq_not_less"; |
|
260 |
||
261 |
Addsimps [le_nat_number_of_eq_not_less]; |
|
262 |
||
263 |
||
264 |
(*** New versions of existing theorems involving 0, 1, 2 ***) |
|
265 |
||
266 |
fun change_theory thy th = |
|
267 |
[th, read_instantiate_sg (sign_of thy) [("t","dummyVar")] refl] |
|
268 |
MRS (conjI RS conjunct1) |> standard; |
|
269 |
||
270 |
(*Maps n to #n for n = 0, 1, 2*) |
|
271 |
val numeral_sym_ss = |
|
272 |
HOL_ss addsimps [numeral_0_eq_0 RS sym, |
|
273 |
numeral_1_eq_1 RS sym, |
|
274 |
numeral_2_eq_2 RS sym, |
|
275 |
Suc_numeral_1_eq_2, Suc_numeral_0_eq_1]; |
|
276 |
||
277 |
fun rename_numerals thy th = simplify numeral_sym_ss (change_theory thy th); |
|
278 |
||
279 |
(*Maps #n to n for n = 0, 1, 2*) |
|
280 |
val numeral_ss = |
|
281 |
simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1, numeral_2_eq_2]; |
|
282 |
||
283 |
(** Nat **) |
|
284 |
||
285 |
Goal "#0 < n ==> n = Suc(n - #1)"; |
|
286 |
by (asm_full_simp_tac numeral_ss 1); |
|
287 |
qed "Suc_pred'"; |
|
288 |
||
289 |
||
290 |
fun inst x t = read_instantiate_sg (sign_of NatBin.thy) [(x,t)]; |
|
291 |
||
292 |
(*Expresses a natural number constant as the Suc of another one. |
|
293 |
NOT suitable for rewriting because n recurs in the condition.*) |
|
294 |
bind_thm ("expand_Suc", inst "n" "number_of ?v" Suc_pred'); |
|
295 |
||
7056
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
296 |
(** NatDef & Nat **) |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
297 |
|
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
298 |
Addsimps (map (rename_numerals thy) |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
299 |
[min_0L, min_0R, max_0L, max_0R]); |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
300 |
|
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
301 |
AddIffs (map (rename_numerals thy) |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
302 |
[Suc_not_Zero, Zero_not_Suc, zero_less_Suc, not_less0, less_one, |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
303 |
le0, le_0_eq, |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
304 |
neq0_conv, zero_neq_conv, not_gr0]); |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
305 |
|
7032 | 306 |
(** Arith **) |
307 |
||
308 |
Addsimps (map (rename_numerals thy) |
|
309 |
[diff_0_eq_0, add_0, add_0_right, add_pred, |
|
7056
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
310 |
diff_is_0_eq, zero_is_diff_eq, zero_less_diff, |
7032 | 311 |
mult_0, mult_0_right, mult_1, mult_1_right, |
7625 | 312 |
mult_is_0, zero_is_mult, zero_less_mult_iff, |
7032 | 313 |
mult_eq_1_iff]); |
314 |
||
315 |
AddIffs (map (rename_numerals thy) [add_is_0, zero_is_add, add_gr_0]); |
|
316 |
||
7056
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
317 |
Goal "Suc n = n + #1"; |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
318 |
by (asm_simp_tac numeral_ss 1); |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
319 |
qed "Suc_eq_add_numeral_1"; |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
320 |
|
7032 | 321 |
(* These two can be useful when m = number_of... *) |
322 |
||
323 |
Goal "(m::nat) + n = (if m=#0 then n else Suc ((m - #1) + n))"; |
|
324 |
by (exhaust_tac "m" 1); |
|
325 |
by (ALLGOALS (asm_simp_tac numeral_ss)); |
|
326 |
qed "add_eq_if"; |
|
327 |
||
328 |
Goal "(m::nat) * n = (if m=#0 then #0 else n + ((m - #1) * n))"; |
|
329 |
by (exhaust_tac "m" 1); |
|
330 |
by (ALLGOALS (asm_simp_tac numeral_ss)); |
|
331 |
qed "mult_eq_if"; |
|
332 |
||
7056
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
333 |
Goal "(p ^ m :: nat) = (if m=#0 then #1 else p * (p ^ (m - #1)))"; |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
334 |
by (exhaust_tac "m" 1); |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
335 |
by (ALLGOALS (asm_simp_tac numeral_ss)); |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
336 |
qed "power_eq_if"; |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
337 |
|
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
338 |
Goal "[| #0<n; #0<m |] ==> m - n < (m::nat)"; |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
339 |
by (asm_full_simp_tac (numeral_ss addsimps [diff_less]) 1); |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
340 |
qed "diff_less'"; |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
341 |
|
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
342 |
Addsimps [inst "n" "number_of ?v" diff_less']; |
522a7013d7df
more existing theorems renamed to use #0; also new results
paulson
parents:
7032
diff
changeset
|
343 |
|
7032 | 344 |
(*various theorems that aren't in the default simpset*) |
345 |
val add_is_one' = rename_numerals thy add_is_1; |
|
346 |
val one_is_add' = rename_numerals thy one_is_add; |
|
347 |
val zero_induct' = rename_numerals thy zero_induct; |
|
348 |
val diff_self_eq_0' = rename_numerals thy diff_self_eq_0; |
|
349 |
val mult_eq_self_implies_10' = rename_numerals thy mult_eq_self_implies_10; |
|
350 |
val le_pred_eq' = rename_numerals thy le_pred_eq; |
|
351 |
val less_pred_eq' = rename_numerals thy less_pred_eq; |
|
352 |
||
353 |
(** Divides **) |
|
354 |
||
355 |
Addsimps (map (rename_numerals thy) |
|
356 |
[mod_1, mod_0, div_1, div_0, mod2_gr_0, mod2_add_self_eq_0, |
|
357 |
mod2_add_self]); |
|
358 |
||
359 |
AddIffs (map (rename_numerals thy) |
|
360 |
[dvd_1_left, dvd_0_right]); |
|
361 |
||
362 |
(*useful?*) |
|
363 |
val mod_self' = rename_numerals thy mod_self; |
|
364 |
val div_self' = rename_numerals thy div_self; |
|
365 |
val div_less' = rename_numerals thy div_less; |
|
366 |
val mod_mult_self_is_zero' = rename_numerals thy mod_mult_self_is_0; |
|
367 |
||
368 |
(** Power **) |
|
369 |
||
370 |
Goal "(p::nat) ^ #0 = #1"; |
|
371 |
by (simp_tac numeral_ss 1); |
|
372 |
qed "power_zero"; |
|
373 |
Addsimps [power_zero]; |
|
374 |
||
375 |
val binomial_zero = rename_numerals thy binomial_0; |
|
376 |
val binomial_Suc' = rename_numerals thy binomial_Suc; |
|
377 |
val binomial_n_n' = rename_numerals thy binomial_n_n; |
|
378 |
||
379 |
(*binomial_0_Suc doesn't work well on numerals*) |
|
380 |
Addsimps (map (rename_numerals thy) |
|
381 |
[binomial_n_0, binomial_zero, binomial_1]); |
|
382 |
||
7519
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
383 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
384 |
(*** Comparisons involving 0 ***) |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
385 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
386 |
Goal "(number_of v = 0) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
387 |
\ (if neg (number_of v) then True else iszero (number_of v))"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
388 |
by (simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym]) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
389 |
qed "eq_number_of_0"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
390 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
391 |
Goal "(0 = number_of v) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
392 |
\ (if neg (number_of v) then True else iszero (number_of v))"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
393 |
by (rtac ([eq_sym_conv, eq_number_of_0] MRS trans) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
394 |
qed "eq_0_number_of"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
395 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
396 |
Goal "(0 < number_of v) = neg (number_of (bin_minus v))"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
397 |
by (simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym]) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
398 |
qed "less_0_number_of"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
399 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
400 |
(*Simplification already handles n<0, n<=0 and 0<=n.*) |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
401 |
Addsimps [eq_number_of_0, eq_0_number_of, less_0_number_of]; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
402 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
403 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
404 |
(*** Comparisons involving Suc ***) |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
405 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
406 |
Goal "(number_of v = Suc n) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
407 |
\ (let pv = number_of (bin_pred v) in \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
408 |
\ if neg pv then False else nat pv = n)"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
409 |
by (simp_tac |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
410 |
(simpset_of Int.thy addsimps |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
411 |
[Let_def, neg_eq_less_0, linorder_not_less, number_of_pred, |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
412 |
nat_number_of_def, zadd_0]@zadd_ac@zcompare_rls) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
413 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
414 |
by (auto_tac (claset(), |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
415 |
simpset() addsimps [nat_eq_iff]@zcompare_rls)); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
416 |
qed "eq_number_of_Suc"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
417 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
418 |
Goal "(Suc n = number_of v) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
419 |
\ (let pv = number_of (bin_pred v) in \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
420 |
\ if neg pv then False else nat pv = n)"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
421 |
by (rtac ([eq_sym_conv, eq_number_of_Suc] MRS trans) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
422 |
qed "Suc_eq_number_of"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
423 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
424 |
Goal "(number_of v < Suc n) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
425 |
\ (let pv = number_of (bin_pred v) in \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
426 |
\ if neg pv then True else nat pv < n)"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
427 |
by (simp_tac |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
428 |
(simpset_of Int.thy addsimps |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
429 |
[Let_def, neg_eq_less_0, linorder_not_less, number_of_pred, |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
430 |
nat_number_of_def, zadd_0]@zadd_ac@zcompare_rls) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
431 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
432 |
by (auto_tac (claset(), |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
433 |
simpset() addsimps [nat_less_iff]@zcompare_rls)); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
434 |
qed "less_number_of_Suc"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
435 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
436 |
Goal "(Suc n < number_of v) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
437 |
\ (let pv = number_of (bin_pred v) in \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
438 |
\ if neg pv then False else n < nat pv)"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
439 |
by (simp_tac |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
440 |
(simpset_of Int.thy addsimps |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
441 |
[Let_def, neg_eq_less_0, linorder_not_less, number_of_pred, |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
442 |
nat_number_of_def, zadd_0]@zadd_ac@zcompare_rls) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
443 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
444 |
by (auto_tac (claset(), |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
445 |
simpset() addsimps [zless_nat_eq_int_zless]@zcompare_rls)); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
446 |
qed "less_Suc_number_of"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
447 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
448 |
Goal "(number_of v <= Suc n) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
449 |
\ (let pv = number_of (bin_pred v) in \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
450 |
\ if neg pv then True else nat pv <= n)"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
451 |
by (simp_tac |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
452 |
(simpset_of Int.thy addsimps |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
453 |
[Let_def, less_Suc_number_of, linorder_not_less RS sym]) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
454 |
qed "le_number_of_Suc"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
455 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
456 |
Goal "(Suc n <= number_of v) = \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
457 |
\ (let pv = number_of (bin_pred v) in \ |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
458 |
\ if neg pv then False else n <= nat pv)"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
459 |
by (simp_tac |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
460 |
(simpset_of Int.thy addsimps |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
461 |
[Let_def, less_number_of_Suc, linorder_not_less RS sym]) 1); |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
462 |
qed "le_Suc_number_of"; |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
463 |
|
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
464 |
Addsimps [eq_number_of_Suc, Suc_eq_number_of, |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
465 |
less_number_of_Suc, less_Suc_number_of, |
8e4a21d1ba4f
simplification of relations involving 0, Suc and natural-number numerals
paulson
parents:
7127
diff
changeset
|
466 |
le_number_of_Suc, le_Suc_number_of]; |