equal
deleted
inserted
replaced
10 |
10 |
11 theory BitSyntax |
11 theory BitSyntax |
12 imports Main |
12 imports Main |
13 begin |
13 begin |
14 |
14 |
15 axclass bit < type |
15 class bit = type + |
|
16 fixes bitNOT :: "'a \<Rightarrow> 'a" |
|
17 and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" |
|
18 and bitOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" |
|
19 and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" |
16 |
20 |
17 text {* |
21 text {* |
18 We want the bitwise operations to bind slightly weaker |
22 We want the bitwise operations to bind slightly weaker |
19 than @{text "+"} and @{text "-"}, but @{text "~~"} to |
23 than @{text "+"} and @{text "-"}, but @{text "~~"} to |
20 bind slightly stronger than @{text "*"}. |
24 bind slightly stronger than @{text "*"}. |
21 *} |
25 *} |
22 consts |
26 |
23 bitNOT :: "'a::bit \<Rightarrow> 'a" ("NOT _" [70] 71) |
27 notation |
24 bitAND :: "'a::bit \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "AND" 64) |
28 bitNOT ("NOT _" [70] 71) |
25 bitOR :: "'a::bit \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "OR" 59) |
29 |
26 bitXOR :: "'a::bit \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "XOR" 59) |
30 notation |
|
31 bitAND (infixr "AND" 64) |
|
32 |
|
33 notation |
|
34 bitOR (infixr "OR" 59) |
|
35 |
|
36 notation |
|
37 bitXOR (infixr "XOR" 59) |
27 |
38 |
28 text {* |
39 text {* |
29 Testing and shifting operations. |
40 Testing and shifting operations. |
30 *} |
41 *} |
31 consts |
42 consts |
38 shiftr :: "'a::bit \<Rightarrow> nat \<Rightarrow> 'a" (infixl ">>" 55) |
49 shiftr :: "'a::bit \<Rightarrow> nat \<Rightarrow> 'a" (infixl ">>" 55) |
39 |
50 |
40 |
51 |
41 subsection {* Bitwise operations on type @{typ bit} *} |
52 subsection {* Bitwise operations on type @{typ bit} *} |
42 |
53 |
43 instance bit :: bit .. |
54 instance bit :: bit |
44 |
|
45 defs (overloaded) |
|
46 NOT_bit_def: "NOT x \<equiv> case x of bit.B0 \<Rightarrow> bit.B1 | bit.B1 \<Rightarrow> bit.B0" |
55 NOT_bit_def: "NOT x \<equiv> case x of bit.B0 \<Rightarrow> bit.B1 | bit.B1 \<Rightarrow> bit.B0" |
47 AND_bit_def: "x AND y \<equiv> case x of bit.B0 \<Rightarrow> bit.B0 | bit.B1 \<Rightarrow> y" |
56 AND_bit_def: "x AND y \<equiv> case x of bit.B0 \<Rightarrow> bit.B0 | bit.B1 \<Rightarrow> y" |
48 OR_bit_def: "x OR y :: bit \<equiv> NOT (NOT x AND NOT y)" |
57 OR_bit_def: "x OR y :: bit \<equiv> NOT (NOT x AND NOT y)" |
49 XOR_bit_def: "x XOR y :: bit \<equiv> (x AND NOT y) OR (NOT x AND y)" |
58 XOR_bit_def: "x XOR y :: bit \<equiv> (x AND NOT y) OR (NOT x AND y)" |
|
59 .. |
50 |
60 |
51 lemma bit_simps [simp]: |
61 lemma bit_simps [simp]: |
52 "NOT bit.B0 = bit.B1" |
62 "NOT bit.B0 = bit.B1" |
53 "NOT bit.B1 = bit.B0" |
63 "NOT bit.B1 = bit.B0" |
54 "bit.B0 AND y = bit.B0" |
64 "bit.B0 AND y = bit.B0" |