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
     1 (*  Title:      HOL/Word/Bits_Bit.thy

     2     Author:     Author: Brian Huffman, PSU and Gerwin Klein, NICTA

     3 *)

     4

     5 section {* Bit operations in $\cal Z_2$ *}

     6

     7 theory Bits_Bit

     8 imports Bits "~~/src/HOL/Library/Bit"

     9 begin

    10

    11 instantiation bit :: bit

    12 begin

    13

    14 primrec bitNOT_bit where

    15   "NOT 0 = (1::bit)"

    16   | "NOT 1 = (0::bit)"

    17

    18 primrec bitAND_bit where

    19   "0 AND y = (0::bit)"

    20   | "1 AND y = (y::bit)"

    21

    22 primrec bitOR_bit where

    23   "0 OR y = (y::bit)"

    24   | "1 OR y = (1::bit)"

    25

    26 primrec bitXOR_bit where

    27   "0 XOR y = (y::bit)"

    28   | "1 XOR y = (NOT y :: bit)"

    29

    30 instance  ..

    31

    32 end

    33

    34 lemmas bit_simps =

    35   bitNOT_bit.simps bitAND_bit.simps bitOR_bit.simps bitXOR_bit.simps

    36

    37 lemma bit_extra_simps [simp]:

    38   "x AND 0 = (0::bit)"

    39   "x AND 1 = (x::bit)"

    40   "x OR 1 = (1::bit)"

    41   "x OR 0 = (x::bit)"

    42   "x XOR 1 = NOT (x::bit)"

    43   "x XOR 0 = (x::bit)"

    44   by (cases x, auto)+

    45

    46 lemma bit_ops_comm:

    47   "(x::bit) AND y = y AND x"

    48   "(x::bit) OR y = y OR x"

    49   "(x::bit) XOR y = y XOR x"

    50   by (cases y, auto)+

    51

    52 lemma bit_ops_same [simp]:

    53   "(x::bit) AND x = x"

    54   "(x::bit) OR x = x"

    55   "(x::bit) XOR x = 0"

    56   by (cases x, auto)+

    57

    58 lemma bit_not_not [simp]: "NOT (NOT (x::bit)) = x"

    59   by (cases x) auto

    60

    61 lemma bit_or_def: "(b::bit) OR c = NOT (NOT b AND NOT c)"

    62   by (induct b, simp_all)

    63

    64 lemma bit_xor_def: "(b::bit) XOR c = (b AND NOT c) OR (NOT b AND c)"

    65   by (induct b, simp_all)

    66

    67 lemma bit_NOT_eq_1_iff [simp]: "NOT (b::bit) = 1 \<longleftrightarrow> b = 0"

    68   by (induct b, simp_all)

    69

    70 lemma bit_AND_eq_1_iff [simp]: "(a::bit) AND b = 1 \<longleftrightarrow> a = 1 \<and> b = 1"

    71   by (induct a, simp_all)

    72

    73 end