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;
wenzelm@55210
     1
(*  Title:      HOL/Word/Bits.thy
haftmann@37655
     2
    Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
kleing@24334
     3
*)
kleing@24334
     4
wenzelm@61799
     5
section \<open>Syntactic classes for bitwise operations\<close>
kleing@24333
     6
haftmann@54854
     7
theory Bits
haftmann@54847
     8
imports Main
kleing@24333
     9
begin
kleing@24333
    10
haftmann@29608
    11
class bit =
haftmann@26559
    12
  fixes bitNOT :: "'a \<Rightarrow> 'a"       ("NOT _" [70] 71)
haftmann@26559
    13
    and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "AND" 64)
haftmann@26559
    14
    and bitOR  :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "OR"  59)
haftmann@26559
    15
    and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "XOR" 59)
kleing@24333
    16
wenzelm@61799
    17
text \<open>
kleing@24333
    18
  We want the bitwise operations to bind slightly weaker
wenzelm@61799
    19
  than \<open>+\<close> and \<open>-\<close>, but \<open>~~\<close> to 
wenzelm@61799
    20
  bind slightly stronger than \<open>*\<close>.
wenzelm@61799
    21
\<close>
huffman@24352
    22
wenzelm@61799
    23
text \<open>
kleing@24333
    24
  Testing and shifting operations.
wenzelm@61799
    25
\<close>
haftmann@26559
    26
haftmann@26559
    27
class bits = bit +
haftmann@26559
    28
  fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool" (infixl "!!" 100)
haftmann@26559
    29
    and lsb      :: "'a \<Rightarrow> bool"
haftmann@26559
    30
    and set_bit  :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a"
haftmann@26559
    31
    and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a" (binder "BITS " 10)
haftmann@26559
    32
    and shiftl   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl "<<" 55)
haftmann@26559
    33
    and shiftr   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl ">>" 55)
haftmann@26559
    34
haftmann@26559
    35
class bitss = bits +
haftmann@26559
    36
  fixes msb      :: "'a \<Rightarrow> bool"
kleing@24333
    37
haftmann@25762
    38
end
kleing@24333
    39