|
1 (* Title: ZF/ex/bin.ML |
|
2 ID: $Id$ |
|
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 Copyright 1993 University of Cambridge |
|
5 |
|
6 For bin.thy. Arithmetic on binary integers. |
|
7 *) |
|
8 |
|
9 open BinFn; |
|
10 |
|
11 |
|
12 (** bin_rec -- by Vset recursion **) |
|
13 |
|
14 goal BinFn.thy "bin_rec(Plus,a,b,h) = a"; |
|
15 by (rtac (bin_rec_def RS def_Vrec RS trans) 1); |
|
16 by (rewrite_goals_tac Bin.con_defs); |
|
17 by (SIMP_TAC rank_ss 1); |
|
18 val bin_rec_Plus = result(); |
|
19 |
|
20 goal BinFn.thy "bin_rec(Minus,a,b,h) = b"; |
|
21 by (rtac (bin_rec_def RS def_Vrec RS trans) 1); |
|
22 by (rewrite_goals_tac Bin.con_defs); |
|
23 by (SIMP_TAC rank_ss 1); |
|
24 val bin_rec_Minus = result(); |
|
25 |
|
26 goal BinFn.thy "bin_rec(w$$x,a,b,h) = h(w, x, bin_rec(w,a,b,h))"; |
|
27 by (rtac (bin_rec_def RS def_Vrec RS trans) 1); |
|
28 by (rewrite_goals_tac Bin.con_defs); |
|
29 by (SIMP_TAC (rank_ss addcongs |
|
30 (mk_typed_congs BinFn.thy [("h", "[i,i,i]=>i")])) 1); |
|
31 val bin_rec_Bcons = result(); |
|
32 |
|
33 (*Type checking*) |
|
34 val prems = goal BinFn.thy |
|
35 "[| w: bin; \ |
|
36 \ a: C(Plus); b: C(Minus); \ |
|
37 \ !!w x r. [| w: bin; x: bool; r: C(w) |] ==> h(w,x,r): C(w$$x) \ |
|
38 \ |] ==> bin_rec(w,a,b,h) : C(w)"; |
|
39 by (bin_ind_tac "w" prems 1); |
|
40 by (ALLGOALS |
|
41 (ASM_SIMP_TAC (ZF_ss addrews (prems@[bin_rec_Plus,bin_rec_Minus, |
|
42 bin_rec_Bcons])))); |
|
43 val bin_rec_type = result(); |
|
44 |
|
45 (** Versions for use with definitions **) |
|
46 |
|
47 val [rew] = goal BinFn.thy |
|
48 "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(Plus) = a"; |
|
49 by (rewtac rew); |
|
50 by (rtac bin_rec_Plus 1); |
|
51 val def_bin_rec_Plus = result(); |
|
52 |
|
53 val [rew] = goal BinFn.thy |
|
54 "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(Minus) = b"; |
|
55 by (rewtac rew); |
|
56 by (rtac bin_rec_Minus 1); |
|
57 val def_bin_rec_Minus = result(); |
|
58 |
|
59 val [rew] = goal BinFn.thy |
|
60 "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(w$$x) = h(w,x,j(w))"; |
|
61 by (rewtac rew); |
|
62 by (rtac bin_rec_Bcons 1); |
|
63 val def_bin_rec_Bcons = result(); |
|
64 |
|
65 fun bin_recs def = map standard |
|
66 ([def] RL [def_bin_rec_Plus, def_bin_rec_Minus, def_bin_rec_Bcons]); |
|
67 |
|
68 (** Type checking **) |
|
69 |
|
70 val bin_typechecks0 = bin_rec_type :: Bin.intrs; |
|
71 |
|
72 goalw BinFn.thy [integ_of_bin_def] |
|
73 "!!w. w: bin ==> integ_of_bin(w) : integ"; |
|
74 by (typechk_tac (bin_typechecks0@integ_typechecks@ |
|
75 nat_typechecks@[bool_into_nat])); |
|
76 val integ_of_bin_type = result(); |
|
77 |
|
78 goalw BinFn.thy [bin_succ_def] |
|
79 "!!w. w: bin ==> bin_succ(w) : bin"; |
|
80 by (typechk_tac (bin_typechecks0@bool_typechecks)); |
|
81 val bin_succ_type = result(); |
|
82 |
|
83 goalw BinFn.thy [bin_pred_def] |
|
84 "!!w. w: bin ==> bin_pred(w) : bin"; |
|
85 by (typechk_tac (bin_typechecks0@bool_typechecks)); |
|
86 val bin_pred_type = result(); |
|
87 |
|
88 goalw BinFn.thy [bin_minus_def] |
|
89 "!!w. w: bin ==> bin_minus(w) : bin"; |
|
90 by (typechk_tac ([bin_pred_type]@bin_typechecks0@bool_typechecks)); |
|
91 val bin_minus_type = result(); |
|
92 |
|
93 goalw BinFn.thy [bin_add_def] |
|
94 "!!v w. [| v: bin; w: bin |] ==> bin_add(v,w) : bin"; |
|
95 by (typechk_tac ([bin_succ_type,bin_pred_type]@bin_typechecks0@ |
|
96 bool_typechecks@ZF_typechecks)); |
|
97 val bin_add_type = result(); |
|
98 |
|
99 goalw BinFn.thy [bin_mult_def] |
|
100 "!!v w. [| v: bin; w: bin |] ==> bin_mult(v,w) : bin"; |
|
101 by (typechk_tac ([bin_minus_type,bin_add_type]@bin_typechecks0@ |
|
102 bool_typechecks)); |
|
103 val bin_mult_type = result(); |
|
104 |
|
105 val bin_typechecks = bin_typechecks0 @ |
|
106 [integ_of_bin_type, bin_succ_type, bin_pred_type, |
|
107 bin_minus_type, bin_add_type, bin_mult_type]; |
|
108 |
|
109 val bin_congs = mk_congs BinFn.thy |
|
110 ["bin_rec","op $$","integ_of_bin","bin_succ","bin_pred", |
|
111 "bin_minus","bin_add","bin_mult"]; |
|
112 |
|
113 val bin_ss = integ_ss |
|
114 addcongs (bin_congs@bool_congs) |
|
115 addrews([bool_1I, bool_0I, |
|
116 bin_rec_Plus, bin_rec_Minus, bin_rec_Bcons] @ |
|
117 bin_recs integ_of_bin_def @ bool_rews @ bin_typechecks); |
|
118 |
|
119 val typechecks = bin_typechecks @ integ_typechecks @ nat_typechecks @ |
|
120 [bool_subset_nat RS subsetD]; |
|
121 |
|
122 (**** The carry/borrow functions, bin_succ and bin_pred ****) |
|
123 |
|
124 (** Lemmas **) |
|
125 |
|
126 goal Integ.thy |
|
127 "!!z v. [| z $+ v = z' $+ v'; \ |
|
128 \ z: integ; z': integ; v: integ; v': integ; w: integ |] \ |
|
129 \ ==> z $+ (v $+ w) = z' $+ (v' $+ w)"; |
|
130 by (ASM_SIMP_TAC (integ_ss addrews ([zadd_assoc RS sym])) 1); |
|
131 val zadd_assoc_cong = result(); |
|
132 |
|
133 goal Integ.thy |
|
134 "!!z v w. [| z: integ; v: integ; w: integ |] \ |
|
135 \ ==> z $+ (v $+ w) = v $+ (z $+ w)"; |
|
136 by (REPEAT (ares_tac [zadd_commute RS zadd_assoc_cong] 1)); |
|
137 val zadd_assoc_swap = result(); |
|
138 |
|
139 val [zadd_cong] = mk_congs Integ.thy ["op $+"]; |
|
140 |
|
141 val zadd_kill = (refl RS zadd_cong); |
|
142 val zadd_assoc_swap_kill = zadd_kill RSN (4, zadd_assoc_swap RS trans); |
|
143 |
|
144 (*Pushes 'constants' of the form $#m to the right -- LOOPS if two!*) |
|
145 val zadd_assoc_znat = standard (znat_type RS zadd_assoc_swap); |
|
146 |
|
147 goal Integ.thy |
|
148 "!!z w. [| z: integ; w: integ |] \ |
|
149 \ ==> w $+ (z $+ (w $+ z)) = w $+ (w $+ (z $+ z))"; |
|
150 by (REPEAT (ares_tac [zadd_kill, zadd_assoc_swap] 1)); |
|
151 val zadd_swap_pairs = result(); |
|
152 |
|
153 |
|
154 val carry_ss = bin_ss addrews |
|
155 (bin_recs bin_succ_def @ bin_recs bin_pred_def); |
|
156 |
|
157 goal BinFn.thy |
|
158 "!!w. w: bin ==> integ_of_bin(bin_succ(w)) = $#1 $+ integ_of_bin(w)"; |
|
159 by (etac Bin.induct 1); |
|
160 by (SIMP_TAC (carry_ss addrews [zadd_0_right]) 1); |
|
161 by (SIMP_TAC (carry_ss addrews [zadd_zminus_inverse]) 1); |
|
162 by (etac boolE 1); |
|
163 by (ALLGOALS (ASM_SIMP_TAC (carry_ss addrews [zadd_assoc]))); |
|
164 by (REPEAT (ares_tac (zadd_swap_pairs::typechecks) 1)); |
|
165 val integ_of_bin_succ = result(); |
|
166 |
|
167 goal BinFn.thy |
|
168 "!!w. w: bin ==> integ_of_bin(bin_pred(w)) = $~ ($#1) $+ integ_of_bin(w)"; |
|
169 by (etac Bin.induct 1); |
|
170 by (SIMP_TAC (carry_ss addrews [zadd_0_right]) 1); |
|
171 by (SIMP_TAC (carry_ss addrews [zadd_zminus_inverse]) 1); |
|
172 by (etac boolE 1); |
|
173 by (ALLGOALS |
|
174 (ASM_SIMP_TAC |
|
175 (carry_ss addrews [zadd_assoc RS sym, |
|
176 zadd_zminus_inverse, zadd_zminus_inverse2]))); |
|
177 by (REPEAT (ares_tac ([zadd_commute, zadd_cong, refl]@typechecks) 1)); |
|
178 val integ_of_bin_pred = result(); |
|
179 |
|
180 (*These two results replace the definitions of bin_succ and bin_pred*) |
|
181 |
|
182 |
|
183 (*** bin_minus: (unary!) negation of binary integers ***) |
|
184 |
|
185 val bin_minus_ss = |
|
186 bin_ss addrews (bin_recs bin_minus_def @ |
|
187 [integ_of_bin_succ, integ_of_bin_pred]); |
|
188 |
|
189 goal BinFn.thy |
|
190 "!!w. w: bin ==> integ_of_bin(bin_minus(w)) = $~ integ_of_bin(w)"; |
|
191 by (etac Bin.induct 1); |
|
192 by (SIMP_TAC (bin_minus_ss addrews [zminus_0]) 1); |
|
193 by (SIMP_TAC (bin_minus_ss addrews [zadd_0_right]) 1); |
|
194 by (etac boolE 1); |
|
195 by (ALLGOALS |
|
196 (ASM_SIMP_TAC (bin_minus_ss addrews [zminus_zadd_distrib, zadd_assoc]))); |
|
197 val integ_of_bin_minus = result(); |
|
198 |
|
199 |
|
200 (*** bin_add: binary addition ***) |
|
201 |
|
202 goalw BinFn.thy [bin_add_def] "!!w. w: bin ==> bin_add(Plus,w) = w"; |
|
203 by (ASM_SIMP_TAC bin_ss 1); |
|
204 val bin_add_Plus = result(); |
|
205 |
|
206 goalw BinFn.thy [bin_add_def] "!!w. w: bin ==> bin_add(Minus,w) = bin_pred(w)"; |
|
207 by (ASM_SIMP_TAC bin_ss 1); |
|
208 val bin_add_Minus = result(); |
|
209 |
|
210 goalw BinFn.thy [bin_add_def] "bin_add(v$$x,Plus) = v$$x"; |
|
211 by (SIMP_TAC bin_ss 1); |
|
212 val bin_add_Bcons_Plus = result(); |
|
213 |
|
214 goalw BinFn.thy [bin_add_def] "bin_add(v$$x,Minus) = bin_pred(v$$x)"; |
|
215 by (SIMP_TAC bin_ss 1); |
|
216 val bin_add_Bcons_Minus = result(); |
|
217 |
|
218 goalw BinFn.thy [bin_add_def] |
|
219 "!!w y. [| w: bin; y: bool |] ==> \ |
|
220 \ bin_add(v$$x, w$$y) = \ |
|
221 \ bin_add(v, cond(x and y, bin_succ(w), w)) $$ (x xor y)"; |
|
222 by (ASM_SIMP_TAC bin_ss 1); |
|
223 val bin_add_Bcons_Bcons = result(); |
|
224 |
|
225 val bin_add_rews = [bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus, |
|
226 bin_add_Bcons_Minus, bin_add_Bcons_Bcons, |
|
227 integ_of_bin_succ, integ_of_bin_pred]; |
|
228 |
|
229 val bin_add_ss = bin_ss addrews ([bool_subset_nat RS subsetD] @ bin_add_rews); |
|
230 |
|
231 goal BinFn.thy |
|
232 "!!v. v: bin ==> \ |
|
233 \ ALL w: bin. integ_of_bin(bin_add(v,w)) = \ |
|
234 \ integ_of_bin(v) $+ integ_of_bin(w)"; |
|
235 by (etac Bin.induct 1); |
|
236 by (SIMP_TAC bin_add_ss 1); |
|
237 by (SIMP_TAC bin_add_ss 1); |
|
238 by (rtac ballI 1); |
|
239 by (bin_ind_tac "wa" [] 1); |
|
240 by (ASM_SIMP_TAC (bin_add_ss addrews [zadd_0_right]) 1); |
|
241 by (ASM_SIMP_TAC bin_add_ss 1); |
|
242 by (REPEAT (ares_tac (zadd_commute::typechecks) 1)); |
|
243 by (etac boolE 1); |
|
244 by (ASM_SIMP_TAC (bin_add_ss addrews [zadd_assoc, zadd_swap_pairs]) 2); |
|
245 by (REPEAT (ares_tac ([refl, zadd_kill, zadd_assoc_swap_kill]@typechecks) 2)); |
|
246 by (etac boolE 1); |
|
247 by (ALLGOALS (ASM_SIMP_TAC (bin_add_ss addrews [zadd_assoc,zadd_swap_pairs]))); |
|
248 by (REPEAT (ares_tac ([refl, zadd_kill, zadd_assoc_swap_kill RS sym]@ |
|
249 typechecks) 1)); |
|
250 val integ_of_bin_add_lemma = result(); |
|
251 |
|
252 val integ_of_bin_add = integ_of_bin_add_lemma RS bspec; |
|
253 |
|
254 |
|
255 (*** bin_add: binary multiplication ***) |
|
256 |
|
257 val bin_mult_ss = |
|
258 bin_ss addrews (bin_recs bin_mult_def @ |
|
259 [integ_of_bin_minus, integ_of_bin_add]); |
|
260 |
|
261 |
|
262 val major::prems = goal BinFn.thy |
|
263 "[| v: bin; w: bin |] ==> \ |
|
264 \ integ_of_bin(bin_mult(v,w)) = \ |
|
265 \ integ_of_bin(v) $* integ_of_bin(w)"; |
|
266 by (cut_facts_tac prems 1); |
|
267 by (bin_ind_tac "v" [major] 1); |
|
268 by (SIMP_TAC (bin_mult_ss addrews [zmult_0]) 1); |
|
269 by (SIMP_TAC (bin_mult_ss addrews [zmult_1,zmult_zminus]) 1); |
|
270 by (etac boolE 1); |
|
271 by (ASM_SIMP_TAC (bin_mult_ss addrews [zadd_zmult_distrib]) 2); |
|
272 by (ASM_SIMP_TAC |
|
273 (bin_mult_ss addrews [zadd_zmult_distrib, zmult_1, zadd_assoc]) 1); |
|
274 by (REPEAT (ares_tac ([zadd_commute, zadd_assoc_swap_kill RS sym]@ |
|
275 typechecks) 1)); |
|
276 val integ_of_bin_mult = result(); |
|
277 |
|
278 (**** Computations ****) |
|
279 |
|
280 (** extra rules for bin_succ, bin_pred **) |
|
281 |
|
282 val [bin_succ_Plus, bin_succ_Minus, _] = bin_recs bin_succ_def; |
|
283 val [bin_pred_Plus, bin_pred_Minus, _] = bin_recs bin_pred_def; |
|
284 |
|
285 goal BinFn.thy "bin_succ(w$$1) = bin_succ(w) $$ 0"; |
|
286 by (SIMP_TAC carry_ss 1); |
|
287 val bin_succ_Bcons1 = result(); |
|
288 |
|
289 goal BinFn.thy "bin_succ(w$$0) = w$$1"; |
|
290 by (SIMP_TAC carry_ss 1); |
|
291 val bin_succ_Bcons0 = result(); |
|
292 |
|
293 goal BinFn.thy "bin_pred(w$$1) = w$$0"; |
|
294 by (SIMP_TAC carry_ss 1); |
|
295 val bin_pred_Bcons1 = result(); |
|
296 |
|
297 goal BinFn.thy "bin_pred(w$$0) = bin_pred(w) $$ 1"; |
|
298 by (SIMP_TAC carry_ss 1); |
|
299 val bin_pred_Bcons0 = result(); |
|
300 |
|
301 (** extra rules for bin_minus **) |
|
302 |
|
303 val [bin_minus_Plus, bin_minus_Minus, _] = bin_recs bin_minus_def; |
|
304 |
|
305 goal BinFn.thy "bin_minus(w$$1) = bin_pred(bin_minus(w) $$ 0)"; |
|
306 by (SIMP_TAC bin_minus_ss 1); |
|
307 val bin_minus_Bcons1 = result(); |
|
308 |
|
309 goal BinFn.thy "bin_minus(w$$0) = bin_minus(w) $$ 0"; |
|
310 by (SIMP_TAC bin_minus_ss 1); |
|
311 val bin_minus_Bcons0 = result(); |
|
312 |
|
313 (** extra rules for bin_add **) |
|
314 |
|
315 goal BinFn.thy |
|
316 "!!w. w: bin ==> bin_add(v$$1, w$$1) = bin_add(v, bin_succ(w)) $$ 0"; |
|
317 by (ASM_SIMP_TAC bin_add_ss 1); |
|
318 val bin_add_Bcons_Bcons11 = result(); |
|
319 |
|
320 goal BinFn.thy |
|
321 "!!w. w: bin ==> bin_add(v$$1, w$$0) = bin_add(v,w) $$ 1"; |
|
322 by (ASM_SIMP_TAC bin_add_ss 1); |
|
323 val bin_add_Bcons_Bcons10 = result(); |
|
324 |
|
325 goal BinFn.thy |
|
326 "!!w y.[| w: bin; y: bool |] ==> bin_add(v$$0, w$$y) = bin_add(v,w) $$ y"; |
|
327 by (ASM_SIMP_TAC bin_add_ss 1); |
|
328 val bin_add_Bcons_Bcons0 = result(); |
|
329 |
|
330 (** extra rules for bin_mult **) |
|
331 |
|
332 val [bin_mult_Plus, bin_mult_Minus, _] = bin_recs bin_mult_def; |
|
333 |
|
334 goal BinFn.thy "bin_mult(v$$1, w) = bin_add(bin_mult(v,w)$$0, w)"; |
|
335 by (SIMP_TAC bin_mult_ss 1); |
|
336 val bin_mult_Bcons1 = result(); |
|
337 |
|
338 goal BinFn.thy "bin_mult(v$$0, w) = bin_mult(v,w)$$0"; |
|
339 by (SIMP_TAC bin_mult_ss 1); |
|
340 val bin_mult_Bcons0 = result(); |
|
341 |
|
342 |
|
343 (*** The computation simpset ***) |
|
344 |
|
345 val bin_comp_ss = carry_ss addrews |
|
346 [bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus, bin_add_Bcons_Minus, |
|
347 bin_add_Bcons_Bcons0, bin_add_Bcons_Bcons10, bin_add_Bcons_Bcons11] |
|
348 setauto (type_auto_tac bin_typechecks0); |
|
349 |
|
350 val bin_comp_ss = integ_ss |
|
351 addcongs bin_congs |
|
352 addrews [bin_succ_Plus, bin_succ_Minus, |
|
353 bin_succ_Bcons1, bin_succ_Bcons0, |
|
354 bin_pred_Plus, bin_pred_Minus, |
|
355 bin_pred_Bcons1, bin_pred_Bcons0, |
|
356 bin_minus_Plus, bin_minus_Minus, |
|
357 bin_minus_Bcons1, bin_minus_Bcons0, |
|
358 bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus, |
|
359 bin_add_Bcons_Minus, bin_add_Bcons_Bcons0, |
|
360 bin_add_Bcons_Bcons10, bin_add_Bcons_Bcons11, |
|
361 bin_mult_Plus, bin_mult_Minus, |
|
362 bin_mult_Bcons1, bin_mult_Bcons0] |
|
363 setauto (type_auto_tac ([bool_1I, bool_0I] @ bin_typechecks0)); |
|
364 |
|
365 (*** Examples of performing binary arithmetic by simplification ***) |
|
366 |
|
367 proof_timing := true; |
|
368 (*All runtimes below are on a SPARCserver 10*) |
|
369 |
|
370 (* 13+19 = 32 *) |
|
371 goal BinFn.thy |
|
372 "bin_add(Plus$$1$$1$$0$$1, Plus$$1$$0$$0$$1$$1) = Plus$$1$$0$$0$$0$$0$$0"; |
|
373 by (SIMP_TAC bin_comp_ss 1); (*1.9 secs*) |
|
374 result(); |
|
375 |
|
376 bin_add(binary_of_int 13, binary_of_int 19); |
|
377 |
|
378 (* 1234+5678 = 6912 *) |
|
379 goal BinFn.thy |
|
380 "bin_add(Plus$$1$$0$$0$$1$$1$$0$$1$$0$$0$$1$$0, \ |
|
381 \ Plus$$1$$0$$1$$1$$0$$0$$0$$1$$0$$1$$1$$1$$0) = \ |
|
382 \ Plus$$1$$1$$0$$1$$1$$0$$0$$0$$0$$0$$0$$0$$0"; |
|
383 by (SIMP_TAC bin_comp_ss 1); (*8.9 secs*) |
|
384 result(); |
|
385 |
|
386 bin_add(binary_of_int 1234, binary_of_int 5678); |
|
387 |
|
388 (* 1359-2468 = ~1109 *) |
|
389 goal BinFn.thy |
|
390 "bin_add(Plus$$1$$0$$1$$0$$1$$0$$0$$1$$1$$1$$1, \ |
|
391 \ Minus$$0$$1$$1$$0$$0$$1$$0$$1$$1$$1$$0$$0) = \ |
|
392 \ Minus$$1$$0$$1$$1$$1$$0$$1$$0$$1$$0$$1$$1"; |
|
393 by (SIMP_TAC bin_comp_ss 1); (*7.4 secs*) |
|
394 result(); |
|
395 |
|
396 bin_add(binary_of_int 1359, binary_of_int ~2468); |
|
397 |
|
398 (* 93746-46375 = 47371 *) |
|
399 goal BinFn.thy |
|
400 "bin_add(Plus$$1$$0$$1$$1$$0$$1$$1$$1$$0$$0$$0$$1$$1$$0$$0$$1$$0, \ |
|
401 \ Minus$$0$$1$$0$$0$$1$$0$$1$$0$$1$$1$$0$$1$$1$$0$$0$$1) = \ |
|
402 \ Plus$$0$$1$$0$$1$$1$$1$$0$$0$$1$$0$$0$$0$$0$$1$$0$$1$$1"; |
|
403 by (SIMP_TAC bin_comp_ss 1); (*13.7 secs*) |
|
404 result(); |
|
405 |
|
406 bin_add(binary_of_int 93746, binary_of_int ~46375); |
|
407 |
|
408 (* negation of 65745 *) |
|
409 goal BinFn.thy |
|
410 "bin_minus(Plus$$1$$0$$0$$0$$0$$0$$0$$0$$0$$1$$1$$0$$1$$0$$0$$0$$1) = \ |
|
411 \ Minus$$0$$1$$1$$1$$1$$1$$1$$1$$1$$0$$0$$1$$0$$1$$1$$1$$1"; |
|
412 by (SIMP_TAC bin_comp_ss 1); (*2.8 secs*) |
|
413 result(); |
|
414 |
|
415 bin_minus(binary_of_int 65745); |
|
416 |
|
417 (* negation of ~54321 *) |
|
418 goal BinFn.thy |
|
419 "bin_minus(Minus$$0$$0$$1$$0$$1$$0$$1$$1$$1$$1$$0$$0$$1$$1$$1$$1) = \ |
|
420 \ Plus$$0$$1$$1$$0$$1$$0$$1$$0$$0$$0$$0$$1$$1$$0$$0$$0$$1"; |
|
421 by (SIMP_TAC bin_comp_ss 1); (*3.3 secs*) |
|
422 result(); |
|
423 |
|
424 bin_minus(binary_of_int ~54321); |
|
425 |
|
426 (* 13*19 = 247 *) |
|
427 goal BinFn.thy "bin_mult(Plus$$1$$1$$0$$1, Plus$$1$$0$$0$$1$$1) = \ |
|
428 \ Plus$$1$$1$$1$$1$$0$$1$$1$$1"; |
|
429 by (SIMP_TAC bin_comp_ss 1); (*4.4 secs*) |
|
430 result(); |
|
431 |
|
432 bin_mult(binary_of_int 13, binary_of_int 19); |
|
433 |
|
434 (* ~84 * 51 = ~4284 *) |
|
435 goal BinFn.thy |
|
436 "bin_mult(Minus$$0$$1$$0$$1$$1$$0$$0, Plus$$1$$1$$0$$0$$1$$1) = \ |
|
437 \ Minus$$0$$1$$1$$1$$1$$0$$1$$0$$0$$0$$1$$0$$0"; |
|
438 by (SIMP_TAC bin_comp_ss 1); (*9.2 secs*) |
|
439 result(); |
|
440 |
|
441 bin_mult(binary_of_int ~84, binary_of_int 51); |
|
442 |
|
443 (* 255*255 = 65025; the worst case for 8-bit operands *) |
|
444 goal BinFn.thy |
|
445 "bin_mult(Plus$$1$$1$$1$$1$$1$$1$$1$$1, \ |
|
446 \ Plus$$1$$1$$1$$1$$1$$1$$1$$1) = \ |
|
447 \ Plus$$1$$1$$1$$1$$1$$1$$1$$0$$0$$0$$0$$0$$0$$0$$0$$1"; |
|
448 by (SIMP_TAC bin_comp_ss 1); (*38.4 secs*) |
|
449 result(); |
|
450 |
|
451 bin_mult(binary_of_int 255, binary_of_int 255); |
|
452 |
|
453 (***************** TOO SLOW TO INCLUDE IN TEST RUNS |
|
454 (* 1359 * ~2468 = ~3354012 *) |
|
455 goal BinFn.thy |
|
456 "bin_mult(Plus$$1$$0$$1$$0$$1$$0$$0$$1$$1$$1$$1, \ |
|
457 \ Minus$$0$$1$$1$$0$$0$$1$$0$$1$$1$$1$$0$$0) = \ |
|
458 \ Minus$$0$$0$$1$$1$$0$$0$$1$$1$$0$$1$$0$$0$$1$$0$$0$$1$$1$$0$$0$$1$$0$$0"; |
|
459 by (SIMP_TAC bin_comp_ss 1); (*54.8 secs*) |
|
460 result(); |
|
461 ****************) |
|
462 |
|
463 bin_mult(binary_of_int 1359, binary_of_int ~2468); |