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