author | haftmann |
Sun, 12 Jul 2020 18:10:06 +0000 | |
changeset 72027 | 759532ef0885 |
parent 72000 | 379d0c207c29 |
child 72081 | e4d42f5766dc |
permissions | -rw-r--r-- |
70192 | 1 |
(* Title: HOL/Word/Bit_Comprehension.thy |
2 |
Author: Brian Huffman, PSU; Jeremy Dawson and Gerwin Klein, NICTA |
|
3 |
*) |
|
4 |
||
5 |
section \<open>Comprehension syntax for bit expressions\<close> |
|
6 |
||
7 |
theory Bit_Comprehension |
|
8 |
imports Bits_Int |
|
9 |
begin |
|
10 |
||
72000 | 11 |
class bit_comprehension = semiring_bits + |
70192 | 12 |
fixes set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a" (binder "BITS " 10) |
13 |
||
14 |
instantiation int :: bit_comprehension |
|
15 |
begin |
|
16 |
||
17 |
definition |
|
18 |
"set_bits f = |
|
19 |
(if \<exists>n. \<forall>n'\<ge>n. \<not> f n' then |
|
20 |
let n = LEAST n. \<forall>n'\<ge>n. \<not> f n' |
|
72027
759532ef0885
prefer canonically oriented lists of bits and more direct characterizations in definitions
haftmann
parents:
72000
diff
changeset
|
21 |
in horner_sum of_bool 2 (map f [0..<n]) |
70192 | 22 |
else if \<exists>n. \<forall>n'\<ge>n. f n' then |
23 |
let n = LEAST n. \<forall>n'\<ge>n. f n' |
|
72027
759532ef0885
prefer canonically oriented lists of bits and more direct characterizations in definitions
haftmann
parents:
72000
diff
changeset
|
24 |
in signed_take_bit n (horner_sum of_bool 2 (map f [0..<n] @ [True])) |
70192 | 25 |
else 0 :: int)" |
26 |
||
27 |
instance .. |
|
28 |
||
29 |
end |
|
30 |
||
31 |
lemma int_set_bits_K_False [simp]: "(BITS _. False) = (0 :: int)" |
|
32 |
by (simp add: set_bits_int_def) |
|
33 |
||
34 |
lemma int_set_bits_K_True [simp]: "(BITS _. True) = (-1 :: int)" |
|
35 |
by (auto simp add: set_bits_int_def bl_to_bin_def) |
|
36 |
||
37 |
end |