author | paulson |
Thu, 08 Jul 1999 13:43:42 +0200 | |
changeset 6917 | eba301caceea |
parent 6910 | 7c3503ae3d78 |
child 6941 | f52c70a449fb |
permissions | -rw-r--r-- |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
1 |
(* Title: HOL/Integ/Bin.ML |
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
2 |
Authors: Lawrence C Paulson, Cambridge University Computer Laboratory |
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
3 |
David Spelt, University of Twente |
6060 | 4 |
Tobias Nipkow, Technical University Munich |
1632 | 5 |
Copyright 1994 University of Cambridge |
6060 | 6 |
Copyright 1996 University of Twente |
7 |
Copyright 1999 TU Munich |
|
1632 | 8 |
|
6060 | 9 |
Arithmetic on binary integers; |
10 |
decision procedure for linear arithmetic. |
|
1632 | 11 |
*) |
12 |
||
13 |
(** extra rules for bin_succ, bin_pred, bin_add, bin_mult **) |
|
14 |
||
6910 | 15 |
qed_goal "NCons_Pls_0" thy |
5512 | 16 |
"NCons Pls False = Pls" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
17 |
(fn _ => [(Simp_tac 1)]); |
1632 | 18 |
|
6910 | 19 |
qed_goal "NCons_Pls_1" thy |
5512 | 20 |
"NCons Pls True = Pls BIT True" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
21 |
(fn _ => [(Simp_tac 1)]); |
1632 | 22 |
|
6910 | 23 |
qed_goal "NCons_Min_0" thy |
5512 | 24 |
"NCons Min False = Min BIT False" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
25 |
(fn _ => [(Simp_tac 1)]); |
1632 | 26 |
|
6910 | 27 |
qed_goal "NCons_Min_1" thy |
5512 | 28 |
"NCons Min True = Min" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
29 |
(fn _ => [(Simp_tac 1)]); |
1632 | 30 |
|
6910 | 31 |
qed_goal "bin_succ_1" thy |
5512 | 32 |
"bin_succ(w BIT True) = (bin_succ w) BIT False" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
33 |
(fn _ => [(Simp_tac 1)]); |
1632 | 34 |
|
6910 | 35 |
qed_goal "bin_succ_0" thy |
5512 | 36 |
"bin_succ(w BIT False) = NCons w True" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
37 |
(fn _ => [(Simp_tac 1)]); |
1632 | 38 |
|
6910 | 39 |
qed_goal "bin_pred_1" thy |
5512 | 40 |
"bin_pred(w BIT True) = NCons w False" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
41 |
(fn _ => [(Simp_tac 1)]); |
1632 | 42 |
|
6910 | 43 |
qed_goal "bin_pred_0" thy |
5512 | 44 |
"bin_pred(w BIT False) = (bin_pred w) BIT True" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
45 |
(fn _ => [(Simp_tac 1)]); |
1632 | 46 |
|
6910 | 47 |
qed_goal "bin_minus_1" thy |
5512 | 48 |
"bin_minus(w BIT True) = bin_pred (NCons (bin_minus w) False)" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
49 |
(fn _ => [(Simp_tac 1)]); |
1632 | 50 |
|
6910 | 51 |
qed_goal "bin_minus_0" thy |
5512 | 52 |
"bin_minus(w BIT False) = (bin_minus w) BIT False" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
53 |
(fn _ => [(Simp_tac 1)]); |
1632 | 54 |
|
5491 | 55 |
|
1632 | 56 |
(*** bin_add: binary addition ***) |
57 |
||
6910 | 58 |
qed_goal "bin_add_BIT_11" thy |
5512 | 59 |
"bin_add (v BIT True) (w BIT True) = \ |
60 |
\ NCons (bin_add v (bin_succ w)) False" |
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
61 |
(fn _ => [(Simp_tac 1)]); |
1632 | 62 |
|
6910 | 63 |
qed_goal "bin_add_BIT_10" thy |
5512 | 64 |
"bin_add (v BIT True) (w BIT False) = NCons (bin_add v w) True" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
65 |
(fn _ => [(Simp_tac 1)]); |
1632 | 66 |
|
6910 | 67 |
qed_goal "bin_add_BIT_0" thy |
5512 | 68 |
"bin_add (v BIT False) (w BIT y) = NCons (bin_add v w) y" |
5491 | 69 |
(fn _ => [Auto_tac]); |
1632 | 70 |
|
5551 | 71 |
Goal "bin_add w Pls = w"; |
72 |
by (induct_tac "w" 1); |
|
73 |
by Auto_tac; |
|
74 |
qed "bin_add_Pls_right"; |
|
1632 | 75 |
|
6910 | 76 |
qed_goal "bin_add_BIT_Min" thy |
5512 | 77 |
"bin_add (v BIT x) Min = bin_pred (v BIT x)" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
78 |
(fn _ => [(Simp_tac 1)]); |
1632 | 79 |
|
6910 | 80 |
qed_goal "bin_add_BIT_BIT" thy |
5512 | 81 |
"bin_add (v BIT x) (w BIT y) = \ |
82 |
\ NCons(bin_add v (if x & y then (bin_succ w) else w)) (x~= y)" |
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
83 |
(fn _ => [(Simp_tac 1)]); |
1632 | 84 |
|
85 |
||
6036 | 86 |
(*** bin_mult: binary multiplication ***) |
1632 | 87 |
|
6910 | 88 |
qed_goal "bin_mult_1" thy |
5512 | 89 |
"bin_mult (v BIT True) w = bin_add (NCons (bin_mult v w) False) w" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
90 |
(fn _ => [(Simp_tac 1)]); |
1632 | 91 |
|
6910 | 92 |
qed_goal "bin_mult_0" thy |
5512 | 93 |
"bin_mult (v BIT False) w = NCons (bin_mult v w) False" |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
94 |
(fn _ => [(Simp_tac 1)]); |
1632 | 95 |
|
96 |
||
97 |
(**** The carry/borrow functions, bin_succ and bin_pred ****) |
|
98 |
||
99 |
||
6910 | 100 |
(**** number_of ****) |
1632 | 101 |
|
6910 | 102 |
qed_goal "number_of_NCons" thy |
103 |
"number_of(NCons w b) = (number_of(w BIT b)::int)" |
|
5184 | 104 |
(fn _ =>[(induct_tac "w" 1), |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
105 |
(ALLGOALS Asm_simp_tac) ]); |
1632 | 106 |
|
6910 | 107 |
Addsimps [number_of_NCons]; |
1632 | 108 |
|
6910 | 109 |
qed_goal "number_of_succ" thy |
110 |
"number_of(bin_succ w) = int 1 + number_of w" |
|
111 |
(fn _ =>[induct_tac "w" 1, |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
112 |
(ALLGOALS(asm_simp_tac (simpset() addsimps zadd_ac))) ]); |
5491 | 113 |
|
6910 | 114 |
qed_goal "number_of_pred" thy |
115 |
"number_of(bin_pred w) = - (int 1) + number_of w" |
|
116 |
(fn _ =>[induct_tac "w" 1, |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
117 |
(ALLGOALS(asm_simp_tac (simpset() addsimps zadd_ac))) ]); |
1632 | 118 |
|
6910 | 119 |
Goal "number_of(bin_minus w) = (- (number_of w)::int)"; |
120 |
by (induct_tac "w" 1); |
|
5491 | 121 |
by (Simp_tac 1); |
122 |
by (Simp_tac 1); |
|
123 |
by (asm_simp_tac (simpset() |
|
5551 | 124 |
delsimps [bin_pred_Pls, bin_pred_Min, bin_pred_BIT] |
6910 | 125 |
addsimps [number_of_succ,number_of_pred, |
5491 | 126 |
zadd_assoc]) 1); |
6910 | 127 |
qed "number_of_minus"; |
1632 | 128 |
|
129 |
||
6910 | 130 |
val bin_add_simps = [bin_add_BIT_BIT, number_of_succ, number_of_pred]; |
1632 | 131 |
|
6036 | 132 |
(*This proof is complicated by the mutual recursion*) |
6910 | 133 |
Goal "! w. number_of(bin_add v w) = (number_of v + number_of w::int)"; |
5184 | 134 |
by (induct_tac "v" 1); |
4686 | 135 |
by (simp_tac (simpset() addsimps bin_add_simps) 1); |
136 |
by (simp_tac (simpset() addsimps bin_add_simps) 1); |
|
1632 | 137 |
by (rtac allI 1); |
5184 | 138 |
by (induct_tac "w" 1); |
5540 | 139 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps bin_add_simps @ zadd_ac))); |
6910 | 140 |
qed_spec_mp "number_of_add"; |
1632 | 141 |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
142 |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
143 |
(*Subtraction*) |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
144 |
Goalw [zdiff_def] |
6910 | 145 |
"number_of v - number_of w = (number_of(bin_add v (bin_minus w))::int)"; |
146 |
by (simp_tac (simpset() addsimps [number_of_add, number_of_minus]) 1); |
|
147 |
qed "diff_number_of_eq"; |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
148 |
|
6910 | 149 |
val bin_mult_simps = [zmult_zminus, number_of_minus, number_of_add]; |
1632 | 150 |
|
6910 | 151 |
Goal "number_of(bin_mult v w) = (number_of v * number_of w::int)"; |
5184 | 152 |
by (induct_tac "v" 1); |
4686 | 153 |
by (simp_tac (simpset() addsimps bin_mult_simps) 1); |
154 |
by (simp_tac (simpset() addsimps bin_mult_simps) 1); |
|
5491 | 155 |
by (asm_simp_tac |
5540 | 156 |
(simpset() addsimps bin_mult_simps @ [zadd_zmult_distrib] @ zadd_ac) 1); |
6910 | 157 |
qed "number_of_mult"; |
5491 | 158 |
|
1632 | 159 |
|
5491 | 160 |
(** Simplification rules with integer constants **) |
161 |
||
6910 | 162 |
Goal "#0 + z = (z::int)"; |
5491 | 163 |
by (Simp_tac 1); |
164 |
qed "zadd_0"; |
|
165 |
||
6910 | 166 |
Goal "z + #0 = (z::int)"; |
5491 | 167 |
by (Simp_tac 1); |
168 |
qed "zadd_0_right"; |
|
169 |
||
5592 | 170 |
Addsimps [zadd_0, zadd_0_right]; |
171 |
||
172 |
||
173 |
(** Converting simple cases of (int n) to numerals **) |
|
5491 | 174 |
|
5592 | 175 |
(*int 0 = #0 *) |
6910 | 176 |
bind_thm ("int_0", number_of_Pls RS sym); |
5491 | 177 |
|
5592 | 178 |
Goal "int (Suc n) = #1 + int n"; |
179 |
by (simp_tac (simpset() addsimps [zadd_int]) 1); |
|
180 |
qed "int_Suc"; |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
181 |
|
6910 | 182 |
Goal "- (#0) = (#0::int)"; |
5491 | 183 |
by (Simp_tac 1); |
184 |
qed "zminus_0"; |
|
185 |
||
186 |
Addsimps [zminus_0]; |
|
187 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
188 |
|
6910 | 189 |
Goal "(#0::int) - x = -x"; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
190 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
191 |
qed "zdiff0"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
192 |
|
6910 | 193 |
Goal "x - (#0::int) = x"; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
194 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
195 |
qed "zdiff0_right"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
196 |
|
6910 | 197 |
Goal "x - x = (#0::int)"; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
198 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
199 |
qed "zdiff_self"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
200 |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
201 |
Addsimps [zdiff0, zdiff0_right, zdiff_self]; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
202 |
|
6917 | 203 |
|
204 |
(** Special simplification, for constants only **) |
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
205 |
|
6917 | 206 |
fun inst x t = read_instantiate_sg (sign_of Bin.thy) [(x,t)]; |
207 |
||
208 |
(*Distributive laws*) |
|
209 |
Addsimps (map (inst "w" "number_of ?v") |
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
210 |
[zadd_zmult_distrib, zadd_zmult_distrib2, |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
211 |
zdiff_zmult_distrib, zdiff_zmult_distrib2]); |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
212 |
|
6917 | 213 |
Addsimps (map (inst "x" "number_of ?v") |
214 |
[zless_zminus, zle_zminus, equation_zminus]); |
|
215 |
Addsimps (map (inst "y" "number_of ?v") |
|
216 |
[zminus_zless, zminus_zle, zminus_equation]); |
|
217 |
||
218 |
||
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
219 |
(** Special-case simplification for small constants **) |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
220 |
|
6910 | 221 |
Goal "#0 * z = (#0::int)"; |
5491 | 222 |
by (Simp_tac 1); |
223 |
qed "zmult_0"; |
|
224 |
||
6910 | 225 |
Goal "z * #0 = (#0::int)"; |
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
226 |
by (Simp_tac 1); |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
227 |
qed "zmult_0_right"; |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
228 |
|
6910 | 229 |
Goal "#1 * z = (z::int)"; |
5491 | 230 |
by (Simp_tac 1); |
231 |
qed "zmult_1"; |
|
232 |
||
6910 | 233 |
Goal "z * #1 = (z::int)"; |
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
234 |
by (Simp_tac 1); |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
235 |
qed "zmult_1_right"; |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
236 |
|
6917 | 237 |
Goal "#-1 * z = -(z::int)"; |
238 |
by (simp_tac (simpset() addsimps zcompare_rls@[zmult_zminus]) 1); |
|
239 |
qed "zmult_minus1"; |
|
240 |
||
241 |
Goal "z * #-1 = -(z::int)"; |
|
242 |
by (simp_tac (simpset() addsimps zcompare_rls@[zmult_zminus_right]) 1); |
|
243 |
qed "zmult_minus1_right"; |
|
244 |
||
245 |
Addsimps [zmult_0, zmult_0_right, |
|
246 |
zmult_1, zmult_1_right, |
|
247 |
zmult_minus1, zmult_minus1_right]; |
|
248 |
||
249 |
(*For specialist use: NOT as default simprules*) |
|
6910 | 250 |
Goal "#2 * z = (z+z::int)"; |
5491 | 251 |
by (simp_tac (simpset() addsimps [zadd_zmult_distrib]) 1); |
252 |
qed "zmult_2"; |
|
253 |
||
6910 | 254 |
Goal "z * #2 = (z+z::int)"; |
5491 | 255 |
by (simp_tac (simpset() addsimps [zadd_zmult_distrib2]) 1); |
256 |
qed "zmult_2_right"; |
|
257 |
||
6917 | 258 |
|
259 |
(** Inequality reasoning **) |
|
5491 | 260 |
|
6910 | 261 |
Goal "(w < z + (#1::int)) = (w<z | w=z)"; |
5592 | 262 |
by (simp_tac (simpset() addsimps [zless_add_int_Suc_eq]) 1); |
5491 | 263 |
qed "zless_add1_eq"; |
264 |
||
6910 | 265 |
Goal "(w + (#1::int) <= z) = (w<z)"; |
5592 | 266 |
by (simp_tac (simpset() addsimps [add_int_Suc_zle_eq]) 1); |
5491 | 267 |
qed "add1_zle_eq"; |
268 |
Addsimps [add1_zle_eq]; |
|
269 |
||
5540 | 270 |
Goal "neg x = (x < #0)"; |
6917 | 271 |
by (simp_tac (simpset() addsimps [neg_eq_less_int0]) 1); |
5540 | 272 |
qed "neg_eq_less_0"; |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
273 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
274 |
Goal "(~neg x) = (int 0 <= x)"; |
6917 | 275 |
by (simp_tac (simpset() addsimps [not_neg_eq_ge_int0]) 1); |
5540 | 276 |
qed "not_neg_eq_ge_0"; |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
277 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
278 |
Goal "#0 <= int m"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
279 |
by (Simp_tac 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
280 |
qed "zero_zle_int"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
281 |
AddIffs [zero_zle_int]; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
282 |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
283 |
|
6917 | 284 |
(** Products of signs **) |
285 |
||
286 |
Goal "[| (m::int) < #0; n < #0 |] ==> #0 < m*n"; |
|
287 |
by (dtac zmult_zless_mono1_neg 1); |
|
288 |
by Auto_tac; |
|
289 |
qed "neg_times_neg_is_pos"; |
|
290 |
||
291 |
Goal "[| (m::int) < #0; #0 < n |] ==> m*n < #0"; |
|
292 |
by (dtac zmult_zless_mono1 1); |
|
293 |
by Auto_tac; |
|
294 |
qed "neg_times_pos_is_neg"; |
|
295 |
||
296 |
Goal "[| #0 < (m::int); n < #0 |] ==> m*n < #0"; |
|
297 |
by (dtac zmult_zless_mono1_neg 1); |
|
298 |
by Auto_tac; |
|
299 |
qed "pos_times_neg_is_neg"; |
|
300 |
||
301 |
Goal "[| #0 < (m::int); #0 < n |] ==> #0 < m*n"; |
|
302 |
by (dtac zmult_zless_mono1 1); |
|
303 |
by Auto_tac; |
|
304 |
qed "pos_times_pos_is_pos"; |
|
305 |
||
306 |
||
5747 | 307 |
(** Needed because (int 0) rewrites to #0. |
308 |
Can these be generalized without evaluating large numbers?**) |
|
309 |
||
310 |
Goal "~ (int k < #0)"; |
|
311 |
by (Simp_tac 1); |
|
312 |
qed "int_less_0_conv"; |
|
313 |
||
314 |
Goal "(int k <= #0) = (k=0)"; |
|
315 |
by (Simp_tac 1); |
|
316 |
qed "int_le_0_conv"; |
|
317 |
||
318 |
Goal "(int k = #0) = (k=0)"; |
|
319 |
by (Simp_tac 1); |
|
320 |
qed "int_eq_0_conv"; |
|
321 |
||
322 |
Goal "(#0 = int k) = (k=0)"; |
|
323 |
by Auto_tac; |
|
324 |
qed "int_eq_0_conv'"; |
|
325 |
||
326 |
Addsimps [int_less_0_conv, int_le_0_conv, int_eq_0_conv, int_eq_0_conv']; |
|
327 |
||
328 |
||
5491 | 329 |
(** Simplification rules for comparison of binary numbers (Norbert Voelker) **) |
330 |
||
331 |
(** Equals (=) **) |
|
1632 | 332 |
|
5491 | 333 |
Goalw [iszero_def] |
6910 | 334 |
"((number_of x::int) = number_of y) = iszero(number_of (bin_add x (bin_minus y)))"; |
5491 | 335 |
by (simp_tac (simpset() addsimps |
6910 | 336 |
(zcompare_rls @ [number_of_add, number_of_minus])) 1); |
337 |
qed "eq_number_of_eq"; |
|
5491 | 338 |
|
6910 | 339 |
Goalw [iszero_def] "iszero ((number_of Pls)::int)"; |
5491 | 340 |
by (Simp_tac 1); |
6910 | 341 |
qed "iszero_number_of_Pls"; |
5491 | 342 |
|
6910 | 343 |
Goalw [iszero_def] "~ iszero ((number_of Min)::int)"; |
5491 | 344 |
by (Simp_tac 1); |
6910 | 345 |
qed "nonzero_number_of_Min"; |
5491 | 346 |
|
347 |
Goalw [iszero_def] |
|
6910 | 348 |
"iszero (number_of (w BIT x)) = (~x & iszero (number_of w::int))"; |
5491 | 349 |
by (Simp_tac 1); |
6910 | 350 |
by (int_case_tac "number_of w" 1); |
5491 | 351 |
by (ALLGOALS (asm_simp_tac |
5540 | 352 |
(simpset() addsimps zcompare_rls @ |
353 |
[zminus_zadd_distrib RS sym, |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
354 |
zadd_int]))); |
6910 | 355 |
qed "iszero_number_of_BIT"; |
5491 | 356 |
|
6910 | 357 |
Goal "iszero (number_of (w BIT False)) = iszero (number_of w::int)"; |
358 |
by (simp_tac (HOL_ss addsimps [iszero_number_of_BIT]) 1); |
|
359 |
qed "iszero_number_of_0"; |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
360 |
|
6910 | 361 |
Goal "~ iszero (number_of (w BIT True)::int)"; |
362 |
by (simp_tac (HOL_ss addsimps [iszero_number_of_BIT]) 1); |
|
363 |
qed "iszero_number_of_1"; |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
364 |
|
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
365 |
|
5491 | 366 |
|
367 |
(** Less-than (<) **) |
|
368 |
||
369 |
Goalw [zless_def,zdiff_def] |
|
6910 | 370 |
"(number_of x::int) < number_of y \ |
371 |
\ = neg (number_of (bin_add x (bin_minus y)))"; |
|
5491 | 372 |
by (simp_tac (simpset() addsimps bin_mult_simps) 1); |
6910 | 373 |
qed "less_number_of_eq_neg"; |
5491 | 374 |
|
6910 | 375 |
Goal "~ neg (number_of Pls)"; |
5491 | 376 |
by (Simp_tac 1); |
6910 | 377 |
qed "not_neg_number_of_Pls"; |
5491 | 378 |
|
6910 | 379 |
Goal "neg (number_of Min)"; |
5491 | 380 |
by (Simp_tac 1); |
6910 | 381 |
qed "neg_number_of_Min"; |
5491 | 382 |
|
6910 | 383 |
Goal "neg (number_of (w BIT x)) = neg (number_of w)"; |
5491 | 384 |
by (Asm_simp_tac 1); |
6910 | 385 |
by (int_case_tac "number_of w" 1); |
5491 | 386 |
by (ALLGOALS (asm_simp_tac |
6917 | 387 |
(simpset() addsimps [zadd_int, neg_eq_less_int0, |
5540 | 388 |
symmetric zdiff_def] @ zcompare_rls))); |
6910 | 389 |
qed "neg_number_of_BIT"; |
5491 | 390 |
|
391 |
||
392 |
(** Less-than-or-equals (<=) **) |
|
393 |
||
6910 | 394 |
Goal "(number_of x <= (number_of y::int)) = (~ number_of y < (number_of x::int))"; |
5491 | 395 |
by (simp_tac (simpset() addsimps [zle_def]) 1); |
6910 | 396 |
qed "le_number_of_eq_not_less"; |
5491 | 397 |
|
5540 | 398 |
(*Delete the original rewrites, with their clumsy conditional expressions*) |
5551 | 399 |
Delsimps [bin_succ_BIT, bin_pred_BIT, bin_minus_BIT, |
400 |
NCons_Pls, NCons_Min, bin_add_BIT, bin_mult_BIT]; |
|
5491 | 401 |
|
402 |
(*Hide the binary representation of integer constants*) |
|
6910 | 403 |
Delsimps [number_of_Pls, number_of_Min, number_of_BIT]; |
5491 | 404 |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
405 |
(*simplification of arithmetic operations on integer constants*) |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
406 |
val bin_arith_extra_simps = |
6910 | 407 |
[number_of_add RS sym, |
408 |
number_of_minus RS sym, |
|
409 |
number_of_mult RS sym, |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
410 |
bin_succ_1, bin_succ_0, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
411 |
bin_pred_1, bin_pred_0, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
412 |
bin_minus_1, bin_minus_0, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
413 |
bin_add_Pls_right, bin_add_BIT_Min, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
414 |
bin_add_BIT_0, bin_add_BIT_10, bin_add_BIT_11, |
6910 | 415 |
diff_number_of_eq, |
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
416 |
bin_mult_1, bin_mult_0, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
417 |
NCons_Pls_0, NCons_Pls_1, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
418 |
NCons_Min_0, NCons_Min_1, NCons_BIT]; |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
419 |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
420 |
(*For making a minimal simpset, one must include these default simprules |
6910 | 421 |
of thy. Also include simp_thms, or at least (~False)=True*) |
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
422 |
val bin_arith_simps = |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
423 |
[bin_pred_Pls, bin_pred_Min, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
424 |
bin_succ_Pls, bin_succ_Min, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
425 |
bin_add_Pls, bin_add_Min, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
426 |
bin_minus_Pls, bin_minus_Min, |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
427 |
bin_mult_Pls, bin_mult_Min] @ bin_arith_extra_simps; |
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
428 |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
429 |
(*Simplification of relational operations*) |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
430 |
val bin_rel_simps = |
6910 | 431 |
[eq_number_of_eq, iszero_number_of_Pls, nonzero_number_of_Min, |
432 |
iszero_number_of_0, iszero_number_of_1, |
|
433 |
less_number_of_eq_neg, |
|
434 |
not_neg_number_of_Pls, neg_number_of_Min, neg_number_of_BIT, |
|
435 |
le_number_of_eq_not_less]; |
|
2224
4fc4b465be5b
New material from Norbert Voelker for efficient binary comparisons
paulson
parents:
1894
diff
changeset
|
436 |
|
5779
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
437 |
Addsimps bin_arith_extra_simps; |
5c74f003a68e
Explicit (and improved) simprules for binary arithmetic.
paulson
parents:
5747
diff
changeset
|
438 |
Addsimps bin_rel_simps; |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
439 |
|
6060 | 440 |
(*---------------------------------------------------------------------------*) |
441 |
(* Linear arithmetic *) |
|
442 |
(*---------------------------------------------------------------------------*) |
|
443 |
||
444 |
(* |
|
445 |
Instantiation of the generic linear arithmetic package for int. |
|
446 |
FIXME: multiplication with constants (eg #2 * i) does not work yet. |
|
447 |
Solution: the cancellation simprocs in Int_Cancel should be able to deal with |
|
448 |
it (eg simplify #3 * i <= 2 * i to i <= #0) or `add_rules' below should |
|
449 |
include rules for turning multiplication with constants into addition. |
|
450 |
(The latter option is very inefficient!) |
|
451 |
*) |
|
452 |
||
6128 | 453 |
structure Int_LA_Data(*: LIN_ARITH_DATA*) = |
6060 | 454 |
struct |
6101 | 455 |
|
6128 | 456 |
val lessD = Nat_LA_Data.lessD @ [add1_zle_eq RS iffD2]; |
6060 | 457 |
|
458 |
fun add_atom(t,m,(p,i)) = (case assoc(p,t) of None => ((t,m)::p,i) |
|
459 |
| Some n => (overwrite(p,(t,n+m:int)), i)); |
|
460 |
||
461 |
(* Turn term into list of summand * multiplicity plus a constant *) |
|
462 |
fun poly(Const("op +",_) $ s $ t, m, pi) = poly(s,m,poly(t,m,pi)) |
|
463 |
| poly(Const("op -",_) $ s $ t, m, pi) = poly(s,m,poly(t,~1*m,pi)) |
|
464 |
| poly(Const("uminus",_) $ t, m, pi) = poly(t,~1*m,pi) |
|
6910 | 465 |
| poly(all as Const("op *",_) $ (Const("Numeral.number_of",_)$c) $ t, m, pi) = |
466 |
(poly(t,m*NumeralSyntax.dest_bin c,pi) handle Match => add_atom(all,m,pi)) |
|
467 |
| poly(all as Const("Numeral.number_of",_)$t,m,(p,i)) = |
|
468 |
((p,i + m*NumeralSyntax.dest_bin t) handle Match => add_atom(all,m,(p,i))) |
|
6060 | 469 |
| poly x = add_atom x; |
470 |
||
6128 | 471 |
fun decomp2(rel,lhs,rhs) = |
6060 | 472 |
let val (p,i) = poly(lhs,1,([],0)) and (q,j) = poly(rhs,1,([],0)) |
473 |
in case rel of |
|
474 |
"op <" => Some(p,i,"<",q,j) |
|
475 |
| "op <=" => Some(p,i,"<=",q,j) |
|
476 |
| "op =" => Some(p,i,"=",q,j) |
|
477 |
| _ => None |
|
478 |
end; |
|
479 |
||
6128 | 480 |
val intT = Type("IntDef.int",[]); |
481 |
fun iib T = T = ([intT,intT] ---> HOLogic.boolT); |
|
6060 | 482 |
|
6128 | 483 |
fun decomp1(T,xxx) = |
484 |
if iib T then decomp2 xxx else Nat_LA_Data.decomp1(T,xxx); |
|
485 |
||
486 |
fun decomp(_$(Const(rel,T)$lhs$rhs)) = decomp1(T,(rel,lhs,rhs)) |
|
6060 | 487 |
| decomp(_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) = |
6128 | 488 |
Nat_LA_Data.negate(decomp1(T,(rel,lhs,rhs))) |
6060 | 489 |
| decomp _ = None |
490 |
||
491 |
(* reduce contradictory <= to False *) |
|
492 |
val add_rules = simp_thms@bin_arith_simps@bin_rel_simps@[int_0]; |
|
493 |
||
6128 | 494 |
val cancel_sums_ss = Nat_LA_Data.cancel_sums_ss addsimps add_rules |
6060 | 495 |
addsimprocs [Int_Cancel.sum_conv, Int_Cancel.rel_conv]; |
496 |
||
497 |
val simp = simplify cancel_sums_ss; |
|
498 |
||
6128 | 499 |
val add_mono_thms = Nat_LA_Data.add_mono_thms @ |
500 |
map (fn s => prove_goal Int.thy s |
|
501 |
(fn prems => [cut_facts_tac prems 1, |
|
502 |
asm_simp_tac (simpset() addsimps [zadd_zle_mono]) 1])) |
|
503 |
["(i <= j) & (k <= l) ==> i + k <= j + (l::int)", |
|
504 |
"(i = j) & (k <= l) ==> i + k <= j + (l::int)", |
|
505 |
"(i <= j) & (k = l) ==> i + k <= j + (l::int)", |
|
506 |
"(i = j) & (k = l) ==> i + k = j + (l::int)" |
|
507 |
]; |
|
6060 | 508 |
|
509 |
end; |
|
510 |
||
6128 | 511 |
(* Update parameters of arithmetic prover *) |
512 |
LA_Data_Ref.add_mono_thms := Int_LA_Data.add_mono_thms; |
|
513 |
LA_Data_Ref.lessD := Int_LA_Data.lessD; |
|
514 |
LA_Data_Ref.decomp := Int_LA_Data.decomp; |
|
515 |
LA_Data_Ref.simp := Int_LA_Data.simp; |
|
516 |
||
6060 | 517 |
|
6128 | 518 |
val int_arith_simproc_pats = |
6394 | 519 |
map (fn s => Thm.read_cterm (Theory.sign_of Int.thy) (s, HOLogic.boolT)) |
6128 | 520 |
["(m::int) < n","(m::int) <= n", "(m::int) = n"]; |
6060 | 521 |
|
6128 | 522 |
val fast_int_arith_simproc = mk_simproc "fast_int_arith" int_arith_simproc_pats |
523 |
Fast_Arith.lin_arith_prover; |
|
524 |
||
525 |
Addsimprocs [fast_int_arith_simproc]; |
|
6060 | 526 |
|
527 |
(* FIXME: K true should be replaced by a sensible test to speed things up |
|
528 |
in case there are lots of irrelevant terms involved. |
|
6157 | 529 |
|
6128 | 530 |
val arith_tac = |
531 |
refute_tac (K true) (REPEAT o split_tac[nat_diff_split]) |
|
532 |
((REPEAT_DETERM o etac linorder_neqE) THEN' fast_arith_tac); |
|
6157 | 533 |
*) |
6060 | 534 |
|
535 |
(* Some test data |
|
536 |
Goal "!!a::int. [| a <= b; c <= d; x+y<z |] ==> a+c <= b+d"; |
|
6301 | 537 |
by (fast_arith_tac 1); |
6060 | 538 |
Goal "!!a::int. [| a < b; c < d |] ==> a-d+ #2 <= b+(-c)"; |
6301 | 539 |
by (fast_arith_tac 1); |
6060 | 540 |
Goal "!!a::int. [| a < b; c < d |] ==> a+c+ #1 < b+d"; |
6301 | 541 |
by (fast_arith_tac 1); |
6060 | 542 |
Goal "!!a::int. [| a <= b; b+b <= c |] ==> a+a <= c"; |
6301 | 543 |
by (fast_arith_tac 1); |
6060 | 544 |
Goal "!!a::int. [| a+b <= i+j; a<=b; i<=j |] \ |
545 |
\ ==> a+a <= j+j"; |
|
6301 | 546 |
by (fast_arith_tac 1); |
6060 | 547 |
Goal "!!a::int. [| a+b < i+j; a<b; i<j |] \ |
548 |
\ ==> a+a - - #-1 < j+j - #3"; |
|
6301 | 549 |
by (fast_arith_tac 1); |
6060 | 550 |
Goal "!!a::int. a+b+c <= i+j+k & a<=b & b<=c & i<=j & j<=k --> a+a+a <= k+k+k"; |
6301 | 551 |
by (arith_tac 1); |
6060 | 552 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
553 |
\ ==> a <= l"; |
|
6301 | 554 |
by (fast_arith_tac 1); |
6060 | 555 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
556 |
\ ==> a+a+a+a <= l+l+l+l"; |
|
6301 | 557 |
by (fast_arith_tac 1); |
6060 | 558 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
559 |
\ ==> a+a+a+a+a <= l+l+l+l+i"; |
|
6301 | 560 |
by (fast_arith_tac 1); |
6060 | 561 |
Goal "!!a::int. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \ |
562 |
\ ==> a+a+a+a+a+a <= l+l+l+l+i+l"; |
|
6301 | 563 |
by (fast_arith_tac 1); |
6060 | 564 |
*) |
565 |
||
566 |
(*---------------------------------------------------------------------------*) |
|
567 |
(* End of linear arithmetic *) |
|
568 |
(*---------------------------------------------------------------------------*) |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
569 |
|
5592 | 570 |
(** Simplification of arithmetic when nested to the right **) |
571 |
||
6910 | 572 |
Goal "number_of v + (number_of w + z) = (number_of(bin_add v w) + z::int)"; |
5592 | 573 |
by (simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
6910 | 574 |
qed "add_number_of_left"; |
5592 | 575 |
|
6910 | 576 |
Goal "number_of v * (number_of w * z) = (number_of(bin_mult v w) * z::int)"; |
5592 | 577 |
by (simp_tac (simpset() addsimps [zmult_assoc RS sym]) 1); |
6910 | 578 |
qed "mult_number_of_left"; |
5592 | 579 |
|
6910 | 580 |
Addsimps [add_number_of_left, mult_number_of_left]; |
5592 | 581 |
|
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
582 |
(** Simplification of inequalities involving numerical constants **) |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
583 |
|
6910 | 584 |
Goal "(w <= z + (#1::int)) = (w<=z | w = z + (#1::int))"; |
6301 | 585 |
by (arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
586 |
qed "zle_add1_eq"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
587 |
|
6910 | 588 |
Goal "(w <= z - (#1::int)) = (w<(z::int))"; |
6301 | 589 |
by (arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
590 |
qed "zle_diff1_eq"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
591 |
Addsimps [zle_diff1_eq]; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
592 |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
593 |
(*2nd premise can be proved automatically if v is a literal*) |
6910 | 594 |
Goal "[| w <= z; #0 <= v |] ==> w <= z + (v::int)"; |
6301 | 595 |
by (fast_arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
596 |
qed "zle_imp_zle_zadd"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
597 |
|
6910 | 598 |
Goal "w <= z ==> w <= z + (#1::int)"; |
6301 | 599 |
by (fast_arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
600 |
qed "zle_imp_zle_zadd1"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
601 |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
602 |
(*2nd premise can be proved automatically if v is a literal*) |
6910 | 603 |
Goal "[| w < z; #0 <= v |] ==> w < z + (v::int)"; |
6301 | 604 |
by (fast_arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
605 |
qed "zless_imp_zless_zadd"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
606 |
|
6910 | 607 |
Goal "w < z ==> w < z + (#1::int)"; |
6301 | 608 |
by (fast_arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
609 |
qed "zless_imp_zless_zadd1"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
610 |
|
6910 | 611 |
Goal "(w < z + #1) = (w<=(z::int))"; |
6301 | 612 |
by (arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
613 |
qed "zle_add1_eq_le"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
614 |
Addsimps [zle_add1_eq_le]; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
615 |
|
6910 | 616 |
Goal "(z = z + w) = (w = (#0::int))"; |
6301 | 617 |
by (arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
618 |
qed "zadd_left_cancel0"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
619 |
Addsimps [zadd_left_cancel0]; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
620 |
|
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
621 |
(*LOOPS as a simprule!*) |
6910 | 622 |
Goal "[| w + v < z; #0 <= v |] ==> w < (z::int)"; |
6301 | 623 |
by (fast_arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
624 |
qed "zless_zadd_imp_zless"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
625 |
|
5540 | 626 |
(*LOOPS as a simprule! Analogous to Suc_lessD*) |
6910 | 627 |
Goal "w + #1 < z ==> w < (z::int)"; |
6301 | 628 |
by (fast_arith_tac 1); |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
629 |
qed "zless_zadd1_imp_zless"; |
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
630 |
|
6910 | 631 |
Goal "w + #-1 = w - (#1::int)"; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
632 |
by (Simp_tac 1); |
5551 | 633 |
qed "zplus_minus1_conv"; |
5510
ad120f7c52ad
improved (but still flawed) treatment of binary arithmetic
paulson
parents:
5491
diff
changeset
|
634 |
|
5551 | 635 |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
636 |
(*** nat ***) |
5551 | 637 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
638 |
Goal "#0 <= z ==> int (nat z) = z"; |
5551 | 639 |
by (asm_full_simp_tac |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
640 |
(simpset() addsimps [neg_eq_less_0, zle_def, not_neg_nat]) 1); |
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
641 |
qed "nat_0_le"; |
5551 | 642 |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
643 |
Goal "z < #0 ==> nat z = 0"; |
5551 | 644 |
by (asm_full_simp_tac |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
645 |
(simpset() addsimps [neg_eq_less_0, zle_def, neg_nat]) 1); |
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
646 |
qed "nat_less_0"; |
5551 | 647 |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
648 |
Addsimps [nat_0_le, nat_less_0]; |
5551 | 649 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
650 |
Goal "#0 <= w ==> (nat w = m) = (w = int m)"; |
5551 | 651 |
by Auto_tac; |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
652 |
qed "nat_eq_iff"; |
5551 | 653 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
654 |
Goal "#0 <= w ==> (nat w < m) = (w < int m)"; |
5551 | 655 |
by (rtac iffI 1); |
656 |
by (asm_full_simp_tac |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
657 |
(simpset() delsimps [zless_int] addsimps [zless_int RS sym]) 2); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
658 |
by (etac (nat_0_le RS subst) 1); |
5551 | 659 |
by (Simp_tac 1); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
660 |
qed "nat_less_iff"; |
5551 | 661 |
|
5747 | 662 |
|
6716
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
663 |
(*Users don't want to see (int 0), int(Suc 0) or w + - z*) |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
664 |
Addsimps [int_0, int_Suc, symmetric zdiff_def]; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
665 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
666 |
Goal "nat #0 = 0"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
667 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
668 |
qed "nat_0"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
669 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
670 |
Goal "nat #1 = 1"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
671 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
672 |
qed "nat_1"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
673 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
674 |
Goal "nat #2 = 2"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
675 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
676 |
qed "nat_2"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
677 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
678 |
Goal "nat #3 = Suc 2"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
679 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
680 |
qed "nat_3"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
681 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
682 |
Goal "nat #4 = Suc (Suc 2)"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
683 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
684 |
qed "nat_4"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
685 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
686 |
Goal "nat #5 = Suc (Suc (Suc 2))"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
687 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
688 |
qed "nat_5"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
689 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
690 |
Goal "nat #6 = Suc (Suc (Suc (Suc 2)))"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
691 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
692 |
qed "nat_6"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
693 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
694 |
Goal "nat #7 = Suc (Suc (Suc (Suc (Suc 2))))"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
695 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
696 |
qed "nat_7"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
697 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
698 |
Goal "nat #8 = Suc (Suc (Suc (Suc (Suc (Suc 2)))))"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
699 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
700 |
qed "nat_8"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
701 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
702 |
Goal "nat #9 = Suc (Suc (Suc (Suc (Suc (Suc (Suc 2))))))"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
703 |
by (simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
704 |
qed "nat_9"; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
705 |
|
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
706 |
(*Users also don't want to see (nat 0), (nat 1), ...*) |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
707 |
Addsimps [nat_0, nat_1, nat_2, nat_3, nat_4, |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
708 |
nat_5, nat_6, nat_7, nat_8, nat_9]; |
87c750df8888
Better simplification of (nat #0), (int (Suc 0)), etc
paulson
parents:
6394
diff
changeset
|
709 |
|
5747 | 710 |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
711 |
Goal "#0 <= w ==> (nat w < nat z) = (w<z)"; |
5551 | 712 |
by (case_tac "neg z" 1); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
713 |
by (auto_tac (claset(), simpset() addsimps [nat_less_iff])); |
5551 | 714 |
by (auto_tac (claset() addIs [zless_trans], |
5747 | 715 |
simpset() addsimps [neg_eq_less_0, zle_def])); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5551
diff
changeset
|
716 |
qed "nat_less_eq_zless"; |
5747 | 717 |
|
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
718 |
|
6917 | 719 |
(*Towards canonical simplification*) |
6838
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
720 |
Addsimps zadd_ac; |
941c4f70db91
rewrite rules to distribute CONSTANT multiplication over sum and difference;
paulson
parents:
6716
diff
changeset
|
721 |
Addsimps zmult_ac; |
6917 | 722 |
Addsimps [zmult_zminus, zmult_zminus_right]; |