11399
|
1 |
(* Title: ZF/ex/BinEx.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1994 University of Cambridge
|
|
5 |
|
|
6 |
Examples of performing binary arithmetic by simplification
|
|
7 |
*)
|
|
8 |
|
16417
|
9 |
theory BinEx imports Main begin
|
11399
|
10 |
(*All runtimes below are on a 300MHz Pentium*)
|
|
11 |
|
|
12 |
lemma "#13 $+ #19 = #32"
|
|
13 |
by simp (*0 secs*)
|
|
14 |
|
|
15 |
lemma "#1234 $+ #5678 = #6912"
|
|
16 |
by simp (*190 msec*)
|
|
17 |
|
|
18 |
lemma "#1359 $+ #-2468 = #-1109"
|
|
19 |
by simp (*160 msec*)
|
|
20 |
|
|
21 |
lemma "#93746 $+ #-46375 = #47371"
|
|
22 |
by simp (*300 msec*)
|
|
23 |
|
|
24 |
lemma "$- #65745 = #-65745"
|
|
25 |
by simp (*80 msec*)
|
|
26 |
|
|
27 |
(* negation of ~54321 *)
|
|
28 |
lemma "$- #-54321 = #54321"
|
|
29 |
by simp (*90 msec*)
|
|
30 |
|
|
31 |
lemma "#13 $* #19 = #247"
|
|
32 |
by simp (*110 msec*)
|
|
33 |
|
|
34 |
lemma "#-84 $* #51 = #-4284"
|
|
35 |
by simp (*210 msec*)
|
|
36 |
|
|
37 |
(*The worst case for 8-bit operands *)
|
|
38 |
lemma "#255 $* #255 = #65025"
|
|
39 |
by simp (*730 msec*)
|
|
40 |
|
|
41 |
lemma "#1359 $* #-2468 = #-3354012"
|
|
42 |
by simp (*1.04 secs*)
|
|
43 |
|
|
44 |
|
|
45 |
(** Comparisons **)
|
|
46 |
|
|
47 |
lemma "(#89) $* #10 \<noteq> #889"
|
|
48 |
by simp
|
|
49 |
|
|
50 |
lemma "(#13) $< #18 $- #4"
|
|
51 |
by simp
|
|
52 |
|
|
53 |
lemma "(#-345) $< #-242 $+ #-100"
|
|
54 |
by simp
|
|
55 |
|
|
56 |
lemma "(#13557456) $< #18678654"
|
|
57 |
by simp
|
|
58 |
|
|
59 |
lemma "(#999999) $<= (#1000001 $+ #1) $- #2"
|
|
60 |
by simp
|
|
61 |
|
|
62 |
lemma "(#1234567) $<= #1234567"
|
|
63 |
by simp
|
|
64 |
|
|
65 |
|
|
66 |
(*** Quotient and remainder!! [they could be faster] ***)
|
|
67 |
|
|
68 |
lemma "#23 zdiv #3 = #7"
|
|
69 |
by simp
|
|
70 |
|
|
71 |
lemma "#23 zmod #3 = #2"
|
|
72 |
by simp
|
|
73 |
|
|
74 |
(** negative dividend **)
|
|
75 |
|
|
76 |
lemma "#-23 zdiv #3 = #-8"
|
|
77 |
by simp
|
|
78 |
|
|
79 |
lemma "#-23 zmod #3 = #1"
|
|
80 |
by simp
|
|
81 |
|
|
82 |
(** negative divisor **)
|
|
83 |
|
|
84 |
lemma "#23 zdiv #-3 = #-8"
|
|
85 |
by simp
|
|
86 |
|
|
87 |
lemma "#23 zmod #-3 = #-1"
|
|
88 |
by simp
|
|
89 |
|
|
90 |
(** Negative dividend and divisor **)
|
|
91 |
|
|
92 |
lemma "#-23 zdiv #-3 = #7"
|
|
93 |
by simp
|
|
94 |
|
|
95 |
lemma "#-23 zmod #-3 = #-2"
|
|
96 |
by simp
|
|
97 |
|
|
98 |
end
|
|
99 |
|