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