src/HOL/Word/Bits_Bit.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_Bit.thy
haftmann@54224
     2
    Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA
haftmann@54224
     3
*)
haftmann@54224
     4
wenzelm@58874
     5
section {* Bit operations in $\cal Z_2$ *}
haftmann@54224
     6
haftmann@54854
     7
theory Bits_Bit
haftmann@54854
     8
imports Bits "~~/src/HOL/Library/Bit"
haftmann@54224
     9
begin
haftmann@54224
    10
haftmann@54224
    11
instantiation bit :: bit
haftmann@54224
    12
begin
haftmann@54224
    13
haftmann@54224
    14
primrec bitNOT_bit where
haftmann@54224
    15
  "NOT 0 = (1::bit)"
haftmann@54224
    16
  | "NOT 1 = (0::bit)"
haftmann@54224
    17
haftmann@54224
    18
primrec bitAND_bit where
haftmann@54224
    19
  "0 AND y = (0::bit)"
haftmann@54224
    20
  | "1 AND y = (y::bit)"
haftmann@54224
    21
haftmann@54224
    22
primrec bitOR_bit where
haftmann@54224
    23
  "0 OR y = (y::bit)"
haftmann@54224
    24
  | "1 OR y = (1::bit)"
haftmann@54224
    25
haftmann@54224
    26
primrec bitXOR_bit where
haftmann@54224
    27
  "0 XOR y = (y::bit)"
haftmann@54224
    28
  | "1 XOR y = (NOT y :: bit)"
haftmann@54224
    29
haftmann@54224
    30
instance  ..
haftmann@54224
    31
haftmann@54224
    32
end
haftmann@54224
    33
haftmann@54224
    34
lemmas bit_simps =
haftmann@54224
    35
  bitNOT_bit.simps bitAND_bit.simps bitOR_bit.simps bitXOR_bit.simps
haftmann@54224
    36
haftmann@54224
    37
lemma bit_extra_simps [simp]: 
haftmann@54224
    38
  "x AND 0 = (0::bit)"
haftmann@54224
    39
  "x AND 1 = (x::bit)"
haftmann@54224
    40
  "x OR 1 = (1::bit)"
haftmann@54224
    41
  "x OR 0 = (x::bit)"
haftmann@54224
    42
  "x XOR 1 = NOT (x::bit)"
haftmann@54224
    43
  "x XOR 0 = (x::bit)"
haftmann@54224
    44
  by (cases x, auto)+
haftmann@54224
    45
haftmann@54224
    46
lemma bit_ops_comm: 
haftmann@54224
    47
  "(x::bit) AND y = y AND x"
haftmann@54224
    48
  "(x::bit) OR y = y OR x"
haftmann@54224
    49
  "(x::bit) XOR y = y XOR x"
haftmann@54224
    50
  by (cases y, auto)+
haftmann@54224
    51
haftmann@54224
    52
lemma bit_ops_same [simp]: 
haftmann@54224
    53
  "(x::bit) AND x = x"
haftmann@54224
    54
  "(x::bit) OR x = x"
haftmann@54224
    55
  "(x::bit) XOR x = 0"
haftmann@54224
    56
  by (cases x, auto)+
haftmann@54224
    57
haftmann@54224
    58
lemma bit_not_not [simp]: "NOT (NOT (x::bit)) = x"
haftmann@54224
    59
  by (cases x) auto
haftmann@54224
    60
haftmann@54224
    61
lemma bit_or_def: "(b::bit) OR c = NOT (NOT b AND NOT c)"
haftmann@54224
    62
  by (induct b, simp_all)
haftmann@54224
    63
haftmann@54224
    64
lemma bit_xor_def: "(b::bit) XOR c = (b AND NOT c) OR (NOT b AND c)"
haftmann@54224
    65
  by (induct b, simp_all)
haftmann@54224
    66
haftmann@54224
    67
lemma bit_NOT_eq_1_iff [simp]: "NOT (b::bit) = 1 \<longleftrightarrow> b = 0"
haftmann@54224
    68
  by (induct b, simp_all)
haftmann@54224
    69
haftmann@54224
    70
lemma bit_AND_eq_1_iff [simp]: "(a::bit) AND b = 1 \<longleftrightarrow> a = 1 \<and> b = 1"
haftmann@54224
    71
  by (induct a, simp_all)
haftmann@54224
    72
haftmann@54224
    73
end