author | wenzelm |
Mon, 08 May 2017 10:27:13 +0200 | |
changeset 65767 | 222ed8901008 |
parent 65363 | 5eb619751b14 |
child 70175 | 85fb1a585f52 |
permissions | -rw-r--r-- |
55210 | 1 |
(* Title: HOL/Word/Bits.thy |
37655 | 2 |
Author: Author: Brian Huffman, PSU and Gerwin Klein, NICTA |
24334 | 3 |
*) |
4 |
||
61799 | 5 |
section \<open>Syntactic classes for bitwise operations\<close> |
24333 | 6 |
|
54854
3324a0078636
prefer "Bits" as theory name for abstract bit operations, similar to "Orderings", "Lattices", "Groups" etc.
haftmann
parents:
54847
diff
changeset
|
7 |
theory Bits |
65363 | 8 |
imports Main |
24333 | 9 |
begin |
10 |
||
29608 | 11 |
class bit = |
65363 | 12 |
fixes bitNOT :: "'a \<Rightarrow> 'a" ("NOT _" [70] 71) |
13 |
and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "AND" 64) |
|
14 |
and bitOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "OR" 59) |
|
15 |
and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "XOR" 59) |
|
24333 | 16 |
|
61799 | 17 |
text \<open> |
24333 | 18 |
We want the bitwise operations to bind slightly weaker |
65363 | 19 |
than \<open>+\<close> and \<open>-\<close>, but \<open>~~\<close> to |
61799 | 20 |
bind slightly stronger than \<open>*\<close>. |
21 |
\<close> |
|
24352 | 22 |
|
65363 | 23 |
text \<open>Testing and shifting operations.\<close> |
26559 | 24 |
|
25 |
class bits = bit + |
|
65363 | 26 |
fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool" (infixl "!!" 100) |
27 |
and lsb :: "'a \<Rightarrow> bool" |
|
28 |
and set_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a" |
|
29 |
and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a" (binder "BITS " 10) |
|
30 |
and shiftl :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl "<<" 55) |
|
31 |
and shiftr :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl ">>" 55) |
|
26559 | 32 |
|
33 |
class bitss = bits + |
|
65363 | 34 |
fixes msb :: "'a \<Rightarrow> bool" |
24333 | 35 |
|
25762 | 36 |
end |