src/HOL/Word/Bits.thy
author wenzelm
Sun Sep 18 20:33:48 2016 +0200 (2016-09-18)
changeset 63915 bab633745c7f
parent 61799 4cf66f21b764
child 65363 5eb619751b14
permissions -rw-r--r--
tuned proofs;
     1 (*  Title:      HOL/Word/Bits.thy
     2     Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
     3 *)
     4 
     5 section \<open>Syntactic classes for bitwise operations\<close>
     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 \<open>
    18   We want the bitwise operations to bind slightly weaker
    19   than \<open>+\<close> and \<open>-\<close>, but \<open>~~\<close> to 
    20   bind slightly stronger than \<open>*\<close>.
    21 \<close>
    22 
    23 text \<open>
    24   Testing and shifting operations.
    25 \<close>
    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