equal
deleted
inserted
replaced
|
1 (* Title: HOL/Word/Bits_Z2.thy |
|
2 Author: Author: Brian Huffman, PSU and Gerwin Klein, NICTA |
|
3 *) |
|
4 |
|
5 section \<open>Bit operations in $\cal Z_2$\<close> |
|
6 |
|
7 theory Bits_Z2 |
|
8 imports Bits "HOL-Library.Z2" |
|
9 begin |
|
10 |
|
11 instantiation bit :: bit_operations |
|
12 begin |
|
13 |
|
14 primrec bitNOT_bit |
|
15 where |
|
16 "NOT 0 = (1::bit)" |
|
17 | "NOT 1 = (0::bit)" |
|
18 |
|
19 primrec bitAND_bit |
|
20 where |
|
21 "0 AND y = (0::bit)" |
|
22 | "1 AND y = (y::bit)" |
|
23 |
|
24 primrec bitOR_bit |
|
25 where |
|
26 "0 OR y = (y::bit)" |
|
27 | "1 OR y = (1::bit)" |
|
28 |
|
29 primrec bitXOR_bit |
|
30 where |
|
31 "0 XOR y = (y::bit)" |
|
32 | "1 XOR y = (NOT y :: bit)" |
|
33 |
|
34 instance .. |
|
35 |
|
36 end |
|
37 |
|
38 lemmas bit_simps = |
|
39 bitNOT_bit.simps bitAND_bit.simps bitOR_bit.simps bitXOR_bit.simps |
|
40 |
|
41 lemma bit_extra_simps [simp]: |
|
42 "x AND 0 = 0" |
|
43 "x AND 1 = x" |
|
44 "x OR 1 = 1" |
|
45 "x OR 0 = x" |
|
46 "x XOR 1 = NOT x" |
|
47 "x XOR 0 = x" |
|
48 for x :: bit |
|
49 by (cases x; auto)+ |
|
50 |
|
51 lemma bit_ops_comm: |
|
52 "x AND y = y AND x" |
|
53 "x OR y = y OR x" |
|
54 "x XOR y = y XOR x" |
|
55 for x :: bit |
|
56 by (cases y; auto)+ |
|
57 |
|
58 lemma bit_ops_same [simp]: |
|
59 "x AND x = x" |
|
60 "x OR x = x" |
|
61 "x XOR x = 0" |
|
62 for x :: bit |
|
63 by (cases x; auto)+ |
|
64 |
|
65 lemma bit_not_not [simp]: "NOT (NOT x) = x" |
|
66 for x :: bit |
|
67 by (cases x) auto |
|
68 |
|
69 lemma bit_or_def: "b OR c = NOT (NOT b AND NOT c)" |
|
70 for b c :: bit |
|
71 by (induct b) simp_all |
|
72 |
|
73 lemma bit_xor_def: "b XOR c = (b AND NOT c) OR (NOT b AND c)" |
|
74 for b c :: bit |
|
75 by (induct b) simp_all |
|
76 |
|
77 lemma bit_NOT_eq_1_iff [simp]: "NOT b = 1 \<longleftrightarrow> b = 0" |
|
78 for b :: bit |
|
79 by (induct b) simp_all |
|
80 |
|
81 lemma bit_AND_eq_1_iff [simp]: "a AND b = 1 \<longleftrightarrow> a = 1 \<and> b = 1" |
|
82 for a b :: bit |
|
83 by (induct a) simp_all |
|
84 |
|
85 lemma bit_nand_same [simp]: "x AND NOT x = 0" |
|
86 for x :: bit |
|
87 by (cases x) simp_all |
|
88 |
|
89 end |