src/HOL/Word/Bits.thy
author haftmann
Fri Jun 19 07:53:35 2015 +0200 (2015-06-19)
changeset 60517 f16e4fb20652
parent 58874 7172c7ffb047
child 61799 4cf66f21b764
permissions -rw-r--r--
separate class for notions specific for integral (semi)domains, in contrast to fields where these are trivial
     1 (*  Title:      HOL/Word/Bits.thy
     2     Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
     3 *)
     4 
     5 section {* Syntactic classes for bitwise operations *}
     6 
     7 theory Bits
     8 imports Main
     9 begin
    10 
    11 class bit =
    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)
    16 
    17 text {*
    18   We want the bitwise operations to bind slightly weaker
    19   than @{text "+"} and @{text "-"}, but @{text "~~"} to 
    20   bind slightly stronger than @{text "*"}.
    21 *}
    22 
    23 text {*
    24   Testing and shifting operations.
    25 *}
    26 
    27 class bits = bit +
    28   fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool" (infixl "!!" 100)
    29     and lsb      :: "'a \<Rightarrow> bool"
    30     and set_bit  :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a"
    31     and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a" (binder "BITS " 10)
    32     and shiftl   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl "<<" 55)
    33     and shiftr   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl ">>" 55)
    34 
    35 class bitss = bits +
    36   fixes msb      :: "'a \<Rightarrow> bool"
    37 
    38 end
    39