author | huffman |
Wed, 28 Dec 2011 16:04:58 +0100 | |
changeset 46016 | c42e43287b5f |
parent 46001 | 0b562d564d5f |
child 46017 | c5a1002161c3 |
permissions | -rw-r--r-- |
24333 | 1 |
(* |
2 |
Author: Jeremy Dawson and Gerwin Klein, NICTA |
|
3 |
||
44939
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
kleing
parents:
37667
diff
changeset
|
4 |
Definitions and basic theorems for bit-wise logical operations |
24333 | 5 |
for integers expressed using Pls, Min, BIT, |
44939
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
kleing
parents:
37667
diff
changeset
|
6 |
and converting them to and from lists of bools. |
24333 | 7 |
*) |
8 |
||
24350 | 9 |
header {* Bitwise Operations on Binary Integers *} |
10 |
||
37658 | 11 |
theory Bit_Int |
12 |
imports Bit_Representation Bit_Operations |
|
24333 | 13 |
begin |
14 |
||
37667 | 15 |
subsection {* Recursion combinators for bitstrings *} |
16 |
||
17 |
function bin_rec :: "'a \<Rightarrow> 'a \<Rightarrow> (int \<Rightarrow> bit \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> int \<Rightarrow> 'a" where |
|
18 |
"bin_rec f1 f2 f3 bin = (if bin = 0 then f1 |
|
19 |
else if bin = - 1 then f2 |
|
20 |
else f3 (bin_rest bin) (bin_last bin) (bin_rec f1 f2 f3 (bin_rest bin)))" |
|
21 |
by pat_completeness auto |
|
22 |
||
23 |
termination by (relation "measure (nat o abs o snd o snd o snd)") |
|
24 |
(simp_all add: bin_last_def bin_rest_def) |
|
25 |
||
26 |
declare bin_rec.simps [simp del] |
|
27 |
||
28 |
lemma bin_rec_PM: |
|
29 |
"f = bin_rec f1 f2 f3 ==> f Int.Pls = f1 & f Int.Min = f2" |
|
30 |
by (unfold Pls_def Min_def) (simp add: bin_rec.simps) |
|
31 |
||
32 |
lemma bin_rec_Pls: "bin_rec f1 f2 f3 Int.Pls = f1" |
|
33 |
by (unfold Pls_def Min_def) (simp add: bin_rec.simps) |
|
34 |
||
35 |
lemma bin_rec_Min: "bin_rec f1 f2 f3 Int.Min = f2" |
|
36 |
by (unfold Pls_def Min_def) (simp add: bin_rec.simps) |
|
37 |
||
38 |
lemma bin_rec_Bit0: |
|
39 |
"f3 Int.Pls (0::bit) f1 = f1 \<Longrightarrow> |
|
40 |
bin_rec f1 f2 f3 (Int.Bit0 w) = f3 w (0::bit) (bin_rec f1 f2 f3 w)" |
|
41 |
by (unfold Pls_def Min_def Bit0_def Bit1_def) (simp add: bin_rec.simps bin_last_def bin_rest_def) |
|
42 |
||
43 |
lemma bin_rec_Bit1: |
|
44 |
"f3 Int.Min (1::bit) f2 = f2 \<Longrightarrow> |
|
45 |
bin_rec f1 f2 f3 (Int.Bit1 w) = f3 w (1::bit) (bin_rec f1 f2 f3 w)" |
|
46 |
apply (cases "w = Int.Min") |
|
47 |
apply (simp add: bin_rec_Min) |
|
48 |
apply (cases "w = Int.Pls") |
|
49 |
apply (simp add: bin_rec_Pls number_of_is_id Pls_def [symmetric] bin_rec.simps) |
|
50 |
apply (subst bin_rec.simps) |
|
51 |
apply auto unfolding Pls_def Min_def Bit0_def Bit1_def number_of_is_id apply auto |
|
52 |
done |
|
53 |
||
54 |
lemma bin_rec_Bit: |
|
55 |
"f = bin_rec f1 f2 f3 ==> f3 Int.Pls (0::bit) f1 = f1 ==> |
|
56 |
f3 Int.Min (1::bit) f2 = f2 ==> f (w BIT b) = f3 w b (f w)" |
|
45847 | 57 |
by (cases b, simp add: bin_rec_Bit0 BIT_simps, simp add: bin_rec_Bit1 BIT_simps) |
37667 | 58 |
|
59 |
lemmas bin_rec_simps = refl [THEN bin_rec_Bit] bin_rec_Pls bin_rec_Min |
|
60 |
bin_rec_Bit0 bin_rec_Bit1 |
|
61 |
||
62 |
||
24364 | 63 |
subsection {* Logical operations *} |
24353 | 64 |
|
65 |
text "bit-wise logical operations on the int type" |
|
66 |
||
25762 | 67 |
instantiation int :: bit |
68 |
begin |
|
69 |
||
70 |
definition |
|
46016 | 71 |
int_not_def: "bitNOT = (\<lambda>x::int. - x - 1)" |
25762 | 72 |
|
73 |
definition |
|
37667 | 74 |
int_and_def: "bitAND = bin_rec (\<lambda>x. 0) (\<lambda>y. y) |
24353 | 75 |
(\<lambda>w b s y. s (bin_rest y) BIT (b AND bin_last y))" |
25762 | 76 |
|
77 |
definition |
|
37667 | 78 |
int_or_def: "bitOR = bin_rec (\<lambda>x. x) (\<lambda>y. - 1) |
24353 | 79 |
(\<lambda>w b s y. s (bin_rest y) BIT (b OR bin_last y))" |
25762 | 80 |
|
81 |
definition |
|
37667 | 82 |
int_xor_def: "bitXOR = bin_rec (\<lambda>x. x) bitNOT |
24353 | 83 |
(\<lambda>w b s y. s (bin_rest y) BIT (b XOR bin_last y))" |
25762 | 84 |
|
85 |
instance .. |
|
86 |
||
87 |
end |
|
24353 | 88 |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
89 |
subsubsection {* Basic simplification rules *} |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
90 |
|
46016 | 91 |
lemma int_not_BIT [simp]: |
92 |
"NOT (w BIT b) = (NOT w) BIT (NOT b)" |
|
93 |
unfolding int_not_def Bit_def by (cases b, simp_all) |
|
94 |
||
24333 | 95 |
lemma int_not_simps [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
96 |
"NOT Int.Pls = Int.Min" |
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
97 |
"NOT Int.Min = Int.Pls" |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
98 |
"NOT (Int.Bit0 w) = Int.Bit1 (NOT w)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
99 |
"NOT (Int.Bit1 w) = Int.Bit0 (NOT w)" |
46016 | 100 |
unfolding int_not_def Pls_def Min_def Bit0_def Bit1_def by simp_all |
24333 | 101 |
|
37667 | 102 |
lemma int_xor_Pls [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
103 |
"Int.Pls XOR x = x" |
37667 | 104 |
unfolding int_xor_def Pls_def [symmetric] Min_def [symmetric] by (simp add: bin_rec_PM) |
24333 | 105 |
|
37667 | 106 |
lemma int_xor_Min [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
107 |
"Int.Min XOR x = NOT x" |
37667 | 108 |
unfolding int_xor_def Pls_def [symmetric] Min_def [symmetric] by (simp add: bin_rec_PM) |
24333 | 109 |
|
110 |
lemma int_xor_Bits [simp]: |
|
24353 | 111 |
"(x BIT b) XOR (y BIT c) = (x XOR y) BIT (b XOR c)" |
37667 | 112 |
apply (unfold int_xor_def Pls_def [symmetric] Min_def [symmetric]) |
24333 | 113 |
apply (rule bin_rec_simps (1) [THEN fun_cong, THEN trans]) |
114 |
apply (rule ext, simp) |
|
115 |
prefer 2 |
|
116 |
apply simp |
|
117 |
apply (rule ext) |
|
46016 | 118 |
apply (simp add: int_not_BIT [symmetric]) |
24333 | 119 |
done |
120 |
||
37667 | 121 |
lemma int_xor_Bits2 [simp]: |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
122 |
"(Int.Bit0 x) XOR (Int.Bit0 y) = Int.Bit0 (x XOR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
123 |
"(Int.Bit0 x) XOR (Int.Bit1 y) = Int.Bit1 (x XOR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
124 |
"(Int.Bit1 x) XOR (Int.Bit0 y) = Int.Bit1 (x XOR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
125 |
"(Int.Bit1 x) XOR (Int.Bit1 y) = Int.Bit0 (x XOR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
126 |
unfolding BIT_simps [symmetric] int_xor_Bits by simp_all |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
127 |
|
37667 | 128 |
lemma int_or_Pls [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
129 |
"Int.Pls OR x = x" |
24465 | 130 |
by (unfold int_or_def) (simp add: bin_rec_PM) |
24333 | 131 |
|
37667 | 132 |
lemma int_or_Min [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
133 |
"Int.Min OR x = Int.Min" |
37667 | 134 |
by (unfold int_or_def Pls_def [symmetric] Min_def [symmetric]) (simp add: bin_rec_PM) |
24333 | 135 |
|
136 |
lemma int_or_Bits [simp]: |
|
24353 | 137 |
"(x BIT b) OR (y BIT c) = (x OR y) BIT (b OR c)" |
45847 | 138 |
unfolding int_or_def Pls_def [symmetric] Min_def [symmetric] |
139 |
by (simp add: bin_rec_simps BIT_simps) |
|
24333 | 140 |
|
37667 | 141 |
lemma int_or_Bits2 [simp]: |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
142 |
"(Int.Bit0 x) OR (Int.Bit0 y) = Int.Bit0 (x OR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
143 |
"(Int.Bit0 x) OR (Int.Bit1 y) = Int.Bit1 (x OR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
144 |
"(Int.Bit1 x) OR (Int.Bit0 y) = Int.Bit1 (x OR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
145 |
"(Int.Bit1 x) OR (Int.Bit1 y) = Int.Bit1 (x OR y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
146 |
unfolding BIT_simps [symmetric] int_or_Bits by simp_all |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
147 |
|
37667 | 148 |
lemma int_and_Pls [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
149 |
"Int.Pls AND x = Int.Pls" |
45845
4158f35a5c6f
remove some unwanted numeral-representation-specific simp rules
huffman
parents:
45604
diff
changeset
|
150 |
unfolding int_and_def Pls_def [symmetric] by (simp add: bin_rec_PM) |
24333 | 151 |
|
37667 | 152 |
lemma int_and_Min [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
153 |
"Int.Min AND x = x" |
24465 | 154 |
unfolding int_and_def by (simp add: bin_rec_PM) |
24333 | 155 |
|
156 |
lemma int_and_Bits [simp]: |
|
24353 | 157 |
"(x BIT b) AND (y BIT c) = (x AND y) BIT (b AND c)" |
45847 | 158 |
unfolding int_and_def Pls_def [symmetric] Min_def [symmetric] |
159 |
by (simp add: bin_rec_simps BIT_simps) |
|
24333 | 160 |
|
37667 | 161 |
lemma int_and_Bits2 [simp]: |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
162 |
"(Int.Bit0 x) AND (Int.Bit0 y) = Int.Bit0 (x AND y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
163 |
"(Int.Bit0 x) AND (Int.Bit1 y) = Int.Bit0 (x AND y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
164 |
"(Int.Bit1 x) AND (Int.Bit0 y) = Int.Bit0 (x AND y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
165 |
"(Int.Bit1 x) AND (Int.Bit1 y) = Int.Bit1 (x AND y)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
166 |
unfolding BIT_simps [symmetric] int_and_Bits by simp_all |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
167 |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
168 |
subsubsection {* Binary destructors *} |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
169 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
170 |
lemma bin_rest_NOT [simp]: "bin_rest (NOT x) = NOT (bin_rest x)" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
171 |
by (cases x rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
172 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
173 |
lemma bin_last_NOT [simp]: "bin_last (NOT x) = NOT (bin_last x)" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
174 |
by (cases x rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
175 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
176 |
lemma bin_rest_AND [simp]: "bin_rest (x AND y) = bin_rest x AND bin_rest y" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
177 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
178 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
179 |
lemma bin_last_AND [simp]: "bin_last (x AND y) = bin_last x AND bin_last y" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
180 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
181 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
182 |
lemma bin_rest_OR [simp]: "bin_rest (x OR y) = bin_rest x OR bin_rest y" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
183 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
184 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
185 |
lemma bin_last_OR [simp]: "bin_last (x OR y) = bin_last x OR bin_last y" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
186 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
187 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
188 |
lemma bin_rest_XOR [simp]: "bin_rest (x XOR y) = bin_rest x XOR bin_rest y" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
189 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
190 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
191 |
lemma bin_last_XOR [simp]: "bin_last (x XOR y) = bin_last x XOR bin_last y" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
192 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
193 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
194 |
lemma bit_NOT_eq_1_iff [simp]: "NOT (b::bit) = 1 \<longleftrightarrow> b = 0" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
195 |
by (induct b, simp_all) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
196 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
197 |
lemma bit_AND_eq_1_iff [simp]: "(a::bit) AND b = 1 \<longleftrightarrow> a = 1 \<and> b = 1" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
198 |
by (induct a, simp_all) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
199 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
200 |
lemma bin_nth_ops: |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
201 |
"!!x y. bin_nth (x AND y) n = (bin_nth x n & bin_nth y n)" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
202 |
"!!x y. bin_nth (x OR y) n = (bin_nth x n | bin_nth y n)" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
203 |
"!!x y. bin_nth (x XOR y) n = (bin_nth x n ~= bin_nth y n)" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
204 |
"!!x. bin_nth (NOT x) n = (~ bin_nth x n)" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
205 |
by (induct n) auto |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
206 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
207 |
subsubsection {* Derived properties *} |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
208 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
209 |
lemma int_xor_extra_simps [simp]: |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
210 |
"w XOR Int.Pls = w" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
211 |
"w XOR Int.Min = NOT w" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
212 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
213 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
214 |
lemma int_or_extra_simps [simp]: |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
215 |
"w OR Int.Pls = w" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
216 |
"w OR Int.Min = Int.Min" |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
217 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 218 |
|
37667 | 219 |
lemma int_and_extra_simps [simp]: |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
220 |
"w AND Int.Pls = Int.Pls" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
221 |
"w AND Int.Min = w" |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
222 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 223 |
|
224 |
(* commutativity of the above *) |
|
225 |
lemma bin_ops_comm: |
|
226 |
shows |
|
24353 | 227 |
int_and_comm: "!!y::int. x AND y = y AND x" and |
228 |
int_or_comm: "!!y::int. x OR y = y OR x" and |
|
229 |
int_xor_comm: "!!y::int. x XOR y = y XOR x" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
230 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 231 |
|
232 |
lemma bin_ops_same [simp]: |
|
24353 | 233 |
"(x::int) AND x = x" |
234 |
"(x::int) OR x = x" |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
235 |
"(x::int) XOR x = Int.Pls" |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
236 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 237 |
|
24353 | 238 |
lemma int_not_not [simp]: "NOT (NOT (x::int)) = x" |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
239 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 240 |
|
241 |
lemmas bin_log_esimps = |
|
242 |
int_and_extra_simps int_or_extra_simps int_xor_extra_simps |
|
243 |
int_and_Pls int_and_Min int_or_Pls int_or_Min int_xor_Pls int_xor_Min |
|
244 |
||
245 |
(* basic properties of logical (bit-wise) operations *) |
|
246 |
||
247 |
lemma bbw_ao_absorb: |
|
24353 | 248 |
"!!y::int. x AND (y OR x) = x & x OR (y AND x) = x" |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
249 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 250 |
|
251 |
lemma bbw_ao_absorbs_other: |
|
24353 | 252 |
"x AND (x OR y) = x \<and> (y AND x) OR x = (x::int)" |
253 |
"(y OR x) AND x = x \<and> x OR (x AND y) = (x::int)" |
|
254 |
"(x OR y) AND x = x \<and> (x AND y) OR x = (x::int)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
255 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24353 | 256 |
|
24333 | 257 |
lemmas bbw_ao_absorbs [simp] = bbw_ao_absorb bbw_ao_absorbs_other |
258 |
||
259 |
lemma int_xor_not: |
|
24353 | 260 |
"!!y::int. (NOT x) XOR y = NOT (x XOR y) & |
261 |
x XOR (NOT y) = NOT (x XOR y)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
262 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 263 |
|
264 |
lemma int_and_assoc: |
|
24353 | 265 |
"(x AND y) AND (z::int) = x AND (y AND z)" |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
266 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 267 |
|
268 |
lemma int_or_assoc: |
|
24353 | 269 |
"(x OR y) OR (z::int) = x OR (y OR z)" |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
270 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 271 |
|
272 |
lemma int_xor_assoc: |
|
24353 | 273 |
"(x XOR y) XOR (z::int) = x XOR (y XOR z)" |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
274 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 275 |
|
276 |
lemmas bbw_assocs = int_and_assoc int_or_assoc int_xor_assoc |
|
277 |
||
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
278 |
(* BH: Why are these declared as simp rules??? *) |
24333 | 279 |
lemma bbw_lcs [simp]: |
24353 | 280 |
"(y::int) AND (x AND z) = x AND (y AND z)" |
281 |
"(y::int) OR (x OR z) = x OR (y OR z)" |
|
282 |
"(y::int) XOR (x XOR z) = x XOR (y XOR z)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
283 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 284 |
|
285 |
lemma bbw_not_dist: |
|
24353 | 286 |
"!!y::int. NOT (x OR y) = (NOT x) AND (NOT y)" |
287 |
"!!y::int. NOT (x AND y) = (NOT x) OR (NOT y)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
288 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 289 |
|
290 |
lemma bbw_oa_dist: |
|
24353 | 291 |
"!!y z::int. (x AND y) OR z = |
292 |
(x OR z) AND (y OR z)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
293 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 294 |
|
295 |
lemma bbw_ao_dist: |
|
24353 | 296 |
"!!y z::int. (x OR y) AND z = |
297 |
(x AND z) OR (y AND z)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
298 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 299 |
|
24367
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
huffman
parents:
24366
diff
changeset
|
300 |
(* |
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
huffman
parents:
24366
diff
changeset
|
301 |
Why were these declared simp??? |
24333 | 302 |
declare bin_ops_comm [simp] bbw_assocs [simp] |
24367
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
huffman
parents:
24366
diff
changeset
|
303 |
*) |
24333 | 304 |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
305 |
subsubsection {* Interactions with arithmetic *} |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
306 |
|
24333 | 307 |
lemma plus_and_or [rule_format]: |
24353 | 308 |
"ALL y::int. (x AND y) + (x OR y) = x + y" |
24333 | 309 |
apply (induct x rule: bin_induct) |
310 |
apply clarsimp |
|
311 |
apply clarsimp |
|
312 |
apply clarsimp |
|
313 |
apply (case_tac y rule: bin_exhaust) |
|
314 |
apply clarsimp |
|
315 |
apply (unfold Bit_def) |
|
316 |
apply clarsimp |
|
317 |
apply (erule_tac x = "x" in allE) |
|
37667 | 318 |
apply (simp add: bitval_def split: bit.split) |
24333 | 319 |
done |
320 |
||
321 |
lemma le_int_or: |
|
37667 | 322 |
"bin_sign (y::int) = Int.Pls ==> x <= x OR y" |
323 |
apply (induct y arbitrary: x rule: bin_induct) |
|
24333 | 324 |
apply clarsimp |
325 |
apply clarsimp |
|
326 |
apply (case_tac x rule: bin_exhaust) |
|
327 |
apply (case_tac b) |
|
328 |
apply (case_tac [!] bit) |
|
45847 | 329 |
apply (auto simp: less_eq_int_code BIT_simps) |
24333 | 330 |
done |
331 |
||
332 |
lemmas int_and_le = |
|
45475 | 333 |
xtr3 [OF bbw_ao_absorbs (2) [THEN conjunct2, symmetric] le_int_or] |
24333 | 334 |
|
24364 | 335 |
(* interaction between bit-wise and arithmetic *) |
336 |
(* good example of bin_induction *) |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
337 |
lemma bin_add_not: "x + NOT x = Int.Min" |
24364 | 338 |
apply (induct x rule: bin_induct) |
339 |
apply clarsimp |
|
340 |
apply clarsimp |
|
45847 | 341 |
apply (case_tac bit, auto simp: BIT_simps) |
24364 | 342 |
done |
343 |
||
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
344 |
subsubsection {* Truncating results of bit-wise operations *} |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
345 |
|
24364 | 346 |
lemma bin_trunc_ao: |
347 |
"!!x y. (bintrunc n x) AND (bintrunc n y) = bintrunc n (x AND y)" |
|
348 |
"!!x y. (bintrunc n x) OR (bintrunc n y) = bintrunc n (x OR y)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
349 |
by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) |
24364 | 350 |
|
351 |
lemma bin_trunc_xor: |
|
352 |
"!!x y. bintrunc n (bintrunc n x XOR bintrunc n y) = |
|
353 |
bintrunc n (x XOR y)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
354 |
by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) |
24364 | 355 |
|
356 |
lemma bin_trunc_not: |
|
357 |
"!!x. bintrunc n (NOT (bintrunc n x)) = bintrunc n (NOT x)" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
358 |
by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) |
24364 | 359 |
|
360 |
(* want theorems of the form of bin_trunc_xor *) |
|
361 |
lemma bintr_bintr_i: |
|
362 |
"x = bintrunc n y ==> bintrunc n x = bintrunc n y" |
|
363 |
by auto |
|
364 |
||
365 |
lemmas bin_trunc_and = bin_trunc_ao(1) [THEN bintr_bintr_i] |
|
366 |
lemmas bin_trunc_or = bin_trunc_ao(2) [THEN bintr_bintr_i] |
|
367 |
||
368 |
subsection {* Setting and clearing bits *} |
|
369 |
||
26558 | 370 |
primrec |
24364 | 371 |
bin_sc :: "nat => bit => int => int" |
26558 | 372 |
where |
373 |
Z: "bin_sc 0 b w = bin_rest w BIT b" |
|
374 |
| Suc: "bin_sc (Suc n) b w = bin_sc n b (bin_rest w) BIT bin_last w" |
|
24364 | 375 |
|
24333 | 376 |
(** nth bit, set/clear **) |
377 |
||
378 |
lemma bin_nth_sc [simp]: |
|
45955 | 379 |
"bin_nth (bin_sc n b w) n = (b = 1)" |
380 |
by (induct n arbitrary: w) auto |
|
24333 | 381 |
|
382 |
lemma bin_sc_sc_same [simp]: |
|
45955 | 383 |
"bin_sc n c (bin_sc n b w) = bin_sc n c w" |
384 |
by (induct n arbitrary: w) auto |
|
24333 | 385 |
|
386 |
lemma bin_sc_sc_diff: |
|
45955 | 387 |
"m ~= n ==> |
24333 | 388 |
bin_sc m c (bin_sc n b w) = bin_sc n b (bin_sc m c w)" |
45955 | 389 |
apply (induct n arbitrary: w m) |
24333 | 390 |
apply (case_tac [!] m) |
391 |
apply auto |
|
392 |
done |
|
393 |
||
394 |
lemma bin_nth_sc_gen: |
|
45955 | 395 |
"bin_nth (bin_sc n b w) m = (if m = n then b = 1 else bin_nth w m)" |
396 |
by (induct n arbitrary: w m) (case_tac [!] m, auto) |
|
24333 | 397 |
|
398 |
lemma bin_sc_nth [simp]: |
|
45955 | 399 |
"(bin_sc n (If (bin_nth w n) 1 0) w) = w" |
400 |
by (induct n arbitrary: w) auto |
|
24333 | 401 |
|
402 |
lemma bin_sign_sc [simp]: |
|
45955 | 403 |
"bin_sign (bin_sc n b w) = bin_sign w" |
404 |
by (induct n arbitrary: w) auto |
|
24333 | 405 |
|
406 |
lemma bin_sc_bintr [simp]: |
|
45955 | 407 |
"bintrunc m (bin_sc n x (bintrunc m (w))) = bintrunc m (bin_sc n x w)" |
408 |
apply (induct n arbitrary: w m) |
|
24333 | 409 |
apply (case_tac [!] w rule: bin_exhaust) |
410 |
apply (case_tac [!] m, auto) |
|
411 |
done |
|
412 |
||
413 |
lemma bin_clr_le: |
|
45955 | 414 |
"bin_sc n 0 w <= w" |
415 |
apply (induct n arbitrary: w) |
|
24333 | 416 |
apply (case_tac [!] w rule: bin_exhaust) |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
417 |
apply (auto simp del: BIT_simps) |
24333 | 418 |
apply (unfold Bit_def) |
37667 | 419 |
apply (simp_all add: bitval_def split: bit.split) |
24333 | 420 |
done |
421 |
||
422 |
lemma bin_set_ge: |
|
45955 | 423 |
"bin_sc n 1 w >= w" |
424 |
apply (induct n arbitrary: w) |
|
24333 | 425 |
apply (case_tac [!] w rule: bin_exhaust) |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
426 |
apply (auto simp del: BIT_simps) |
24333 | 427 |
apply (unfold Bit_def) |
37667 | 428 |
apply (simp_all add: bitval_def split: bit.split) |
24333 | 429 |
done |
430 |
||
431 |
lemma bintr_bin_clr_le: |
|
45955 | 432 |
"bintrunc n (bin_sc m 0 w) <= bintrunc n w" |
433 |
apply (induct n arbitrary: w m) |
|
24333 | 434 |
apply simp |
435 |
apply (case_tac w rule: bin_exhaust) |
|
436 |
apply (case_tac m) |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
437 |
apply (auto simp del: BIT_simps) |
24333 | 438 |
apply (unfold Bit_def) |
37667 | 439 |
apply (simp_all add: bitval_def split: bit.split) |
24333 | 440 |
done |
441 |
||
442 |
lemma bintr_bin_set_ge: |
|
45955 | 443 |
"bintrunc n (bin_sc m 1 w) >= bintrunc n w" |
444 |
apply (induct n arbitrary: w m) |
|
24333 | 445 |
apply simp |
446 |
apply (case_tac w rule: bin_exhaust) |
|
447 |
apply (case_tac m) |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25919
diff
changeset
|
448 |
apply (auto simp del: BIT_simps) |
24333 | 449 |
apply (unfold Bit_def) |
37667 | 450 |
apply (simp_all add: bitval_def split: bit.split) |
24333 | 451 |
done |
452 |
||
37654 | 453 |
lemma bin_sc_FP [simp]: "bin_sc n 0 Int.Pls = Int.Pls" |
45847 | 454 |
by (induct n) (auto simp: BIT_simps) |
24333 | 455 |
|
37654 | 456 |
lemma bin_sc_TM [simp]: "bin_sc n 1 Int.Min = Int.Min" |
45847 | 457 |
by (induct n) (auto simp: BIT_simps) |
24333 | 458 |
|
459 |
lemmas bin_sc_simps = bin_sc.Z bin_sc.Suc bin_sc_TM bin_sc_FP |
|
460 |
||
461 |
lemma bin_sc_minus: |
|
462 |
"0 < n ==> bin_sc (Suc (n - 1)) b w = bin_sc n b w" |
|
463 |
by auto |
|
464 |
||
465 |
lemmas bin_sc_Suc_minus = |
|
45604 | 466 |
trans [OF bin_sc_minus [symmetric] bin_sc.Suc] |
24333 | 467 |
|
468 |
lemmas bin_sc_Suc_pred [simp] = |
|
45604 | 469 |
bin_sc_Suc_minus [of "number_of bin", simplified nobm1] for bin |
24333 | 470 |
|
24465 | 471 |
|
24364 | 472 |
subsection {* Splitting and concatenation *} |
24333 | 473 |
|
26558 | 474 |
definition bin_rcat :: "nat \<Rightarrow> int list \<Rightarrow> int" where |
37667 | 475 |
"bin_rcat n = foldl (\<lambda>u v. bin_cat u n v) 0" |
476 |
||
28042 | 477 |
fun bin_rsplit_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where |
26558 | 478 |
"bin_rsplit_aux n m c bs = |
24364 | 479 |
(if m = 0 | n = 0 then bs else |
480 |
let (a, b) = bin_split n c |
|
26558 | 481 |
in bin_rsplit_aux n (m - n) a (b # bs))" |
24364 | 482 |
|
26558 | 483 |
definition bin_rsplit :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where |
484 |
"bin_rsplit n w = bin_rsplit_aux n (fst w) (snd w) []" |
|
485 |
||
28042 | 486 |
fun bin_rsplitl_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where |
26558 | 487 |
"bin_rsplitl_aux n m c bs = |
24364 | 488 |
(if m = 0 | n = 0 then bs else |
489 |
let (a, b) = bin_split (min m n) c |
|
26558 | 490 |
in bin_rsplitl_aux n (m - n) a (b # bs))" |
24364 | 491 |
|
26558 | 492 |
definition bin_rsplitl :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where |
493 |
"bin_rsplitl n w = bin_rsplitl_aux n (fst w) (snd w) []" |
|
494 |
||
24364 | 495 |
declare bin_rsplit_aux.simps [simp del] |
496 |
declare bin_rsplitl_aux.simps [simp del] |
|
497 |
||
498 |
lemma bin_sign_cat: |
|
45955 | 499 |
"bin_sign (bin_cat x n y) = bin_sign x" |
500 |
by (induct n arbitrary: y) auto |
|
24364 | 501 |
|
502 |
lemma bin_cat_Suc_Bit: |
|
503 |
"bin_cat w (Suc n) (v BIT b) = bin_cat w n v BIT b" |
|
504 |
by auto |
|
505 |
||
506 |
lemma bin_nth_cat: |
|
45955 | 507 |
"bin_nth (bin_cat x k y) n = |
24364 | 508 |
(if n < k then bin_nth y n else bin_nth x (n - k))" |
45955 | 509 |
apply (induct k arbitrary: n y) |
24364 | 510 |
apply clarsimp |
511 |
apply (case_tac n, auto) |
|
24333 | 512 |
done |
513 |
||
24364 | 514 |
lemma bin_nth_split: |
45955 | 515 |
"bin_split n c = (a, b) ==> |
24364 | 516 |
(ALL k. bin_nth a k = bin_nth c (n + k)) & |
517 |
(ALL k. bin_nth b k = (k < n & bin_nth c k))" |
|
45955 | 518 |
apply (induct n arbitrary: b c) |
24364 | 519 |
apply clarsimp |
520 |
apply (clarsimp simp: Let_def split: ls_splits) |
|
521 |
apply (case_tac k) |
|
522 |
apply auto |
|
523 |
done |
|
524 |
||
525 |
lemma bin_cat_assoc: |
|
45955 | 526 |
"bin_cat (bin_cat x m y) n z = bin_cat x (m + n) (bin_cat y n z)" |
527 |
by (induct n arbitrary: z) auto |
|
24364 | 528 |
|
45955 | 529 |
lemma bin_cat_assoc_sym: |
530 |
"bin_cat x m (bin_cat y n z) = bin_cat (bin_cat x (m - n) y) (min m n) z" |
|
531 |
apply (induct n arbitrary: z m, clarsimp) |
|
24364 | 532 |
apply (case_tac m, auto) |
24333 | 533 |
done |
534 |
||
45956 | 535 |
lemma bin_cat_zero [simp]: "bin_cat 0 n w = bintrunc n w" |
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45956
diff
changeset
|
536 |
by (induct n arbitrary: w) auto |
45956 | 537 |
|
45955 | 538 |
lemma bin_cat_Pls [simp]: "bin_cat Int.Pls n w = bintrunc n w" |
45956 | 539 |
unfolding Pls_def by (rule bin_cat_zero) |
24364 | 540 |
|
541 |
lemma bintr_cat1: |
|
45955 | 542 |
"bintrunc (k + n) (bin_cat a n b) = bin_cat (bintrunc k a) n b" |
543 |
by (induct n arbitrary: b) auto |
|
24364 | 544 |
|
545 |
lemma bintr_cat: "bintrunc m (bin_cat a n b) = |
|
546 |
bin_cat (bintrunc (m - n) a) n (bintrunc (min m n) b)" |
|
547 |
by (rule bin_eqI) (auto simp: bin_nth_cat nth_bintr) |
|
548 |
||
549 |
lemma bintr_cat_same [simp]: |
|
550 |
"bintrunc n (bin_cat a n b) = bintrunc n b" |
|
551 |
by (auto simp add : bintr_cat) |
|
552 |
||
553 |
lemma cat_bintr [simp]: |
|
45955 | 554 |
"bin_cat a n (bintrunc n b) = bin_cat a n b" |
555 |
by (induct n arbitrary: b) auto |
|
24364 | 556 |
|
557 |
lemma split_bintrunc: |
|
45955 | 558 |
"bin_split n c = (a, b) ==> b = bintrunc n c" |
559 |
by (induct n arbitrary: b c) (auto simp: Let_def split: ls_splits) |
|
24364 | 560 |
|
561 |
lemma bin_cat_split: |
|
45955 | 562 |
"bin_split n w = (u, v) ==> w = bin_cat u n v" |
563 |
by (induct n arbitrary: v w) (auto simp: Let_def split: ls_splits) |
|
24364 | 564 |
|
565 |
lemma bin_split_cat: |
|
45955 | 566 |
"bin_split n (bin_cat v n w) = (v, bintrunc n w)" |
567 |
by (induct n arbitrary: w) auto |
|
24364 | 568 |
|
45956 | 569 |
lemma bin_split_zero [simp]: "bin_split n 0 = (0, 0)" |
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45956
diff
changeset
|
570 |
by (induct n) auto |
45956 | 571 |
|
24364 | 572 |
lemma bin_split_Pls [simp]: |
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
573 |
"bin_split n Int.Pls = (Int.Pls, Int.Pls)" |
45956 | 574 |
unfolding Pls_def by (rule bin_split_zero) |
24364 | 575 |
|
576 |
lemma bin_split_Min [simp]: |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25762
diff
changeset
|
577 |
"bin_split n Int.Min = (Int.Min, bintrunc n Int.Min)" |
24364 | 578 |
by (induct n) (auto simp: Let_def split: ls_splits) |
579 |
||
580 |
lemma bin_split_trunc: |
|
45955 | 581 |
"bin_split (min m n) c = (a, b) ==> |
24364 | 582 |
bin_split n (bintrunc m c) = (bintrunc (m - n) a, b)" |
45955 | 583 |
apply (induct n arbitrary: m b c, clarsimp) |
24364 | 584 |
apply (simp add: bin_rest_trunc Let_def split: ls_splits) |
585 |
apply (case_tac m) |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45956
diff
changeset
|
586 |
apply (auto simp: Let_def split: ls_splits) |
24333 | 587 |
done |
588 |
||
24364 | 589 |
lemma bin_split_trunc1: |
45955 | 590 |
"bin_split n c = (a, b) ==> |
24364 | 591 |
bin_split n (bintrunc m c) = (bintrunc (m - n) a, bintrunc m b)" |
45955 | 592 |
apply (induct n arbitrary: m b c, clarsimp) |
24364 | 593 |
apply (simp add: bin_rest_trunc Let_def split: ls_splits) |
594 |
apply (case_tac m) |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45956
diff
changeset
|
595 |
apply (auto simp: Let_def split: ls_splits) |
24364 | 596 |
done |
24333 | 597 |
|
24364 | 598 |
lemma bin_cat_num: |
45955 | 599 |
"bin_cat a n b = a * 2 ^ n + bintrunc n b" |
600 |
apply (induct n arbitrary: b, clarsimp) |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45956
diff
changeset
|
601 |
apply (simp add: Bit_def) |
24364 | 602 |
done |
603 |
||
604 |
lemma bin_split_num: |
|
45955 | 605 |
"bin_split n b = (b div 2 ^ n, b mod 2 ^ n)" |
606 |
apply (induct n arbitrary: b, simp add: Pls_def) |
|
45529
0e1037d4e049
remove redundant lemmas bin_last_mod and bin_rest_div, use bin_last_def and bin_rest_def instead
huffman
parents:
45475
diff
changeset
|
607 |
apply (simp add: bin_rest_def zdiv_zmult2_eq) |
24364 | 608 |
apply (case_tac b rule: bin_exhaust) |
609 |
apply simp |
|
37667 | 610 |
apply (simp add: Bit_def mod_mult_mult1 p1mod22k bitval_def |
45955 | 611 |
split: bit.split) |
612 |
done |
|
24364 | 613 |
|
614 |
subsection {* Miscellaneous lemmas *} |
|
24333 | 615 |
|
616 |
lemma nth_2p_bin: |
|
45955 | 617 |
"bin_nth (2 ^ n) m = (m = n)" |
618 |
apply (induct n arbitrary: m) |
|
24333 | 619 |
apply clarsimp |
620 |
apply safe |
|
621 |
apply (case_tac m) |
|
622 |
apply (auto simp: trans [OF numeral_1_eq_1 [symmetric] number_of_eq]) |
|
623 |
apply (case_tac m) |
|
624 |
apply (auto simp: Bit_B0_2t [symmetric]) |
|
625 |
done |
|
626 |
||
627 |
(* for use when simplifying with bin_nth_Bit *) |
|
628 |
||
629 |
lemma ex_eq_or: |
|
630 |
"(EX m. n = Suc m & (m = k | P m)) = (n = Suc k | (EX m. n = Suc m & P m))" |
|
631 |
by auto |
|
632 |
||
633 |
end |
|
634 |