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
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@58874
     5
section {* Syntactic classes for bitwise operations *}
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
kleing@24333
    17
text {*
kleing@24333
    18
  We want the bitwise operations to bind slightly weaker
kleing@24333
    19
  than @{text "+"} and @{text "-"}, but @{text "~~"} to 
kleing@24333
    20
  bind slightly stronger than @{text "*"}.
kleing@24333
    21
*}
huffman@24352
    22
kleing@24333
    23
text {*
kleing@24333
    24
  Testing and shifting operations.
kleing@24333
    25
*}
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