author | haftmann |
Thu, 18 Apr 2019 06:06:54 +0000 | |
changeset 70183 | 3ea80c950023 |
parent 70175 | 85fb1a585f52 |
child 70190 | ff9efdc84289 |
permissions | -rw-r--r-- |
65363 | 1 |
(* Title: HOL/Word/Bits_Int.thy |
2 |
Author: Jeremy Dawson and Gerwin Klein, NICTA |
|
24333 | 3 |
|
65363 | 4 |
Definitions and basic theorems for bit-wise logical operations |
5 |
for integers expressed using Pls, Min, BIT, |
|
6 |
and converting them to and from lists of bools. |
|
7 |
*) |
|
24333 | 8 |
|
61799 | 9 |
section \<open>Bitwise Operations on Binary Integers\<close> |
24350 | 10 |
|
54854
3324a0078636
prefer "Bits" as theory name for abstract bit operations, similar to "Orderings", "Lattices", "Groups" etc.
haftmann
parents:
54848
diff
changeset
|
11 |
theory Bits_Int |
70169 | 12 |
imports Bits Bit_Representation Bool_List_Representation |
24333 | 13 |
begin |
14 |
||
61799 | 15 |
subsection \<open>Logical operations\<close> |
24353 | 16 |
|
17 |
text "bit-wise logical operations on the int type" |
|
18 |
||
25762 | 19 |
instantiation int :: bit |
20 |
begin |
|
21 |
||
65363 | 22 |
definition int_not_def: "bitNOT = (\<lambda>x::int. - x - 1)" |
46019 | 23 |
|
65363 | 24 |
function bitAND_int |
25 |
where "bitAND_int x y = |
|
26 |
(if x = 0 then 0 else if x = -1 then y |
|
27 |
else (bin_rest x AND bin_rest y) BIT (bin_last x \<and> bin_last y))" |
|
46019 | 28 |
by pat_completeness simp |
25762 | 29 |
|
46019 | 30 |
termination |
65363 | 31 |
by (relation "measure (nat \<circ> abs \<circ> fst)", simp_all add: bin_rest_def) |
46019 | 32 |
|
33 |
declare bitAND_int.simps [simp del] |
|
25762 | 34 |
|
67120 | 35 |
definition int_or_def: "bitOR = (\<lambda>x y::int. NOT (NOT x AND NOT y))" |
25762 | 36 |
|
67120 | 37 |
definition int_xor_def: "bitXOR = (\<lambda>x y::int. (x AND NOT y) OR (NOT x AND y))" |
25762 | 38 |
|
39 |
instance .. |
|
40 |
||
41 |
end |
|
24353 | 42 |
|
61799 | 43 |
subsubsection \<open>Basic simplification rules\<close> |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
44 |
|
67120 | 45 |
lemma int_not_BIT [simp]: "NOT (w BIT b) = (NOT w) BIT (\<not> b)" |
46 |
by (cases b) (simp_all add: int_not_def Bit_def) |
|
46016 | 47 |
|
24333 | 48 |
lemma int_not_simps [simp]: |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
49 |
"NOT (0::int) = -1" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
50 |
"NOT (1::int) = -2" |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
51 |
"NOT (- 1::int) = 0" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
52 |
"NOT (numeral w::int) = - numeral (w + Num.One)" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
53 |
"NOT (- numeral (Num.Bit0 w)::int) = numeral (Num.BitM w)" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
54 |
"NOT (- numeral (Num.Bit1 w)::int) = numeral (Num.Bit0 w)" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
55 |
unfolding int_not_def by simp_all |
24333 | 56 |
|
67120 | 57 |
lemma int_not_not [simp]: "NOT (NOT x) = x" |
58 |
for x :: int |
|
46017 | 59 |
unfolding int_not_def by simp |
60 |
||
67120 | 61 |
lemma int_and_0 [simp]: "0 AND x = 0" |
62 |
for x :: int |
|
46019 | 63 |
by (simp add: bitAND_int.simps) |
64 |
||
67120 | 65 |
lemma int_and_m1 [simp]: "-1 AND x = x" |
66 |
for x :: int |
|
46019 | 67 |
by (simp add: bitAND_int.simps) |
68 |
||
67120 | 69 |
lemma int_and_Bits [simp]: "(x BIT b) AND (y BIT c) = (x AND y) BIT (b \<and> c)" |
70 |
by (subst bitAND_int.simps) (simp add: Bit_eq_0_iff Bit_eq_m1_iff) |
|
46017 | 71 |
|
67120 | 72 |
lemma int_or_zero [simp]: "0 OR x = x" |
73 |
for x :: int |
|
74 |
by (simp add: int_or_def) |
|
46018 | 75 |
|
67120 | 76 |
lemma int_or_minus1 [simp]: "-1 OR x = -1" |
77 |
for x :: int |
|
78 |
by (simp add: int_or_def) |
|
46017 | 79 |
|
67120 | 80 |
lemma int_or_Bits [simp]: "(x BIT b) OR (y BIT c) = (x OR y) BIT (b \<or> c)" |
81 |
by (simp add: int_or_def) |
|
24333 | 82 |
|
67120 | 83 |
lemma int_xor_zero [simp]: "0 XOR x = x" |
84 |
for x :: int |
|
85 |
by (simp add: int_xor_def) |
|
46018 | 86 |
|
67120 | 87 |
lemma int_xor_Bits [simp]: "(x BIT b) XOR (y BIT c) = (x XOR y) BIT ((b \<or> c) \<and> \<not> (b \<and> c))" |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
88 |
unfolding int_xor_def by auto |
46018 | 89 |
|
67120 | 90 |
|
61799 | 91 |
subsubsection \<open>Binary destructors\<close> |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
92 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
93 |
lemma bin_rest_NOT [simp]: "bin_rest (NOT x) = NOT (bin_rest x)" |
67120 | 94 |
by (cases x rule: bin_exhaust) simp |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
95 |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
96 |
lemma bin_last_NOT [simp]: "bin_last (NOT x) \<longleftrightarrow> \<not> bin_last x" |
67120 | 97 |
by (cases x rule: bin_exhaust) simp |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
98 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
99 |
lemma bin_rest_AND [simp]: "bin_rest (x AND y) = bin_rest x AND bin_rest y" |
67120 | 100 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust) simp |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
101 |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
102 |
lemma bin_last_AND [simp]: "bin_last (x AND y) \<longleftrightarrow> bin_last x \<and> bin_last y" |
67120 | 103 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust) simp |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
104 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
105 |
lemma bin_rest_OR [simp]: "bin_rest (x OR y) = bin_rest x OR bin_rest y" |
67120 | 106 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust) simp |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
107 |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
108 |
lemma bin_last_OR [simp]: "bin_last (x OR y) \<longleftrightarrow> bin_last x \<or> bin_last y" |
67120 | 109 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust) simp |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
110 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
111 |
lemma bin_rest_XOR [simp]: "bin_rest (x XOR y) = bin_rest x XOR bin_rest y" |
67120 | 112 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust) simp |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
113 |
|
67120 | 114 |
lemma bin_last_XOR [simp]: |
115 |
"bin_last (x XOR y) \<longleftrightarrow> (bin_last x \<or> bin_last y) \<and> \<not> (bin_last x \<and> bin_last y)" |
|
116 |
by (cases x rule: bin_exhaust, cases y rule: bin_exhaust) simp |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
117 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
118 |
lemma bin_nth_ops: |
67120 | 119 |
"\<And>x y. bin_nth (x AND y) n \<longleftrightarrow> bin_nth x n \<and> bin_nth y n" |
120 |
"\<And>x y. bin_nth (x OR y) n \<longleftrightarrow> bin_nth x n \<or> bin_nth y n" |
|
121 |
"\<And>x y. bin_nth (x XOR y) n \<longleftrightarrow> bin_nth x n \<noteq> bin_nth y n" |
|
122 |
"\<And>x. bin_nth (NOT x) n \<longleftrightarrow> \<not> bin_nth x n" |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
123 |
by (induct n) auto |
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
124 |
|
67120 | 125 |
|
61799 | 126 |
subsubsection \<open>Derived properties\<close> |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
127 |
|
67120 | 128 |
lemma int_xor_minus1 [simp]: "-1 XOR x = NOT x" |
129 |
for x :: int |
|
46018 | 130 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
131 |
||
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
132 |
lemma int_xor_extra_simps [simp]: |
67120 | 133 |
"w XOR 0 = w" |
134 |
"w XOR -1 = NOT w" |
|
135 |
for w :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
136 |
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
|
137 |
|
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
138 |
lemma int_or_extra_simps [simp]: |
67120 | 139 |
"w OR 0 = w" |
140 |
"w OR -1 = -1" |
|
141 |
for w :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
142 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 143 |
|
37667 | 144 |
lemma int_and_extra_simps [simp]: |
67120 | 145 |
"w AND 0 = 0" |
146 |
"w AND -1 = w" |
|
147 |
for w :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
148 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 149 |
|
67120 | 150 |
text \<open>Commutativity of the above.\<close> |
24333 | 151 |
lemma bin_ops_comm: |
67120 | 152 |
fixes x y :: int |
153 |
shows int_and_comm: "x AND y = y AND x" |
|
154 |
and int_or_comm: "x OR y = y OR x" |
|
155 |
and int_xor_comm: "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
|
156 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 157 |
|
158 |
lemma bin_ops_same [simp]: |
|
67120 | 159 |
"x AND x = x" |
160 |
"x OR x = x" |
|
161 |
"x XOR x = 0" |
|
162 |
for x :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
163 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 164 |
|
65363 | 165 |
lemmas bin_log_esimps = |
24333 | 166 |
int_and_extra_simps int_or_extra_simps int_xor_extra_simps |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
167 |
int_and_0 int_and_m1 int_or_zero int_or_minus1 int_xor_zero int_xor_minus1 |
24333 | 168 |
|
67120 | 169 |
|
170 |
subsubsection \<open>Basic properties of logical (bit-wise) operations\<close> |
|
24333 | 171 |
|
67120 | 172 |
lemma bbw_ao_absorb: "x AND (y OR x) = x \<and> x OR (y AND x) = x" |
173 |
for x y :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
174 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 175 |
|
176 |
lemma bbw_ao_absorbs_other: |
|
67120 | 177 |
"x AND (x OR y) = x \<and> (y AND x) OR x = x" |
178 |
"(y OR x) AND x = x \<and> x OR (x AND y) = x" |
|
179 |
"(x OR y) AND x = x \<and> (x AND y) OR x = x" |
|
180 |
for x y :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
181 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24353 | 182 |
|
24333 | 183 |
lemmas bbw_ao_absorbs [simp] = bbw_ao_absorb bbw_ao_absorbs_other |
184 |
||
67120 | 185 |
lemma int_xor_not: "(NOT x) XOR y = NOT (x XOR y) \<and> x XOR (NOT y) = NOT (x XOR y)" |
186 |
for x y :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
187 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 188 |
|
67120 | 189 |
lemma int_and_assoc: "(x AND y) AND z = x AND (y AND z)" |
190 |
for x y z :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
191 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 192 |
|
67120 | 193 |
lemma int_or_assoc: "(x OR y) OR z = x OR (y OR z)" |
194 |
for x y z :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
195 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 196 |
|
67120 | 197 |
lemma int_xor_assoc: "(x XOR y) XOR z = x XOR (y XOR z)" |
198 |
for x y z :: int |
|
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 bbw_assocs = int_and_assoc int_or_assoc int_xor_assoc |
|
202 |
||
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
203 |
(* BH: Why are these declared as simp rules??? *) |
65363 | 204 |
lemma bbw_lcs [simp]: |
67120 | 205 |
"y AND (x AND z) = x AND (y AND z)" |
206 |
"y OR (x OR z) = x OR (y OR z)" |
|
207 |
"y XOR (x XOR z) = x XOR (y XOR z)" |
|
208 |
for x y :: int |
|
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 |
|
65363 | 211 |
lemma bbw_not_dist: |
67120 | 212 |
"NOT (x OR y) = (NOT x) AND (NOT y)" |
213 |
"NOT (x AND y) = (NOT x) OR (NOT y)" |
|
214 |
for x y :: 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) |
24333 | 216 |
|
67120 | 217 |
lemma bbw_oa_dist: "(x AND y) OR z = (x OR z) AND (y OR z)" |
218 |
for x y z :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
219 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 220 |
|
67120 | 221 |
lemma bbw_ao_dist: "(x OR y) AND z = (x AND z) OR (y AND z)" |
222 |
for x y z :: int |
|
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
223 |
by (auto simp add: bin_eq_iff bin_nth_ops) |
24333 | 224 |
|
24367
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
huffman
parents:
24366
diff
changeset
|
225 |
(* |
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
huffman
parents:
24366
diff
changeset
|
226 |
Why were these declared simp??? |
65363 | 227 |
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
|
228 |
*) |
24333 | 229 |
|
67120 | 230 |
|
61799 | 231 |
subsubsection \<open>Simplification with numerals\<close> |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
232 |
|
67120 | 233 |
text \<open>Cases for \<open>0\<close> and \<open>-1\<close> are already covered by other simp rules.\<close> |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
234 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
235 |
lemma bin_rl_eqI: "\<lbrakk>bin_rest x = bin_rest y; bin_last x = bin_last y\<rbrakk> \<Longrightarrow> x = y" |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
236 |
by (metis (mono_tags) BIT_eq_iff bin_ex_rl bin_last_BIT bin_rest_BIT) |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
237 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
238 |
lemma bin_rest_neg_numeral_BitM [simp]: |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
239 |
"bin_rest (- numeral (Num.BitM w)) = - numeral w" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
240 |
by (simp only: BIT_bin_simps [symmetric] bin_rest_BIT) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
241 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
242 |
lemma bin_last_neg_numeral_BitM [simp]: |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
243 |
"bin_last (- numeral (Num.BitM w))" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
244 |
by (simp only: BIT_bin_simps [symmetric] bin_last_BIT) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
245 |
|
67120 | 246 |
(* FIXME: The rule sets below are very large (24 rules for each |
247 |
operator). Is there a simpler way to do this? *) |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
248 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
249 |
lemma int_and_numerals [simp]: |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
250 |
"numeral (Num.Bit0 x) AND numeral (Num.Bit0 y) = (numeral x AND numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
251 |
"numeral (Num.Bit0 x) AND numeral (Num.Bit1 y) = (numeral x AND numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
252 |
"numeral (Num.Bit1 x) AND numeral (Num.Bit0 y) = (numeral x AND numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
253 |
"numeral (Num.Bit1 x) AND numeral (Num.Bit1 y) = (numeral x AND numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
254 |
"numeral (Num.Bit0 x) AND - numeral (Num.Bit0 y) = (numeral x AND - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
255 |
"numeral (Num.Bit0 x) AND - numeral (Num.Bit1 y) = (numeral x AND - numeral (y + Num.One)) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
256 |
"numeral (Num.Bit1 x) AND - numeral (Num.Bit0 y) = (numeral x AND - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
257 |
"numeral (Num.Bit1 x) AND - numeral (Num.Bit1 y) = (numeral x AND - numeral (y + Num.One)) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
258 |
"- numeral (Num.Bit0 x) AND numeral (Num.Bit0 y) = (- numeral x AND numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
259 |
"- numeral (Num.Bit0 x) AND numeral (Num.Bit1 y) = (- numeral x AND numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
260 |
"- numeral (Num.Bit1 x) AND numeral (Num.Bit0 y) = (- numeral (x + Num.One) AND numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
261 |
"- numeral (Num.Bit1 x) AND numeral (Num.Bit1 y) = (- numeral (x + Num.One) AND numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
262 |
"- numeral (Num.Bit0 x) AND - numeral (Num.Bit0 y) = (- numeral x AND - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
263 |
"- numeral (Num.Bit0 x) AND - numeral (Num.Bit1 y) = (- numeral x AND - numeral (y + Num.One)) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
264 |
"- numeral (Num.Bit1 x) AND - numeral (Num.Bit0 y) = (- numeral (x + Num.One) AND - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
265 |
"- numeral (Num.Bit1 x) AND - numeral (Num.Bit1 y) = (- numeral (x + Num.One) AND - numeral (y + Num.One)) BIT True" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
266 |
"(1::int) AND numeral (Num.Bit0 y) = 0" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
267 |
"(1::int) AND numeral (Num.Bit1 y) = 1" |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
268 |
"(1::int) AND - numeral (Num.Bit0 y) = 0" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
269 |
"(1::int) AND - numeral (Num.Bit1 y) = 1" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
270 |
"numeral (Num.Bit0 x) AND (1::int) = 0" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
271 |
"numeral (Num.Bit1 x) AND (1::int) = 1" |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
272 |
"- numeral (Num.Bit0 x) AND (1::int) = 0" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
273 |
"- numeral (Num.Bit1 x) AND (1::int) = 1" |
67120 | 274 |
by (rule bin_rl_eqI; simp)+ |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
275 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
276 |
lemma int_or_numerals [simp]: |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
277 |
"numeral (Num.Bit0 x) OR numeral (Num.Bit0 y) = (numeral x OR numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
278 |
"numeral (Num.Bit0 x) OR numeral (Num.Bit1 y) = (numeral x OR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
279 |
"numeral (Num.Bit1 x) OR numeral (Num.Bit0 y) = (numeral x OR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
280 |
"numeral (Num.Bit1 x) OR numeral (Num.Bit1 y) = (numeral x OR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
281 |
"numeral (Num.Bit0 x) OR - numeral (Num.Bit0 y) = (numeral x OR - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
282 |
"numeral (Num.Bit0 x) OR - numeral (Num.Bit1 y) = (numeral x OR - numeral (y + Num.One)) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
283 |
"numeral (Num.Bit1 x) OR - numeral (Num.Bit0 y) = (numeral x OR - numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
284 |
"numeral (Num.Bit1 x) OR - numeral (Num.Bit1 y) = (numeral x OR - numeral (y + Num.One)) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
285 |
"- numeral (Num.Bit0 x) OR numeral (Num.Bit0 y) = (- numeral x OR numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
286 |
"- numeral (Num.Bit0 x) OR numeral (Num.Bit1 y) = (- numeral x OR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
287 |
"- numeral (Num.Bit1 x) OR numeral (Num.Bit0 y) = (- numeral (x + Num.One) OR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
288 |
"- numeral (Num.Bit1 x) OR numeral (Num.Bit1 y) = (- numeral (x + Num.One) OR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
289 |
"- numeral (Num.Bit0 x) OR - numeral (Num.Bit0 y) = (- numeral x OR - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
290 |
"- numeral (Num.Bit0 x) OR - numeral (Num.Bit1 y) = (- numeral x OR - numeral (y + Num.One)) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
291 |
"- numeral (Num.Bit1 x) OR - numeral (Num.Bit0 y) = (- numeral (x + Num.One) OR - numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
292 |
"- numeral (Num.Bit1 x) OR - numeral (Num.Bit1 y) = (- numeral (x + Num.One) OR - numeral (y + Num.One)) BIT True" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
293 |
"(1::int) OR numeral (Num.Bit0 y) = numeral (Num.Bit1 y)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
294 |
"(1::int) OR numeral (Num.Bit1 y) = numeral (Num.Bit1 y)" |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
295 |
"(1::int) OR - numeral (Num.Bit0 y) = - numeral (Num.BitM y)" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
296 |
"(1::int) OR - numeral (Num.Bit1 y) = - numeral (Num.Bit1 y)" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
297 |
"numeral (Num.Bit0 x) OR (1::int) = numeral (Num.Bit1 x)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
298 |
"numeral (Num.Bit1 x) OR (1::int) = numeral (Num.Bit1 x)" |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
299 |
"- numeral (Num.Bit0 x) OR (1::int) = - numeral (Num.BitM x)" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
300 |
"- numeral (Num.Bit1 x) OR (1::int) = - numeral (Num.Bit1 x)" |
67120 | 301 |
by (rule bin_rl_eqI; simp)+ |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
302 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
303 |
lemma int_xor_numerals [simp]: |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
304 |
"numeral (Num.Bit0 x) XOR numeral (Num.Bit0 y) = (numeral x XOR numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
305 |
"numeral (Num.Bit0 x) XOR numeral (Num.Bit1 y) = (numeral x XOR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
306 |
"numeral (Num.Bit1 x) XOR numeral (Num.Bit0 y) = (numeral x XOR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
307 |
"numeral (Num.Bit1 x) XOR numeral (Num.Bit1 y) = (numeral x XOR numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
308 |
"numeral (Num.Bit0 x) XOR - numeral (Num.Bit0 y) = (numeral x XOR - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
309 |
"numeral (Num.Bit0 x) XOR - numeral (Num.Bit1 y) = (numeral x XOR - numeral (y + Num.One)) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
310 |
"numeral (Num.Bit1 x) XOR - numeral (Num.Bit0 y) = (numeral x XOR - numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
311 |
"numeral (Num.Bit1 x) XOR - numeral (Num.Bit1 y) = (numeral x XOR - numeral (y + Num.One)) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
312 |
"- numeral (Num.Bit0 x) XOR numeral (Num.Bit0 y) = (- numeral x XOR numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
313 |
"- numeral (Num.Bit0 x) XOR numeral (Num.Bit1 y) = (- numeral x XOR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
314 |
"- numeral (Num.Bit1 x) XOR numeral (Num.Bit0 y) = (- numeral (x + Num.One) XOR numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
315 |
"- numeral (Num.Bit1 x) XOR numeral (Num.Bit1 y) = (- numeral (x + Num.One) XOR numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
316 |
"- numeral (Num.Bit0 x) XOR - numeral (Num.Bit0 y) = (- numeral x XOR - numeral y) BIT False" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
317 |
"- numeral (Num.Bit0 x) XOR - numeral (Num.Bit1 y) = (- numeral x XOR - numeral (y + Num.One)) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
318 |
"- numeral (Num.Bit1 x) XOR - numeral (Num.Bit0 y) = (- numeral (x + Num.One) XOR - numeral y) BIT True" |
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
319 |
"- numeral (Num.Bit1 x) XOR - numeral (Num.Bit1 y) = (- numeral (x + Num.One) XOR - numeral (y + Num.One)) BIT False" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
320 |
"(1::int) XOR numeral (Num.Bit0 y) = numeral (Num.Bit1 y)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
321 |
"(1::int) XOR numeral (Num.Bit1 y) = numeral (Num.Bit0 y)" |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
322 |
"(1::int) XOR - numeral (Num.Bit0 y) = - numeral (Num.BitM y)" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
323 |
"(1::int) XOR - numeral (Num.Bit1 y) = - numeral (Num.Bit0 (y + Num.One))" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
324 |
"numeral (Num.Bit0 x) XOR (1::int) = numeral (Num.Bit1 x)" |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
325 |
"numeral (Num.Bit1 x) XOR (1::int) = numeral (Num.Bit0 x)" |
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
326 |
"- numeral (Num.Bit0 x) XOR (1::int) = - numeral (Num.BitM x)" |
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54427
diff
changeset
|
327 |
"- numeral (Num.Bit1 x) XOR (1::int) = - numeral (Num.Bit0 (x + Num.One))" |
67120 | 328 |
by (rule bin_rl_eqI; simp)+ |
329 |
||
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
330 |
|
61799 | 331 |
subsubsection \<open>Interactions with arithmetic\<close> |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
332 |
|
67120 | 333 |
lemma plus_and_or [rule_format]: "\<forall>y::int. (x AND y) + (x OR y) = x + y" |
24333 | 334 |
apply (induct x rule: bin_induct) |
335 |
apply clarsimp |
|
336 |
apply clarsimp |
|
337 |
apply clarsimp |
|
338 |
apply (case_tac y rule: bin_exhaust) |
|
339 |
apply clarsimp |
|
340 |
apply (unfold Bit_def) |
|
341 |
apply clarsimp |
|
342 |
apply (erule_tac x = "x" in allE) |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
343 |
apply simp |
24333 | 344 |
done |
345 |
||
67120 | 346 |
lemma le_int_or: "bin_sign y = 0 \<Longrightarrow> x \<le> x OR y" |
347 |
for x y :: int |
|
37667 | 348 |
apply (induct y arbitrary: x rule: bin_induct) |
24333 | 349 |
apply clarsimp |
350 |
apply clarsimp |
|
351 |
apply (case_tac x rule: bin_exhaust) |
|
352 |
apply (case_tac b) |
|
353 |
apply (case_tac [!] bit) |
|
46604
9f9e85264e4d
make uses of bin_sign respect int/bin distinction
huffman
parents:
46023
diff
changeset
|
354 |
apply (auto simp: le_Bits) |
24333 | 355 |
done |
356 |
||
357 |
lemmas int_and_le = |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
358 |
xtrans(3) [OF bbw_ao_absorbs (2) [THEN conjunct2, symmetric] le_int_or] |
24333 | 359 |
|
67120 | 360 |
text \<open>Interaction between bit-wise and arithmetic: good example of \<open>bin_induction\<close>.\<close> |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
361 |
lemma bin_add_not: "x + NOT x = (-1::int)" |
24364 | 362 |
apply (induct x rule: bin_induct) |
363 |
apply clarsimp |
|
364 |
apply clarsimp |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
365 |
apply (case_tac bit, auto) |
24364 | 366 |
done |
367 |
||
70169 | 368 |
lemma mod_BIT: "bin BIT bit mod 2 ^ Suc n = (bin mod 2 ^ n) BIT bit" |
369 |
proof - |
|
370 |
have "2 * (bin mod 2 ^ n) + 1 = (2 * bin mod 2 ^ Suc n) + 1" |
|
371 |
by (simp add: mod_mult_mult1) |
|
372 |
also have "\<dots> = ((2 * bin mod 2 ^ Suc n) + 1) mod 2 ^ Suc n" |
|
70170 | 373 |
by (simp add: ac_simps pos_zmod_mult_2) |
70169 | 374 |
also have "\<dots> = (2 * bin + 1) mod 2 ^ Suc n" |
375 |
by (simp only: mod_simps) |
|
376 |
finally show ?thesis |
|
377 |
by (auto simp add: Bit_def) |
|
378 |
qed |
|
379 |
||
380 |
lemma AND_mod: "x AND 2 ^ n - 1 = x mod 2 ^ n" |
|
381 |
for x :: int |
|
382 |
proof (induct x arbitrary: n rule: bin_induct) |
|
383 |
case 1 |
|
384 |
then show ?case |
|
385 |
by simp |
|
386 |
next |
|
387 |
case 2 |
|
388 |
then show ?case |
|
389 |
by (simp, simp add: m1mod2k) |
|
390 |
next |
|
391 |
case (3 bin bit) |
|
392 |
show ?case |
|
393 |
proof (cases n) |
|
394 |
case 0 |
|
395 |
then show ?thesis by simp |
|
396 |
next |
|
397 |
case (Suc m) |
|
398 |
with 3 show ?thesis |
|
399 |
by (simp only: power_BIT mod_BIT int_and_Bits) simp |
|
400 |
qed |
|
401 |
qed |
|
402 |
||
67120 | 403 |
|
70172 | 404 |
subsubsection \<open>Comparison\<close> |
405 |
||
406 |
lemma AND_lower [simp]: \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
407 |
fixes x y :: int |
|
408 |
assumes "0 \<le> x" |
|
409 |
shows "0 \<le> x AND y" |
|
410 |
using assms |
|
411 |
proof (induct x arbitrary: y rule: bin_induct) |
|
412 |
case 1 |
|
413 |
then show ?case by simp |
|
414 |
next |
|
415 |
case 2 |
|
416 |
then show ?case by (simp only: Min_def) |
|
417 |
next |
|
418 |
case (3 bin bit) |
|
419 |
show ?case |
|
420 |
proof (cases y rule: bin_exhaust) |
|
421 |
case (1 bin' bit') |
|
422 |
from 3 have "0 \<le> bin" |
|
423 |
by (cases bit) (simp_all add: Bit_def) |
|
424 |
then have "0 \<le> bin AND bin'" by (rule 3) |
|
425 |
with 1 show ?thesis |
|
426 |
by simp (simp add: Bit_def) |
|
427 |
qed |
|
428 |
qed |
|
429 |
||
430 |
lemma OR_lower [simp]: \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
431 |
fixes x y :: int |
|
432 |
assumes "0 \<le> x" "0 \<le> y" |
|
433 |
shows "0 \<le> x OR y" |
|
434 |
using assms |
|
435 |
proof (induct x arbitrary: y rule: bin_induct) |
|
436 |
case (3 bin bit) |
|
437 |
show ?case |
|
438 |
proof (cases y rule: bin_exhaust) |
|
439 |
case (1 bin' bit') |
|
440 |
from 3 have "0 \<le> bin" |
|
441 |
by (cases bit) (simp_all add: Bit_def) |
|
442 |
moreover from 1 3 have "0 \<le> bin'" |
|
443 |
by (cases bit') (simp_all add: Bit_def) |
|
444 |
ultimately have "0 \<le> bin OR bin'" by (rule 3) |
|
445 |
with 1 show ?thesis |
|
446 |
by simp (simp add: Bit_def) |
|
447 |
qed |
|
448 |
qed simp_all |
|
449 |
||
450 |
lemma XOR_lower [simp]: \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
451 |
fixes x y :: int |
|
452 |
assumes "0 \<le> x" "0 \<le> y" |
|
453 |
shows "0 \<le> x XOR y" |
|
454 |
using assms |
|
455 |
proof (induct x arbitrary: y rule: bin_induct) |
|
456 |
case (3 bin bit) |
|
457 |
show ?case |
|
458 |
proof (cases y rule: bin_exhaust) |
|
459 |
case (1 bin' bit') |
|
460 |
from 3 have "0 \<le> bin" |
|
461 |
by (cases bit) (simp_all add: Bit_def) |
|
462 |
moreover from 1 3 have "0 \<le> bin'" |
|
463 |
by (cases bit') (simp_all add: Bit_def) |
|
464 |
ultimately have "0 \<le> bin XOR bin'" by (rule 3) |
|
465 |
with 1 show ?thesis |
|
466 |
by simp (simp add: Bit_def) |
|
467 |
qed |
|
468 |
next |
|
469 |
case 2 |
|
470 |
then show ?case by (simp only: Min_def) |
|
471 |
qed simp |
|
472 |
||
473 |
lemma AND_upper1 [simp]: \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
474 |
fixes x y :: int |
|
475 |
assumes "0 \<le> x" |
|
476 |
shows "x AND y \<le> x" |
|
477 |
using assms |
|
478 |
proof (induct x arbitrary: y rule: bin_induct) |
|
479 |
case (3 bin bit) |
|
480 |
show ?case |
|
481 |
proof (cases y rule: bin_exhaust) |
|
482 |
case (1 bin' bit') |
|
483 |
from 3 have "0 \<le> bin" |
|
484 |
by (cases bit) (simp_all add: Bit_def) |
|
485 |
then have "bin AND bin' \<le> bin" by (rule 3) |
|
486 |
with 1 show ?thesis |
|
487 |
by simp (simp add: Bit_def) |
|
488 |
qed |
|
489 |
next |
|
490 |
case 2 |
|
491 |
then show ?case by (simp only: Min_def) |
|
492 |
qed simp |
|
493 |
||
494 |
lemmas AND_upper1' [simp] = order_trans [OF AND_upper1] \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
495 |
lemmas AND_upper1'' [simp] = order_le_less_trans [OF AND_upper1] \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
496 |
||
497 |
lemma AND_upper2 [simp]: \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
498 |
fixes x y :: int |
|
499 |
assumes "0 \<le> y" |
|
500 |
shows "x AND y \<le> y" |
|
501 |
using assms |
|
502 |
proof (induct y arbitrary: x rule: bin_induct) |
|
503 |
case 1 |
|
504 |
then show ?case by simp |
|
505 |
next |
|
506 |
case 2 |
|
507 |
then show ?case by (simp only: Min_def) |
|
508 |
next |
|
509 |
case (3 bin bit) |
|
510 |
show ?case |
|
511 |
proof (cases x rule: bin_exhaust) |
|
512 |
case (1 bin' bit') |
|
513 |
from 3 have "0 \<le> bin" |
|
514 |
by (cases bit) (simp_all add: Bit_def) |
|
515 |
then have "bin' AND bin \<le> bin" by (rule 3) |
|
516 |
with 1 show ?thesis |
|
517 |
by simp (simp add: Bit_def) |
|
518 |
qed |
|
519 |
qed |
|
520 |
||
521 |
lemmas AND_upper2' [simp] = order_trans [OF AND_upper2] \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
522 |
lemmas AND_upper2'' [simp] = order_le_less_trans [OF AND_upper2] \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
523 |
||
524 |
lemma OR_upper: \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
525 |
fixes x y :: int |
|
526 |
assumes "0 \<le> x" "x < 2 ^ n" "y < 2 ^ n" |
|
527 |
shows "x OR y < 2 ^ n" |
|
528 |
using assms |
|
529 |
proof (induct x arbitrary: y n rule: bin_induct) |
|
530 |
case (3 bin bit) |
|
531 |
show ?case |
|
532 |
proof (cases y rule: bin_exhaust) |
|
533 |
case (1 bin' bit') |
|
534 |
show ?thesis |
|
535 |
proof (cases n) |
|
536 |
case 0 |
|
537 |
with 3 have "bin BIT bit = 0" by simp |
|
538 |
then have "bin = 0" and "\<not> bit" |
|
539 |
by (auto simp add: Bit_def split: if_splits) arith |
|
540 |
then show ?thesis using 0 1 \<open>y < 2 ^ n\<close> |
|
541 |
by simp |
|
542 |
next |
|
543 |
case (Suc m) |
|
544 |
from 3 have "0 \<le> bin" |
|
545 |
by (cases bit) (simp_all add: Bit_def) |
|
546 |
moreover from 3 Suc have "bin < 2 ^ m" |
|
547 |
by (cases bit) (simp_all add: Bit_def) |
|
548 |
moreover from 1 3 Suc have "bin' < 2 ^ m" |
|
549 |
by (cases bit') (simp_all add: Bit_def) |
|
550 |
ultimately have "bin OR bin' < 2 ^ m" by (rule 3) |
|
551 |
with 1 Suc show ?thesis |
|
552 |
by simp (simp add: Bit_def) |
|
553 |
qed |
|
554 |
qed |
|
555 |
qed simp_all |
|
556 |
||
557 |
lemma XOR_upper: \<^marker>\<open>contributor \<open>Stefan Berghofer\<close>\<close> |
|
558 |
fixes x y :: int |
|
559 |
assumes "0 \<le> x" "x < 2 ^ n" "y < 2 ^ n" |
|
560 |
shows "x XOR y < 2 ^ n" |
|
561 |
using assms |
|
562 |
proof (induct x arbitrary: y n rule: bin_induct) |
|
563 |
case 1 |
|
564 |
then show ?case by simp |
|
565 |
next |
|
566 |
case 2 |
|
567 |
then show ?case by (simp only: Min_def) |
|
568 |
next |
|
569 |
case (3 bin bit) |
|
570 |
show ?case |
|
571 |
proof (cases y rule: bin_exhaust) |
|
572 |
case (1 bin' bit') |
|
573 |
show ?thesis |
|
574 |
proof (cases n) |
|
575 |
case 0 |
|
576 |
with 3 have "bin BIT bit = 0" by simp |
|
577 |
then have "bin = 0" and "\<not> bit" |
|
578 |
by (auto simp add: Bit_def split: if_splits) arith |
|
579 |
then show ?thesis using 0 1 \<open>y < 2 ^ n\<close> |
|
580 |
by simp |
|
581 |
next |
|
582 |
case (Suc m) |
|
583 |
from 3 have "0 \<le> bin" |
|
584 |
by (cases bit) (simp_all add: Bit_def) |
|
585 |
moreover from 3 Suc have "bin < 2 ^ m" |
|
586 |
by (cases bit) (simp_all add: Bit_def) |
|
587 |
moreover from 1 3 Suc have "bin' < 2 ^ m" |
|
588 |
by (cases bit') (simp_all add: Bit_def) |
|
589 |
ultimately have "bin XOR bin' < 2 ^ m" by (rule 3) |
|
590 |
with 1 Suc show ?thesis |
|
591 |
by simp (simp add: Bit_def) |
|
592 |
qed |
|
593 |
qed |
|
594 |
qed |
|
595 |
||
596 |
||
597 |
||
61799 | 598 |
subsubsection \<open>Truncating results of bit-wise operations\<close> |
45543
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
huffman
parents:
45529
diff
changeset
|
599 |
|
65363 | 600 |
lemma bin_trunc_ao: |
67120 | 601 |
"bintrunc n x AND bintrunc n y = bintrunc n (x AND y)" |
602 |
"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
|
603 |
by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) |
24364 | 604 |
|
67120 | 605 |
lemma bin_trunc_xor: "bintrunc n (bintrunc n x XOR bintrunc n y) = 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
|
606 |
by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) |
24364 | 607 |
|
67120 | 608 |
lemma bin_trunc_not: "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
|
609 |
by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) |
24364 | 610 |
|
67120 | 611 |
text \<open>Want theorems of the form of \<open>bin_trunc_xor\<close>.\<close> |
612 |
lemma bintr_bintr_i: "x = bintrunc n y \<Longrightarrow> bintrunc n x = bintrunc n y" |
|
24364 | 613 |
by auto |
614 |
||
615 |
lemmas bin_trunc_and = bin_trunc_ao(1) [THEN bintr_bintr_i] |
|
616 |
lemmas bin_trunc_or = bin_trunc_ao(2) [THEN bintr_bintr_i] |
|
617 |
||
70169 | 618 |
lemma bl_xor_aux_bin: |
619 |
"map2 (\<lambda>x y. x \<noteq> y) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = |
|
620 |
bin_to_bl_aux n (v XOR w) (map2 (\<lambda>x y. x \<noteq> y) bs cs)" |
|
621 |
apply (induct n arbitrary: v w bs cs) |
|
622 |
apply simp |
|
623 |
apply (case_tac v rule: bin_exhaust) |
|
624 |
apply (case_tac w rule: bin_exhaust) |
|
625 |
apply clarsimp |
|
626 |
apply (case_tac b) |
|
627 |
apply auto |
|
628 |
done |
|
629 |
||
630 |
lemma bl_or_aux_bin: |
|
631 |
"map2 (\<or>) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = |
|
632 |
bin_to_bl_aux n (v OR w) (map2 (\<or>) bs cs)" |
|
633 |
apply (induct n arbitrary: v w bs cs) |
|
634 |
apply simp |
|
635 |
apply (case_tac v rule: bin_exhaust) |
|
636 |
apply (case_tac w rule: bin_exhaust) |
|
637 |
apply clarsimp |
|
638 |
done |
|
639 |
||
640 |
lemma bl_and_aux_bin: |
|
641 |
"map2 (\<and>) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = |
|
642 |
bin_to_bl_aux n (v AND w) (map2 (\<and>) bs cs)" |
|
643 |
apply (induct n arbitrary: v w bs cs) |
|
644 |
apply simp |
|
645 |
apply (case_tac v rule: bin_exhaust) |
|
646 |
apply (case_tac w rule: bin_exhaust) |
|
647 |
apply clarsimp |
|
648 |
done |
|
649 |
||
650 |
lemma bl_not_aux_bin: "map Not (bin_to_bl_aux n w cs) = bin_to_bl_aux n (NOT w) (map Not cs)" |
|
651 |
by (induct n arbitrary: w cs) auto |
|
652 |
||
653 |
lemma bl_not_bin: "map Not (bin_to_bl n w) = bin_to_bl n (NOT w)" |
|
654 |
by (simp add: bin_to_bl_def bl_not_aux_bin) |
|
655 |
||
656 |
lemma bl_and_bin: "map2 (\<and>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v AND w)" |
|
657 |
by (simp add: bin_to_bl_def bl_and_aux_bin) |
|
658 |
||
659 |
lemma bl_or_bin: "map2 (\<or>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v OR w)" |
|
660 |
by (simp add: bin_to_bl_def bl_or_aux_bin) |
|
661 |
||
662 |
lemma bl_xor_bin: "map2 (\<lambda>x y. x \<noteq> y) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v XOR w)" |
|
663 |
by (simp only: bin_to_bl_def bl_xor_aux_bin map2_Nil) |
|
664 |
||
67120 | 665 |
|
61799 | 666 |
subsection \<open>Setting and clearing bits\<close> |
24364 | 667 |
|
67120 | 668 |
text \<open>nth bit, set/clear\<close> |
54874 | 669 |
|
67120 | 670 |
primrec bin_sc :: "nat \<Rightarrow> bool \<Rightarrow> int \<Rightarrow> int" |
671 |
where |
|
672 |
Z: "bin_sc 0 b w = bin_rest w BIT b" |
|
26558 | 673 |
| Suc: "bin_sc (Suc n) b w = bin_sc n b (bin_rest w) BIT bin_last w" |
24364 | 674 |
|
67120 | 675 |
lemma bin_nth_sc [simp]: "bin_nth (bin_sc n b w) n \<longleftrightarrow> b" |
45955 | 676 |
by (induct n arbitrary: w) auto |
24333 | 677 |
|
67120 | 678 |
lemma bin_sc_sc_same [simp]: "bin_sc n c (bin_sc n b w) = bin_sc n c w" |
45955 | 679 |
by (induct n arbitrary: w) auto |
24333 | 680 |
|
67120 | 681 |
lemma bin_sc_sc_diff: "m \<noteq> n \<Longrightarrow> bin_sc m c (bin_sc n b w) = bin_sc n b (bin_sc m c w)" |
45955 | 682 |
apply (induct n arbitrary: w m) |
24333 | 683 |
apply (case_tac [!] m) |
684 |
apply auto |
|
685 |
done |
|
686 |
||
67120 | 687 |
lemma bin_nth_sc_gen: "bin_nth (bin_sc n b w) m = (if m = n then b else bin_nth w m)" |
45955 | 688 |
by (induct n arbitrary: w m) (case_tac [!] m, auto) |
65363 | 689 |
|
67120 | 690 |
lemma bin_sc_nth [simp]: "bin_sc n (bin_nth w n) w = w" |
45955 | 691 |
by (induct n arbitrary: w) auto |
24333 | 692 |
|
67120 | 693 |
lemma bin_sign_sc [simp]: "bin_sign (bin_sc n b w) = bin_sign w" |
45955 | 694 |
by (induct n arbitrary: w) auto |
65363 | 695 |
|
67120 | 696 |
lemma bin_sc_bintr [simp]: "bintrunc m (bin_sc n x (bintrunc m (w))) = bintrunc m (bin_sc n x w)" |
45955 | 697 |
apply (induct n arbitrary: w m) |
24333 | 698 |
apply (case_tac [!] w rule: bin_exhaust) |
699 |
apply (case_tac [!] m, auto) |
|
700 |
done |
|
701 |
||
67120 | 702 |
lemma bin_clr_le: "bin_sc n False w \<le> w" |
45955 | 703 |
apply (induct n arbitrary: w) |
24333 | 704 |
apply (case_tac [!] w rule: bin_exhaust) |
46605 | 705 |
apply (auto simp: le_Bits) |
24333 | 706 |
done |
707 |
||
67120 | 708 |
lemma bin_set_ge: "bin_sc n True w \<ge> w" |
45955 | 709 |
apply (induct n arbitrary: w) |
24333 | 710 |
apply (case_tac [!] w rule: bin_exhaust) |
46605 | 711 |
apply (auto simp: le_Bits) |
24333 | 712 |
done |
713 |
||
67120 | 714 |
lemma bintr_bin_clr_le: "bintrunc n (bin_sc m False w) \<le> bintrunc n w" |
45955 | 715 |
apply (induct n arbitrary: w m) |
24333 | 716 |
apply simp |
717 |
apply (case_tac w rule: bin_exhaust) |
|
718 |
apply (case_tac m) |
|
46605 | 719 |
apply (auto simp: le_Bits) |
24333 | 720 |
done |
721 |
||
67120 | 722 |
lemma bintr_bin_set_ge: "bintrunc n (bin_sc m True w) \<ge> bintrunc n w" |
45955 | 723 |
apply (induct n arbitrary: w m) |
24333 | 724 |
apply simp |
725 |
apply (case_tac w rule: bin_exhaust) |
|
726 |
apply (case_tac m) |
|
46605 | 727 |
apply (auto simp: le_Bits) |
24333 | 728 |
done |
729 |
||
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
54489
diff
changeset
|
730 |
lemma bin_sc_FP [simp]: "bin_sc n False 0 = 0" |
46608
37e383cc7831
make uses of constant bin_sc respect int/bin distinction
huffman
parents:
46605
diff
changeset
|
731 |
by (induct n) auto |
24333 | 732 |
|
58410
6d46ad54a2ab
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents:
54874
diff
changeset
|
733 |
lemma bin_sc_TM [simp]: "bin_sc n True (- 1) = - 1" |
46608
37e383cc7831
make uses of constant bin_sc respect int/bin distinction
huffman
parents:
46605
diff
changeset
|
734 |
by (induct n) auto |
65363 | 735 |
|
24333 | 736 |
lemmas bin_sc_simps = bin_sc.Z bin_sc.Suc bin_sc_TM bin_sc_FP |
737 |
||
67120 | 738 |
lemma bin_sc_minus: "0 < n \<Longrightarrow> bin_sc (Suc (n - 1)) b w = bin_sc n b w" |
24333 | 739 |
by auto |
740 |
||
65363 | 741 |
lemmas bin_sc_Suc_minus = |
45604 | 742 |
trans [OF bin_sc_minus [symmetric] bin_sc.Suc] |
24333 | 743 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
744 |
lemma bin_sc_numeral [simp]: |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46610
diff
changeset
|
745 |
"bin_sc (numeral k) b w = |
47219
172c031ad743
restate various simp rules for word operations using pred_numeral
huffman
parents:
47108
diff
changeset
|
746 |
bin_sc (pred_numeral k) b (bin_rest w) BIT bin_last w" |
172c031ad743
restate various simp rules for word operations using pred_numeral
huffman
parents:
47108
diff
changeset
|
747 |
by (simp add: numeral_eq_Suc) |
24333 | 748 |
|
70175 | 749 |
instantiation int :: bits |
70169 | 750 |
begin |
24333 | 751 |
|
70169 | 752 |
definition [iff]: "i !! n \<longleftrightarrow> bin_nth i n" |
24333 | 753 |
|
70169 | 754 |
definition "lsb i = i !! 0" for i :: int |
65363 | 755 |
|
70169 | 756 |
definition "set_bit i n b = bin_sc n b i" |
24364 | 757 |
|
70169 | 758 |
definition |
759 |
"set_bits f = |
|
760 |
(if \<exists>n. \<forall>n'\<ge>n. \<not> f n' then |
|
761 |
let n = LEAST n. \<forall>n'\<ge>n. \<not> f n' |
|
762 |
in bl_to_bin (rev (map f [0..<n])) |
|
763 |
else if \<exists>n. \<forall>n'\<ge>n. f n' then |
|
764 |
let n = LEAST n. \<forall>n'\<ge>n. f n' |
|
765 |
in sbintrunc n (bl_to_bin (True # rev (map f [0..<n]))) |
|
766 |
else 0 :: int)" |
|
24333 | 767 |
|
70169 | 768 |
definition "shiftl x n = x * 2 ^ n" for x :: int |
24333 | 769 |
|
70169 | 770 |
definition "shiftr x n = x div 2 ^ n" for x :: int |
54427
783861a66a60
separated comparision on bit operations into separate theory
haftmann
parents:
54224
diff
changeset
|
771 |
|
70169 | 772 |
definition "msb x \<longleftrightarrow> x < 0" for x :: int |
54427
783861a66a60
separated comparision on bit operations into separate theory
haftmann
parents:
54224
diff
changeset
|
773 |
|
70169 | 774 |
instance .. |
54427
783861a66a60
separated comparision on bit operations into separate theory
haftmann
parents:
54224
diff
changeset
|
775 |
|
24333 | 776 |
end |
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
777 |
|
70183
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
778 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
779 |
subsection \<open>More lemmas\<close> |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
780 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
781 |
lemma twice_conv_BIT: "2 * x = x BIT False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
782 |
by (rule bin_rl_eqI) (simp_all, simp_all add: bin_rest_def bin_last_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
783 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
784 |
lemma not_int_cmp_0 [simp]: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
785 |
fixes i :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
786 |
"0 < NOT i \<longleftrightarrow> i < -1" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
787 |
"0 \<le> NOT i \<longleftrightarrow> i < 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
788 |
"NOT i < 0 \<longleftrightarrow> i \<ge> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
789 |
"NOT i \<le> 0 \<longleftrightarrow> i \<ge> -1" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
790 |
by(simp_all add: int_not_def) arith+ |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
791 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
792 |
lemma bbw_ao_dist2: "(x :: int) AND (y OR z) = x AND y OR x AND z" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
793 |
by(metis int_and_comm bbw_ao_dist) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
794 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
795 |
lemmas int_and_ac = bbw_lcs(1) int_and_comm int_and_assoc |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
796 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
797 |
lemma int_nand_same [simp]: fixes x :: int shows "x AND NOT x = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
798 |
by(induct x y\<equiv>"NOT x" rule: bitAND_int.induct)(subst bitAND_int.simps, clarsimp) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
799 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
800 |
lemma int_nand_same_middle: fixes x :: int shows "x AND y AND NOT x = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
801 |
by (metis bbw_lcs(1) int_and_0 int_nand_same) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
802 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
803 |
lemma and_xor_dist: fixes x :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
804 |
"x AND (y XOR z) = (x AND y) XOR (x AND z)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
805 |
by(simp add: int_xor_def bbw_ao_dist2 bbw_ao_dist bbw_not_dist int_and_ac int_nand_same_middle) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
806 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
807 |
lemma BIT_lt0 [simp]: "x BIT b < 0 \<longleftrightarrow> x < 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
808 |
by(cases b)(auto simp add: Bit_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
809 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
810 |
lemma BIT_ge0 [simp]: "x BIT b \<ge> 0 \<longleftrightarrow> x \<ge> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
811 |
by(cases b)(auto simp add: Bit_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
812 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
813 |
lemma [simp]: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
814 |
shows bin_rest_lt0: "bin_rest i < 0 \<longleftrightarrow> i < 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
815 |
and bin_rest_ge_0: "bin_rest i \<ge> 0 \<longleftrightarrow> i \<ge> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
816 |
by(auto simp add: bin_rest_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
817 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
818 |
lemma bin_rest_gt_0 [simp]: "bin_rest x > 0 \<longleftrightarrow> x > 1" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
819 |
by(simp add: bin_rest_def add1_zle_eq pos_imp_zdiv_pos_iff) (metis add1_zle_eq one_add_one) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
820 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
821 |
lemma int_and_lt0 [simp]: fixes x y :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
822 |
"x AND y < 0 \<longleftrightarrow> x < 0 \<and> y < 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
823 |
by(induct x y rule: bitAND_int.induct)(subst bitAND_int.simps, simp) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
824 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
825 |
lemma int_and_ge0 [simp]: fixes x y :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
826 |
"x AND y \<ge> 0 \<longleftrightarrow> x \<ge> 0 \<or> y \<ge> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
827 |
by (metis int_and_lt0 linorder_not_less) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
828 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
829 |
lemma int_and_1: fixes x :: int shows "x AND 1 = x mod 2" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
830 |
by(subst bitAND_int.simps)(simp add: Bit_def bin_last_def zmod_minus1) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
831 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
832 |
lemma int_1_and: fixes x :: int shows "1 AND x = x mod 2" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
833 |
by(subst int_and_comm)(simp add: int_and_1) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
834 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
835 |
lemma int_or_lt0 [simp]: fixes x y :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
836 |
"x OR y < 0 \<longleftrightarrow> x < 0 \<or> y < 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
837 |
by(simp add: int_or_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
838 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
839 |
lemma int_xor_lt0 [simp]: fixes x y :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
840 |
"x XOR y < 0 \<longleftrightarrow> ((x < 0) \<noteq> (y < 0))" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
841 |
by(auto simp add: int_xor_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
842 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
843 |
lemma int_xor_ge0 [simp]: fixes x y :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
844 |
"x XOR y \<ge> 0 \<longleftrightarrow> ((x \<ge> 0) \<longleftrightarrow> (y \<ge> 0))" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
845 |
by (metis int_xor_lt0 linorder_not_le) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
846 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
847 |
lemma bin_last_conv_AND: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
848 |
"bin_last i \<longleftrightarrow> i AND 1 \<noteq> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
849 |
proof - |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
850 |
obtain x b where "i = x BIT b" by(cases i rule: bin_exhaust) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
851 |
hence "i AND 1 = 0 BIT b" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
852 |
by(simp add: BIT_special_simps(2)[symmetric] del: BIT_special_simps(2)) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
853 |
thus ?thesis using \<open>i = x BIT b\<close> by(cases b) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
854 |
qed |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
855 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
856 |
lemma bitval_bin_last: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
857 |
"of_bool (bin_last i) = i AND 1" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
858 |
proof - |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
859 |
obtain x b where "i = x BIT b" by(cases i rule: bin_exhaust) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
860 |
hence "i AND 1 = 0 BIT b" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
861 |
by(simp add: BIT_special_simps(2)[symmetric] del: BIT_special_simps(2)) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
862 |
thus ?thesis by(cases b)(simp_all add: bin_last_conv_AND) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
863 |
qed |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
864 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
865 |
lemma bl_to_bin_BIT: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
866 |
"bl_to_bin bs BIT b = bl_to_bin (bs @ [b])" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
867 |
by(simp add: bl_to_bin_append) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
868 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
869 |
lemma bin_last_bl_to_bin: "bin_last (bl_to_bin bs) \<longleftrightarrow> bs \<noteq> [] \<and> last bs" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
870 |
by(cases "bs = []")(auto simp add: bl_to_bin_def last_bin_last'[where w=0]) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
871 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
872 |
lemma bin_rest_bl_to_bin: "bin_rest (bl_to_bin bs) = bl_to_bin (butlast bs)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
873 |
by(cases "bs = []")(simp_all add: bl_to_bin_def butlast_rest_bl2bin_aux) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
874 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
875 |
lemma bin_nth_numeral_unfold: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
876 |
"bin_nth (numeral (num.Bit0 x)) n \<longleftrightarrow> n > 0 \<and> bin_nth (numeral x) (n - 1)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
877 |
"bin_nth (numeral (num.Bit1 x)) n \<longleftrightarrow> (n > 0 \<longrightarrow> bin_nth (numeral x) (n - 1))" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
878 |
by(case_tac [!] n) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
879 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
880 |
lemma bin_sign_and: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
881 |
"bin_sign (i AND j) = - (bin_sign i * bin_sign j)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
882 |
by(simp add: bin_sign_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
883 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
884 |
lemma minus_BIT_0: fixes x y :: int shows "x BIT b - y BIT False = (x - y) BIT b" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
885 |
by(simp add: Bit_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
886 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
887 |
lemma int_not_neg_numeral: "NOT (- numeral n) = (Num.sub n num.One :: int)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
888 |
by(simp add: int_not_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
889 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
890 |
lemma sub_inc_One: "Num.sub (Num.inc n) num.One = numeral n" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
891 |
by (metis add_diff_cancel diff_minus_eq_add diff_numeral_special(2) diff_numeral_special(6)) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
892 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
893 |
lemma inc_BitM: "Num.inc (Num.BitM n) = num.Bit0 n" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
894 |
by(simp add: BitM_plus_one[symmetric] add_One) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
895 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
896 |
lemma int_neg_numeral_pOne_conv_not: "- numeral (n + num.One) = (NOT (numeral n) :: int)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
897 |
by(simp add: int_not_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
898 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
899 |
lemma int_lsb_BIT [simp]: fixes x :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
900 |
"lsb (x BIT b) \<longleftrightarrow> b" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
901 |
by(simp add: lsb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
902 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
903 |
lemma bin_last_conv_lsb: "bin_last = lsb" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
904 |
by(clarsimp simp add: lsb_int_def fun_eq_iff) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
905 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
906 |
lemma int_lsb_numeral [simp]: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
907 |
"lsb (0 :: int) = False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
908 |
"lsb (1 :: int) = True" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
909 |
"lsb (Numeral1 :: int) = True" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
910 |
"lsb (- 1 :: int) = True" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
911 |
"lsb (- Numeral1 :: int) = True" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
912 |
"lsb (numeral (num.Bit0 w) :: int) = False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
913 |
"lsb (numeral (num.Bit1 w) :: int) = True" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
914 |
"lsb (- numeral (num.Bit0 w) :: int) = False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
915 |
"lsb (- numeral (num.Bit1 w) :: int) = True" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
916 |
by(simp_all add: lsb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
917 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
918 |
lemma int_set_bit_0 [simp]: fixes x :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
919 |
"set_bit x 0 b = bin_rest x BIT b" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
920 |
by(auto simp add: set_bit_int_def intro: bin_rl_eqI) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
921 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
922 |
lemma int_set_bit_Suc: fixes x :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
923 |
"set_bit x (Suc n) b = set_bit (bin_rest x) n b BIT bin_last x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
924 |
by(auto simp add: set_bit_int_def twice_conv_BIT intro: bin_rl_eqI) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
925 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
926 |
lemma bin_last_set_bit: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
927 |
"bin_last (set_bit x n b) = (if n > 0 then bin_last x else b)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
928 |
by(cases n)(simp_all add: int_set_bit_Suc) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
929 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
930 |
lemma bin_rest_set_bit: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
931 |
"bin_rest (set_bit x n b) = (if n > 0 then set_bit (bin_rest x) (n - 1) b else bin_rest x)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
932 |
by(cases n)(simp_all add: int_set_bit_Suc) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
933 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
934 |
lemma int_set_bit_numeral: fixes x :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
935 |
"set_bit x (numeral w) b = set_bit (bin_rest x) (pred_numeral w) b BIT bin_last x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
936 |
by(simp add: set_bit_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
937 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
938 |
lemmas int_set_bit_numerals [simp] = |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
939 |
int_set_bit_numeral[where x="numeral w'"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
940 |
int_set_bit_numeral[where x="- numeral w'"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
941 |
int_set_bit_numeral[where x="Numeral1"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
942 |
int_set_bit_numeral[where x="1"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
943 |
int_set_bit_numeral[where x="0"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
944 |
int_set_bit_Suc[where x="numeral w'"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
945 |
int_set_bit_Suc[where x="- numeral w'"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
946 |
int_set_bit_Suc[where x="Numeral1"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
947 |
int_set_bit_Suc[where x="1"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
948 |
int_set_bit_Suc[where x="0"] |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
949 |
for w' |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
950 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
951 |
lemma int_shiftl_BIT: fixes x :: int |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
952 |
shows int_shiftl0 [simp]: "x << 0 = x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
953 |
and int_shiftl_Suc [simp]: "x << Suc n = (x << n) BIT False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
954 |
by(auto simp add: shiftl_int_def Bit_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
955 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
956 |
lemma int_0_shiftl [simp]: "0 << n = (0 :: int)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
957 |
by(induct n) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
958 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
959 |
lemma bin_last_shiftl: "bin_last (x << n) \<longleftrightarrow> n = 0 \<and> bin_last x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
960 |
by(cases n)(simp_all) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
961 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
962 |
lemma bin_rest_shiftl: "bin_rest (x << n) = (if n > 0 then x << (n - 1) else bin_rest x)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
963 |
by(cases n)(simp_all) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
964 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
965 |
lemma bin_nth_shiftl [simp]: "bin_nth (x << n) m \<longleftrightarrow> n \<le> m \<and> bin_nth x (m - n)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
966 |
proof(induct n arbitrary: x m) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
967 |
case (Suc n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
968 |
thus ?case by(cases m) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
969 |
qed simp |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
970 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
971 |
lemma int_shiftr_BIT [simp]: fixes x :: int |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
972 |
shows int_shiftr0: "x >> 0 = x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
973 |
and int_shiftr_Suc: "x BIT b >> Suc n = x >> n" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
974 |
proof - |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
975 |
show "x >> 0 = x" by (simp add: shiftr_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
976 |
show "x BIT b >> Suc n = x >> n" by (cases b) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
977 |
(simp_all add: shiftr_int_def Bit_def add.commute pos_zdiv_mult_2) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
978 |
qed |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
979 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
980 |
lemma bin_last_shiftr: "bin_last (x >> n) \<longleftrightarrow> x !! n" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
981 |
proof(induct n arbitrary: x) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
982 |
case 0 thus ?case by simp |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
983 |
next |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
984 |
case (Suc n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
985 |
thus ?case by(cases x rule: bin_exhaust) simp |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
986 |
qed |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
987 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
988 |
lemma bin_rest_shiftr [simp]: "bin_rest (x >> n) = x >> Suc n" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
989 |
proof(induct n arbitrary: x) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
990 |
case 0 |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
991 |
thus ?case by(cases x rule: bin_exhaust) auto |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
992 |
next |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
993 |
case (Suc n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
994 |
thus ?case by(cases x rule: bin_exhaust) auto |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
995 |
qed |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
996 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
997 |
lemma bin_nth_shiftr [simp]: "bin_nth (x >> n) m = bin_nth x (n + m)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
998 |
proof(induct n arbitrary: x m) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
999 |
case (Suc n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1000 |
thus ?case by(cases x rule: bin_exhaust) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1001 |
qed simp |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1002 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1003 |
lemma bin_nth_conv_AND: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1004 |
fixes x :: int shows |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1005 |
"bin_nth x n \<longleftrightarrow> x AND (1 << n) \<noteq> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1006 |
proof(induct n arbitrary: x) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1007 |
case 0 |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1008 |
thus ?case by(simp add: int_and_1 bin_last_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1009 |
next |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1010 |
case (Suc n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1011 |
thus ?case by(cases x rule: bin_exhaust)(simp_all add: bin_nth_ops Bit_eq_0_iff) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1012 |
qed |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1013 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1014 |
lemma int_shiftl_numeral [simp]: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1015 |
"(numeral w :: int) << numeral w' = numeral (num.Bit0 w) << pred_numeral w'" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1016 |
"(- numeral w :: int) << numeral w' = - numeral (num.Bit0 w) << pred_numeral w'" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1017 |
by(simp_all add: numeral_eq_Suc Bit_def shiftl_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1018 |
(metis add_One mult_inc semiring_norm(11) semiring_norm(13) semiring_norm(2) semiring_norm(6) semiring_norm(87))+ |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1019 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1020 |
lemma int_shiftl_One_numeral [simp]: "(1 :: int) << numeral w = 2 << pred_numeral w" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1021 |
by(metis int_shiftl_numeral numeral_One) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1022 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1023 |
lemma shiftl_ge_0 [simp]: fixes i :: int shows "i << n \<ge> 0 \<longleftrightarrow> i \<ge> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1024 |
by(induct n) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1025 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1026 |
lemma shiftl_lt_0 [simp]: fixes i :: int shows "i << n < 0 \<longleftrightarrow> i < 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1027 |
by (metis not_le shiftl_ge_0) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1028 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1029 |
lemma int_shiftl_test_bit: "(n << i :: int) !! m \<longleftrightarrow> m \<ge> i \<and> n !! (m - i)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1030 |
proof(induction i) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1031 |
case (Suc n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1032 |
thus ?case by(cases m) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1033 |
qed simp |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1034 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1035 |
lemma int_0shiftr [simp]: "(0 :: int) >> x = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1036 |
by(simp add: shiftr_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1037 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1038 |
lemma int_minus1_shiftr [simp]: "(-1 :: int) >> x = -1" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1039 |
by(simp add: shiftr_int_def div_eq_minus1) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1040 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1041 |
lemma int_shiftr_ge_0 [simp]: fixes i :: int shows "i >> n \<ge> 0 \<longleftrightarrow> i \<ge> 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1042 |
proof(induct n arbitrary: i) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1043 |
case (Suc n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1044 |
thus ?case by(cases i rule: bin_exhaust) simp_all |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1045 |
qed simp |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1046 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1047 |
lemma int_shiftr_lt_0 [simp]: fixes i :: int shows "i >> n < 0 \<longleftrightarrow> i < 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1048 |
by (metis int_shiftr_ge_0 not_less) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1049 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1050 |
lemma uminus_Bit_eq: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1051 |
"- k BIT b = (- k - of_bool b) BIT b" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1052 |
by (cases b) (simp_all add: Bit_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1053 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1054 |
lemma int_shiftr_numeral [simp]: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1055 |
"(1 :: int) >> numeral w' = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1056 |
"(numeral num.One :: int) >> numeral w' = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1057 |
"(numeral (num.Bit0 w) :: int) >> numeral w' = numeral w >> pred_numeral w'" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1058 |
"(numeral (num.Bit1 w) :: int) >> numeral w' = numeral w >> pred_numeral w'" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1059 |
"(- numeral (num.Bit0 w) :: int) >> numeral w' = - numeral w >> pred_numeral w'" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1060 |
"(- numeral (num.Bit1 w) :: int) >> numeral w' = - numeral (Num.inc w) >> pred_numeral w'" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1061 |
by (simp_all only: numeral_One expand_BIT numeral_eq_Suc int_shiftr_Suc BIT_special_simps(2)[symmetric] int_0shiftr add_One uminus_Bit_eq) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1062 |
(simp_all add: add_One) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1063 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1064 |
lemma int_shiftr_numeral_Suc0 [simp]: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1065 |
"(1 :: int) >> Suc 0 = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1066 |
"(numeral num.One :: int) >> Suc 0 = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1067 |
"(numeral (num.Bit0 w) :: int) >> Suc 0 = numeral w" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1068 |
"(numeral (num.Bit1 w) :: int) >> Suc 0 = numeral w" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1069 |
"(- numeral (num.Bit0 w) :: int) >> Suc 0 = - numeral w" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1070 |
"(- numeral (num.Bit1 w) :: int) >> Suc 0 = - numeral (Num.inc w)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1071 |
by(simp_all only: One_nat_def[symmetric] numeral_One[symmetric] int_shiftr_numeral pred_numeral_simps int_shiftr0) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1072 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1073 |
lemma bin_nth_minus_p2: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1074 |
assumes sign: "bin_sign x = 0" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1075 |
and y: "y = 1 << n" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1076 |
and m: "m < n" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1077 |
and x: "x < y" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1078 |
shows "bin_nth (x - y) m = bin_nth x m" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1079 |
using sign m x unfolding y |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1080 |
proof(induction m arbitrary: x y n) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1081 |
case 0 |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1082 |
thus ?case |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1083 |
by(simp add: bin_last_def shiftl_int_def) (metis (hide_lams, no_types) mod_diff_right_eq mod_self neq0_conv numeral_One power_eq_0_iff power_mod diff_zero zero_neq_numeral) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1084 |
next |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1085 |
case (Suc m) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1086 |
from \<open>Suc m < n\<close> obtain n' where [simp]: "n = Suc n'" by(cases n) auto |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1087 |
obtain x' b where [simp]: "x = x' BIT b" by(cases x rule: bin_exhaust) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1088 |
from \<open>bin_sign x = 0\<close> have "bin_sign x' = 0" by simp |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1089 |
moreover from \<open>x < 1 << n\<close> have "x' < 1 << n'" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1090 |
by(cases b)(simp_all add: Bit_def shiftl_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1091 |
moreover have "(2 * x' + of_bool b - 2 * 2 ^ n') div 2 = x' + (- (2 ^ n') + of_bool b div 2)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1092 |
by(simp only: add_diff_eq[symmetric] add.commute div_mult_self2[OF zero_neq_numeral[symmetric]]) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1093 |
ultimately show ?case using Suc.IH[of x' n'] Suc.prems |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1094 |
by(cases b)(simp_all add: Bit_def bin_rest_def shiftl_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1095 |
qed |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1096 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1097 |
lemma bin_clr_conv_NAND: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1098 |
"bin_sc n False i = i AND NOT (1 << n)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1099 |
by(induct n arbitrary: i)(auto intro: bin_rl_eqI) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1100 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1101 |
lemma bin_set_conv_OR: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1102 |
"bin_sc n True i = i OR (1 << n)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1103 |
by(induct n arbitrary: i)(auto intro: bin_rl_eqI) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1104 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1105 |
lemma int_set_bits_K_True [simp]: "(BITS _. True) = (-1 :: int)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1106 |
by(auto simp add: set_bits_int_def bin_last_bl_to_bin) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1107 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1108 |
lemma int_set_bits_K_False [simp]: "(BITS _. False) = (0 :: int)" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1109 |
by(auto simp add: set_bits_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1110 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1111 |
lemma msb_conv_bin_sign: "msb x \<longleftrightarrow> bin_sign x = -1" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1112 |
by(simp add: bin_sign_def not_le msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1113 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1114 |
lemma msb_BIT [simp]: "msb (x BIT b) = msb x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1115 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1116 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1117 |
lemma msb_bin_rest [simp]: "msb (bin_rest x) = msb x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1118 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1119 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1120 |
lemma int_msb_and [simp]: "msb ((x :: int) AND y) \<longleftrightarrow> msb x \<and> msb y" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1121 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1122 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1123 |
lemma int_msb_or [simp]: "msb ((x :: int) OR y) \<longleftrightarrow> msb x \<or> msb y" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1124 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1125 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1126 |
lemma int_msb_xor [simp]: "msb ((x :: int) XOR y) \<longleftrightarrow> msb x \<noteq> msb y" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1127 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1128 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1129 |
lemma int_msb_not [simp]: "msb (NOT (x :: int)) \<longleftrightarrow> \<not> msb x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1130 |
by(simp add: msb_int_def not_less) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1131 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1132 |
lemma msb_shiftl [simp]: "msb ((x :: int) << n) \<longleftrightarrow> msb x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1133 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1134 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1135 |
lemma msb_shiftr [simp]: "msb ((x :: int) >> r) \<longleftrightarrow> msb x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1136 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1137 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1138 |
lemma msb_bin_sc [simp]: "msb (bin_sc n b x) \<longleftrightarrow> msb x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1139 |
by(simp add: msb_conv_bin_sign) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1140 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1141 |
lemma msb_set_bit [simp]: "msb (set_bit (x :: int) n b) \<longleftrightarrow> msb x" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1142 |
by(simp add: msb_conv_bin_sign set_bit_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1143 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1144 |
lemma msb_0 [simp]: "msb (0 :: int) = False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1145 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1146 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1147 |
lemma msb_1 [simp]: "msb (1 :: int) = False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1148 |
by(simp add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1149 |
|
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1150 |
lemma msb_numeral [simp]: |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1151 |
"msb (numeral n :: int) = False" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1152 |
"msb (- numeral n :: int) = True" |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1153 |
by(simp_all add: msb_int_def) |
3ea80c950023
incorporated various material from the AFP into the distribution
haftmann
parents:
70175
diff
changeset
|
1154 |
|
70169 | 1155 |
end |