Theory Bits

theory Bits
imports Main
(*  Title:      HOL/Word/Bits.thy
    Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
*)

section ‹Syntactic classes for bitwise operations›

theory Bits
imports Main
begin

class bit =
  fixes bitNOT :: "'a ⇒ 'a"       ("NOT _" [70] 71)
    and bitAND :: "'a ⇒ 'a ⇒ 'a" (infixr "AND" 64)
    and bitOR  :: "'a ⇒ 'a ⇒ 'a" (infixr "OR"  59)
    and bitXOR :: "'a ⇒ 'a ⇒ 'a" (infixr "XOR" 59)

text ‹
  We want the bitwise operations to bind slightly weaker
  than ‹+› and ‹-›, but ‹~~› to 
  bind slightly stronger than ‹*›.
›

text ‹
  Testing and shifting operations.
›

class bits = bit +
  fixes test_bit :: "'a ⇒ nat ⇒ bool" (infixl "!!" 100)
    and lsb      :: "'a ⇒ bool"
    and set_bit  :: "'a ⇒ nat ⇒ bool ⇒ 'a"
    and set_bits :: "(nat ⇒ bool) ⇒ 'a" (binder "BITS " 10)
    and shiftl   :: "'a ⇒ nat ⇒ 'a" (infixl "<<" 55)
    and shiftr   :: "'a ⇒ nat ⇒ 'a" (infixl ">>" 55)

class bitss = bits +
  fixes msb      :: "'a ⇒ bool"

end