147 using word_of_int_Ex [where x=x] |
147 using word_of_int_Ex [where x=x] |
148 word_of_int_Ex [where x=y] |
148 word_of_int_Ex [where x=y] |
149 by (auto simp: bwsimps) |
149 by (auto simp: bwsimps) |
150 |
150 |
151 lemma word_not_not [simp]: |
151 lemma word_not_not [simp]: |
152 "NOT NOT (x::'a::len0 word) = x" |
152 "NOT NOT (x::'a word) = x" |
153 using word_of_int_Ex [where x=x] |
153 using word_of_int_Ex [where x=x] |
154 by (auto simp: bwsimps) |
154 by (auto simp: bwsimps) |
155 |
155 |
156 lemma word_ao_dist: |
156 lemma word_ao_dist: |
157 fixes x :: "'a::len0 word" |
157 fixes x :: "'a word" |
158 shows "(x OR y) AND z = x AND z OR y AND z" |
158 shows "(x OR y) AND z = x AND z OR y AND z" |
159 using word_of_int_Ex [where x=x] |
159 using word_of_int_Ex [where x=x] |
160 word_of_int_Ex [where x=y] |
160 word_of_int_Ex [where x=y] |
161 word_of_int_Ex [where x=z] |
161 word_of_int_Ex [where x=z] |
162 by (auto simp: bwsimps bbw_ao_dist simp del: bin_ops_comm) |
162 by (auto simp: bwsimps bbw_ao_dist simp del: bin_ops_comm) |
163 |
163 |
164 lemma word_oa_dist: |
164 lemma word_oa_dist: |
165 fixes x :: "'a::len0 word" |
165 fixes x :: "'a word" |
166 shows "x AND y OR z = (x OR z) AND (y OR z)" |
166 shows "x AND y OR z = (x OR z) AND (y OR z)" |
167 using word_of_int_Ex [where x=x] |
167 using word_of_int_Ex [where x=x] |
168 word_of_int_Ex [where x=y] |
168 word_of_int_Ex [where x=y] |
169 word_of_int_Ex [where x=z] |
169 word_of_int_Ex [where x=z] |
170 by (auto simp: bwsimps bbw_oa_dist simp del: bin_ops_comm) |
170 by (auto simp: bwsimps bbw_oa_dist simp del: bin_ops_comm) |
171 |
171 |
172 lemma word_add_not [simp]: |
172 lemma word_add_not [simp]: |
173 fixes x :: "'a::len0 word" |
173 fixes x :: "'a word" |
174 shows "x + NOT x = -1" |
174 shows "x + NOT x = -1" |
175 using word_of_int_Ex [where x=x] |
175 using word_of_int_Ex [where x=x] |
176 by (auto simp: bwsimps bin_add_not) |
176 by (auto simp: bwsimps bin_add_not) |
177 |
177 |
178 lemma word_plus_and_or [simp]: |
178 lemma word_plus_and_or [simp]: |
179 fixes x :: "'a::len0 word" |
179 fixes x :: "'a word" |
180 shows "(x AND y) + (x OR y) = x + y" |
180 shows "(x AND y) + (x OR y) = x + y" |
181 using word_of_int_Ex [where x=x] |
181 using word_of_int_Ex [where x=x] |
182 word_of_int_Ex [where x=y] |
182 word_of_int_Ex [where x=y] |
183 by (auto simp: bwsimps plus_and_or) |
183 by (auto simp: bwsimps plus_and_or) |
184 |
184 |
185 lemma leoa: |
185 lemma leoa: |
186 fixes x :: "'a::len0 word" |
186 fixes x :: "'a word" |
187 shows "(w = (x OR y)) ==> (y = (w AND y))" by auto |
187 shows "(w = (x OR y)) ==> (y = (w AND y))" by auto |
188 lemma leao: |
188 lemma leao: |
189 fixes x' :: "'a::len0 word" |
189 fixes x' :: "'a word" |
190 shows "(w' = (x' AND y')) ==> (x' = (x' OR w'))" by auto |
190 shows "(w' = (x' AND y')) ==> (x' = (x' OR w'))" by auto |
191 |
191 |
192 lemmas word_ao_equiv = leao [COMP leoa [COMP iffI]] |
192 lemmas word_ao_equiv = leao [COMP leoa [COMP iffI]] |
193 |
193 |
194 lemma le_word_or2: "x <= x OR (y::'a::len0 word)" |
194 lemma le_word_or2: "x <= x OR (y::'a word)" |
195 unfolding word_le_def uint_or |
195 unfolding word_le_def uint_or |
196 by (auto intro: le_int_or) |
196 by (auto intro: le_int_or) |
197 |
197 |
198 lemmas le_word_or1 = xtr3 [OF word_bw_comms (2) le_word_or2, standard] |
198 lemmas le_word_or1 = xtr3 [OF word_bw_comms (2) le_word_or2, standard] |
199 lemmas word_and_le1 = |
199 lemmas word_and_le1 = |
200 xtr3 [OF word_ao_absorbs (4) [symmetric] le_word_or2, standard] |
200 xtr3 [OF word_ao_absorbs (4) [symmetric] le_word_or2, standard] |
201 lemmas word_and_le2 = |
201 lemmas word_and_le2 = |
202 xtr3 [OF word_ao_absorbs (8) [symmetric] le_word_or2, standard] |
202 xtr3 [OF word_ao_absorbs (8) [symmetric] le_word_or2, standard] |
203 |
203 |
204 lemma word_lsb_alt: "lsb (w::'a::len0 word) = test_bit w 0" |
204 lemma word_lsb_alt: "lsb (w::'a word) = test_bit w 0" |
205 by (auto simp: word_test_bit_def word_lsb_def) |
205 by (auto simp: word_test_bit_def word_lsb_def) |
206 |
206 |
207 lemma word_lsb_1_0: "lsb (1::'a::len word) & ~ lsb (0::'b::len0 word)" |
207 lemma word_lsb_1_0: "lsb (1::'a::finite word) & ~ lsb (0::'b word)" |
208 unfolding word_lsb_def word_1_no word_0_no by auto |
208 unfolding word_lsb_def word_1_no word_0_no by auto |
209 |
209 |
210 lemma word_lsb_int: "lsb w = (uint w mod 2 = 1)" |
210 lemma word_lsb_int: "lsb w = (uint w mod 2 = 1)" |
211 unfolding word_lsb_def bin_last_mod by auto |
211 unfolding word_lsb_def bin_last_mod by auto |
212 |
212 |
213 lemma word_msb_sint: "msb w = (sint w < 0)" |
213 lemma word_msb_sint: "msb w = (sint w < 0)" |
214 unfolding word_msb_def |
214 unfolding word_msb_def |
215 by (simp add : sign_Min_lt_0 number_of_is_id) |
215 by (simp add : sign_Min_lt_0 number_of_is_id) |
216 |
216 |
217 lemma word_msb_no': |
217 lemma word_msb_no': |
218 "w = number_of bin ==> msb (w::'a::len word) = bin_nth bin (size w - 1)" |
218 "w = number_of bin ==> msb (w::'a::finite word) = bin_nth bin (size w - 1)" |
219 unfolding word_msb_def word_number_of_def |
219 unfolding word_msb_def word_number_of_def |
220 by (clarsimp simp add: word_sbin.eq_norm word_size bin_sign_lem) |
220 by (clarsimp simp add: word_sbin.eq_norm word_size bin_sign_lem) |
221 |
221 |
222 lemmas word_msb_no = refl [THEN word_msb_no', unfolded word_size] |
222 lemmas word_msb_no = refl [THEN word_msb_no', unfolded word_size] |
223 |
223 |
224 lemma word_msb_nth': "msb (w::'a::len word) = bin_nth (uint w) (size w - 1)" |
224 lemma word_msb_nth': "msb (w::'a::finite word) = bin_nth (uint w) (size w - 1)" |
225 apply (unfold word_size) |
225 apply (unfold word_size) |
226 apply (rule trans [OF _ word_msb_no]) |
226 apply (rule trans [OF _ word_msb_no]) |
227 apply (simp add : word_number_of_def) |
227 apply (simp add : word_number_of_def) |
228 done |
228 done |
229 |
229 |
230 lemmas word_msb_nth = word_msb_nth' [unfolded word_size] |
230 lemmas word_msb_nth = word_msb_nth' [unfolded word_size] |
231 |
231 |
232 lemma word_set_nth: |
232 lemma word_set_nth: |
233 "set_bit w n (test_bit w n) = (w::'a::len0 word)" |
233 "set_bit w n (test_bit w n) = (w::'a word)" |
234 unfolding word_test_bit_def word_set_bit_def by auto |
234 unfolding word_test_bit_def word_set_bit_def by auto |
235 |
235 |
236 lemma test_bit_set: |
236 lemma test_bit_set: |
237 fixes w :: "'a::len0 word" |
237 fixes w :: "'a word" |
238 shows "(set_bit w n x) !! n = (n < size w & x)" |
238 shows "(set_bit w n x) !! n = (n < size w & x)" |
239 unfolding word_size word_test_bit_def word_set_bit_def |
239 unfolding word_size word_test_bit_def word_set_bit_def |
240 by (clarsimp simp add : word_ubin.eq_norm nth_bintr) |
240 by (clarsimp simp add : word_ubin.eq_norm nth_bintr) |
241 |
241 |
242 lemma test_bit_set_gen: |
242 lemma test_bit_set_gen: |
243 fixes w :: "'a::len0 word" |
243 fixes w :: "'a word" |
244 shows "test_bit (set_bit w n x) m = |
244 shows "test_bit (set_bit w n x) m = |
245 (if m = n then n < size w & x else test_bit w m)" |
245 (if m = n then n < size w & x else test_bit w m)" |
246 apply (unfold word_size word_test_bit_def word_set_bit_def) |
246 apply (unfold word_size word_test_bit_def word_set_bit_def) |
247 apply (clarsimp simp add: word_ubin.eq_norm nth_bintr bin_nth_sc_gen) |
247 apply (clarsimp simp add: word_ubin.eq_norm nth_bintr bin_nth_sc_gen) |
248 apply (auto elim!: test_bit_size [unfolded word_size] |
248 apply (auto elim!: test_bit_size [unfolded word_size] |
249 simp add: word_test_bit_def [symmetric]) |
249 simp add: word_test_bit_def [symmetric]) |
250 done |
250 done |
251 |
251 |
252 lemma msb_nth': |
252 lemma msb_nth': |
253 fixes w :: "'a::len word" |
253 fixes w :: "'a::finite word" |
254 shows "msb w = w !! (size w - 1)" |
254 shows "msb w = w !! (size w - 1)" |
255 unfolding word_msb_nth' word_test_bit_def by simp |
255 unfolding word_msb_nth' word_test_bit_def by simp |
256 |
256 |
257 lemmas msb_nth = msb_nth' [unfolded word_size] |
257 lemmas msb_nth = msb_nth' [unfolded word_size] |
258 |
258 |
259 lemmas msb0 = len_gt_0 [THEN diff_Suc_less, THEN |
259 lemmas msb0 = zero_less_card_finite [THEN diff_Suc_less, THEN |
260 word_ops_nth_size [unfolded word_size], standard] |
260 word_ops_nth_size [unfolded word_size], standard] |
261 lemmas msb1 = msb0 [where i = 0] |
261 lemmas msb1 = msb0 [where i = 0] |
262 lemmas word_ops_msb = msb1 [unfolded msb_nth [symmetric, unfolded One_nat_def]] |
262 lemmas word_ops_msb = msb1 [unfolded msb_nth [symmetric, unfolded One_nat_def]] |
263 |
263 |
264 lemmas lsb0 = len_gt_0 [THEN word_ops_nth_size [unfolded word_size], standard] |
264 lemmas lsb0 = zero_less_card_finite [THEN word_ops_nth_size [unfolded word_size], standard] |
265 lemmas word_ops_lsb = lsb0 [unfolded word_lsb_alt] |
265 lemmas word_ops_lsb = lsb0 [unfolded word_lsb_alt] |
266 |
266 |
267 lemma word_set_set_same: |
267 lemma word_set_set_same: |
268 fixes w :: "'a::len0 word" |
268 fixes w :: "'a word" |
269 shows "set_bit (set_bit w n x) n y = set_bit w n y" |
269 shows "set_bit (set_bit w n x) n y = set_bit w n y" |
270 by (rule word_eqI) (simp add : test_bit_set_gen word_size) |
270 by (rule word_eqI) (simp add : test_bit_set_gen word_size) |
271 |
271 |
272 lemma word_set_set_diff: |
272 lemma word_set_set_diff: |
273 fixes w :: "'a::len0 word" |
273 fixes w :: "'a word" |
274 assumes "m ~= n" |
274 assumes "m ~= n" |
275 shows "set_bit (set_bit w m x) n y = set_bit (set_bit w n y) m x" |
275 shows "set_bit (set_bit w m x) n y = set_bit (set_bit w n y) m x" |
276 by (rule word_eqI) (clarsimp simp add : test_bit_set_gen word_size prems) |
276 by (rule word_eqI) (clarsimp simp add : test_bit_set_gen word_size prems) |
277 |
277 |
278 lemma test_bit_no': |
278 lemma test_bit_no': |
279 fixes w :: "'a::len0 word" |
279 fixes w :: "'a word" |
280 shows "w = number_of bin ==> test_bit w n = (n < size w & bin_nth bin n)" |
280 shows "w = number_of bin ==> test_bit w n = (n < size w & bin_nth bin n)" |
281 unfolding word_test_bit_def word_number_of_def word_size |
281 unfolding word_test_bit_def word_number_of_def word_size |
282 by (simp add : nth_bintr [symmetric] word_ubin.eq_norm) |
282 by (simp add : nth_bintr [symmetric] word_ubin.eq_norm) |
283 |
283 |
284 lemmas test_bit_no = |
284 lemmas test_bit_no = |
285 refl [THEN test_bit_no', unfolded word_size, THEN eq_reflection, standard] |
285 refl [THEN test_bit_no', unfolded word_size, THEN eq_reflection, standard] |
286 |
286 |
287 lemma nth_0: "~ (0::'a::len0 word) !! n" |
287 lemma nth_0: "~ (0::'a word) !! n" |
288 unfolding test_bit_no word_0_no by auto |
288 unfolding test_bit_no word_0_no by auto |
289 |
289 |
290 lemma nth_sint: |
290 lemma nth_sint: |
291 fixes w :: "'a::len word" |
291 fixes w :: "'a::finite word" |
292 defines "l \<equiv> len_of TYPE ('a)" |
292 defines "l \<equiv> CARD('a)" |
293 shows "bin_nth (sint w) n = (if n < l - 1 then w !! n else w !! (l - 1))" |
293 shows "bin_nth (sint w) n = (if n < l - 1 then w !! n else w !! (l - 1))" |
294 unfolding sint_uint l_def |
294 unfolding sint_uint l_def |
295 by (clarsimp simp add: nth_sbintr word_test_bit_def [symmetric]) |
295 by (clarsimp simp add: nth_sbintr word_test_bit_def [symmetric]) |
296 |
296 |
297 lemma word_lsb_no: |
297 lemma word_lsb_no: |
298 "lsb (number_of bin :: 'a :: len word) = (bin_last bin = bit.B1)" |
298 "lsb (number_of bin :: 'a :: finite word) = (bin_last bin = bit.B1)" |
299 unfolding word_lsb_alt test_bit_no by auto |
299 unfolding word_lsb_alt test_bit_no by auto |
300 |
300 |
301 lemma word_set_no: |
301 lemma word_set_no: |
302 "set_bit (number_of bin::'a::len0 word) n b = |
302 "set_bit (number_of bin::'a word) n b = |
303 number_of (bin_sc n (if b then bit.B1 else bit.B0) bin)" |
303 number_of (bin_sc n (if b then bit.B1 else bit.B0) bin)" |
304 apply (unfold word_set_bit_def word_number_of_def [symmetric]) |
304 apply (unfold word_set_bit_def word_number_of_def [symmetric]) |
305 apply (rule word_eqI) |
305 apply (rule word_eqI) |
306 apply (clarsimp simp: word_size bin_nth_sc_gen number_of_is_id |
306 apply (clarsimp simp: word_size bin_nth_sc_gen number_of_is_id |
307 test_bit_no nth_bintr) |
307 test_bit_no nth_bintr) |
360 apply (drule word_gt_0 [THEN iffD1]) |
360 apply (drule word_gt_0 [THEN iffD1]) |
361 apply (safe intro!: word_eqI bin_nth_lem ext) |
361 apply (safe intro!: word_eqI bin_nth_lem ext) |
362 apply (auto simp add: test_bit_2p nth_2p_bin word_test_bit_def [symmetric]) |
362 apply (auto simp add: test_bit_2p nth_2p_bin word_test_bit_def [symmetric]) |
363 done |
363 done |
364 |
364 |
365 lemma word_of_int_2p: "(word_of_int (2 ^ n) :: 'a :: len word) = 2 ^ n" |
365 lemma word_of_int_2p: "(word_of_int (2 ^ n) :: 'a :: finite word) = 2 ^ n" |
366 apply (unfold word_arith_power_alt) |
366 apply (unfold word_arith_power_alt) |
367 apply (case_tac "len_of TYPE ('a)") |
367 apply (case_tac "CARD('a)") |
368 apply clarsimp |
368 apply clarsimp |
369 apply (case_tac "nat") |
369 apply (case_tac "nat") |
370 apply (rule word_ubin.norm_eq_iff [THEN iffD1]) |
370 apply (rule word_ubin.norm_eq_iff [THEN iffD1]) |
371 apply (rule box_equals) |
371 apply (rule box_equals) |
372 apply (rule_tac [2] bintr_ariths (1))+ |
372 apply (rule_tac [2] bintr_ariths (1))+ |
373 apply (clarsimp simp add : number_of_is_id) |
373 apply (clarsimp simp add : number_of_is_id) |
374 apply simp |
374 apply simp |
375 done |
375 done |
376 |
376 |
377 lemma bang_is_le: "x !! m ==> 2 ^ m <= (x :: 'a :: len word)" |
377 lemma bang_is_le: "x !! m ==> 2 ^ m <= (x :: 'a :: finite word)" |
378 apply (rule xtr3) |
378 apply (rule xtr3) |
379 apply (rule_tac [2] y = "x" in le_word_or2) |
379 apply (rule_tac [2] y = "x" in le_word_or2) |
380 apply (rule word_eqI) |
380 apply (rule word_eqI) |
381 apply (auto simp add: word_ao_nth nth_w2p word_size) |
381 apply (auto simp add: word_ao_nth nth_w2p word_size) |
382 done |
382 done |
383 |
383 |
384 lemma word_clr_le: |
384 lemma word_clr_le: |
385 fixes w :: "'a::len0 word" |
385 fixes w :: "'a word" |
386 shows "w >= set_bit w n False" |
386 shows "w >= set_bit w n False" |
387 apply (unfold word_set_bit_def word_le_def word_ubin.eq_norm) |
387 apply (unfold word_set_bit_def word_le_def word_ubin.eq_norm) |
388 apply simp |
388 apply simp |
389 apply (rule order_trans) |
389 apply (rule order_trans) |
390 apply (rule bintr_bin_clr_le) |
390 apply (rule bintr_bin_clr_le) |
391 apply simp |
391 apply simp |
392 done |
392 done |
393 |
393 |
394 lemma word_set_ge: |
394 lemma word_set_ge: |
395 fixes w :: "'a::len word" |
395 fixes w :: "'a::finite word" |
396 shows "w <= set_bit w n True" |
396 shows "w <= set_bit w n True" |
397 apply (unfold word_set_bit_def word_le_def word_ubin.eq_norm) |
397 apply (unfold word_set_bit_def word_le_def word_ubin.eq_norm) |
398 apply simp |
398 apply simp |
399 apply (rule order_trans [OF _ bintr_bin_set_ge]) |
399 apply (rule order_trans [OF _ bintr_bin_set_ge]) |
400 apply simp |
400 apply simp |