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