author | nipkow |
Wed, 10 Aug 2016 09:33:54 +0200 | |
changeset 63648 | f9f3006a5579 |
parent 63501 | 34b7e2da95f6 |
child 64507 | eace715f4988 |
permissions | -rw-r--r-- |
24333 | 1 |
(* |
2 |
Author: Jeremy Dawson, NICTA |
|
3 |
||
44939
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
kleing
parents:
41842
diff
changeset
|
4 |
Theorems to do with integers, expressed using Pls, Min, BIT, |
24333 | 5 |
theorems linking them to lists of booleans, and repeated splitting |
6 |
and concatenation. |
|
7 |
*) |
|
8 |
||
58874 | 9 |
section "Bool lists and integers" |
24333 | 10 |
|
37658 | 11 |
theory Bool_List_Representation |
63501 | 12 |
imports Complex_Main Bits_Int |
26557 | 13 |
begin |
24333 | 14 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
15 |
definition map2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
16 |
where |
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
58874
diff
changeset
|
17 |
"map2 f as bs = map (case_prod f) (zip as bs)" |
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
18 |
|
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
19 |
lemma map2_Nil [simp, code]: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
20 |
"map2 f [] ys = []" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
21 |
unfolding map2_def by auto |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
22 |
|
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
23 |
lemma map2_Nil2 [simp, code]: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
24 |
"map2 f xs [] = []" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
25 |
unfolding map2_def by auto |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
26 |
|
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
27 |
lemma map2_Cons [simp, code]: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
28 |
"map2 f (x # xs) (y # ys) = f x y # map2 f xs ys" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
29 |
unfolding map2_def by auto |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
30 |
|
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
31 |
|
61799 | 32 |
subsection \<open>Operations on lists of booleans\<close> |
37657 | 33 |
|
54848 | 34 |
primrec bl_to_bin_aux :: "bool list \<Rightarrow> int \<Rightarrow> int" |
35 |
where |
|
37657 | 36 |
Nil: "bl_to_bin_aux [] w = w" |
37 |
| Cons: "bl_to_bin_aux (b # bs) w = |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
38 |
bl_to_bin_aux bs (w BIT b)" |
37657 | 39 |
|
54848 | 40 |
definition bl_to_bin :: "bool list \<Rightarrow> int" |
41 |
where |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
42 |
bl_to_bin_def: "bl_to_bin bs = bl_to_bin_aux bs 0" |
37667 | 43 |
|
54848 | 44 |
primrec bin_to_bl_aux :: "nat \<Rightarrow> int \<Rightarrow> bool list \<Rightarrow> bool list" |
45 |
where |
|
37657 | 46 |
Z: "bin_to_bl_aux 0 w bl = bl" |
47 |
| Suc: "bin_to_bl_aux (Suc n) w bl = |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
48 |
bin_to_bl_aux n (bin_rest w) ((bin_last w) # bl)" |
37657 | 49 |
|
54848 | 50 |
definition bin_to_bl :: "nat \<Rightarrow> int \<Rightarrow> bool list" |
51 |
where |
|
37657 | 52 |
bin_to_bl_def : "bin_to_bl n w = bin_to_bl_aux n w []" |
53 |
||
54848 | 54 |
primrec bl_of_nth :: "nat \<Rightarrow> (nat \<Rightarrow> bool) \<Rightarrow> bool list" |
55 |
where |
|
37657 | 56 |
Suc: "bl_of_nth (Suc n) f = f n # bl_of_nth n f" |
57 |
| Z: "bl_of_nth 0 f = []" |
|
58 |
||
54848 | 59 |
primrec takefill :: "'a \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list" |
60 |
where |
|
37657 | 61 |
Z: "takefill fill 0 xs = []" |
62 |
| Suc: "takefill fill (Suc n) xs = ( |
|
63 |
case xs of [] => fill # takefill fill n xs |
|
64 |
| y # ys => y # takefill fill n ys)" |
|
65 |
||
66 |
||
24465 | 67 |
subsection "Arithmetic in terms of bool lists" |
68 |
||
61799 | 69 |
text \<open> |
44939
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
kleing
parents:
41842
diff
changeset
|
70 |
Arithmetic operations in terms of the reversed bool list, |
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
kleing
parents:
41842
diff
changeset
|
71 |
assuming input list(s) the same length, and don't extend them. |
61799 | 72 |
\<close> |
24465 | 73 |
|
54848 | 74 |
primrec rbl_succ :: "bool list => bool list" |
75 |
where |
|
24465 | 76 |
Nil: "rbl_succ Nil = Nil" |
26557 | 77 |
| Cons: "rbl_succ (x # xs) = (if x then False # rbl_succ xs else True # xs)" |
24465 | 78 |
|
54848 | 79 |
primrec rbl_pred :: "bool list => bool list" |
80 |
where |
|
26557 | 81 |
Nil: "rbl_pred Nil = Nil" |
82 |
| Cons: "rbl_pred (x # xs) = (if x then False # xs else True # rbl_pred xs)" |
|
24465 | 83 |
|
54848 | 84 |
primrec rbl_add :: "bool list => bool list => bool list" |
85 |
where |
|
61799 | 86 |
\<comment> "result is length of first arg, second arg may be longer" |
26557 | 87 |
Nil: "rbl_add Nil x = Nil" |
88 |
| Cons: "rbl_add (y # ys) x = (let ws = rbl_add ys (tl x) in |
|
24465 | 89 |
(y ~= hd x) # (if hd x & y then rbl_succ ws else ws))" |
90 |
||
54848 | 91 |
primrec rbl_mult :: "bool list => bool list => bool list" |
92 |
where |
|
61799 | 93 |
\<comment> "result is length of first arg, second arg may be longer" |
26557 | 94 |
Nil: "rbl_mult Nil x = Nil" |
95 |
| Cons: "rbl_mult (y # ys) x = (let ws = False # rbl_mult ys x in |
|
24465 | 96 |
if y then rbl_add ws x else ws)" |
24333 | 97 |
|
98 |
lemma butlast_power: |
|
30971 | 99 |
"(butlast ^^ n) bl = take (length bl - n) bl" |
24333 | 100 |
by (induct n) (auto simp: butlast_take) |
101 |
||
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
102 |
lemma bin_to_bl_aux_zero_minus_simp [simp]: |
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
103 |
"0 < n \<Longrightarrow> bin_to_bl_aux n 0 bl = |
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
104 |
bin_to_bl_aux (n - 1) 0 (False # bl)" |
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
105 |
by (cases n) auto |
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
106 |
|
46617
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
107 |
lemma bin_to_bl_aux_minus1_minus_simp [simp]: |
58410
6d46ad54a2ab
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents:
57514
diff
changeset
|
108 |
"0 < n ==> bin_to_bl_aux n (- 1) bl = |
6d46ad54a2ab
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents:
57514
diff
changeset
|
109 |
bin_to_bl_aux (n - 1) (- 1) (True # bl)" |
24333 | 110 |
by (cases n) auto |
111 |
||
46617
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
112 |
lemma bin_to_bl_aux_one_minus_simp [simp]: |
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
113 |
"0 < n \<Longrightarrow> bin_to_bl_aux n 1 bl = |
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
114 |
bin_to_bl_aux (n - 1) 0 (True # bl)" |
24333 | 115 |
by (cases n) auto |
116 |
||
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset
|
117 |
lemma bin_to_bl_aux_Bit_minus_simp [simp]: |
24333 | 118 |
"0 < n ==> bin_to_bl_aux n (w BIT b) bl = |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
119 |
bin_to_bl_aux (n - 1) w (b # bl)" |
24333 | 120 |
by (cases n) auto |
121 |
||
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset
|
122 |
lemma bin_to_bl_aux_Bit0_minus_simp [simp]: |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
123 |
"0 < n ==> bin_to_bl_aux n (numeral (Num.Bit0 w)) bl = |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
124 |
bin_to_bl_aux (n - 1) (numeral w) (False # bl)" |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset
|
125 |
by (cases n) auto |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset
|
126 |
|
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset
|
127 |
lemma bin_to_bl_aux_Bit1_minus_simp [simp]: |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
128 |
"0 < n ==> bin_to_bl_aux n (numeral (Num.Bit1 w)) bl = |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
129 |
bin_to_bl_aux (n - 1) (numeral w) (True # bl)" |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset
|
130 |
by (cases n) auto |
24333 | 131 |
|
61799 | 132 |
text \<open>Link between bin and bool list.\<close> |
24465 | 133 |
|
26557 | 134 |
lemma bl_to_bin_aux_append: |
135 |
"bl_to_bin_aux (bs @ cs) w = bl_to_bin_aux cs (bl_to_bin_aux bs w)" |
|
136 |
by (induct bs arbitrary: w) auto |
|
24465 | 137 |
|
26557 | 138 |
lemma bin_to_bl_aux_append: |
139 |
"bin_to_bl_aux n w bs @ cs = bin_to_bl_aux n w (bs @ cs)" |
|
140 |
by (induct n arbitrary: w bs) auto |
|
24333 | 141 |
|
24465 | 142 |
lemma bl_to_bin_append: |
26557 | 143 |
"bl_to_bin (bs @ cs) = bl_to_bin_aux cs (bl_to_bin bs)" |
24465 | 144 |
unfolding bl_to_bin_def by (rule bl_to_bin_aux_append) |
145 |
||
24333 | 146 |
lemma bin_to_bl_aux_alt: |
147 |
"bin_to_bl_aux n w bs = bin_to_bl n w @ bs" |
|
148 |
unfolding bin_to_bl_def by (simp add : bin_to_bl_aux_append) |
|
149 |
||
45996
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
huffman
parents:
45854
diff
changeset
|
150 |
lemma bin_to_bl_0 [simp]: "bin_to_bl 0 bs = []" |
24333 | 151 |
unfolding bin_to_bl_def by auto |
152 |
||
26557 | 153 |
lemma size_bin_to_bl_aux: |
154 |
"size (bin_to_bl_aux n w bs) = n + length bs" |
|
155 |
by (induct n arbitrary: w bs) auto |
|
24333 | 156 |
|
45996
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
huffman
parents:
45854
diff
changeset
|
157 |
lemma size_bin_to_bl [simp]: "size (bin_to_bl n w) = n" |
24333 | 158 |
unfolding bin_to_bl_def by (simp add : size_bin_to_bl_aux) |
159 |
||
26557 | 160 |
lemma bin_bl_bin': |
161 |
"bl_to_bin (bin_to_bl_aux n w bs) = |
|
162 |
bl_to_bin_aux bs (bintrunc n w)" |
|
163 |
by (induct n arbitrary: w bs) (auto simp add : bl_to_bin_def) |
|
24465 | 164 |
|
45996
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
huffman
parents:
45854
diff
changeset
|
165 |
lemma bin_bl_bin [simp]: "bl_to_bin (bin_to_bl n w) = bintrunc n w" |
24465 | 166 |
unfolding bin_to_bl_def bin_bl_bin' by auto |
167 |
||
26557 | 168 |
lemma bl_bin_bl': |
169 |
"bin_to_bl (n + length bs) (bl_to_bin_aux bs w) = |
|
24465 | 170 |
bin_to_bl_aux n w bs" |
26557 | 171 |
apply (induct bs arbitrary: w n) |
24465 | 172 |
apply auto |
173 |
apply (simp_all only : add_Suc [symmetric]) |
|
174 |
apply (auto simp add : bin_to_bl_def) |
|
175 |
done |
|
176 |
||
45996
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
huffman
parents:
45854
diff
changeset
|
177 |
lemma bl_bin_bl [simp]: "bin_to_bl (length bs) (bl_to_bin bs) = bs" |
24465 | 178 |
unfolding bl_to_bin_def |
179 |
apply (rule box_equals) |
|
180 |
apply (rule bl_bin_bl') |
|
181 |
prefer 2 |
|
182 |
apply (rule bin_to_bl_aux.Z) |
|
183 |
apply simp |
|
184 |
done |
|
185 |
||
186 |
lemma bl_to_bin_inj: |
|
187 |
"bl_to_bin bs = bl_to_bin cs ==> length bs = length cs ==> bs = cs" |
|
188 |
apply (rule_tac box_equals) |
|
189 |
defer |
|
190 |
apply (rule bl_bin_bl) |
|
191 |
apply (rule bl_bin_bl) |
|
192 |
apply simp |
|
193 |
done |
|
194 |
||
45996
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
huffman
parents:
45854
diff
changeset
|
195 |
lemma bl_to_bin_False [simp]: "bl_to_bin (False # bl) = bl_to_bin bl" |
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
196 |
unfolding bl_to_bin_def by auto |
45996
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
huffman
parents:
45854
diff
changeset
|
197 |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
198 |
lemma bl_to_bin_Nil [simp]: "bl_to_bin [] = 0" |
24465 | 199 |
unfolding bl_to_bin_def by auto |
200 |
||
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
201 |
lemma bin_to_bl_zero_aux: |
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
202 |
"bin_to_bl_aux n 0 bl = replicate n False @ bl" |
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
203 |
by (induct n arbitrary: bl) (auto simp: replicate_app_Cons_same) |
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
204 |
|
46617
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
205 |
lemma bin_to_bl_zero: "bin_to_bl n 0 = replicate n False" |
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
206 |
unfolding bin_to_bl_def by (simp add: bin_to_bl_zero_aux) |
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
207 |
|
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
208 |
lemma bin_to_bl_minus1_aux: |
58410
6d46ad54a2ab
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents:
57514
diff
changeset
|
209 |
"bin_to_bl_aux n (- 1) bl = replicate n True @ bl" |
26557 | 210 |
by (induct n arbitrary: bl) (auto simp: replicate_app_Cons_same) |
24333 | 211 |
|
58410
6d46ad54a2ab
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
haftmann
parents:
57514
diff
changeset
|
212 |
lemma bin_to_bl_minus1: "bin_to_bl n (- 1) = replicate n True" |
46617
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
213 |
unfolding bin_to_bl_def by (simp add: bin_to_bl_minus1_aux) |
24333 | 214 |
|
24465 | 215 |
lemma bl_to_bin_rep_F: |
216 |
"bl_to_bin (replicate n False @ bl) = bl_to_bin bl" |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
217 |
apply (simp add: bin_to_bl_zero_aux [symmetric] bin_bl_bin') |
24465 | 218 |
apply (simp add: bl_to_bin_def) |
219 |
done |
|
220 |
||
45996
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
huffman
parents:
45854
diff
changeset
|
221 |
lemma bin_to_bl_trunc [simp]: |
24465 | 222 |
"n <= m ==> bin_to_bl n (bintrunc m w) = bin_to_bl n w" |
223 |
by (auto intro: bl_to_bin_inj) |
|
224 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
225 |
lemma bin_to_bl_aux_bintr: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
226 |
"bin_to_bl_aux n (bintrunc m bin) bl = |
24333 | 227 |
replicate (n - m) False @ bin_to_bl_aux (min n m) bin bl" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
228 |
apply (induct n arbitrary: m bin bl) |
24333 | 229 |
apply clarsimp |
230 |
apply clarsimp |
|
231 |
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:
45997
diff
changeset
|
232 |
apply (clarsimp simp: bin_to_bl_zero_aux) |
24333 | 233 |
apply (erule thin_rl) |
234 |
apply (induct_tac n) |
|
235 |
apply auto |
|
236 |
done |
|
237 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
238 |
lemma bin_to_bl_bintr: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
239 |
"bin_to_bl n (bintrunc m bin) = |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
240 |
replicate (n - m) False @ bin_to_bl (min n m) bin" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
241 |
unfolding bin_to_bl_def by (rule bin_to_bl_aux_bintr) |
24333 | 242 |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
243 |
lemma bl_to_bin_rep_False: "bl_to_bin (replicate n False) = 0" |
24465 | 244 |
by (induct n) auto |
245 |
||
26557 | 246 |
lemma len_bin_to_bl_aux: |
247 |
"length (bin_to_bl_aux n w bs) = n + length bs" |
|
54869 | 248 |
by (fact size_bin_to_bl_aux) |
24333 | 249 |
|
250 |
lemma len_bin_to_bl [simp]: "length (bin_to_bl n w) = n" |
|
46617
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
251 |
by (fact size_bin_to_bl) (* FIXME: duplicate *) |
24333 | 252 |
|
26557 | 253 |
lemma sign_bl_bin': |
254 |
"bin_sign (bl_to_bin_aux bs w) = bin_sign w" |
|
255 |
by (induct bs arbitrary: w) auto |
|
24333 | 256 |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
257 |
lemma sign_bl_bin: "bin_sign (bl_to_bin bs) = 0" |
24333 | 258 |
unfolding bl_to_bin_def by (simp add : sign_bl_bin') |
259 |
||
26557 | 260 |
lemma bl_sbin_sign_aux: |
261 |
"hd (bin_to_bl_aux (Suc n) w bs) = |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
262 |
(bin_sign (sbintrunc n w) = -1)" |
26557 | 263 |
apply (induct n arbitrary: w bs) |
24333 | 264 |
apply clarsimp |
26557 | 265 |
apply (cases w rule: bin_exhaust) |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
266 |
apply simp |
24333 | 267 |
done |
268 |
||
269 |
lemma bl_sbin_sign: |
|
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
270 |
"hd (bin_to_bl (Suc n) w) = (bin_sign (sbintrunc n w) = -1)" |
24333 | 271 |
unfolding bin_to_bl_def by (rule bl_sbin_sign_aux) |
272 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
273 |
lemma bin_nth_of_bl_aux: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
274 |
"bin_nth (bl_to_bin_aux bl w) n = |
24333 | 275 |
(n < size bl & rev bl ! n | n >= length bl & bin_nth w (n - size bl))" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
276 |
apply (induct bl arbitrary: w) |
24333 | 277 |
apply clarsimp |
278 |
apply clarsimp |
|
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
279 |
apply (cut_tac x=n and y="size bl" in linorder_less_linear) |
24333 | 280 |
apply (erule disjE, simp add: nth_append)+ |
26557 | 281 |
apply auto |
24333 | 282 |
done |
283 |
||
45475 | 284 |
lemma bin_nth_of_bl: "bin_nth (bl_to_bin bl) n = (n < length bl & rev bl ! n)" |
24333 | 285 |
unfolding bl_to_bin_def by (simp add : bin_nth_of_bl_aux) |
286 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
287 |
lemma bin_nth_bl: "n < m \<Longrightarrow> bin_nth w n = nth (rev (bin_to_bl m w)) n" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
288 |
apply (induct n arbitrary: m w) |
24333 | 289 |
apply clarsimp |
290 |
apply (case_tac m, clarsimp) |
|
291 |
apply (clarsimp simp: bin_to_bl_def) |
|
292 |
apply (simp add: bin_to_bl_aux_alt) |
|
293 |
apply clarsimp |
|
294 |
apply (case_tac m, clarsimp) |
|
295 |
apply (clarsimp simp: bin_to_bl_def) |
|
296 |
apply (simp add: bin_to_bl_aux_alt) |
|
297 |
done |
|
298 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
299 |
lemma nth_rev: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
300 |
"n < length xs \<Longrightarrow> rev xs ! n = xs ! (length xs - 1 - n)" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
301 |
apply (induct xs) |
24465 | 302 |
apply simp |
63648 | 303 |
apply (clarsimp simp add : nth_append nth.simps split: nat.split) |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
304 |
apply (rule_tac f = "\<lambda>n. xs ! n" in arg_cong) |
24465 | 305 |
apply arith |
306 |
done |
|
307 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
308 |
lemma nth_rev_alt: "n < length ys \<Longrightarrow> ys ! n = rev ys ! (length ys - Suc n)" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
309 |
by (simp add: nth_rev) |
24465 | 310 |
|
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
311 |
lemma nth_bin_to_bl_aux: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
312 |
"n < m + length bl \<Longrightarrow> (bin_to_bl_aux m w bl) ! n = |
24333 | 313 |
(if n < m then bin_nth w (m - 1 - n) else bl ! (n - m))" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
314 |
apply (induct m arbitrary: w n bl) |
24333 | 315 |
apply clarsimp |
316 |
apply clarsimp |
|
317 |
apply (case_tac w rule: bin_exhaust) |
|
318 |
apply simp |
|
319 |
done |
|
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
320 |
|
24333 | 321 |
lemma nth_bin_to_bl: "n < m ==> (bin_to_bl m w) ! n = bin_nth w (m - Suc n)" |
322 |
unfolding bin_to_bl_def by (simp add : nth_bin_to_bl_aux) |
|
323 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
324 |
lemma bl_to_bin_lt2p_aux: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
325 |
"bl_to_bin_aux bs w < (w + 1) * (2 ^ length bs)" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
326 |
apply (induct bs arbitrary: w) |
24333 | 327 |
apply clarsimp |
328 |
apply clarsimp |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
329 |
apply (drule meta_spec, erule xtrans(8) [rotated], simp add: Bit_def)+ |
24333 | 330 |
done |
331 |
||
62701 | 332 |
lemma bl_to_bin_lt2p_drop: |
333 |
"bl_to_bin bs < 2 ^ length (dropWhile Not bs)" |
|
334 |
proof (induct bs) |
|
335 |
case (Cons b bs) with bl_to_bin_lt2p_aux[where w=1] |
|
336 |
show ?case unfolding bl_to_bin_def by simp |
|
337 |
qed simp |
|
338 |
||
339 |
lemma bl_to_bin_lt2p: "bl_to_bin bs < 2 ^ length bs" |
|
340 |
by (metis bin_bl_bin bintr_lt2p bl_bin_bl) |
|
24333 | 341 |
|
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
342 |
lemma bl_to_bin_ge2p_aux: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
343 |
"bl_to_bin_aux bs w >= w * (2 ^ length bs)" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
344 |
apply (induct bs arbitrary: w) |
24333 | 345 |
apply clarsimp |
346 |
apply clarsimp |
|
46652 | 347 |
apply (drule meta_spec, erule order_trans [rotated], |
348 |
simp add: Bit_B0_2t Bit_B1_2t algebra_simps)+ |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
349 |
apply (simp add: Bit_def) |
24333 | 350 |
done |
351 |
||
352 |
lemma bl_to_bin_ge0: "bl_to_bin bs >= 0" |
|
353 |
apply (unfold bl_to_bin_def) |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
354 |
apply (rule xtrans(4)) |
24333 | 355 |
apply (rule bl_to_bin_ge2p_aux) |
46617
8c5d10d41391
make bool list functions respect int/bin distinction
huffman
parents:
46240
diff
changeset
|
356 |
apply simp |
24333 | 357 |
done |
358 |
||
359 |
lemma butlast_rest_bin: |
|
360 |
"butlast (bin_to_bl n w) = bin_to_bl (n - 1) (bin_rest w)" |
|
361 |
apply (unfold bin_to_bl_def) |
|
362 |
apply (cases w rule: bin_exhaust) |
|
363 |
apply (cases n, clarsimp) |
|
364 |
apply clarsimp |
|
365 |
apply (auto simp add: bin_to_bl_aux_alt) |
|
366 |
done |
|
367 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
368 |
lemma butlast_bin_rest: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
369 |
"butlast bl = bin_to_bl (length bl - Suc 0) (bin_rest (bl_to_bin bl))" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
370 |
using butlast_rest_bin [where w="bl_to_bin bl" and n="length bl"] by simp |
24333 | 371 |
|
26557 | 372 |
lemma butlast_rest_bl2bin_aux: |
373 |
"bl ~= [] \<Longrightarrow> |
|
374 |
bl_to_bin_aux (butlast bl) w = bin_rest (bl_to_bin_aux bl w)" |
|
375 |
by (induct bl arbitrary: w) auto |
|
24333 | 376 |
|
377 |
lemma butlast_rest_bl2bin: |
|
378 |
"bl_to_bin (butlast bl) = bin_rest (bl_to_bin bl)" |
|
379 |
apply (unfold bl_to_bin_def) |
|
380 |
apply (cases bl) |
|
381 |
apply (auto simp add: butlast_rest_bl2bin_aux) |
|
382 |
done |
|
383 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
384 |
lemma trunc_bl2bin_aux: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
385 |
"bintrunc m (bl_to_bin_aux bl w) = |
26557 | 386 |
bl_to_bin_aux (drop (length bl - m) bl) (bintrunc (m - length bl) w)" |
53438 | 387 |
proof (induct bl arbitrary: w) |
388 |
case Nil show ?case by simp |
|
389 |
next |
|
390 |
case (Cons b bl) show ?case |
|
391 |
proof (cases "m - length bl") |
|
392 |
case 0 then have "Suc (length bl) - m = Suc (length bl - m)" by simp |
|
393 |
with Cons show ?thesis by simp |
|
394 |
next |
|
395 |
case (Suc n) then have *: "m - Suc (length bl) = n" by simp |
|
396 |
with Suc Cons show ?thesis by simp |
|
397 |
qed |
|
398 |
qed |
|
24333 | 399 |
|
400 |
lemma trunc_bl2bin: |
|
401 |
"bintrunc m (bl_to_bin bl) = bl_to_bin (drop (length bl - m) bl)" |
|
402 |
unfolding bl_to_bin_def by (simp add : trunc_bl2bin_aux) |
|
403 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
404 |
lemma trunc_bl2bin_len [simp]: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
405 |
"bintrunc (length bl) (bl_to_bin bl) = bl_to_bin bl" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
406 |
by (simp add: trunc_bl2bin) |
24333 | 407 |
|
408 |
lemma bl2bin_drop: |
|
409 |
"bl_to_bin (drop k bl) = bintrunc (length bl - k) (bl_to_bin bl)" |
|
410 |
apply (rule trans) |
|
411 |
prefer 2 |
|
412 |
apply (rule trunc_bl2bin [symmetric]) |
|
413 |
apply (cases "k <= length bl") |
|
414 |
apply auto |
|
415 |
done |
|
416 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
417 |
lemma nth_rest_power_bin: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
418 |
"bin_nth ((bin_rest ^^ k) w) n = bin_nth w (n + k)" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
419 |
apply (induct k arbitrary: n, clarsimp) |
24333 | 420 |
apply clarsimp |
421 |
apply (simp only: bin_nth.Suc [symmetric] add_Suc) |
|
422 |
done |
|
423 |
||
424 |
lemma take_rest_power_bin: |
|
30971 | 425 |
"m <= n ==> take m (bin_to_bl n w) = bin_to_bl m ((bin_rest ^^ (n - m)) w)" |
24333 | 426 |
apply (rule nth_equalityI) |
427 |
apply simp |
|
428 |
apply (clarsimp simp add: nth_bin_to_bl nth_rest_power_bin) |
|
429 |
done |
|
430 |
||
24465 | 431 |
lemma hd_butlast: "size xs > 1 ==> hd (butlast xs) = hd xs" |
432 |
by (cases xs) auto |
|
24333 | 433 |
|
26557 | 434 |
lemma last_bin_last': |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
435 |
"size xs > 0 \<Longrightarrow> last xs \<longleftrightarrow> bin_last (bl_to_bin_aux xs w)" |
26557 | 436 |
by (induct xs arbitrary: w) auto |
24333 | 437 |
|
438 |
lemma last_bin_last: |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
439 |
"size xs > 0 ==> last xs \<longleftrightarrow> bin_last (bl_to_bin xs)" |
24333 | 440 |
unfolding bl_to_bin_def by (erule last_bin_last') |
441 |
||
442 |
lemma bin_last_last: |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
443 |
"bin_last w \<longleftrightarrow> last (bin_to_bl (Suc n) w)" |
24333 | 444 |
apply (unfold bin_to_bl_def) |
445 |
apply simp |
|
446 |
apply (auto simp add: bin_to_bl_aux_alt) |
|
447 |
done |
|
448 |
||
24465 | 449 |
(** links between bit-wise operations and operations on bool lists **) |
450 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
451 |
lemma bl_xor_aux_bin: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
452 |
"map2 (%x y. x ~= y) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = |
26557 | 453 |
bin_to_bl_aux n (v XOR w) (map2 (%x y. x ~= y) bs cs)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
454 |
apply (induct n arbitrary: v w bs cs) |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
455 |
apply simp |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
456 |
apply (case_tac v rule: bin_exhaust) |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
457 |
apply (case_tac w rule: bin_exhaust) |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
458 |
apply clarsimp |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
459 |
apply (case_tac b) |
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
460 |
apply auto |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
461 |
done |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
462 |
|
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
463 |
lemma bl_or_aux_bin: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
464 |
"map2 (op | ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
465 |
bin_to_bl_aux n (v OR w) (map2 (op | ) bs cs)" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
466 |
apply (induct n arbitrary: v w bs cs) |
24333 | 467 |
apply simp |
468 |
apply (case_tac v rule: bin_exhaust) |
|
469 |
apply (case_tac w rule: bin_exhaust) |
|
470 |
apply clarsimp |
|
471 |
done |
|
472 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
473 |
lemma bl_and_aux_bin: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
474 |
"map2 (op & ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = |
26557 | 475 |
bin_to_bl_aux n (v AND w) (map2 (op & ) bs cs)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
476 |
apply (induct n arbitrary: v w bs cs) |
24333 | 477 |
apply simp |
478 |
apply (case_tac v rule: bin_exhaust) |
|
479 |
apply (case_tac w rule: bin_exhaust) |
|
480 |
apply clarsimp |
|
481 |
done |
|
482 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
483 |
lemma bl_not_aux_bin: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
484 |
"map Not (bin_to_bl_aux n w cs) = |
24353 | 485 |
bin_to_bl_aux n (NOT w) (map Not cs)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
486 |
apply (induct n arbitrary: w cs) |
24333 | 487 |
apply clarsimp |
488 |
apply clarsimp |
|
489 |
done |
|
490 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
491 |
lemma bl_not_bin: "map Not (bin_to_bl n w) = bin_to_bl n (NOT w)" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
492 |
unfolding bin_to_bl_def by (simp add: bl_not_aux_bin) |
24333 | 493 |
|
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
494 |
lemma bl_and_bin: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
495 |
"map2 (op \<and>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v AND w)" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
496 |
unfolding bin_to_bl_def by (simp add: bl_and_aux_bin) |
24333 | 497 |
|
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
498 |
lemma bl_or_bin: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
499 |
"map2 (op \<or>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v OR w)" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
500 |
unfolding bin_to_bl_def by (simp add: bl_or_aux_bin) |
24333 | 501 |
|
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
502 |
lemma bl_xor_bin: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
503 |
"map2 (\<lambda>x y. x \<noteq> y) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v XOR w)" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
504 |
unfolding bin_to_bl_def by (simp only: bl_xor_aux_bin map2_Nil) |
24333 | 505 |
|
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
506 |
lemma drop_bin2bl_aux: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
507 |
"drop m (bin_to_bl_aux n bin bs) = |
24333 | 508 |
bin_to_bl_aux (n - m) bin (drop (m - n) bs)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
509 |
apply (induct n arbitrary: m bin bs, clarsimp) |
24333 | 510 |
apply clarsimp |
511 |
apply (case_tac bin rule: bin_exhaust) |
|
512 |
apply (case_tac "m <= n", simp) |
|
513 |
apply (case_tac "m - n", simp) |
|
514 |
apply simp |
|
515 |
apply (rule_tac f = "%nat. drop nat bs" in arg_cong) |
|
516 |
apply simp |
|
517 |
done |
|
518 |
||
519 |
lemma drop_bin2bl: "drop m (bin_to_bl n bin) = bin_to_bl (n - m) bin" |
|
520 |
unfolding bin_to_bl_def by (simp add : drop_bin2bl_aux) |
|
521 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
522 |
lemma take_bin2bl_lem1: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
523 |
"take m (bin_to_bl_aux m w bs) = bin_to_bl m w" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
524 |
apply (induct m arbitrary: w bs, clarsimp) |
24333 | 525 |
apply clarsimp |
526 |
apply (simp add: bin_to_bl_aux_alt) |
|
527 |
apply (simp add: bin_to_bl_def) |
|
528 |
apply (simp add: bin_to_bl_aux_alt) |
|
529 |
done |
|
530 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
531 |
lemma take_bin2bl_lem: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
532 |
"take m (bin_to_bl_aux (m + n) w bs) = |
24333 | 533 |
take m (bin_to_bl (m + n) w)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
534 |
apply (induct n arbitrary: w bs) |
24333 | 535 |
apply (simp_all (no_asm) add: bin_to_bl_def take_bin2bl_lem1) |
536 |
apply simp |
|
537 |
done |
|
538 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
539 |
lemma bin_split_take: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
540 |
"bin_split n c = (a, b) \<Longrightarrow> |
24333 | 541 |
bin_to_bl m a = take m (bin_to_bl (m + n) c)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
542 |
apply (induct n arbitrary: b c) |
24333 | 543 |
apply clarsimp |
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
544 |
apply (clarsimp simp: Let_def split: prod.split_asm) |
24333 | 545 |
apply (simp add: bin_to_bl_def) |
546 |
apply (simp add: take_bin2bl_lem) |
|
547 |
done |
|
548 |
||
549 |
lemma bin_split_take1: |
|
550 |
"k = m + n ==> bin_split n c = (a, b) ==> |
|
551 |
bin_to_bl m a = take m (bin_to_bl k c)" |
|
552 |
by (auto elim: bin_split_take) |
|
553 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
554 |
lemma nth_takefill: "m < n \<Longrightarrow> |
24333 | 555 |
takefill fill n l ! m = (if m < length l then l ! m else fill)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
556 |
apply (induct n arbitrary: m l, clarsimp) |
24333 | 557 |
apply clarsimp |
558 |
apply (case_tac m) |
|
559 |
apply (simp split: list.split) |
|
560 |
apply (simp split: list.split) |
|
561 |
done |
|
562 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
563 |
lemma takefill_alt: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
564 |
"takefill fill n l = take n l @ replicate (n - length l) fill" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
565 |
by (induct n arbitrary: l) (auto split: list.split) |
24333 | 566 |
|
567 |
lemma takefill_replicate [simp]: |
|
568 |
"takefill fill n (replicate m fill) = replicate n fill" |
|
569 |
by (simp add : takefill_alt replicate_add [symmetric]) |
|
570 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
571 |
lemma takefill_le': |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
572 |
"n = m + k \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
573 |
by (induct m arbitrary: l n) (auto split: list.split) |
24333 | 574 |
|
575 |
lemma length_takefill [simp]: "length (takefill fill n l) = n" |
|
576 |
by (simp add : takefill_alt) |
|
577 |
||
578 |
lemma take_takefill': |
|
579 |
"!!w n. n = k + m ==> take k (takefill fill n w) = takefill fill k w" |
|
63648 | 580 |
by (induct k) (auto split: list.split) |
24333 | 581 |
|
582 |
lemma drop_takefill: |
|
583 |
"!!w. drop k (takefill fill (m + k) w) = takefill fill m (drop k w)" |
|
63648 | 584 |
by (induct k) (auto split: list.split) |
24333 | 585 |
|
586 |
lemma takefill_le [simp]: |
|
587 |
"m \<le> n \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l" |
|
588 |
by (auto simp: le_iff_add takefill_le') |
|
589 |
||
590 |
lemma take_takefill [simp]: |
|
591 |
"m \<le> n \<Longrightarrow> take m (takefill fill n w) = takefill fill m w" |
|
592 |
by (auto simp: le_iff_add take_takefill') |
|
593 |
||
594 |
lemma takefill_append: |
|
595 |
"takefill fill (m + length xs) (xs @ w) = xs @ (takefill fill m w)" |
|
596 |
by (induct xs) auto |
|
597 |
||
598 |
lemma takefill_same': |
|
599 |
"l = length xs ==> takefill fill l xs = xs" |
|
57492
74bf65a1910a
Hypsubst preserves equality hypotheses
Thomas Sewell <thomas.sewell@nicta.com.au>
parents:
56073
diff
changeset
|
600 |
by (induct xs arbitrary: l, auto) |
24333 | 601 |
|
602 |
lemmas takefill_same [simp] = takefill_same' [OF refl] |
|
603 |
||
604 |
lemma takefill_bintrunc: |
|
605 |
"takefill False n bl = rev (bin_to_bl n (bl_to_bin (rev bl)))" |
|
606 |
apply (rule nth_equalityI) |
|
607 |
apply simp |
|
608 |
apply (clarsimp simp: nth_takefill nth_rev nth_bin_to_bl bin_nth_of_bl) |
|
609 |
done |
|
610 |
||
611 |
lemma bl_bin_bl_rtf: |
|
612 |
"bin_to_bl n (bl_to_bin bl) = rev (takefill False n (rev bl))" |
|
613 |
by (simp add : takefill_bintrunc) |
|
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
614 |
|
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
615 |
lemma bl_bin_bl_rep_drop: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
616 |
"bin_to_bl n (bl_to_bin bl) = |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
617 |
replicate (n - length bl) False @ drop (length bl - n) bl" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
618 |
by (simp add: bl_bin_bl_rtf takefill_alt rev_take) |
24333 | 619 |
|
620 |
lemma tf_rev: |
|
621 |
"n + k = m + length bl ==> takefill x m (rev (takefill y n bl)) = |
|
622 |
rev (takefill y m (rev (takefill x k (rev bl))))" |
|
623 |
apply (rule nth_equalityI) |
|
624 |
apply (auto simp add: nth_takefill nth_rev) |
|
625 |
apply (rule_tac f = "%n. bl ! n" in arg_cong) |
|
626 |
apply arith |
|
627 |
done |
|
628 |
||
629 |
lemma takefill_minus: |
|
630 |
"0 < n ==> takefill fill (Suc (n - 1)) w = takefill fill n w" |
|
631 |
by auto |
|
632 |
||
633 |
lemmas takefill_Suc_cases = |
|
45604 | 634 |
list.cases [THEN takefill.Suc [THEN trans]] |
24333 | 635 |
|
636 |
lemmas takefill_Suc_Nil = takefill_Suc_cases (1) |
|
637 |
lemmas takefill_Suc_Cons = takefill_Suc_cases (2) |
|
638 |
||
639 |
lemmas takefill_minus_simps = takefill_Suc_cases [THEN [2] |
|
45604 | 640 |
takefill_minus [symmetric, THEN trans]] |
24333 | 641 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
642 |
lemma takefill_numeral_Nil [simp]: |
47219
172c031ad743
restate various simp rules for word operations using pred_numeral
huffman
parents:
47108
diff
changeset
|
643 |
"takefill fill (numeral k) [] = fill # takefill fill (pred_numeral k) []" |
172c031ad743
restate various simp rules for word operations using pred_numeral
huffman
parents:
47108
diff
changeset
|
644 |
by (simp add: numeral_eq_Suc) |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
645 |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
646 |
lemma takefill_numeral_Cons [simp]: |
47219
172c031ad743
restate various simp rules for word operations using pred_numeral
huffman
parents:
47108
diff
changeset
|
647 |
"takefill fill (numeral k) (x # xs) = x # takefill fill (pred_numeral k) xs" |
172c031ad743
restate various simp rules for word operations using pred_numeral
huffman
parents:
47108
diff
changeset
|
648 |
by (simp add: numeral_eq_Suc) |
24333 | 649 |
|
650 |
(* links with function bl_to_bin *) |
|
651 |
||
652 |
lemma bl_to_bin_aux_cat: |
|
26557 | 653 |
"!!nv v. bl_to_bin_aux bs (bin_cat w nv v) = |
654 |
bin_cat w (nv + length bs) (bl_to_bin_aux bs v)" |
|
24333 | 655 |
apply (induct bs) |
656 |
apply simp |
|
657 |
apply (simp add: bin_cat_Suc_Bit [symmetric] del: bin_cat.simps) |
|
658 |
done |
|
659 |
||
660 |
lemma bin_to_bl_aux_cat: |
|
661 |
"!!w bs. bin_to_bl_aux (nv + nw) (bin_cat v nw w) bs = |
|
662 |
bin_to_bl_aux nv v (bin_to_bl_aux nw w bs)" |
|
663 |
by (induct nw) auto |
|
664 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
665 |
lemma bl_to_bin_aux_alt: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
666 |
"bl_to_bin_aux bs w = bin_cat w (length bs) (bl_to_bin bs)" |
46001
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
huffman
parents:
45997
diff
changeset
|
667 |
using bl_to_bin_aux_cat [where nv = "0" and v = "0"] |
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
668 |
unfolding bl_to_bin_def [symmetric] by simp |
24333 | 669 |
|
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
670 |
lemma bin_to_bl_cat: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
671 |
"bin_to_bl (nv + nw) (bin_cat v nw w) = |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
672 |
bin_to_bl_aux nv v (bin_to_bl nw w)" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
673 |
unfolding bin_to_bl_def by (simp add: bin_to_bl_aux_cat) |
24333 | 674 |
|
675 |
lemmas bl_to_bin_aux_app_cat = |
|
676 |
trans [OF bl_to_bin_aux_append bl_to_bin_aux_alt] |
|
677 |
||
678 |
lemmas bin_to_bl_aux_cat_app = |
|
679 |
trans [OF bin_to_bl_aux_cat bin_to_bl_aux_alt] |
|
680 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
681 |
lemma bl_to_bin_app_cat: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
682 |
"bl_to_bin (bsa @ bs) = bin_cat (bl_to_bin bsa) (length bs) (bl_to_bin bs)" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
683 |
by (simp only: bl_to_bin_aux_app_cat bl_to_bin_def) |
24333 | 684 |
|
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
685 |
lemma bin_to_bl_cat_app: |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
686 |
"bin_to_bl (n + nw) (bin_cat w nw wa) = bin_to_bl n w @ bin_to_bl nw wa" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
687 |
by (simp only: bin_to_bl_def bin_to_bl_aux_cat_app) |
24333 | 688 |
|
689 |
(* bl_to_bin_app_cat_alt and bl_to_bin_app_cat are easily interderivable *) |
|
690 |
lemma bl_to_bin_app_cat_alt: |
|
691 |
"bin_cat (bl_to_bin cs) n w = bl_to_bin (cs @ bin_to_bl n w)" |
|
692 |
by (simp add : bl_to_bin_app_cat) |
|
693 |
||
694 |
lemma mask_lem: "(bl_to_bin (True # replicate n False)) = |
|
46645
573aff6b9b0a
adapt lemma mask_lem to respect int/bin distinction
huffman
parents:
46617
diff
changeset
|
695 |
(bl_to_bin (replicate n True)) + 1" |
24333 | 696 |
apply (unfold bl_to_bin_def) |
697 |
apply (induct n) |
|
46645
573aff6b9b0a
adapt lemma mask_lem to respect int/bin distinction
huffman
parents:
46617
diff
changeset
|
698 |
apply simp |
31790 | 699 |
apply (simp only: Suc_eq_plus1 replicate_add |
24333 | 700 |
append_Cons [symmetric] bl_to_bin_aux_append) |
46645
573aff6b9b0a
adapt lemma mask_lem to respect int/bin distinction
huffman
parents:
46617
diff
changeset
|
701 |
apply (simp add: Bit_B0_2t Bit_B1_2t) |
24333 | 702 |
done |
703 |
||
24465 | 704 |
(* function bl_of_nth *) |
24333 | 705 |
lemma length_bl_of_nth [simp]: "length (bl_of_nth n f) = n" |
706 |
by (induct n) auto |
|
707 |
||
708 |
lemma nth_bl_of_nth [simp]: |
|
709 |
"m < n \<Longrightarrow> rev (bl_of_nth n f) ! m = f m" |
|
710 |
apply (induct n) |
|
711 |
apply simp |
|
712 |
apply (clarsimp simp add : nth_append) |
|
713 |
apply (rule_tac f = "f" in arg_cong) |
|
714 |
apply simp |
|
715 |
done |
|
716 |
||
717 |
lemma bl_of_nth_inj: |
|
718 |
"(!!k. k < n ==> f k = g k) ==> bl_of_nth n f = bl_of_nth n g" |
|
719 |
by (induct n) auto |
|
720 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
721 |
lemma bl_of_nth_nth_le: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
722 |
"n \<le> length xs \<Longrightarrow> bl_of_nth n (nth (rev xs)) = drop (length xs - n) xs" |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
723 |
apply (induct n arbitrary: xs, clarsimp) |
24333 | 724 |
apply clarsimp |
725 |
apply (rule trans [OF _ hd_Cons_tl]) |
|
726 |
apply (frule Suc_le_lessD) |
|
727 |
apply (simp add: nth_rev trans [OF drop_Suc drop_tl, symmetric]) |
|
728 |
apply (subst hd_drop_conv_nth) |
|
729 |
apply force |
|
730 |
apply simp_all |
|
731 |
apply (rule_tac f = "%n. drop n xs" in arg_cong) |
|
732 |
apply simp |
|
733 |
done |
|
734 |
||
45854
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
735 |
lemma bl_of_nth_nth [simp]: "bl_of_nth (length xs) (op ! (rev xs)) = xs" |
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
huffman
parents:
45847
diff
changeset
|
736 |
by (simp add: bl_of_nth_nth_le) |
24333 | 737 |
|
738 |
lemma size_rbl_pred: "length (rbl_pred bl) = length bl" |
|
739 |
by (induct bl) auto |
|
740 |
||
741 |
lemma size_rbl_succ: "length (rbl_succ bl) = length bl" |
|
742 |
by (induct bl) auto |
|
743 |
||
744 |
lemma size_rbl_add: |
|
745 |
"!!cl. length (rbl_add bl cl) = length bl" |
|
746 |
by (induct bl) (auto simp: Let_def size_rbl_succ) |
|
747 |
||
748 |
lemma size_rbl_mult: |
|
749 |
"!!cl. length (rbl_mult bl cl) = length bl" |
|
750 |
by (induct bl) (auto simp add : Let_def size_rbl_add) |
|
751 |
||
752 |
lemmas rbl_sizes [simp] = |
|
753 |
size_rbl_pred size_rbl_succ size_rbl_add size_rbl_mult |
|
754 |
||
755 |
lemmas rbl_Nils = |
|
756 |
rbl_pred.Nil rbl_succ.Nil rbl_add.Nil rbl_mult.Nil |
|
757 |
||
46653 | 758 |
lemma rbl_pred: |
759 |
"rbl_pred (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin - 1))" |
|
760 |
apply (induct n arbitrary: bin, simp) |
|
24333 | 761 |
apply (unfold bin_to_bl_def) |
762 |
apply clarsimp |
|
763 |
apply (case_tac bin rule: bin_exhaust) |
|
764 |
apply (case_tac b) |
|
46653 | 765 |
apply (clarsimp simp: bin_to_bl_aux_alt)+ |
24333 | 766 |
done |
767 |
||
768 |
lemma rbl_succ: |
|
46653 | 769 |
"rbl_succ (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin + 1))" |
770 |
apply (induct n arbitrary: bin, simp) |
|
24333 | 771 |
apply (unfold bin_to_bl_def) |
772 |
apply clarsimp |
|
773 |
apply (case_tac bin rule: bin_exhaust) |
|
774 |
apply (case_tac b) |
|
46653 | 775 |
apply (clarsimp simp: bin_to_bl_aux_alt)+ |
24333 | 776 |
done |
777 |
||
778 |
lemma rbl_add: |
|
779 |
"!!bina binb. rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = |
|
780 |
rev (bin_to_bl n (bina + binb))" |
|
781 |
apply (induct n, simp) |
|
782 |
apply (unfold bin_to_bl_def) |
|
783 |
apply clarsimp |
|
784 |
apply (case_tac bina rule: bin_exhaust) |
|
785 |
apply (case_tac binb rule: bin_exhaust) |
|
786 |
apply (case_tac b) |
|
787 |
apply (case_tac [!] "ba") |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57492
diff
changeset
|
788 |
apply (auto simp: rbl_succ bin_to_bl_aux_alt Let_def ac_simps) |
24333 | 789 |
done |
790 |
||
791 |
lemma rbl_add_app2: |
|
792 |
"!!blb. length blb >= length bla ==> |
|
793 |
rbl_add bla (blb @ blc) = rbl_add bla blb" |
|
794 |
apply (induct bla, simp) |
|
795 |
apply clarsimp |
|
796 |
apply (case_tac blb, clarsimp) |
|
797 |
apply (clarsimp simp: Let_def) |
|
798 |
done |
|
799 |
||
800 |
lemma rbl_add_take2: |
|
801 |
"!!blb. length blb >= length bla ==> |
|
802 |
rbl_add bla (take (length bla) blb) = rbl_add bla blb" |
|
803 |
apply (induct bla, simp) |
|
804 |
apply clarsimp |
|
805 |
apply (case_tac blb, clarsimp) |
|
806 |
apply (clarsimp simp: Let_def) |
|
807 |
done |
|
808 |
||
809 |
lemma rbl_add_long: |
|
810 |
"m >= n ==> rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = |
|
811 |
rev (bin_to_bl n (bina + binb))" |
|
812 |
apply (rule box_equals [OF _ rbl_add_take2 rbl_add]) |
|
813 |
apply (rule_tac f = "rbl_add (rev (bin_to_bl n bina))" in arg_cong) |
|
814 |
apply (rule rev_swap [THEN iffD1]) |
|
815 |
apply (simp add: rev_take drop_bin2bl) |
|
816 |
apply simp |
|
817 |
done |
|
818 |
||
819 |
lemma rbl_mult_app2: |
|
820 |
"!!blb. length blb >= length bla ==> |
|
821 |
rbl_mult bla (blb @ blc) = rbl_mult bla blb" |
|
822 |
apply (induct bla, simp) |
|
823 |
apply clarsimp |
|
824 |
apply (case_tac blb, clarsimp) |
|
825 |
apply (clarsimp simp: Let_def rbl_add_app2) |
|
826 |
done |
|
827 |
||
828 |
lemma rbl_mult_take2: |
|
829 |
"length blb >= length bla ==> |
|
830 |
rbl_mult bla (take (length bla) blb) = rbl_mult bla blb" |
|
831 |
apply (rule trans) |
|
832 |
apply (rule rbl_mult_app2 [symmetric]) |
|
833 |
apply simp |
|
834 |
apply (rule_tac f = "rbl_mult bla" in arg_cong) |
|
835 |
apply (rule append_take_drop_id) |
|
836 |
done |
|
837 |
||
838 |
lemma rbl_mult_gt1: |
|
839 |
"m >= length bl ==> rbl_mult bl (rev (bin_to_bl m binb)) = |
|
840 |
rbl_mult bl (rev (bin_to_bl (length bl) binb))" |
|
841 |
apply (rule trans) |
|
842 |
apply (rule rbl_mult_take2 [symmetric]) |
|
843 |
apply simp_all |
|
844 |
apply (rule_tac f = "rbl_mult bl" in arg_cong) |
|
845 |
apply (rule rev_swap [THEN iffD1]) |
|
846 |
apply (simp add: rev_take drop_bin2bl) |
|
847 |
done |
|
848 |
||
849 |
lemma rbl_mult_gt: |
|
850 |
"m > n ==> rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = |
|
851 |
rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb))" |
|
852 |
by (auto intro: trans [OF rbl_mult_gt1]) |
|
853 |
||
854 |
lemmas rbl_mult_Suc = lessI [THEN rbl_mult_gt] |
|
855 |
||
856 |
lemma rbbl_Cons: |
|
54847
d6cf9a5b9be9
prefer plain bool over dedicated type for binary digits
haftmann
parents:
53438
diff
changeset
|
857 |
"b # rev (bin_to_bl n x) = rev (bin_to_bl (Suc n) (x BIT b))" |
24333 | 858 |
apply (unfold bin_to_bl_def) |
859 |
apply simp |
|
860 |
apply (simp add: bin_to_bl_aux_alt) |
|
861 |
done |
|
46653 | 862 |
|
24333 | 863 |
lemma rbl_mult: "!!bina binb. |
864 |
rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = |
|
865 |
rev (bin_to_bl n (bina * binb))" |
|
866 |
apply (induct n) |
|
867 |
apply simp |
|
868 |
apply (unfold bin_to_bl_def) |
|
869 |
apply clarsimp |
|
870 |
apply (case_tac bina rule: bin_exhaust) |
|
871 |
apply (case_tac binb rule: bin_exhaust) |
|
872 |
apply (case_tac b) |
|
873 |
apply (case_tac [!] "ba") |
|
46653 | 874 |
apply (auto simp: bin_to_bl_aux_alt Let_def) |
875 |
apply (auto simp: rbbl_Cons rbl_mult_Suc rbl_add) |
|
24333 | 876 |
done |
877 |
||
878 |
lemma rbl_add_split: |
|
879 |
"P (rbl_add (y # ys) (x # xs)) = |
|
880 |
(ALL ws. length ws = length ys --> ws = rbl_add ys xs --> |
|
26008 | 881 |
(y --> ((x --> P (False # rbl_succ ws)) & (~ x --> P (True # ws)))) & |
24333 | 882 |
(~ y --> P (x # ws)))" |
883 |
apply (auto simp add: Let_def) |
|
884 |
apply (case_tac [!] "y") |
|
885 |
apply auto |
|
886 |
done |
|
887 |
||
888 |
lemma rbl_mult_split: |
|
889 |
"P (rbl_mult (y # ys) xs) = |
|
890 |
(ALL ws. length ws = Suc (length ys) --> ws = False # rbl_mult ys xs --> |
|
891 |
(y --> P (rbl_add ws xs)) & (~ y --> P ws))" |
|
892 |
by (clarsimp simp add : Let_def) |
|
893 |
||
894 |
||
24350 | 895 |
subsection "Repeated splitting or concatenation" |
24333 | 896 |
|
897 |
lemma sclem: |
|
898 |
"size (concat (map (bin_to_bl n) xs)) = length xs * n" |
|
899 |
by (induct xs) auto |
|
900 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
901 |
lemma bin_cat_foldl_lem: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
902 |
"foldl (%u. bin_cat u n) x xs = |
24333 | 903 |
bin_cat x (size xs * n) (foldl (%u. bin_cat u n) y xs)" |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
904 |
apply (induct xs arbitrary: x) |
24333 | 905 |
apply simp |
906 |
apply (simp (no_asm)) |
|
907 |
apply (frule asm_rl) |
|
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
908 |
apply (drule meta_spec) |
24333 | 909 |
apply (erule trans) |
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
910 |
apply (drule_tac x = "bin_cat y n a" in meta_spec) |
54863
82acc20ded73
prefer more canonical names for lemmas on min/max
haftmann
parents:
54854
diff
changeset
|
911 |
apply (simp add : bin_cat_assoc_sym min.absorb2) |
24333 | 912 |
done |
913 |
||
914 |
lemma bin_rcat_bl: |
|
915 |
"(bin_rcat n wl) = bl_to_bin (concat (map (bin_to_bl n) wl))" |
|
916 |
apply (unfold bin_rcat_def) |
|
917 |
apply (rule sym) |
|
918 |
apply (induct wl) |
|
919 |
apply (auto simp add : bl_to_bin_append) |
|
920 |
apply (simp add : bl_to_bin_aux_alt sclem) |
|
921 |
apply (simp add : bin_cat_foldl_lem [symmetric]) |
|
922 |
done |
|
923 |
||
924 |
lemmas bin_rsplit_aux_simps = bin_rsplit_aux.simps bin_rsplitl_aux.simps |
|
925 |
lemmas rsplit_aux_simps = bin_rsplit_aux_simps |
|
926 |
||
62390 | 927 |
lemmas th_if_simp1 = if_split [where P = "op = l", THEN iffD1, THEN conjunct1, THEN mp] for l |
928 |
lemmas th_if_simp2 = if_split [where P = "op = l", THEN iffD1, THEN conjunct2, THEN mp] for l |
|
24333 | 929 |
|
930 |
lemmas rsplit_aux_simp1s = rsplit_aux_simps [THEN th_if_simp1] |
|
931 |
||
932 |
lemmas rsplit_aux_simp2ls = rsplit_aux_simps [THEN th_if_simp2] |
|
933 |
(* these safe to [simp add] as require calculating m - n *) |
|
934 |
lemmas bin_rsplit_aux_simp2s [simp] = rsplit_aux_simp2ls [unfolded Let_def] |
|
935 |
lemmas rbscl = bin_rsplit_aux_simp2s (2) |
|
936 |
||
937 |
lemmas rsplit_aux_0_simps [simp] = |
|
938 |
rsplit_aux_simp1s [OF disjI1] rsplit_aux_simp1s [OF disjI2] |
|
939 |
||
940 |
lemma bin_rsplit_aux_append: |
|
26557 | 941 |
"bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs" |
942 |
apply (induct n m c bs rule: bin_rsplit_aux.induct) |
|
24333 | 943 |
apply (subst bin_rsplit_aux.simps) |
944 |
apply (subst bin_rsplit_aux.simps) |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
945 |
apply (clarsimp split: prod.split) |
24333 | 946 |
done |
947 |
||
948 |
lemma bin_rsplitl_aux_append: |
|
26557 | 949 |
"bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs" |
950 |
apply (induct n m c bs rule: bin_rsplitl_aux.induct) |
|
24333 | 951 |
apply (subst bin_rsplitl_aux.simps) |
952 |
apply (subst bin_rsplitl_aux.simps) |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
953 |
apply (clarsimp split: prod.split) |
24333 | 954 |
done |
955 |
||
956 |
lemmas rsplit_aux_apps [where bs = "[]"] = |
|
957 |
bin_rsplit_aux_append bin_rsplitl_aux_append |
|
958 |
||
959 |
lemmas rsplit_def_auxs = bin_rsplit_def bin_rsplitl_def |
|
960 |
||
961 |
lemmas rsplit_aux_alts = rsplit_aux_apps |
|
962 |
[unfolded append_Nil rsplit_def_auxs [symmetric]] |
|
963 |
||
964 |
lemma bin_split_minus: "0 < n ==> bin_split (Suc (n - 1)) w = bin_split n w" |
|
965 |
by auto |
|
966 |
||
967 |
lemmas bin_split_minus_simp = |
|
45604 | 968 |
bin_split.Suc [THEN [2] bin_split_minus [symmetric, THEN trans]] |
24333 | 969 |
|
970 |
lemma bin_split_pred_simp [simp]: |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
971 |
"(0::nat) < numeral bin \<Longrightarrow> |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
972 |
bin_split (numeral bin) w = |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
973 |
(let (w1, w2) = bin_split (numeral bin - 1) (bin_rest w) |
24333 | 974 |
in (w1, w2 BIT bin_last w))" |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46655
diff
changeset
|
975 |
by (simp only: bin_split_minus_simp) |
24333 | 976 |
|
977 |
lemma bin_rsplit_aux_simp_alt: |
|
26557 | 978 |
"bin_rsplit_aux n m c bs = |
24333 | 979 |
(if m = 0 \<or> n = 0 |
980 |
then bs |
|
981 |
else let (a, b) = bin_split n c in bin_rsplit n (m - n, a) @ b # bs)" |
|
26557 | 982 |
unfolding bin_rsplit_aux.simps [of n m c bs] |
983 |
apply simp |
|
984 |
apply (subst rsplit_aux_alts) |
|
985 |
apply (simp add: bin_rsplit_def) |
|
24333 | 986 |
done |
987 |
||
988 |
lemmas bin_rsplit_simp_alt = |
|
45604 | 989 |
trans [OF bin_rsplit_def bin_rsplit_aux_simp_alt] |
24333 | 990 |
|
991 |
lemmas bthrs = bin_rsplit_simp_alt [THEN [2] trans] |
|
992 |
||
993 |
lemma bin_rsplit_size_sign' [rule_format] : |
|
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
994 |
"\<lbrakk>n > 0; rev sw = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
995 |
(ALL v: set sw. bintrunc n v = v)" |
62957 | 996 |
apply (induct sw arbitrary: nw w) |
24333 | 997 |
apply clarsimp |
998 |
apply clarsimp |
|
999 |
apply (drule bthrs) |
|
62390 | 1000 |
apply (simp (no_asm_use) add: Let_def split: prod.split_asm if_split_asm) |
24333 | 1001 |
apply clarify |
1002 |
apply (drule split_bintrunc) |
|
1003 |
apply simp |
|
1004 |
done |
|
1005 |
||
1006 |
lemmas bin_rsplit_size_sign = bin_rsplit_size_sign' [OF asm_rl |
|
45604 | 1007 |
rev_rev_ident [THEN trans] set_rev [THEN equalityD2 [THEN subsetD]]] |
24333 | 1008 |
|
1009 |
lemma bin_nth_rsplit [rule_format] : |
|
1010 |
"n > 0 ==> m < n ==> (ALL w k nw. rev sw = bin_rsplit n (nw, w) --> |
|
1011 |
k < size sw --> bin_nth (sw ! k) m = bin_nth w (k * n + m))" |
|
1012 |
apply (induct sw) |
|
1013 |
apply clarsimp |
|
1014 |
apply clarsimp |
|
1015 |
apply (drule bthrs) |
|
62390 | 1016 |
apply (simp (no_asm_use) add: Let_def split: prod.split_asm if_split_asm) |
24333 | 1017 |
apply clarify |
1018 |
apply (erule allE, erule impE, erule exI) |
|
1019 |
apply (case_tac k) |
|
1020 |
apply clarsimp |
|
1021 |
prefer 2 |
|
1022 |
apply clarsimp |
|
1023 |
apply (erule allE) |
|
1024 |
apply (erule (1) impE) |
|
1025 |
apply (drule bin_nth_split, erule conjE, erule allE, |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57492
diff
changeset
|
1026 |
erule trans, simp add : ac_simps)+ |
24333 | 1027 |
done |
1028 |
||
1029 |
lemma bin_rsplit_all: |
|
1030 |
"0 < nw ==> nw <= n ==> bin_rsplit n (nw, w) = [bintrunc n w]" |
|
1031 |
unfolding bin_rsplit_def |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
1032 |
by (clarsimp dest!: split_bintrunc simp: rsplit_aux_simp2ls split: prod.split) |
24333 | 1033 |
|
1034 |
lemma bin_rsplit_l [rule_format] : |
|
1035 |
"ALL bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, bintrunc m bin)" |
|
1036 |
apply (rule_tac a = "m" in wf_less_than [THEN wf_induct]) |
|
1037 |
apply (simp (no_asm) add : bin_rsplitl_def bin_rsplit_def) |
|
1038 |
apply (rule allI) |
|
1039 |
apply (subst bin_rsplitl_aux.simps) |
|
1040 |
apply (subst bin_rsplit_aux.simps) |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
1041 |
apply (clarsimp simp: Let_def split: prod.split) |
24333 | 1042 |
apply (drule bin_split_trunc) |
1043 |
apply (drule sym [THEN trans], assumption) |
|
26557 | 1044 |
apply (subst rsplit_aux_alts(1)) |
1045 |
apply (subst rsplit_aux_alts(2)) |
|
1046 |
apply clarsimp |
|
1047 |
unfolding bin_rsplit_def bin_rsplitl_def |
|
1048 |
apply simp |
|
24333 | 1049 |
done |
26557 | 1050 |
|
24333 | 1051 |
lemma bin_rsplit_rcat [rule_format] : |
1052 |
"n > 0 --> bin_rsplit n (n * size ws, bin_rcat n ws) = map (bintrunc n) ws" |
|
1053 |
apply (unfold bin_rsplit_def bin_rcat_def) |
|
1054 |
apply (rule_tac xs = "ws" in rev_induct) |
|
1055 |
apply clarsimp |
|
1056 |
apply clarsimp |
|
26557 | 1057 |
apply (subst rsplit_aux_alts) |
1058 |
unfolding bin_split_cat |
|
1059 |
apply simp |
|
24333 | 1060 |
done |
1061 |
||
1062 |
lemma bin_rsplit_aux_len_le [rule_format] : |
|
26557 | 1063 |
"\<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> |
1064 |
length ws \<le> m \<longleftrightarrow> nw + length bs * n \<le> m * n" |
|
54871 | 1065 |
proof - |
1066 |
{ fix i j j' k k' m :: nat and R |
|
1067 |
assume d: "(i::nat) \<le> j \<or> m < j'" |
|
1068 |
assume R1: "i * k \<le> j * k \<Longrightarrow> R" |
|
1069 |
assume R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R" |
|
1070 |
have "R" using d |
|
1071 |
apply safe |
|
1072 |
apply (rule R1, erule mult_le_mono1) |
|
1073 |
apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]]) |
|
1074 |
done |
|
1075 |
} note A = this |
|
1076 |
{ fix sc m n lb :: nat |
|
1077 |
have "(0::nat) < sc \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n \<longleftrightarrow> sc + lb * n \<le> m * n" |
|
1078 |
apply safe |
|
1079 |
apply arith |
|
1080 |
apply (case_tac "sc >= n") |
|
1081 |
apply arith |
|
1082 |
apply (insert linorder_le_less_linear [of m lb]) |
|
1083 |
apply (erule_tac k2=n and k'2=n in A) |
|
1084 |
apply arith |
|
1085 |
apply simp |
|
1086 |
done |
|
1087 |
} note B = this |
|
1088 |
show ?thesis |
|
1089 |
apply (induct n nw w bs rule: bin_rsplit_aux.induct) |
|
1090 |
apply (subst bin_rsplit_aux.simps) |
|
1091 |
apply (simp add: B Let_def split: prod.split) |
|
1092 |
done |
|
1093 |
qed |
|
24333 | 1094 |
|
1095 |
lemma bin_rsplit_len_le: |
|
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
1096 |
"n \<noteq> 0 --> ws = bin_rsplit n (nw, w) --> (length ws <= m) = (nw <= m * n)" |
24333 | 1097 |
unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len_le) |
1098 |
||
45997
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
1099 |
lemma bin_rsplit_aux_len: |
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
huffman
parents:
45996
diff
changeset
|
1100 |
"n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw w cs) = |
24333 | 1101 |
(nw + n - 1) div n + length cs" |
26557 | 1102 |
apply (induct n nw w cs rule: bin_rsplit_aux.induct) |
24333 | 1103 |
apply (subst bin_rsplit_aux.simps) |
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
1104 |
apply (clarsimp simp: Let_def split: prod.split) |
24333 | 1105 |
apply (erule thin_rl) |
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
27105
diff
changeset
|
1106 |
apply (case_tac m) |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
27105
diff
changeset
|
1107 |
apply simp |
24333 | 1108 |
apply (case_tac "m <= n") |
63501 | 1109 |
apply auto |
24333 | 1110 |
done |
1111 |
||
1112 |
lemma bin_rsplit_len: |
|
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
1113 |
"n\<noteq>0 ==> length (bin_rsplit n (nw, w)) = (nw + n - 1) div n" |
24333 | 1114 |
unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len) |
1115 |
||
26557 | 1116 |
lemma bin_rsplit_aux_len_indep: |
1117 |
"n \<noteq> 0 \<Longrightarrow> length bs = length cs \<Longrightarrow> |
|
1118 |
length (bin_rsplit_aux n nw v bs) = |
|
1119 |
length (bin_rsplit_aux n nw w cs)" |
|
1120 |
proof (induct n nw w cs arbitrary: v bs rule: bin_rsplit_aux.induct) |
|
1121 |
case (1 n m w cs v bs) show ?case |
|
1122 |
proof (cases "m = 0") |
|
61799 | 1123 |
case True then show ?thesis using \<open>length bs = length cs\<close> by simp |
26557 | 1124 |
next |
1125 |
case False |
|
61799 | 1126 |
from "1.hyps" \<open>m \<noteq> 0\<close> \<open>n \<noteq> 0\<close> have hyp: "\<And>v bs. length bs = Suc (length cs) \<Longrightarrow> |
26557 | 1127 |
length (bin_rsplit_aux n (m - n) v bs) = |
1128 |
length (bin_rsplit_aux n (m - n) (fst (bin_split n w)) (snd (bin_split n w) # cs))" |
|
1129 |
by auto |
|
61799 | 1130 |
show ?thesis using \<open>length bs = length cs\<close> \<open>n \<noteq> 0\<close> |
26557 | 1131 |
by (auto simp add: bin_rsplit_aux_simp_alt Let_def bin_rsplit_len |
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
47219
diff
changeset
|
1132 |
split: prod.split) |
26557 | 1133 |
qed |
1134 |
qed |
|
24333 | 1135 |
|
1136 |
lemma bin_rsplit_len_indep: |
|
25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset
|
1137 |
"n\<noteq>0 ==> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))" |
24333 | 1138 |
apply (unfold bin_rsplit_def) |
26557 | 1139 |
apply (simp (no_asm)) |
24333 | 1140 |
apply (erule bin_rsplit_aux_len_indep) |
1141 |
apply (rule refl) |
|
1142 |
done |
|
1143 |
||
54874 | 1144 |
|
61799 | 1145 |
text \<open>Even more bit operations\<close> |
54874 | 1146 |
|
1147 |
instantiation int :: bitss |
|
1148 |
begin |
|
1149 |
||
1150 |
definition [iff]: |
|
1151 |
"i !! n \<longleftrightarrow> bin_nth i n" |
|
1152 |
||
1153 |
definition |
|
1154 |
"lsb i = (i :: int) !! 0" |
|
1155 |
||
1156 |
definition |
|
1157 |
"set_bit i n b = bin_sc n b i" |
|
1158 |
||
1159 |
definition |
|
1160 |
"set_bits f = |
|
1161 |
(if \<exists>n. \<forall>n'\<ge>n. \<not> f n' then |
|
1162 |
let n = LEAST n. \<forall>n'\<ge>n. \<not> f n' |
|
1163 |
in bl_to_bin (rev (map f [0..<n])) |
|
1164 |
else if \<exists>n. \<forall>n'\<ge>n. f n' then |
|
1165 |
let n = LEAST n. \<forall>n'\<ge>n. f n' |
|
1166 |
in sbintrunc n (bl_to_bin (True # rev (map f [0..<n]))) |
|
1167 |
else 0 :: int)" |
|
1168 |
||
1169 |
definition |
|
1170 |
"shiftl x n = (x :: int) * 2 ^ n" |
|
1171 |
||
1172 |
definition |
|
1173 |
"shiftr x n = (x :: int) div 2 ^ n" |
|
1174 |
||
1175 |
definition |
|
1176 |
"msb x \<longleftrightarrow> (x :: int) < 0" |
|
1177 |
||
1178 |
instance .. |
|
1179 |
||
24333 | 1180 |
end |
54874 | 1181 |
|
1182 |
end |