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