src/HOL/Word/Bits.thy
changeset 70191 bdc835d934b7
parent 70190 ff9efdc84289
child 70192 b4bf82ed0ad5
equal deleted inserted replaced
70190:ff9efdc84289 70191:bdc835d934b7
     1 (*  Title:      HOL/Word/Bits.thy
     1 (*  Title:      HOL/Word/Bits.thy
     2     Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
     2     Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
     3 *)
     3 *)
     4 
     4 
     5 section \<open>Syntactic classes for bitwise operations\<close>
     5 section \<open>Syntactic type classes for bit operations\<close>
     6 
     6 
     7 theory Bits
     7 theory Bits
     8   imports Main
     8   imports Main
     9 begin
     9 begin
    10 
    10 
    11 class bit =
    11 class bit_operations =
    12   fixes bitNOT :: "'a \<Rightarrow> 'a"  ("NOT _" [70] 71)
    12   fixes bitNOT :: "'a \<Rightarrow> 'a"  ("NOT _" [70] 71)
    13     and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "AND" 64)
    13     and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "AND" 64)
    14     and bitOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "OR"  59)
    14     and bitOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "OR"  59)
    15     and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "XOR" 59)
    15     and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "XOR" 59)
       
    16     and shiftl :: "'a \<Rightarrow> nat \<Rightarrow> 'a"  (infixl "<<" 55)
       
    17     and shiftr :: "'a \<Rightarrow> nat \<Rightarrow> 'a"  (infixl ">>" 55)
       
    18   fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool"  (infixl "!!" 100)
       
    19     and lsb :: "'a \<Rightarrow> bool"
       
    20     and msb :: "'a \<Rightarrow> bool"
       
    21     and set_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a"
       
    22     and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a"  (binder "BITS " 10)
    16 
    23 
    17 text \<open>
    24 text \<open>
    18   We want the bitwise operations to bind slightly weaker
    25   We want the bitwise operations to bind slightly weaker
    19   than \<open>+\<close> and \<open>-\<close>, but \<open>~~\<close> to
    26   than \<open>+\<close> and \<open>-\<close>, but \<open>~~\<close> to
    20   bind slightly stronger than \<open>*\<close>.
    27   bind slightly stronger than \<open>*\<close>.
    21 \<close>
    28 \<close>
    22 
    29 
    23 class bits = bit +
       
    24   fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool"  (infixl "!!" 100)
       
    25     and lsb :: "'a \<Rightarrow> bool"
       
    26     and msb :: "'a \<Rightarrow> bool"
       
    27     and set_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a"
       
    28     and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a"  (binder "BITS " 10)
       
    29     and shiftl :: "'a \<Rightarrow> nat \<Rightarrow> 'a"  (infixl "<<" 55)
       
    30     and shiftr :: "'a \<Rightarrow> nat \<Rightarrow> 'a"  (infixl ">>" 55)
       
    31 
       
    32 end
    30 end