src/HOL/Word/Bit_Operations.thy
author wenzelm
Thu, 12 Dec 2013 16:56:53 +0100
changeset 54727 a806e7251cf0
parent 54224 9fda41a04c32
child 54847 d6cf9a5b9be9
permissions -rw-r--r--
tuned whitespace;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37655
f4d616d41a59 more speaking theory names
haftmann
parents: 29631
diff changeset
     1
(*  Title:      HOL/Word/Bit_Operations.thy
f4d616d41a59 more speaking theory names
haftmann
parents: 29631
diff changeset
     2
    Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
24334
22863f364531 added header
kleing
parents: 24333
diff changeset
     3
*)
22863f364531 added header
kleing
parents: 24333
diff changeset
     4
26559
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
     5
header {* Syntactic classes for bitwise operations *}
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
37655
f4d616d41a59 more speaking theory names
haftmann
parents: 29631
diff changeset
     7
theory Bit_Operations
41413
64cd30d6b0b8 explicit file specifications -- avoid secondary load path;
wenzelm
parents: 37655
diff changeset
     8
imports "~~/src/HOL/Library/Bit"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     9
begin
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    10
29608
564ea783ace8 no base sort in class import
haftmann
parents: 26559
diff changeset
    11
class bit =
26559
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    12
  fixes bitNOT :: "'a \<Rightarrow> 'a"       ("NOT _" [70] 71)
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    13
    and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "AND" 64)
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    14
    and bitOR  :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "OR"  59)
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    15
    and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "XOR" 59)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    16
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    17
text {*
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    18
  We want the bitwise operations to bind slightly weaker
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    19
  than @{text "+"} and @{text "-"}, but @{text "~~"} to 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    20
  bind slightly stronger than @{text "*"}.
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    21
*}
24352
eda777a2785b use class instead of axclass
huffman
parents: 24334
diff changeset
    22
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    23
text {*
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    24
  Testing and shifting operations.
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    25
*}
26559
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    26
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    27
class bits = bit +
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    28
  fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool" (infixl "!!" 100)
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    29
    and lsb      :: "'a \<Rightarrow> bool"
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    30
    and set_bit  :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a"
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    31
    and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a" (binder "BITS " 10)
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    32
    and shiftl   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl "<<" 55)
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    33
    and shiftr   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl ">>" 55)
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    34
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    35
class bitss = bits +
799983936aad syntactic classes for bit operations
haftmann
parents: 26086
diff changeset
    36
  fixes msb      :: "'a \<Rightarrow> bool"
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    37
25762
c03e9d04b3e4 splitted class uminus from class minus
haftmann
parents: 25382
diff changeset
    38
end
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    39