author | paulson |
Wed, 25 Feb 2004 16:22:36 +0100 | |
changeset 14413 | 7ce47ab455eb |
parent 14387 | e96d5c42c4b0 |
child 14443 | 75910c7557c5 |
permissions | -rw-r--r-- |
6905 | 1 |
(* Title: HOL/Numeral.thy |
2 |
ID: $Id$ |
|
3 |
Author: Larry Paulson and Markus Wenzel |
|
4 |
||
9410
612ee826a409
removed selector syntax -- improper tuples are broken beyond repair :-(
wenzelm
parents:
9358
diff
changeset
|
5 |
Generic numerals represented as twos-complement bit strings. |
6905 | 6 |
*) |
7 |
||
8 |
theory Numeral = Datatype |
|
9035 | 9 |
files "Tools/numeral_syntax.ML": |
6905 | 10 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
11 |
text{* The file @{text numeral_syntax.ML} hides the constructors Pls and Min. |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
12 |
Only qualified access bin.Pls and bin.Min is allowed. |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
13 |
We do not hide Bit because we need the BIT infix syntax.*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
14 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
15 |
text{*A number can have multiple representations, namely leading Falses with |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
16 |
sign @{term Pls} and leading Trues with sign @{term Min}. |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
17 |
See @{text "ZF/Integ/twos-compl.ML"}, function @{text int_of_binary}, |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
18 |
for the numerical interpretation. |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
19 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
20 |
The representation expects that @{text "(m mod 2)"} is 0 or 1, |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
21 |
even if m is negative; |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
22 |
For instance, @{text "-5 div 2 = -3"} and @{text "-5 mod 2 = 1"}; thus |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
23 |
@{text "-5 = (-3)*2 + 1"}. |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
24 |
*} |
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
12738
diff
changeset
|
25 |
|
6905 | 26 |
datatype |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
27 |
bin = Pls --{*Plus: Stands for an infinite string of leading Falses*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
28 |
| Min --{*Minus: Stands for an infinite string of leading Trues*} |
9358
973672495414
added syntax for proper / improper selector functions;
wenzelm
parents:
9035
diff
changeset
|
29 |
| Bit bin bool (infixl "BIT" 90) |
6905 | 30 |
|
31 |
axclass |
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
12098
diff
changeset
|
32 |
number < type -- {* for numeric types: nat, int, real, \dots *} |
6905 | 33 |
|
34 |
consts |
|
9035 | 35 |
number_of :: "bin => 'a::number" |
6905 | 36 |
|
37 |
syntax |
|
12098 | 38 |
"_Numeral" :: "num_const => 'a" ("_") |
11699 | 39 |
Numeral0 :: 'a |
40 |
Numeral1 :: 'a |
|
41 |
||
42 |
translations |
|
13490
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
12738
diff
changeset
|
43 |
"Numeral0" == "number_of bin.Pls" |
44bdc150211b
Added Mi and Max on sets, hid Min and Pls on numerals.
nipkow
parents:
12738
diff
changeset
|
44 |
"Numeral1" == "number_of (bin.Pls BIT True)" |
11488
4ff900551340
constify numeral tokens in order to allow translations;
wenzelm
parents:
9410
diff
changeset
|
45 |
|
6905 | 46 |
|
9035 | 47 |
setup NumeralSyntax.setup |
6905 | 48 |
|
12738
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
49 |
syntax (xsymbols) |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
50 |
"_square" :: "'a => 'a" ("(_\<twosuperior>)" [1000] 999) |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
51 |
syntax (HTML output) |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
52 |
"_square" :: "'a => 'a" ("(_\<twosuperior>)" [1000] 999) |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
53 |
syntax (output) |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
54 |
"_square" :: "'a => 'a" ("(_ ^/ 2)" [81] 80) |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
55 |
translations |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
56 |
"x\<twosuperior>" == "x^2" |
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
57 |
"x\<twosuperior>" <= "x^(2::nat)" |
11699 | 58 |
|
12738
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
59 |
|
11699 | 60 |
lemma Let_number_of [simp]: "Let (number_of v) f == f (number_of v)" |
12738
9d80e3746eb0
symbolic syntax for x^2 (faills back on plain infix "^");
wenzelm
parents:
12338
diff
changeset
|
61 |
-- {* Unfold all @{text let}s involving constants *} |
11699 | 62 |
by (simp add: Let_def) |
63 |
||
11868
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11704
diff
changeset
|
64 |
lemma Let_0 [simp]: "Let 0 f == f 0" |
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11704
diff
changeset
|
65 |
by (simp add: Let_def) |
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11704
diff
changeset
|
66 |
|
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11704
diff
changeset
|
67 |
lemma Let_1 [simp]: "Let 1 f == f 1" |
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11704
diff
changeset
|
68 |
by (simp add: Let_def) |
11699 | 69 |
|
14288 | 70 |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
71 |
consts |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
72 |
ring_of :: "bin => 'a::ring" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
73 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
74 |
NCons :: "[bin,bool]=>bin" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
75 |
bin_succ :: "bin=>bin" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
76 |
bin_pred :: "bin=>bin" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
77 |
bin_minus :: "bin=>bin" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
78 |
bin_add :: "[bin,bin]=>bin" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
79 |
bin_mult :: "[bin,bin]=>bin" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
80 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
81 |
text{*@{term NCons} inserts a bit, suppressing leading 0s and 1s*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
82 |
primrec |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
83 |
NCons_Pls: "NCons bin.Pls b = (if b then (bin.Pls BIT b) else bin.Pls)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
84 |
NCons_Min: "NCons bin.Min b = (if b then bin.Min else (bin.Min BIT b))" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
85 |
NCons_BIT: "NCons (w BIT x) b = (w BIT x) BIT b" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
86 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
87 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
88 |
primrec |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
89 |
ring_of_Pls: "ring_of bin.Pls = 0" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
90 |
ring_of_Min: "ring_of bin.Min = - (1::'a::ring)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
91 |
ring_of_BIT: "ring_of(w BIT x) = (if x then 1 else 0) + |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
92 |
(ring_of w) + (ring_of w)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
93 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
94 |
primrec |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
95 |
bin_succ_Pls: "bin_succ bin.Pls = bin.Pls BIT True" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
96 |
bin_succ_Min: "bin_succ bin.Min = bin.Pls" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
97 |
bin_succ_BIT: "bin_succ(w BIT x) = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
98 |
(if x then bin_succ w BIT False |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
99 |
else NCons w True)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
100 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
101 |
primrec |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
102 |
bin_pred_Pls: "bin_pred bin.Pls = bin.Min" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
103 |
bin_pred_Min: "bin_pred bin.Min = bin.Min BIT False" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
104 |
bin_pred_BIT: "bin_pred(w BIT x) = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
105 |
(if x then NCons w False |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
106 |
else (bin_pred w) BIT True)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
107 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
108 |
primrec |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
109 |
bin_minus_Pls: "bin_minus bin.Pls = bin.Pls" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
110 |
bin_minus_Min: "bin_minus bin.Min = bin.Pls BIT True" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
111 |
bin_minus_BIT: "bin_minus(w BIT x) = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
112 |
(if x then bin_pred (NCons (bin_minus w) False) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
113 |
else bin_minus w BIT False)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
114 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
115 |
primrec |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
116 |
bin_add_Pls: "bin_add bin.Pls w = w" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
117 |
bin_add_Min: "bin_add bin.Min w = bin_pred w" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
118 |
bin_add_BIT: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
119 |
"bin_add (v BIT x) w = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
120 |
(case w of Pls => v BIT x |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
121 |
| Min => bin_pred (v BIT x) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
122 |
| (w BIT y) => |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
123 |
NCons (bin_add v (if (x & y) then bin_succ w else w)) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
124 |
(x~=y))" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
125 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
126 |
primrec |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
127 |
bin_mult_Pls: "bin_mult bin.Pls w = bin.Pls" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
128 |
bin_mult_Min: "bin_mult bin.Min w = bin_minus w" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
129 |
bin_mult_BIT: "bin_mult (v BIT x) w = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
130 |
(if x then (bin_add (NCons (bin_mult v w) False) w) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
131 |
else (NCons (bin_mult v w) False))" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
132 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
133 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
134 |
subsection{*Extra rules for @{term bin_succ}, @{term bin_pred}, |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
135 |
@{term bin_add} and @{term bin_mult}*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
136 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
137 |
lemma NCons_Pls_0: "NCons bin.Pls False = bin.Pls" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
138 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
139 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
140 |
lemma NCons_Pls_1: "NCons bin.Pls True = bin.Pls BIT True" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
141 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
142 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
143 |
lemma NCons_Min_0: "NCons bin.Min False = bin.Min BIT False" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
144 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
145 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
146 |
lemma NCons_Min_1: "NCons bin.Min True = bin.Min" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
147 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
148 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
149 |
lemma bin_succ_1: "bin_succ(w BIT True) = (bin_succ w) BIT False" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
150 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
151 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
152 |
lemma bin_succ_0: "bin_succ(w BIT False) = NCons w True" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
153 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
154 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
155 |
lemma bin_pred_1: "bin_pred(w BIT True) = NCons w False" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
156 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
157 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
158 |
lemma bin_pred_0: "bin_pred(w BIT False) = (bin_pred w) BIT True" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
159 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
160 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
161 |
lemma bin_minus_1: "bin_minus(w BIT True) = bin_pred (NCons (bin_minus w) False)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
162 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
163 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
164 |
lemma bin_minus_0: "bin_minus(w BIT False) = (bin_minus w) BIT False" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
165 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
166 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
167 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
168 |
subsection{*Binary Addition and Multiplication: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
169 |
@{term bin_add} and @{term bin_mult}*} |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
170 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
171 |
lemma bin_add_BIT_11: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
172 |
"bin_add (v BIT True) (w BIT True) = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
173 |
NCons (bin_add v (bin_succ w)) False" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
174 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
175 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
176 |
lemma bin_add_BIT_10: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
177 |
"bin_add (v BIT True) (w BIT False) = NCons (bin_add v w) True" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
178 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
179 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
180 |
lemma bin_add_BIT_0: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
181 |
"bin_add (v BIT False) (w BIT y) = NCons (bin_add v w) y" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
182 |
by auto |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
183 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
184 |
lemma bin_add_Pls_right: "bin_add w bin.Pls = w" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
185 |
by (induct_tac "w", auto) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
186 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
187 |
lemma bin_add_Min_right: "bin_add w bin.Min = bin_pred w" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
188 |
by (induct_tac "w", auto) |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
189 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
190 |
lemma bin_add_BIT_BIT: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
191 |
"bin_add (v BIT x) (w BIT y) = |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
192 |
NCons(bin_add v (if x & y then (bin_succ w) else w)) (x~= y)" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
193 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
194 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
195 |
lemma bin_mult_1: |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
196 |
"bin_mult (v BIT True) w = bin_add (NCons (bin_mult v w) False) w" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
197 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
198 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
199 |
lemma bin_mult_0: "bin_mult (v BIT False) w = NCons (bin_mult v w) False" |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
200 |
by simp |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
201 |
|
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14288
diff
changeset
|
202 |
|
9035 | 203 |
end |