| author | wenzelm | 
| Thu, 04 Apr 2013 18:44:22 +0200 | |
| changeset 51620 | 7c39677f9ea0 | 
| parent 47219 | 172c031ad743 | 
| child 53062 | 3af1a6020014 | 
| permissions | -rw-r--r-- | 
| 24333 | 1 | (* | 
| 2 | Author: Jeremy Dawson and Gerwin Klein, NICTA | |
| 3 | ||
| 44939 
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
 kleing parents: 
37667diff
changeset | 4 | Definitions and basic theorems for bit-wise logical operations | 
| 24333 | 5 | for integers expressed using Pls, Min, BIT, | 
| 44939 
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
 kleing parents: 
37667diff
changeset | 6 | and converting them to and from lists of bools. | 
| 24333 | 7 | *) | 
| 8 | ||
| 24350 | 9 | header {* Bitwise Operations on Binary Integers *}
 | 
| 10 | ||
| 37658 | 11 | theory Bit_Int | 
| 12 | imports Bit_Representation Bit_Operations | |
| 24333 | 13 | begin | 
| 14 | ||
| 24364 | 15 | subsection {* Logical operations *}
 | 
| 24353 | 16 | |
| 17 | text "bit-wise logical operations on the int type" | |
| 18 | ||
| 25762 | 19 | instantiation int :: bit | 
| 20 | begin | |
| 21 | ||
| 46019 | 22 | definition int_not_def: | 
| 23 | "bitNOT = (\<lambda>x::int. - x - 1)" | |
| 24 | ||
| 25 | function bitAND_int where | |
| 26 | "bitAND_int x y = | |
| 27 | (if x = 0 then 0 else if x = -1 then y else | |
| 28 | (bin_rest x AND bin_rest y) BIT (bin_last x AND bin_last y))" | |
| 29 | by pat_completeness simp | |
| 25762 | 30 | |
| 46019 | 31 | termination | 
| 32 | by (relation "measure (nat o abs o fst)", simp_all add: bin_rest_def) | |
| 33 | ||
| 34 | declare bitAND_int.simps [simp del] | |
| 25762 | 35 | |
| 46019 | 36 | definition int_or_def: | 
| 37 | "bitOR = (\<lambda>x y::int. NOT (NOT x AND NOT y))" | |
| 25762 | 38 | |
| 46019 | 39 | definition int_xor_def: | 
| 40 | "bitXOR = (\<lambda>x y::int. (x AND NOT y) OR (NOT x AND y))" | |
| 25762 | 41 | |
| 42 | instance .. | |
| 43 | ||
| 44 | end | |
| 24353 | 45 | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 46 | subsubsection {* Basic simplification rules *}
 | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 47 | |
| 46016 | 48 | lemma int_not_BIT [simp]: | 
| 49 | "NOT (w BIT b) = (NOT w) BIT (NOT b)" | |
| 50 | unfolding int_not_def Bit_def by (cases b, simp_all) | |
| 51 | ||
| 24333 | 52 | lemma int_not_simps [simp]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 53 | "NOT (0::int) = -1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 54 | "NOT (1::int) = -2" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 55 | "NOT (-1::int) = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 56 | "NOT (numeral w::int) = neg_numeral (w + Num.One)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 57 | "NOT (neg_numeral (Num.Bit0 w)::int) = numeral (Num.BitM w)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 58 | "NOT (neg_numeral (Num.Bit1 w)::int) = numeral (Num.Bit0 w)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 59 | unfolding int_not_def by simp_all | 
| 24333 | 60 | |
| 46017 | 61 | lemma int_not_not [simp]: "NOT (NOT (x::int)) = x" | 
| 62 | unfolding int_not_def by simp | |
| 63 | ||
| 46019 | 64 | lemma int_and_0 [simp]: "(0::int) AND x = 0" | 
| 65 | by (simp add: bitAND_int.simps) | |
| 66 | ||
| 67 | lemma int_and_m1 [simp]: "(-1::int) AND x = x" | |
| 68 | by (simp add: bitAND_int.simps) | |
| 69 | ||
| 70 | lemma Bit_eq_0_iff: "w BIT b = 0 \<longleftrightarrow> w = 0 \<and> b = 0" | |
| 71 | by (subst BIT_eq_iff [symmetric], simp) | |
| 72 | ||
| 73 | lemma Bit_eq_m1_iff: "w BIT b = -1 \<longleftrightarrow> w = -1 \<and> b = 1" | |
| 74 | by (subst BIT_eq_iff [symmetric], simp) | |
| 46017 | 75 | |
| 76 | lemma int_and_Bits [simp]: | |
| 77 | "(x BIT b) AND (y BIT c) = (x AND y) BIT (b AND c)" | |
| 46019 | 78 | by (subst bitAND_int.simps, simp add: Bit_eq_0_iff Bit_eq_m1_iff) | 
| 46017 | 79 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 80 | lemma int_or_zero [simp]: "(0::int) OR x = x" | 
| 46017 | 81 | unfolding int_or_def by simp | 
| 46018 | 82 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 83 | lemma int_or_minus1 [simp]: "(-1::int) OR x = -1" | 
| 46017 | 84 | unfolding int_or_def by simp | 
| 85 | ||
| 86 | lemma bit_or_def: "(b::bit) OR c = NOT (NOT b AND NOT c)" | |
| 87 | by (induct b, simp_all) (* TODO: move *) | |
| 24333 | 88 | |
| 89 | lemma int_or_Bits [simp]: | |
| 24353 | 90 | "(x BIT b) OR (y BIT c) = (x OR y) BIT (b OR c)" | 
| 46017 | 91 | unfolding int_or_def bit_or_def by simp | 
| 24333 | 92 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 93 | lemma int_xor_zero [simp]: "(0::int) XOR x = x" | 
| 46018 | 94 | unfolding int_xor_def by simp | 
| 95 | ||
| 96 | lemma bit_xor_def: "(b::bit) XOR c = (b AND NOT c) OR (NOT b AND c)" | |
| 97 | by (induct b, simp_all) (* TODO: move *) | |
| 98 | ||
| 99 | lemma int_xor_Bits [simp]: | |
| 100 | "(x BIT b) XOR (y BIT c) = (x XOR y) BIT (b XOR c)" | |
| 101 | unfolding int_xor_def bit_xor_def by simp | |
| 102 | ||
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 103 | subsubsection {* Binary destructors *}
 | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 104 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 105 | lemma bin_rest_NOT [simp]: "bin_rest (NOT x) = NOT (bin_rest x)" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 106 | by (cases x rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 107 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 108 | lemma bin_last_NOT [simp]: "bin_last (NOT x) = NOT (bin_last x)" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 109 | by (cases x rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 110 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 111 | lemma bin_rest_AND [simp]: "bin_rest (x AND y) = bin_rest x AND bin_rest y" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 112 | by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 113 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 114 | lemma bin_last_AND [simp]: "bin_last (x AND y) = bin_last x AND bin_last y" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 115 | by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 116 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 117 | lemma bin_rest_OR [simp]: "bin_rest (x OR y) = bin_rest x OR bin_rest y" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 118 | by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 119 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 120 | lemma bin_last_OR [simp]: "bin_last (x OR y) = bin_last x OR bin_last y" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 121 | by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 122 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 123 | lemma bin_rest_XOR [simp]: "bin_rest (x XOR y) = bin_rest x XOR bin_rest y" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 124 | by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 125 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 126 | lemma bin_last_XOR [simp]: "bin_last (x XOR y) = bin_last x XOR bin_last y" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 127 | by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 128 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 129 | lemma bit_NOT_eq_1_iff [simp]: "NOT (b::bit) = 1 \<longleftrightarrow> b = 0" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 130 | by (induct b, simp_all) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 131 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 132 | lemma bit_AND_eq_1_iff [simp]: "(a::bit) AND b = 1 \<longleftrightarrow> a = 1 \<and> b = 1" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 133 | by (induct a, simp_all) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 134 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 135 | lemma bin_nth_ops: | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 136 | "!!x y. bin_nth (x AND y) n = (bin_nth x n & bin_nth y n)" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 137 | "!!x y. bin_nth (x OR y) n = (bin_nth x n | bin_nth y n)" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 138 | "!!x y. bin_nth (x XOR y) n = (bin_nth x n ~= bin_nth y n)" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 139 | "!!x. bin_nth (NOT x) n = (~ bin_nth x n)" | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 140 | by (induct n) auto | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 141 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 142 | subsubsection {* Derived properties *}
 | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 143 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 144 | lemma int_xor_minus1 [simp]: "(-1::int) XOR x = NOT x" | 
| 46018 | 145 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 146 | ||
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 147 | lemma int_xor_extra_simps [simp]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 148 | "w XOR (0::int) = w" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 149 | "w XOR (-1::int) = NOT w" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 150 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 151 | |
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 152 | lemma int_or_extra_simps [simp]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 153 | "w OR (0::int) = w" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 154 | "w OR (-1::int) = -1" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 155 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 156 | |
| 37667 | 157 | lemma int_and_extra_simps [simp]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 158 | "w AND (0::int) = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 159 | "w AND (-1::int) = w" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 160 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 161 | |
| 162 | (* commutativity of the above *) | |
| 163 | lemma bin_ops_comm: | |
| 164 | shows | |
| 24353 | 165 | int_and_comm: "!!y::int. x AND y = y AND x" and | 
| 166 | int_or_comm: "!!y::int. x OR y = y OR x" and | |
| 167 | int_xor_comm: "!!y::int. x XOR y = y XOR x" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 168 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 169 | |
| 170 | lemma bin_ops_same [simp]: | |
| 24353 | 171 | "(x::int) AND x = x" | 
| 172 | "(x::int) OR x = x" | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 173 | "(x::int) XOR x = 0" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 174 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 175 | |
| 176 | lemmas bin_log_esimps = | |
| 177 | int_and_extra_simps int_or_extra_simps int_xor_extra_simps | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 178 | int_and_0 int_and_m1 int_or_zero int_or_minus1 int_xor_zero int_xor_minus1 | 
| 24333 | 179 | |
| 180 | (* basic properties of logical (bit-wise) operations *) | |
| 181 | ||
| 182 | lemma bbw_ao_absorb: | |
| 24353 | 183 | "!!y::int. x AND (y OR x) = x & x OR (y AND x) = x" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 184 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 185 | |
| 186 | lemma bbw_ao_absorbs_other: | |
| 24353 | 187 | "x AND (x OR y) = x \<and> (y AND x) OR x = (x::int)" | 
| 188 | "(y OR x) AND x = x \<and> x OR (x AND y) = (x::int)" | |
| 189 | "(x OR y) AND x = x \<and> (x AND y) OR x = (x::int)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 190 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24353 | 191 | |
| 24333 | 192 | lemmas bbw_ao_absorbs [simp] = bbw_ao_absorb bbw_ao_absorbs_other | 
| 193 | ||
| 194 | lemma int_xor_not: | |
| 24353 | 195 | "!!y::int. (NOT x) XOR y = NOT (x XOR y) & | 
| 196 | x XOR (NOT y) = NOT (x XOR y)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 197 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 198 | |
| 199 | lemma int_and_assoc: | |
| 24353 | 200 | "(x AND y) AND (z::int) = x AND (y AND z)" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 201 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 202 | |
| 203 | lemma int_or_assoc: | |
| 24353 | 204 | "(x OR y) OR (z::int) = x OR (y OR z)" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 205 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 206 | |
| 207 | lemma int_xor_assoc: | |
| 24353 | 208 | "(x XOR y) XOR (z::int) = x XOR (y XOR z)" | 
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 209 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 210 | |
| 211 | lemmas bbw_assocs = int_and_assoc int_or_assoc int_xor_assoc | |
| 212 | ||
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 213 | (* BH: Why are these declared as simp rules??? *) | 
| 24333 | 214 | lemma bbw_lcs [simp]: | 
| 24353 | 215 | "(y::int) AND (x AND z) = x AND (y AND z)" | 
| 216 | "(y::int) OR (x OR z) = x OR (y OR z)" | |
| 217 | "(y::int) XOR (x XOR z) = x XOR (y XOR z)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 218 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 219 | |
| 220 | lemma bbw_not_dist: | |
| 24353 | 221 | "!!y::int. NOT (x OR y) = (NOT x) AND (NOT y)" | 
| 222 | "!!y::int. NOT (x AND y) = (NOT x) OR (NOT y)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 223 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 224 | |
| 225 | lemma bbw_oa_dist: | |
| 24353 | 226 | "!!y z::int. (x AND y) OR z = | 
| 227 | (x OR z) AND (y OR z)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 228 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 229 | |
| 230 | lemma bbw_ao_dist: | |
| 24353 | 231 | "!!y z::int. (x OR y) AND z = | 
| 232 | (x AND z) OR (y AND z)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 233 | by (auto simp add: bin_eq_iff bin_nth_ops) | 
| 24333 | 234 | |
| 24367 
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
 huffman parents: 
24366diff
changeset | 235 | (* | 
| 
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
 huffman parents: 
24366diff
changeset | 236 | Why were these declared simp??? | 
| 24333 | 237 | declare bin_ops_comm [simp] bbw_assocs [simp] | 
| 24367 
3e29eafabe16
AC rules for bitwise logical operators no longer declared simp
 huffman parents: 
24366diff
changeset | 238 | *) | 
| 24333 | 239 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 240 | subsubsection {* Simplification with numerals *}
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 241 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 242 | text {* Cases for @{text "0"} and @{text "-1"} are already covered by
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 243 | other simp rules. *} | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 244 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 245 | lemma bin_rl_eqI: "\<lbrakk>bin_rest x = bin_rest y; bin_last x = bin_last y\<rbrakk> \<Longrightarrow> x = y" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 246 | by (metis bin_rl_simp) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 247 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 248 | lemma bin_rest_neg_numeral_BitM [simp]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 249 | "bin_rest (neg_numeral (Num.BitM w)) = neg_numeral w" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 250 | by (simp only: BIT_bin_simps [symmetric] bin_rest_BIT) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 251 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 252 | lemma bin_last_neg_numeral_BitM [simp]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 253 | "bin_last (neg_numeral (Num.BitM w)) = 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 254 | by (simp only: BIT_bin_simps [symmetric] bin_last_BIT) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 255 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 256 | text {* FIXME: The rule sets below are very large (24 rules for each
 | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 257 | operator). Is there a simpler way to do this? *} | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 258 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 259 | lemma int_and_numerals [simp]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 260 | "numeral (Num.Bit0 x) AND numeral (Num.Bit0 y) = (numeral x AND numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 261 | "numeral (Num.Bit0 x) AND numeral (Num.Bit1 y) = (numeral x AND numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 262 | "numeral (Num.Bit1 x) AND numeral (Num.Bit0 y) = (numeral x AND numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 263 | "numeral (Num.Bit1 x) AND numeral (Num.Bit1 y) = (numeral x AND numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 264 | "numeral (Num.Bit0 x) AND neg_numeral (Num.Bit0 y) = (numeral x AND neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 265 | "numeral (Num.Bit0 x) AND neg_numeral (Num.Bit1 y) = (numeral x AND neg_numeral (y + Num.One)) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 266 | "numeral (Num.Bit1 x) AND neg_numeral (Num.Bit0 y) = (numeral x AND neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 267 | "numeral (Num.Bit1 x) AND neg_numeral (Num.Bit1 y) = (numeral x AND neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 268 | "neg_numeral (Num.Bit0 x) AND numeral (Num.Bit0 y) = (neg_numeral x AND numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 269 | "neg_numeral (Num.Bit0 x) AND numeral (Num.Bit1 y) = (neg_numeral x AND numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 270 | "neg_numeral (Num.Bit1 x) AND numeral (Num.Bit0 y) = (neg_numeral (x + Num.One) AND numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 271 | "neg_numeral (Num.Bit1 x) AND numeral (Num.Bit1 y) = (neg_numeral (x + Num.One) AND numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 272 | "neg_numeral (Num.Bit0 x) AND neg_numeral (Num.Bit0 y) = (neg_numeral x AND neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 273 | "neg_numeral (Num.Bit0 x) AND neg_numeral (Num.Bit1 y) = (neg_numeral x AND neg_numeral (y + Num.One)) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 274 | "neg_numeral (Num.Bit1 x) AND neg_numeral (Num.Bit0 y) = (neg_numeral (x + Num.One) AND neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 275 | "neg_numeral (Num.Bit1 x) AND neg_numeral (Num.Bit1 y) = (neg_numeral (x + Num.One) AND neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 276 | "(1::int) AND numeral (Num.Bit0 y) = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 277 | "(1::int) AND numeral (Num.Bit1 y) = 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 278 | "(1::int) AND neg_numeral (Num.Bit0 y) = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 279 | "(1::int) AND neg_numeral (Num.Bit1 y) = 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 280 | "numeral (Num.Bit0 x) AND (1::int) = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 281 | "numeral (Num.Bit1 x) AND (1::int) = 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 282 | "neg_numeral (Num.Bit0 x) AND (1::int) = 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 283 | "neg_numeral (Num.Bit1 x) AND (1::int) = 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 284 | by (rule bin_rl_eqI, simp, simp)+ | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 285 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 286 | lemma int_or_numerals [simp]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 287 | "numeral (Num.Bit0 x) OR numeral (Num.Bit0 y) = (numeral x OR numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 288 | "numeral (Num.Bit0 x) OR numeral (Num.Bit1 y) = (numeral x OR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 289 | "numeral (Num.Bit1 x) OR numeral (Num.Bit0 y) = (numeral x OR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 290 | "numeral (Num.Bit1 x) OR numeral (Num.Bit1 y) = (numeral x OR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 291 | "numeral (Num.Bit0 x) OR neg_numeral (Num.Bit0 y) = (numeral x OR neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 292 | "numeral (Num.Bit0 x) OR neg_numeral (Num.Bit1 y) = (numeral x OR neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 293 | "numeral (Num.Bit1 x) OR neg_numeral (Num.Bit0 y) = (numeral x OR neg_numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 294 | "numeral (Num.Bit1 x) OR neg_numeral (Num.Bit1 y) = (numeral x OR neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 295 | "neg_numeral (Num.Bit0 x) OR numeral (Num.Bit0 y) = (neg_numeral x OR numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 296 | "neg_numeral (Num.Bit0 x) OR numeral (Num.Bit1 y) = (neg_numeral x OR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 297 | "neg_numeral (Num.Bit1 x) OR numeral (Num.Bit0 y) = (neg_numeral (x + Num.One) OR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 298 | "neg_numeral (Num.Bit1 x) OR numeral (Num.Bit1 y) = (neg_numeral (x + Num.One) OR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 299 | "neg_numeral (Num.Bit0 x) OR neg_numeral (Num.Bit0 y) = (neg_numeral x OR neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 300 | "neg_numeral (Num.Bit0 x) OR neg_numeral (Num.Bit1 y) = (neg_numeral x OR neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 301 | "neg_numeral (Num.Bit1 x) OR neg_numeral (Num.Bit0 y) = (neg_numeral (x + Num.One) OR neg_numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 302 | "neg_numeral (Num.Bit1 x) OR neg_numeral (Num.Bit1 y) = (neg_numeral (x + Num.One) OR neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 303 | "(1::int) OR numeral (Num.Bit0 y) = numeral (Num.Bit1 y)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 304 | "(1::int) OR numeral (Num.Bit1 y) = numeral (Num.Bit1 y)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 305 | "(1::int) OR neg_numeral (Num.Bit0 y) = neg_numeral (Num.BitM y)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 306 | "(1::int) OR neg_numeral (Num.Bit1 y) = neg_numeral (Num.Bit1 y)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 307 | "numeral (Num.Bit0 x) OR (1::int) = numeral (Num.Bit1 x)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 308 | "numeral (Num.Bit1 x) OR (1::int) = numeral (Num.Bit1 x)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 309 | "neg_numeral (Num.Bit0 x) OR (1::int) = neg_numeral (Num.BitM x)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 310 | "neg_numeral (Num.Bit1 x) OR (1::int) = neg_numeral (Num.Bit1 x)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 311 | by (rule bin_rl_eqI, simp, simp)+ | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 312 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 313 | lemma int_xor_numerals [simp]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 314 | "numeral (Num.Bit0 x) XOR numeral (Num.Bit0 y) = (numeral x XOR numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 315 | "numeral (Num.Bit0 x) XOR numeral (Num.Bit1 y) = (numeral x XOR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 316 | "numeral (Num.Bit1 x) XOR numeral (Num.Bit0 y) = (numeral x XOR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 317 | "numeral (Num.Bit1 x) XOR numeral (Num.Bit1 y) = (numeral x XOR numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 318 | "numeral (Num.Bit0 x) XOR neg_numeral (Num.Bit0 y) = (numeral x XOR neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 319 | "numeral (Num.Bit0 x) XOR neg_numeral (Num.Bit1 y) = (numeral x XOR neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 320 | "numeral (Num.Bit1 x) XOR neg_numeral (Num.Bit0 y) = (numeral x XOR neg_numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 321 | "numeral (Num.Bit1 x) XOR neg_numeral (Num.Bit1 y) = (numeral x XOR neg_numeral (y + Num.One)) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 322 | "neg_numeral (Num.Bit0 x) XOR numeral (Num.Bit0 y) = (neg_numeral x XOR numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 323 | "neg_numeral (Num.Bit0 x) XOR numeral (Num.Bit1 y) = (neg_numeral x XOR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 324 | "neg_numeral (Num.Bit1 x) XOR numeral (Num.Bit0 y) = (neg_numeral (x + Num.One) XOR numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 325 | "neg_numeral (Num.Bit1 x) XOR numeral (Num.Bit1 y) = (neg_numeral (x + Num.One) XOR numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 326 | "neg_numeral (Num.Bit0 x) XOR neg_numeral (Num.Bit0 y) = (neg_numeral x XOR neg_numeral y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 327 | "neg_numeral (Num.Bit0 x) XOR neg_numeral (Num.Bit1 y) = (neg_numeral x XOR neg_numeral (y + Num.One)) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 328 | "neg_numeral (Num.Bit1 x) XOR neg_numeral (Num.Bit0 y) = (neg_numeral (x + Num.One) XOR neg_numeral y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 329 | "neg_numeral (Num.Bit1 x) XOR neg_numeral (Num.Bit1 y) = (neg_numeral (x + Num.One) XOR neg_numeral (y + Num.One)) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 330 | "(1::int) XOR numeral (Num.Bit0 y) = numeral (Num.Bit1 y)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 331 | "(1::int) XOR numeral (Num.Bit1 y) = numeral (Num.Bit0 y)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 332 | "(1::int) XOR neg_numeral (Num.Bit0 y) = neg_numeral (Num.BitM y)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 333 | "(1::int) XOR neg_numeral (Num.Bit1 y) = neg_numeral (Num.Bit0 (y + Num.One))" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 334 | "numeral (Num.Bit0 x) XOR (1::int) = numeral (Num.Bit1 x)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 335 | "numeral (Num.Bit1 x) XOR (1::int) = numeral (Num.Bit0 x)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 336 | "neg_numeral (Num.Bit0 x) XOR (1::int) = neg_numeral (Num.BitM x)" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 337 | "neg_numeral (Num.Bit1 x) XOR (1::int) = neg_numeral (Num.Bit0 (x + Num.One))" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 338 | by (rule bin_rl_eqI, simp, simp)+ | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 339 | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 340 | subsubsection {* Interactions with arithmetic *}
 | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 341 | |
| 24333 | 342 | lemma plus_and_or [rule_format]: | 
| 24353 | 343 | "ALL y::int. (x AND y) + (x OR y) = x + y" | 
| 24333 | 344 | apply (induct x rule: bin_induct) | 
| 345 | apply clarsimp | |
| 346 | apply clarsimp | |
| 347 | apply clarsimp | |
| 348 | apply (case_tac y rule: bin_exhaust) | |
| 349 | apply clarsimp | |
| 350 | apply (unfold Bit_def) | |
| 351 | apply clarsimp | |
| 352 | apply (erule_tac x = "x" in allE) | |
| 37667 | 353 | apply (simp add: bitval_def split: bit.split) | 
| 24333 | 354 | done | 
| 355 | ||
| 356 | lemma le_int_or: | |
| 46604 
9f9e85264e4d
make uses of bin_sign respect int/bin distinction
 huffman parents: 
46023diff
changeset | 357 | "bin_sign (y::int) = 0 ==> x <= x OR y" | 
| 37667 | 358 | apply (induct y arbitrary: x rule: bin_induct) | 
| 24333 | 359 | apply clarsimp | 
| 360 | apply clarsimp | |
| 361 | apply (case_tac x rule: bin_exhaust) | |
| 362 | apply (case_tac b) | |
| 363 | apply (case_tac [!] bit) | |
| 46604 
9f9e85264e4d
make uses of bin_sign respect int/bin distinction
 huffman parents: 
46023diff
changeset | 364 | apply (auto simp: le_Bits) | 
| 24333 | 365 | done | 
| 366 | ||
| 367 | lemmas int_and_le = | |
| 45475 | 368 | xtr3 [OF bbw_ao_absorbs (2) [THEN conjunct2, symmetric] le_int_or] | 
| 24333 | 369 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 370 | lemma add_BIT_simps [simp]: (* FIXME: move *) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 371 | "x BIT 0 + y BIT 0 = (x + y) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 372 | "x BIT 0 + y BIT 1 = (x + y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 373 | "x BIT 1 + y BIT 0 = (x + y) BIT 1" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 374 | "x BIT 1 + y BIT 1 = (x + y + 1) BIT 0" | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 375 | by (simp_all add: Bit_B0_2t Bit_B1_2t) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 376 | |
| 24364 | 377 | (* interaction between bit-wise and arithmetic *) | 
| 378 | (* good example of bin_induction *) | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 379 | lemma bin_add_not: "x + NOT x = (-1::int)" | 
| 24364 | 380 | apply (induct x rule: bin_induct) | 
| 381 | apply clarsimp | |
| 382 | apply clarsimp | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 383 | apply (case_tac bit, auto) | 
| 24364 | 384 | done | 
| 385 | ||
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 386 | subsubsection {* Truncating results of bit-wise operations *}
 | 
| 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 387 | |
| 24364 | 388 | lemma bin_trunc_ao: | 
| 389 | "!!x y. (bintrunc n x) AND (bintrunc n y) = bintrunc n (x AND y)" | |
| 390 | "!!x y. (bintrunc n x) OR (bintrunc n y) = bintrunc n (x OR y)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 391 | by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) | 
| 24364 | 392 | |
| 393 | lemma bin_trunc_xor: | |
| 394 | "!!x y. bintrunc n (bintrunc n x XOR bintrunc n y) = | |
| 395 | bintrunc n (x XOR y)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 396 | by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) | 
| 24364 | 397 | |
| 398 | lemma bin_trunc_not: | |
| 399 | "!!x. bintrunc n (NOT (bintrunc n x)) = bintrunc n (NOT x)" | |
| 45543 
827bf668c822
HOL-Word: add simp rules for bin_rest, bin_last; shorten several proofs
 huffman parents: 
45529diff
changeset | 400 | by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr) | 
| 24364 | 401 | |
| 402 | (* want theorems of the form of bin_trunc_xor *) | |
| 403 | lemma bintr_bintr_i: | |
| 404 | "x = bintrunc n y ==> bintrunc n x = bintrunc n y" | |
| 405 | by auto | |
| 406 | ||
| 407 | lemmas bin_trunc_and = bin_trunc_ao(1) [THEN bintr_bintr_i] | |
| 408 | lemmas bin_trunc_or = bin_trunc_ao(2) [THEN bintr_bintr_i] | |
| 409 | ||
| 410 | subsection {* Setting and clearing bits *}
 | |
| 411 | ||
| 26558 | 412 | primrec | 
| 24364 | 413 | bin_sc :: "nat => bit => int => int" | 
| 26558 | 414 | where | 
| 415 | Z: "bin_sc 0 b w = bin_rest w BIT b" | |
| 416 | | Suc: "bin_sc (Suc n) b w = bin_sc n b (bin_rest w) BIT bin_last w" | |
| 24364 | 417 | |
| 24333 | 418 | (** nth bit, set/clear **) | 
| 419 | ||
| 420 | lemma bin_nth_sc [simp]: | |
| 45955 | 421 | "bin_nth (bin_sc n b w) n = (b = 1)" | 
| 422 | by (induct n arbitrary: w) auto | |
| 24333 | 423 | |
| 424 | lemma bin_sc_sc_same [simp]: | |
| 45955 | 425 | "bin_sc n c (bin_sc n b w) = bin_sc n c w" | 
| 426 | by (induct n arbitrary: w) auto | |
| 24333 | 427 | |
| 428 | lemma bin_sc_sc_diff: | |
| 45955 | 429 | "m ~= n ==> | 
| 24333 | 430 | bin_sc m c (bin_sc n b w) = bin_sc n b (bin_sc m c w)" | 
| 45955 | 431 | apply (induct n arbitrary: w m) | 
| 24333 | 432 | apply (case_tac [!] m) | 
| 433 | apply auto | |
| 434 | done | |
| 435 | ||
| 436 | lemma bin_nth_sc_gen: | |
| 45955 | 437 | "bin_nth (bin_sc n b w) m = (if m = n then b = 1 else bin_nth w m)" | 
| 438 | by (induct n arbitrary: w m) (case_tac [!] m, auto) | |
| 24333 | 439 | |
| 440 | lemma bin_sc_nth [simp]: | |
| 45955 | 441 | "(bin_sc n (If (bin_nth w n) 1 0) w) = w" | 
| 442 | by (induct n arbitrary: w) auto | |
| 24333 | 443 | |
| 444 | lemma bin_sign_sc [simp]: | |
| 45955 | 445 | "bin_sign (bin_sc n b w) = bin_sign w" | 
| 446 | by (induct n arbitrary: w) auto | |
| 24333 | 447 | |
| 448 | lemma bin_sc_bintr [simp]: | |
| 45955 | 449 | "bintrunc m (bin_sc n x (bintrunc m (w))) = bintrunc m (bin_sc n x w)" | 
| 450 | apply (induct n arbitrary: w m) | |
| 24333 | 451 | apply (case_tac [!] w rule: bin_exhaust) | 
| 452 | apply (case_tac [!] m, auto) | |
| 453 | done | |
| 454 | ||
| 455 | lemma bin_clr_le: | |
| 45955 | 456 | "bin_sc n 0 w <= w" | 
| 457 | apply (induct n arbitrary: w) | |
| 24333 | 458 | apply (case_tac [!] w rule: bin_exhaust) | 
| 46605 | 459 | apply (auto simp: le_Bits) | 
| 24333 | 460 | done | 
| 461 | ||
| 462 | lemma bin_set_ge: | |
| 45955 | 463 | "bin_sc n 1 w >= w" | 
| 464 | apply (induct n arbitrary: w) | |
| 24333 | 465 | apply (case_tac [!] w rule: bin_exhaust) | 
| 46605 | 466 | apply (auto simp: le_Bits) | 
| 24333 | 467 | done | 
| 468 | ||
| 469 | lemma bintr_bin_clr_le: | |
| 45955 | 470 | "bintrunc n (bin_sc m 0 w) <= bintrunc n w" | 
| 471 | apply (induct n arbitrary: w m) | |
| 24333 | 472 | apply simp | 
| 473 | apply (case_tac w rule: bin_exhaust) | |
| 474 | apply (case_tac m) | |
| 46605 | 475 | apply (auto simp: le_Bits) | 
| 24333 | 476 | done | 
| 477 | ||
| 478 | lemma bintr_bin_set_ge: | |
| 45955 | 479 | "bintrunc n (bin_sc m 1 w) >= bintrunc n w" | 
| 480 | apply (induct n arbitrary: w m) | |
| 24333 | 481 | apply simp | 
| 482 | apply (case_tac w rule: bin_exhaust) | |
| 483 | apply (case_tac m) | |
| 46605 | 484 | apply (auto simp: le_Bits) | 
| 24333 | 485 | done | 
| 486 | ||
| 46608 
37e383cc7831
make uses of constant bin_sc respect int/bin distinction
 huffman parents: 
46605diff
changeset | 487 | lemma bin_sc_FP [simp]: "bin_sc n 0 0 = 0" | 
| 
37e383cc7831
make uses of constant bin_sc respect int/bin distinction
 huffman parents: 
46605diff
changeset | 488 | by (induct n) auto | 
| 24333 | 489 | |
| 46608 
37e383cc7831
make uses of constant bin_sc respect int/bin distinction
 huffman parents: 
46605diff
changeset | 490 | lemma bin_sc_TM [simp]: "bin_sc n 1 -1 = -1" | 
| 
37e383cc7831
make uses of constant bin_sc respect int/bin distinction
 huffman parents: 
46605diff
changeset | 491 | by (induct n) auto | 
| 24333 | 492 | |
| 493 | lemmas bin_sc_simps = bin_sc.Z bin_sc.Suc bin_sc_TM bin_sc_FP | |
| 494 | ||
| 495 | lemma bin_sc_minus: | |
| 496 | "0 < n ==> bin_sc (Suc (n - 1)) b w = bin_sc n b w" | |
| 497 | by auto | |
| 498 | ||
| 499 | lemmas bin_sc_Suc_minus = | |
| 45604 | 500 | trans [OF bin_sc_minus [symmetric] bin_sc.Suc] | 
| 24333 | 501 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 502 | lemma bin_sc_numeral [simp]: | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46610diff
changeset | 503 | "bin_sc (numeral k) b w = | 
| 47219 
172c031ad743
restate various simp rules for word operations using pred_numeral
 huffman parents: 
47108diff
changeset | 504 | bin_sc (pred_numeral k) b (bin_rest w) BIT bin_last w" | 
| 
172c031ad743
restate various simp rules for word operations using pred_numeral
 huffman parents: 
47108diff
changeset | 505 | by (simp add: numeral_eq_Suc) | 
| 24333 | 506 | |
| 24465 | 507 | |
| 24364 | 508 | subsection {* Splitting and concatenation *}
 | 
| 24333 | 509 | |
| 26558 | 510 | definition bin_rcat :: "nat \<Rightarrow> int list \<Rightarrow> int" where | 
| 37667 | 511 | "bin_rcat n = foldl (\<lambda>u v. bin_cat u n v) 0" | 
| 512 | ||
| 28042 | 513 | fun bin_rsplit_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where | 
| 26558 | 514 | "bin_rsplit_aux n m c bs = | 
| 24364 | 515 | (if m = 0 | n = 0 then bs else | 
| 516 | let (a, b) = bin_split n c | |
| 26558 | 517 | in bin_rsplit_aux n (m - n) a (b # bs))" | 
| 24364 | 518 | |
| 26558 | 519 | definition bin_rsplit :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where | 
| 520 | "bin_rsplit n w = bin_rsplit_aux n (fst w) (snd w) []" | |
| 521 | ||
| 28042 | 522 | fun bin_rsplitl_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where | 
| 26558 | 523 | "bin_rsplitl_aux n m c bs = | 
| 24364 | 524 | (if m = 0 | n = 0 then bs else | 
| 525 | let (a, b) = bin_split (min m n) c | |
| 26558 | 526 | in bin_rsplitl_aux n (m - n) a (b # bs))" | 
| 24364 | 527 | |
| 26558 | 528 | definition bin_rsplitl :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where | 
| 529 | "bin_rsplitl n w = bin_rsplitl_aux n (fst w) (snd w) []" | |
| 530 | ||
| 24364 | 531 | declare bin_rsplit_aux.simps [simp del] | 
| 532 | declare bin_rsplitl_aux.simps [simp del] | |
| 533 | ||
| 534 | lemma bin_sign_cat: | |
| 45955 | 535 | "bin_sign (bin_cat x n y) = bin_sign x" | 
| 536 | by (induct n arbitrary: y) auto | |
| 24364 | 537 | |
| 538 | lemma bin_cat_Suc_Bit: | |
| 539 | "bin_cat w (Suc n) (v BIT b) = bin_cat w n v BIT b" | |
| 540 | by auto | |
| 541 | ||
| 542 | lemma bin_nth_cat: | |
| 45955 | 543 | "bin_nth (bin_cat x k y) n = | 
| 24364 | 544 | (if n < k then bin_nth y n else bin_nth x (n - k))" | 
| 45955 | 545 | apply (induct k arbitrary: n y) | 
| 24364 | 546 | apply clarsimp | 
| 547 | apply (case_tac n, auto) | |
| 24333 | 548 | done | 
| 549 | ||
| 24364 | 550 | lemma bin_nth_split: | 
| 45955 | 551 | "bin_split n c = (a, b) ==> | 
| 24364 | 552 | (ALL k. bin_nth a k = bin_nth c (n + k)) & | 
| 553 | (ALL k. bin_nth b k = (k < n & bin_nth c k))" | |
| 45955 | 554 | apply (induct n arbitrary: b c) | 
| 24364 | 555 | apply clarsimp | 
| 556 | apply (clarsimp simp: Let_def split: ls_splits) | |
| 557 | apply (case_tac k) | |
| 558 | apply auto | |
| 559 | done | |
| 560 | ||
| 561 | lemma bin_cat_assoc: | |
| 45955 | 562 | "bin_cat (bin_cat x m y) n z = bin_cat x (m + n) (bin_cat y n z)" | 
| 563 | by (induct n arbitrary: z) auto | |
| 24364 | 564 | |
| 45955 | 565 | lemma bin_cat_assoc_sym: | 
| 566 | "bin_cat x m (bin_cat y n z) = bin_cat (bin_cat x (m - n) y) (min m n) z" | |
| 567 | apply (induct n arbitrary: z m, clarsimp) | |
| 24364 | 568 | apply (case_tac m, auto) | 
| 24333 | 569 | done | 
| 570 | ||
| 45956 | 571 | lemma bin_cat_zero [simp]: "bin_cat 0 n w = bintrunc n w" | 
| 46001 
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
 huffman parents: 
45956diff
changeset | 572 | by (induct n arbitrary: w) auto | 
| 45956 | 573 | |
| 24364 | 574 | lemma bintr_cat1: | 
| 45955 | 575 | "bintrunc (k + n) (bin_cat a n b) = bin_cat (bintrunc k a) n b" | 
| 576 | by (induct n arbitrary: b) auto | |
| 24364 | 577 | |
| 578 | lemma bintr_cat: "bintrunc m (bin_cat a n b) = | |
| 579 | bin_cat (bintrunc (m - n) a) n (bintrunc (min m n) b)" | |
| 580 | by (rule bin_eqI) (auto simp: bin_nth_cat nth_bintr) | |
| 581 | ||
| 582 | lemma bintr_cat_same [simp]: | |
| 583 | "bintrunc n (bin_cat a n b) = bintrunc n b" | |
| 584 | by (auto simp add : bintr_cat) | |
| 585 | ||
| 586 | lemma cat_bintr [simp]: | |
| 45955 | 587 | "bin_cat a n (bintrunc n b) = bin_cat a n b" | 
| 588 | by (induct n arbitrary: b) auto | |
| 24364 | 589 | |
| 590 | lemma split_bintrunc: | |
| 45955 | 591 | "bin_split n c = (a, b) ==> b = bintrunc n c" | 
| 592 | by (induct n arbitrary: b c) (auto simp: Let_def split: ls_splits) | |
| 24364 | 593 | |
| 594 | lemma bin_cat_split: | |
| 45955 | 595 | "bin_split n w = (u, v) ==> w = bin_cat u n v" | 
| 596 | by (induct n arbitrary: v w) (auto simp: Let_def split: ls_splits) | |
| 24364 | 597 | |
| 598 | lemma bin_split_cat: | |
| 45955 | 599 | "bin_split n (bin_cat v n w) = (v, bintrunc n w)" | 
| 600 | by (induct n arbitrary: w) auto | |
| 24364 | 601 | |
| 45956 | 602 | lemma bin_split_zero [simp]: "bin_split n 0 = (0, 0)" | 
| 46001 
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
 huffman parents: 
45956diff
changeset | 603 | by (induct n) auto | 
| 45956 | 604 | |
| 46610 
0c3a5e28f425
make uses of bin_split respect int/bin distinction
 huffman parents: 
46609diff
changeset | 605 | lemma bin_split_minus1 [simp]: | 
| 
0c3a5e28f425
make uses of bin_split respect int/bin distinction
 huffman parents: 
46609diff
changeset | 606 | "bin_split n -1 = (-1, bintrunc n -1)" | 
| 
0c3a5e28f425
make uses of bin_split respect int/bin distinction
 huffman parents: 
46609diff
changeset | 607 | by (induct n) auto | 
| 24364 | 608 | |
| 609 | lemma bin_split_trunc: | |
| 45955 | 610 | "bin_split (min m n) c = (a, b) ==> | 
| 24364 | 611 | bin_split n (bintrunc m c) = (bintrunc (m - n) a, b)" | 
| 45955 | 612 | apply (induct n arbitrary: m b c, clarsimp) | 
| 24364 | 613 | apply (simp add: bin_rest_trunc Let_def split: ls_splits) | 
| 614 | apply (case_tac m) | |
| 46001 
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
 huffman parents: 
45956diff
changeset | 615 | apply (auto simp: Let_def split: ls_splits) | 
| 24333 | 616 | done | 
| 617 | ||
| 24364 | 618 | lemma bin_split_trunc1: | 
| 45955 | 619 | "bin_split n c = (a, b) ==> | 
| 24364 | 620 | bin_split n (bintrunc m c) = (bintrunc (m - n) a, bintrunc m b)" | 
| 45955 | 621 | apply (induct n arbitrary: m b c, clarsimp) | 
| 24364 | 622 | apply (simp add: bin_rest_trunc Let_def split: ls_splits) | 
| 623 | apply (case_tac m) | |
| 46001 
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
 huffman parents: 
45956diff
changeset | 624 | apply (auto simp: Let_def split: ls_splits) | 
| 24364 | 625 | done | 
| 24333 | 626 | |
| 24364 | 627 | lemma bin_cat_num: | 
| 45955 | 628 | "bin_cat a n b = a * 2 ^ n + bintrunc n b" | 
| 629 | apply (induct n arbitrary: b, clarsimp) | |
| 46001 
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
 huffman parents: 
45956diff
changeset | 630 | apply (simp add: Bit_def) | 
| 24364 | 631 | done | 
| 632 | ||
| 633 | lemma bin_split_num: | |
| 45955 | 634 | "bin_split n b = (b div 2 ^ n, b mod 2 ^ n)" | 
| 46610 
0c3a5e28f425
make uses of bin_split respect int/bin distinction
 huffman parents: 
46609diff
changeset | 635 | apply (induct n arbitrary: b, simp) | 
| 45529 
0e1037d4e049
remove redundant lemmas bin_last_mod and bin_rest_div, use bin_last_def and bin_rest_def instead
 huffman parents: 
45475diff
changeset | 636 | apply (simp add: bin_rest_def zdiv_zmult2_eq) | 
| 24364 | 637 | apply (case_tac b rule: bin_exhaust) | 
| 638 | apply simp | |
| 37667 | 639 | apply (simp add: Bit_def mod_mult_mult1 p1mod22k bitval_def | 
| 45955 | 640 | split: bit.split) | 
| 641 | done | |
| 24364 | 642 | |
| 643 | subsection {* Miscellaneous lemmas *}
 | |
| 24333 | 644 | |
| 645 | lemma nth_2p_bin: | |
| 45955 | 646 | "bin_nth (2 ^ n) m = (m = n)" | 
| 647 | apply (induct n arbitrary: m) | |
| 24333 | 648 | apply clarsimp | 
| 649 | apply safe | |
| 650 | apply (case_tac m) | |
| 651 | apply (auto simp: Bit_B0_2t [symmetric]) | |
| 652 | done | |
| 653 | ||
| 654 | (* for use when simplifying with bin_nth_Bit *) | |
| 655 | ||
| 656 | lemma ex_eq_or: | |
| 657 | "(EX m. n = Suc m & (m = k | P m)) = (n = Suc k | (EX m. n = Suc m & P m))" | |
| 658 | by auto | |
| 659 | ||
| 660 | end |