author  huffman 
Sat, 12 Nov 2011 13:01:56 +0100  
changeset 45475  b2b087c20e45 
parent 44939  5930d35c976d 
child 45543  827bf668c822 
permissions  rwrr 
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 

23 
bl_to_bin_def : "bl_to_bin bs = bl_to_bin_aux bs Int.Pls" 

24 

37667  25 
lemma [code]: 
26 
"bl_to_bin bs = bl_to_bin_aux bs 0" 

27 
by (simp add: bl_to_bin_def Pls_def) 

28 

37657  29 
primrec bin_to_bl_aux :: "nat \<Rightarrow> int \<Rightarrow> bool list \<Rightarrow> bool list" where 
30 
Z: "bin_to_bl_aux 0 w bl = bl" 

31 
 Suc: "bin_to_bl_aux (Suc n) w bl = 

32 
bin_to_bl_aux n (bin_rest w) ((bin_last w = 1) # bl)" 

33 

34 
definition bin_to_bl :: "nat \<Rightarrow> int \<Rightarrow> bool list" where 

35 
bin_to_bl_def : "bin_to_bl n w = bin_to_bl_aux n w []" 

36 

37 
primrec bl_of_nth :: "nat \<Rightarrow> (nat \<Rightarrow> bool) \<Rightarrow> bool list" where 

38 
Suc: "bl_of_nth (Suc n) f = f n # bl_of_nth n f" 

39 
 Z: "bl_of_nth 0 f = []" 

40 

41 
primrec takefill :: "'a \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list" where 

42 
Z: "takefill fill 0 xs = []" 

43 
 Suc: "takefill fill (Suc n) xs = ( 

44 
case xs of [] => fill # takefill fill n xs 

45 
 y # ys => y # takefill fill n ys)" 

46 

47 
definition map2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list" where 

48 
"map2 f as bs = map (split f) (zip as bs)" 

49 

50 
lemma map2_Nil [simp]: "map2 f [] ys = []" 

51 
unfolding map2_def by auto 

52 

53 
lemma map2_Nil2 [simp]: "map2 f xs [] = []" 

54 
unfolding map2_def by auto 

55 

56 
lemma map2_Cons [simp]: 

57 
"map2 f (x # xs) (y # ys) = f x y # map2 f xs ys" 

58 
unfolding map2_def by auto 

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 

26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

92 
lemma bin_to_bl_aux_Pls_minus_simp [simp]: 
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

93 
"0 < n ==> bin_to_bl_aux n Int.Pls bl = 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

94 
bin_to_bl_aux (n  1) Int.Pls (False # bl)" 
24333  95 
by (cases n) auto 
96 

26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

97 
lemma bin_to_bl_aux_Min_minus_simp [simp]: 
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

98 
"0 < n ==> bin_to_bl_aux n Int.Min bl = 
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

99 
bin_to_bl_aux (n  1) Int.Min (True # bl)" 
24333  100 
by (cases n) auto 
101 

26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

102 
lemma bin_to_bl_aux_Bit_minus_simp [simp]: 
24333  103 
"0 < n ==> bin_to_bl_aux n (w BIT b) bl = 
37654  104 
bin_to_bl_aux (n  1) w ((b = 1) # 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_Bit0_minus_simp [simp]: 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

108 
"0 < n ==> bin_to_bl_aux n (Int.Bit0 w) bl = 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

109 
bin_to_bl_aux (n  1) w (False # bl)" 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

110 
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

111 

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_Bit1_minus_simp [simp]: 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

113 
"0 < n ==> bin_to_bl_aux n (Int.Bit1 w) bl = 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26008
diff
changeset

114 
bin_to_bl_aux (n  1) w (True # bl)" 
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 
24333  116 

44939
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
kleing
parents:
41842
diff
changeset

117 
text {* Link between bin and bool list. *} 
24465  118 

26557  119 
lemma bl_to_bin_aux_append: 
120 
"bl_to_bin_aux (bs @ cs) w = bl_to_bin_aux cs (bl_to_bin_aux bs w)" 

121 
by (induct bs arbitrary: w) auto 

24465  122 

26557  123 
lemma bin_to_bl_aux_append: 
124 
"bin_to_bl_aux n w bs @ cs = bin_to_bl_aux n w (bs @ cs)" 

125 
by (induct n arbitrary: w bs) auto 

24333  126 

24465  127 
lemma bl_to_bin_append: 
26557  128 
"bl_to_bin (bs @ cs) = bl_to_bin_aux cs (bl_to_bin bs)" 
24465  129 
unfolding bl_to_bin_def by (rule bl_to_bin_aux_append) 
130 

24333  131 
lemma bin_to_bl_aux_alt: 
132 
"bin_to_bl_aux n w bs = bin_to_bl n w @ bs" 

133 
unfolding bin_to_bl_def by (simp add : bin_to_bl_aux_append) 

134 

24465  135 
lemma bin_to_bl_0: "bin_to_bl 0 bs = []" 
24333  136 
unfolding bin_to_bl_def by auto 
137 

26557  138 
lemma size_bin_to_bl_aux: 
139 
"size (bin_to_bl_aux n w bs) = n + length bs" 

140 
by (induct n arbitrary: w bs) auto 

24333  141 

24465  142 
lemma size_bin_to_bl: "size (bin_to_bl n w) = n" 
24333  143 
unfolding bin_to_bl_def by (simp add : size_bin_to_bl_aux) 
144 

26557  145 
lemma bin_bl_bin': 
146 
"bl_to_bin (bin_to_bl_aux n w bs) = 

147 
bl_to_bin_aux bs (bintrunc n w)" 

148 
by (induct n arbitrary: w bs) (auto simp add : bl_to_bin_def) 

24465  149 

150 
lemma bin_bl_bin: "bl_to_bin (bin_to_bl n w) = bintrunc n w" 

151 
unfolding bin_to_bl_def bin_bl_bin' by auto 

152 

26557  153 
lemma bl_bin_bl': 
154 
"bin_to_bl (n + length bs) (bl_to_bin_aux bs w) = 

24465  155 
bin_to_bl_aux n w bs" 
26557  156 
apply (induct bs arbitrary: w n) 
24465  157 
apply auto 
158 
apply (simp_all only : add_Suc [symmetric]) 

159 
apply (auto simp add : bin_to_bl_def) 

160 
done 

161 

162 
lemma bl_bin_bl: "bin_to_bl (length bs) (bl_to_bin bs) = bs" 

163 
unfolding bl_to_bin_def 

164 
apply (rule box_equals) 

165 
apply (rule bl_bin_bl') 

166 
prefer 2 

167 
apply (rule bin_to_bl_aux.Z) 

168 
apply simp 

169 
done 

170 

171 
declare 

172 
bin_to_bl_0 [simp] 

173 
size_bin_to_bl [simp] 

174 
bin_bl_bin [simp] 

175 
bl_bin_bl [simp] 

176 

177 
lemma bl_to_bin_inj: 

178 
"bl_to_bin bs = bl_to_bin cs ==> length bs = length cs ==> bs = cs" 

179 
apply (rule_tac box_equals) 

180 
defer 

181 
apply (rule bl_bin_bl) 

182 
apply (rule bl_bin_bl) 

183 
apply simp 

184 
done 

185 

186 
lemma bl_to_bin_False: "bl_to_bin (False # bl) = bl_to_bin bl" 

187 
unfolding bl_to_bin_def by auto 

188 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

189 
lemma bl_to_bin_Nil: "bl_to_bin [] = Int.Pls" 
24465  190 
unfolding bl_to_bin_def by auto 
191 

26557  192 
lemma bin_to_bl_Pls_aux: 
193 
"bin_to_bl_aux n Int.Pls bl = replicate n False @ bl" 

194 
by (induct n arbitrary: bl) (auto simp: replicate_app_Cons_same) 

24333  195 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

196 
lemma bin_to_bl_Pls: "bin_to_bl n Int.Pls = replicate n False" 
24333  197 
unfolding bin_to_bl_def by (simp add : bin_to_bl_Pls_aux) 
198 

199 
lemma bin_to_bl_Min_aux [rule_format] : 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

200 
"ALL bl. bin_to_bl_aux n Int.Min bl = replicate n True @ bl" 
24333  201 
by (induct n) (auto simp: replicate_app_Cons_same) 
202 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

203 
lemma bin_to_bl_Min: "bin_to_bl n Int.Min = replicate n True" 
24333  204 
unfolding bin_to_bl_def by (simp add : bin_to_bl_Min_aux) 
205 

24465  206 
lemma bl_to_bin_rep_F: 
207 
"bl_to_bin (replicate n False @ bl) = bl_to_bin bl" 

208 
apply (simp add: bin_to_bl_Pls_aux [symmetric] bin_bl_bin') 

209 
apply (simp add: bl_to_bin_def) 

210 
done 

211 

212 
lemma bin_to_bl_trunc: 

213 
"n <= m ==> bin_to_bl n (bintrunc m w) = bin_to_bl n w" 

214 
by (auto intro: bl_to_bin_inj) 

215 

216 
declare 

217 
bin_to_bl_trunc [simp] 

218 
bl_to_bin_False [simp] 

219 
bl_to_bin_Nil [simp] 

220 

24333  221 
lemma bin_to_bl_aux_bintr [rule_format] : 
222 
"ALL m bin bl. bin_to_bl_aux n (bintrunc m bin) bl = 

223 
replicate (n  m) False @ bin_to_bl_aux (min n m) bin bl" 

27105
5f139027c365
slightly tuning of some proofs involving case distinction and induction on natural numbers and similar
haftmann
parents:
26584
diff
changeset

224 
apply (induct n) 
24333  225 
apply clarsimp 
226 
apply clarsimp 

227 
apply (case_tac "m") 

228 
apply (clarsimp simp: bin_to_bl_Pls_aux) 

229 
apply (erule thin_rl) 

230 
apply (induct_tac n) 

231 
apply auto 

232 
done 

233 

234 
lemmas bin_to_bl_bintr = 

235 
bin_to_bl_aux_bintr [where bl = "[]", folded bin_to_bl_def] 

236 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

237 
lemma bl_to_bin_rep_False: "bl_to_bin (replicate n False) = Int.Pls" 
24465  238 
by (induct n) auto 
239 

26557  240 
lemma len_bin_to_bl_aux: 
241 
"length (bin_to_bl_aux n w bs) = n + length bs" 

242 
by (induct n arbitrary: w bs) auto 

24333  243 

244 
lemma len_bin_to_bl [simp]: "length (bin_to_bl n w) = n" 

245 
unfolding bin_to_bl_def len_bin_to_bl_aux by auto 

246 

26557  247 
lemma sign_bl_bin': 
248 
"bin_sign (bl_to_bin_aux bs w) = bin_sign w" 

249 
by (induct bs arbitrary: w) auto 

24333  250 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

251 
lemma sign_bl_bin: "bin_sign (bl_to_bin bs) = Int.Pls" 
24333  252 
unfolding bl_to_bin_def by (simp add : sign_bl_bin') 
253 

26557  254 
lemma bl_sbin_sign_aux: 
255 
"hd (bin_to_bl_aux (Suc n) w bs) = 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

256 
(bin_sign (sbintrunc n w) = Int.Min)" 
26557  257 
apply (induct n arbitrary: w bs) 
24333  258 
apply clarsimp 
26557  259 
apply (cases w rule: bin_exhaust) 
24333  260 
apply (simp split add : bit.split) 
261 
apply clarsimp 

262 
done 

263 

264 
lemma bl_sbin_sign: 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

265 
"hd (bin_to_bl (Suc n) w) = (bin_sign (sbintrunc n w) = Int.Min)" 
24333  266 
unfolding bin_to_bl_def by (rule bl_sbin_sign_aux) 
267 

26557  268 
lemma bin_nth_of_bl_aux [rule_format]: 
269 
"\<forall>w. bin_nth (bl_to_bin_aux bl w) n = 

24333  270 
(n < size bl & rev bl ! n  n >= length bl & bin_nth w (n  size bl))" 
271 
apply (induct_tac bl) 

272 
apply clarsimp 

273 
apply clarsimp 

274 
apply (cut_tac x=n and y="size list" in linorder_less_linear) 

275 
apply (erule disjE, simp add: nth_append)+ 

26557  276 
apply auto 
24333  277 
done 
278 

45475  279 
lemma bin_nth_of_bl: "bin_nth (bl_to_bin bl) n = (n < length bl & rev bl ! n)" 
24333  280 
unfolding bl_to_bin_def by (simp add : bin_nth_of_bl_aux) 
281 

282 
lemma bin_nth_bl [rule_format] : "ALL m w. n < m > 

283 
bin_nth w n = nth (rev (bin_to_bl m w)) n" 

284 
apply (induct n) 

285 
apply clarsimp 

286 
apply (case_tac m, clarsimp) 

287 
apply (clarsimp simp: bin_to_bl_def) 

288 
apply (simp add: bin_to_bl_aux_alt) 

289 
apply clarsimp 

290 
apply (case_tac m, clarsimp) 

291 
apply (clarsimp simp: bin_to_bl_def) 

292 
apply (simp add: bin_to_bl_aux_alt) 

293 
done 

294 

24465  295 
lemma nth_rev [rule_format] : 
296 
"n < length xs > rev xs ! n = xs ! (length xs  1  n)" 

297 
apply (induct_tac "xs") 

298 
apply simp 

299 
apply (clarsimp simp add : nth_append nth.simps split add : nat.split) 

300 
apply (rule_tac f = "%n. list ! n" in arg_cong) 

301 
apply arith 

302 
done 

303 

25350
a5fcf6d12a53
eliminated illegal schematic variables in where/of;
wenzelm
parents:
25134
diff
changeset

304 
lemmas nth_rev_alt = nth_rev [where xs = "rev ys", simplified, standard] 
24465  305 

24333  306 
lemma nth_bin_to_bl_aux [rule_format] : 
307 
"ALL w n bl. n < m + length bl > (bin_to_bl_aux m w bl) ! n = 

308 
(if n < m then bin_nth w (m  1  n) else bl ! (n  m))" 

27105
5f139027c365
slightly tuning of some proofs involving case distinction and induction on natural numbers and similar
haftmann
parents:
26584
diff
changeset

309 
apply (induct m) 
24333  310 
apply clarsimp 
311 
apply clarsimp 

312 
apply (case_tac w rule: bin_exhaust) 

313 
apply simp 

314 
done 

315 

316 
lemma nth_bin_to_bl: "n < m ==> (bin_to_bl m w) ! n = bin_nth w (m  Suc n)" 

317 
unfolding bin_to_bl_def by (simp add : nth_bin_to_bl_aux) 

318 

26557  319 
lemma bl_to_bin_lt2p_aux [rule_format]: 
320 
"\<forall>w. bl_to_bin_aux bs w < (w + 1) * (2 ^ length bs)" 

321 
apply (induct bs) 

24333  322 
apply clarsimp 
323 
apply clarsimp 

324 
apply safe 

26557  325 
apply (erule allE, erule xtr8 [rotated], 
29667  326 
simp add: numeral_simps algebra_simps cong add : number_of_False_cong)+ 
24333  327 
done 
328 

329 
lemma bl_to_bin_lt2p: "bl_to_bin bs < (2 ^ length bs)" 

330 
apply (unfold bl_to_bin_def) 

331 
apply (rule xtr1) 

332 
prefer 2 

333 
apply (rule bl_to_bin_lt2p_aux) 

334 
apply simp 

335 
done 

336 

337 
lemma bl_to_bin_ge2p_aux [rule_format] : 

26557  338 
"\<forall>w. bl_to_bin_aux bs w >= w * (2 ^ length bs)" 
24333  339 
apply (induct bs) 
340 
apply clarsimp 

341 
apply clarsimp 

342 
apply safe 

28059  343 
apply (erule allE, erule preorder_class.order_trans [rotated], 
29667  344 
simp add: numeral_simps algebra_simps cong add : number_of_False_cong)+ 
24333  345 
done 
346 

347 
lemma bl_to_bin_ge0: "bl_to_bin bs >= 0" 

348 
apply (unfold bl_to_bin_def) 

349 
apply (rule xtr4) 

350 
apply (rule bl_to_bin_ge2p_aux) 

351 
apply simp 

352 
done 

353 

354 
lemma butlast_rest_bin: 

355 
"butlast (bin_to_bl n w) = bin_to_bl (n  1) (bin_rest w)" 

356 
apply (unfold bin_to_bl_def) 

357 
apply (cases w rule: bin_exhaust) 

358 
apply (cases n, clarsimp) 

359 
apply clarsimp 

360 
apply (auto simp add: bin_to_bl_aux_alt) 

361 
done 

362 

363 
lemmas butlast_bin_rest = butlast_rest_bin 

25350
a5fcf6d12a53
eliminated illegal schematic variables in where/of;
wenzelm
parents:
25134
diff
changeset

364 
[where w="bl_to_bin bl" and n="length bl", simplified, standard] 
24333  365 

26557  366 
lemma butlast_rest_bl2bin_aux: 
367 
"bl ~= [] \<Longrightarrow> 

368 
bl_to_bin_aux (butlast bl) w = bin_rest (bl_to_bin_aux bl w)" 

369 
by (induct bl arbitrary: w) auto 

24333  370 

371 
lemma butlast_rest_bl2bin: 

372 
"bl_to_bin (butlast bl) = bin_rest (bl_to_bin bl)" 

373 
apply (unfold bl_to_bin_def) 

374 
apply (cases bl) 

375 
apply (auto simp add: butlast_rest_bl2bin_aux) 

376 
done 

377 

26557  378 
lemma trunc_bl2bin_aux [rule_format]: 
379 
"ALL w. bintrunc m (bl_to_bin_aux bl w) = 

380 
bl_to_bin_aux (drop (length bl  m) bl) (bintrunc (m  length bl) w)" 

24333  381 
apply (induct_tac bl) 
382 
apply clarsimp 

383 
apply clarsimp 

384 
apply safe 

385 
apply (case_tac "m  size list") 

386 
apply (simp add : diff_is_0_eq [THEN iffD1, THEN Suc_diff_le]) 

387 
apply simp 

26557  388 
apply (rule_tac f = "%nat. bl_to_bin_aux list (Int.Bit1 (bintrunc nat w))" 
24333  389 
in arg_cong) 
390 
apply simp 

391 
apply (case_tac "m  size list") 

392 
apply (simp add: diff_is_0_eq [THEN iffD1, THEN Suc_diff_le]) 

393 
apply simp 

26557  394 
apply (rule_tac f = "%nat. bl_to_bin_aux list (Int.Bit0 (bintrunc nat w))" 
24333  395 
in arg_cong) 
396 
apply simp 

397 
done 

398 

399 
lemma trunc_bl2bin: 

400 
"bintrunc m (bl_to_bin bl) = bl_to_bin (drop (length bl  m) bl)" 

401 
unfolding bl_to_bin_def by (simp add : trunc_bl2bin_aux) 

402 

403 
lemmas trunc_bl2bin_len [simp] = 

404 
trunc_bl2bin [of "length bl" bl, simplified, standard] 

405 

406 
lemma bl2bin_drop: 

407 
"bl_to_bin (drop k bl) = bintrunc (length bl  k) (bl_to_bin bl)" 

408 
apply (rule trans) 

409 
prefer 2 

410 
apply (rule trunc_bl2bin [symmetric]) 

411 
apply (cases "k <= length bl") 

412 
apply auto 

413 
done 

414 

415 
lemma nth_rest_power_bin [rule_format] : 

30971  416 
"ALL n. bin_nth ((bin_rest ^^ k) w) n = bin_nth w (n + k)" 
24333  417 
apply (induct k, clarsimp) 
418 
apply clarsimp 

419 
apply (simp only: bin_nth.Suc [symmetric] add_Suc) 

420 
done 

421 

422 
lemma take_rest_power_bin: 

30971  423 
"m <= n ==> take m (bin_to_bl n w) = bin_to_bl m ((bin_rest ^^ (n  m)) w)" 
24333  424 
apply (rule nth_equalityI) 
425 
apply simp 

426 
apply (clarsimp simp add: nth_bin_to_bl nth_rest_power_bin) 

427 
done 

428 

24465  429 
lemma hd_butlast: "size xs > 1 ==> hd (butlast xs) = hd xs" 
430 
by (cases xs) auto 

24333  431 

26557  432 
lemma last_bin_last': 
37654  433 
"size xs > 0 \<Longrightarrow> last xs = (bin_last (bl_to_bin_aux xs w) = 1)" 
26557  434 
by (induct xs arbitrary: w) auto 
24333  435 

436 
lemma last_bin_last: 

37654  437 
"size xs > 0 ==> last xs = (bin_last (bl_to_bin xs) = 1)" 
24333  438 
unfolding bl_to_bin_def by (erule last_bin_last') 
439 

440 
lemma bin_last_last: 

37654  441 
"bin_last w = (if last (bin_to_bl (Suc n) w) then 1 else 0)" 
24333  442 
apply (unfold bin_to_bl_def) 
443 
apply simp 

444 
apply (auto simp add: bin_to_bl_aux_alt) 

445 
done 

446 

24465  447 
(** links between bitwise operations and operations on bool lists **) 
448 

24333  449 
lemma bl_xor_aux_bin [rule_format] : "ALL v w bs cs. 
26557  450 
map2 (%x y. x ~= y) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
451 
bin_to_bl_aux n (v XOR w) (map2 (%x y. x ~= y) bs cs)" 

24333  452 
apply (induct_tac n) 
453 
apply safe 

454 
apply simp 

455 
apply (case_tac v rule: bin_exhaust) 

456 
apply (case_tac w rule: bin_exhaust) 

457 
apply clarsimp 

458 
apply (case_tac b) 

459 
apply (case_tac ba, safe, simp_all)+ 

460 
done 

461 

462 
lemma bl_or_aux_bin [rule_format] : "ALL v w bs cs. 

26557  463 
map2 (op  ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
464 
bin_to_bl_aux n (v OR w) (map2 (op  ) bs cs)" 

24333  465 
apply (induct_tac n) 
466 
apply safe 

467 
apply simp 

468 
apply (case_tac v rule: bin_exhaust) 

469 
apply (case_tac w rule: bin_exhaust) 

470 
apply clarsimp 

471 
apply (case_tac b) 

472 
apply (case_tac ba, safe, simp_all)+ 

473 
done 

474 

475 
lemma bl_and_aux_bin [rule_format] : "ALL v w bs cs. 

26557  476 
map2 (op & ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
477 
bin_to_bl_aux n (v AND w) (map2 (op & ) bs cs)" 

24333  478 
apply (induct_tac n) 
479 
apply safe 

480 
apply simp 

481 
apply (case_tac v rule: bin_exhaust) 

482 
apply (case_tac w rule: bin_exhaust) 

483 
apply clarsimp 

484 
apply (case_tac b) 

485 
apply (case_tac ba, safe, simp_all)+ 

486 
done 

487 

488 
lemma bl_not_aux_bin [rule_format] : 

489 
"ALL w cs. map Not (bin_to_bl_aux n w cs) = 

24353  490 
bin_to_bl_aux n (NOT w) (map Not cs)" 
24333  491 
apply (induct n) 
492 
apply clarsimp 

493 
apply clarsimp 

494 
apply (case_tac w rule: bin_exhaust) 

495 
apply (case_tac b) 

496 
apply auto 

497 
done 

498 

499 
lemmas bl_not_bin = bl_not_aux_bin 

500 
[where cs = "[]", unfolded bin_to_bl_def [symmetric] map.simps] 

501 

502 
lemmas bl_and_bin = bl_and_aux_bin [where bs="[]" and cs="[]", 

26557  503 
unfolded map2_Nil, folded bin_to_bl_def] 
24333  504 

505 
lemmas bl_or_bin = bl_or_aux_bin [where bs="[]" and cs="[]", 

26557  506 
unfolded map2_Nil, folded bin_to_bl_def] 
24333  507 

508 
lemmas bl_xor_bin = bl_xor_aux_bin [where bs="[]" and cs="[]", 

26557  509 
unfolded map2_Nil, folded bin_to_bl_def] 
24333  510 

511 
lemma drop_bin2bl_aux [rule_format] : 

512 
"ALL m bin bs. drop m (bin_to_bl_aux n bin bs) = 

513 
bin_to_bl_aux (n  m) bin (drop (m  n) bs)" 

514 
apply (induct n, clarsimp) 

515 
apply clarsimp 

516 
apply (case_tac bin rule: bin_exhaust) 

517 
apply (case_tac "m <= n", simp) 

518 
apply (case_tac "m  n", simp) 

519 
apply simp 

520 
apply (rule_tac f = "%nat. drop nat bs" in arg_cong) 

521 
apply simp 

522 
done 

523 

524 
lemma drop_bin2bl: "drop m (bin_to_bl n bin) = bin_to_bl (n  m) bin" 

525 
unfolding bin_to_bl_def by (simp add : drop_bin2bl_aux) 

526 

527 
lemma take_bin2bl_lem1 [rule_format] : 

528 
"ALL w bs. take m (bin_to_bl_aux m w bs) = bin_to_bl m w" 

529 
apply (induct m, clarsimp) 

530 
apply clarsimp 

531 
apply (simp add: bin_to_bl_aux_alt) 

532 
apply (simp add: bin_to_bl_def) 

533 
apply (simp add: bin_to_bl_aux_alt) 

534 
done 

535 

536 
lemma take_bin2bl_lem [rule_format] : 

537 
"ALL w bs. take m (bin_to_bl_aux (m + n) w bs) = 

538 
take m (bin_to_bl (m + n) w)" 

539 
apply (induct n) 

540 
apply clarify 

541 
apply (simp_all (no_asm) add: bin_to_bl_def take_bin2bl_lem1) 

542 
apply simp 

543 
done 

544 

545 
lemma bin_split_take [rule_format] : 

546 
"ALL b c. bin_split n c = (a, b) > 

547 
bin_to_bl m a = take m (bin_to_bl (m + n) c)" 

548 
apply (induct n) 

549 
apply clarsimp 

550 
apply (clarsimp simp: Let_def split: ls_splits) 

551 
apply (simp add: bin_to_bl_def) 

552 
apply (simp add: take_bin2bl_lem) 

553 
done 

554 

555 
lemma bin_split_take1: 

556 
"k = m + n ==> bin_split n c = (a, b) ==> 

557 
bin_to_bl m a = take m (bin_to_bl k c)" 

558 
by (auto elim: bin_split_take) 

559 

560 
lemma nth_takefill [rule_format] : "ALL m l. m < n > 

561 
takefill fill n l ! m = (if m < length l then l ! m else fill)" 

562 
apply (induct n, clarsimp) 

563 
apply clarsimp 

564 
apply (case_tac m) 

565 
apply (simp split: list.split) 

566 
apply clarsimp 

567 
apply (erule allE)+ 

568 
apply (erule (1) impE) 

569 
apply (simp split: list.split) 

570 
done 

571 

572 
lemma takefill_alt [rule_format] : 

573 
"ALL l. takefill fill n l = take n l @ replicate (n  length l) fill" 

574 
by (induct n) (auto split: list.split) 

575 

576 
lemma takefill_replicate [simp]: 

577 
"takefill fill n (replicate m fill) = replicate n fill" 

578 
by (simp add : takefill_alt replicate_add [symmetric]) 

579 

580 
lemma takefill_le' [rule_format] : 

581 
"ALL l n. n = m + k > takefill x m (takefill x n l) = takefill x m l" 

582 
by (induct m) (auto split: list.split) 

583 

584 
lemma length_takefill [simp]: "length (takefill fill n l) = n" 

585 
by (simp add : takefill_alt) 

586 

587 
lemma take_takefill': 

588 
"!!w n. n = k + m ==> take k (takefill fill n w) = takefill fill k w" 

589 
by (induct k) (auto split add : list.split) 

590 

591 
lemma drop_takefill: 

592 
"!!w. drop k (takefill fill (m + k) w) = takefill fill m (drop k w)" 

593 
by (induct k) (auto split add : list.split) 

594 

595 
lemma takefill_le [simp]: 

596 
"m \<le> n \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l" 

597 
by (auto simp: le_iff_add takefill_le') 

598 

599 
lemma take_takefill [simp]: 

600 
"m \<le> n \<Longrightarrow> take m (takefill fill n w) = takefill fill m w" 

601 
by (auto simp: le_iff_add take_takefill') 

602 

603 
lemma takefill_append: 

604 
"takefill fill (m + length xs) (xs @ w) = xs @ (takefill fill m w)" 

605 
by (induct xs) auto 

606 

607 
lemma takefill_same': 

608 
"l = length xs ==> takefill fill l xs = xs" 

609 
by clarify (induct xs, auto) 

610 

611 
lemmas takefill_same [simp] = takefill_same' [OF refl] 

612 

613 
lemma takefill_bintrunc: 

614 
"takefill False n bl = rev (bin_to_bl n (bl_to_bin (rev bl)))" 

615 
apply (rule nth_equalityI) 

616 
apply simp 

617 
apply (clarsimp simp: nth_takefill nth_rev nth_bin_to_bl bin_nth_of_bl) 

618 
done 

619 

620 
lemma bl_bin_bl_rtf: 

621 
"bin_to_bl n (bl_to_bin bl) = rev (takefill False n (rev bl))" 

622 
by (simp add : takefill_bintrunc) 

623 

624 
lemmas bl_bin_bl_rep_drop = 

625 
bl_bin_bl_rtf [simplified takefill_alt, 

626 
simplified, simplified rev_take, simplified] 

627 

628 
lemma tf_rev: 

629 
"n + k = m + length bl ==> takefill x m (rev (takefill y n bl)) = 

630 
rev (takefill y m (rev (takefill x k (rev bl))))" 

631 
apply (rule nth_equalityI) 

632 
apply (auto simp add: nth_takefill nth_rev) 

633 
apply (rule_tac f = "%n. bl ! n" in arg_cong) 

634 
apply arith 

635 
done 

636 

637 
lemma takefill_minus: 

638 
"0 < n ==> takefill fill (Suc (n  1)) w = takefill fill n w" 

639 
by auto 

640 

641 
lemmas takefill_Suc_cases = 

642 
list.cases [THEN takefill.Suc [THEN trans], standard] 

643 

644 
lemmas takefill_Suc_Nil = takefill_Suc_cases (1) 

645 
lemmas takefill_Suc_Cons = takefill_Suc_cases (2) 

646 

647 
lemmas takefill_minus_simps = takefill_Suc_cases [THEN [2] 

648 
takefill_minus [symmetric, THEN trans], standard] 

649 

650 
lemmas takefill_pred_simps [simp] = 

651 
takefill_minus_simps [where n="number_of bin", simplified nobm1, standard] 

652 

653 
(* links with function bl_to_bin *) 

654 

655 
lemma bl_to_bin_aux_cat: 

26557  656 
"!!nv v. bl_to_bin_aux bs (bin_cat w nv v) = 
657 
bin_cat w (nv + length bs) (bl_to_bin_aux bs v)" 

24333  658 
apply (induct bs) 
659 
apply simp 

660 
apply (simp add: bin_cat_Suc_Bit [symmetric] del: bin_cat.simps) 

661 
done 

662 

663 
lemma bin_to_bl_aux_cat: 

664 
"!!w bs. bin_to_bl_aux (nv + nw) (bin_cat v nw w) bs = 

665 
bin_to_bl_aux nv v (bin_to_bl_aux nw w bs)" 

666 
by (induct nw) auto 

667 

668 
lemmas bl_to_bin_aux_alt = 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

669 
bl_to_bin_aux_cat [where nv = "0" and v = "Int.Pls", 
24333  670 
simplified bl_to_bin_def [symmetric], simplified] 
671 

672 
lemmas bin_to_bl_cat = 

673 
bin_to_bl_aux_cat [where bs = "[]", folded bin_to_bl_def] 

674 

675 
lemmas bl_to_bin_aux_app_cat = 

676 
trans [OF bl_to_bin_aux_append bl_to_bin_aux_alt] 

677 

678 
lemmas bin_to_bl_aux_cat_app = 

679 
trans [OF bin_to_bl_aux_cat bin_to_bl_aux_alt] 

680 

681 
lemmas bl_to_bin_app_cat = bl_to_bin_aux_app_cat 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

682 
[where w = "Int.Pls", folded bl_to_bin_def] 
24333  683 

684 
lemmas bin_to_bl_cat_app = bin_to_bl_aux_cat_app 

685 
[where bs = "[]", folded bin_to_bl_def] 

686 

687 
(* bl_to_bin_app_cat_alt and bl_to_bin_app_cat are easily interderivable *) 

688 
lemma bl_to_bin_app_cat_alt: 

689 
"bin_cat (bl_to_bin cs) n w = bl_to_bin (cs @ bin_to_bl n w)" 

690 
by (simp add : bl_to_bin_app_cat) 

691 

692 
lemma mask_lem: "(bl_to_bin (True # replicate n False)) = 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

693 
Int.succ (bl_to_bin (replicate n True))" 
24333  694 
apply (unfold bl_to_bin_def) 
695 
apply (induct n) 

696 
apply simp 

31790  697 
apply (simp only: Suc_eq_plus1 replicate_add 
24333  698 
append_Cons [symmetric] bl_to_bin_aux_append) 
699 
apply simp 

700 
done 

701 

24465  702 
(* function bl_of_nth *) 
24333  703 
lemma length_bl_of_nth [simp]: "length (bl_of_nth n f) = n" 
704 
by (induct n) auto 

705 

706 
lemma nth_bl_of_nth [simp]: 

707 
"m < n \<Longrightarrow> rev (bl_of_nth n f) ! m = f m" 

708 
apply (induct n) 

709 
apply simp 

710 
apply (clarsimp simp add : nth_append) 

711 
apply (rule_tac f = "f" in arg_cong) 

712 
apply simp 

713 
done 

714 

715 
lemma bl_of_nth_inj: 

716 
"(!!k. k < n ==> f k = g k) ==> bl_of_nth n f = bl_of_nth n g" 

717 
by (induct n) auto 

718 

719 
lemma bl_of_nth_nth_le [rule_format] : "ALL xs. 

45475  720 
length xs >= n > bl_of_nth n (nth (rev xs)) = drop (length xs  n) xs" 
24333  721 
apply (induct n, clarsimp) 
722 
apply clarsimp 

723 
apply (rule trans [OF _ hd_Cons_tl]) 

724 
apply (frule Suc_le_lessD) 

725 
apply (simp add: nth_rev trans [OF drop_Suc drop_tl, symmetric]) 

726 
apply (subst hd_drop_conv_nth) 

727 
apply force 

728 
apply simp_all 

729 
apply (rule_tac f = "%n. drop n xs" in arg_cong) 

730 
apply simp 

731 
done 

732 

733 
lemmas bl_of_nth_nth [simp] = order_refl [THEN bl_of_nth_nth_le, simplified] 

734 

735 
lemma size_rbl_pred: "length (rbl_pred bl) = length bl" 

736 
by (induct bl) auto 

737 

738 
lemma size_rbl_succ: "length (rbl_succ bl) = length bl" 

739 
by (induct bl) auto 

740 

741 
lemma size_rbl_add: 

742 
"!!cl. length (rbl_add bl cl) = length bl" 

743 
by (induct bl) (auto simp: Let_def size_rbl_succ) 

744 

745 
lemma size_rbl_mult: 

746 
"!!cl. length (rbl_mult bl cl) = length bl" 

747 
by (induct bl) (auto simp add : Let_def size_rbl_add) 

748 

749 
lemmas rbl_sizes [simp] = 

750 
size_rbl_pred size_rbl_succ size_rbl_add size_rbl_mult 

751 

752 
lemmas rbl_Nils = 

753 
rbl_pred.Nil rbl_succ.Nil rbl_add.Nil rbl_mult.Nil 

754 

755 
lemma rbl_pred: 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

756 
"!!bin. rbl_pred (rev (bin_to_bl n bin)) = rev (bin_to_bl n (Int.pred bin))" 
24333  757 
apply (induct n, simp) 
758 
apply (unfold bin_to_bl_def) 

759 
apply clarsimp 

760 
apply (case_tac bin rule: bin_exhaust) 

761 
apply (case_tac b) 

762 
apply (clarsimp simp: bin_to_bl_aux_alt)+ 

763 
done 

764 

765 
lemma rbl_succ: 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

766 
"!!bin. rbl_succ (rev (bin_to_bl n bin)) = rev (bin_to_bl n (Int.succ bin))" 
24333  767 
apply (induct n, simp) 
768 
apply (unfold bin_to_bl_def) 

769 
apply clarsimp 

770 
apply (case_tac bin rule: bin_exhaust) 

771 
apply (case_tac b) 

772 
apply (clarsimp simp: bin_to_bl_aux_alt)+ 

773 
done 

774 

775 
lemma rbl_add: 

776 
"!!bina binb. rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = 

777 
rev (bin_to_bl n (bina + binb))" 

778 
apply (induct n, simp) 

779 
apply (unfold bin_to_bl_def) 

780 
apply clarsimp 

781 
apply (case_tac bina rule: bin_exhaust) 

782 
apply (case_tac binb rule: bin_exhaust) 

783 
apply (case_tac b) 

784 
apply (case_tac [!] "ba") 

785 
apply (auto simp: rbl_succ succ_def bin_to_bl_aux_alt Let_def add_ac) 

786 
done 

787 

788 
lemma rbl_add_app2: 

789 
"!!blb. length blb >= length bla ==> 

790 
rbl_add bla (blb @ blc) = rbl_add bla blb" 

791 
apply (induct bla, simp) 

792 
apply clarsimp 

793 
apply (case_tac blb, clarsimp) 

794 
apply (clarsimp simp: Let_def) 

795 
done 

796 

797 
lemma rbl_add_take2: 

798 
"!!blb. length blb >= length bla ==> 

799 
rbl_add bla (take (length bla) blb) = rbl_add bla blb" 

800 
apply (induct bla, simp) 

801 
apply clarsimp 

802 
apply (case_tac blb, clarsimp) 

803 
apply (clarsimp simp: Let_def) 

804 
done 

805 

806 
lemma rbl_add_long: 

807 
"m >= n ==> rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = 

808 
rev (bin_to_bl n (bina + binb))" 

809 
apply (rule box_equals [OF _ rbl_add_take2 rbl_add]) 

810 
apply (rule_tac f = "rbl_add (rev (bin_to_bl n bina))" in arg_cong) 

811 
apply (rule rev_swap [THEN iffD1]) 

812 
apply (simp add: rev_take drop_bin2bl) 

813 
apply simp 

814 
done 

815 

816 
lemma rbl_mult_app2: 

817 
"!!blb. length blb >= length bla ==> 

818 
rbl_mult bla (blb @ blc) = rbl_mult bla blb" 

819 
apply (induct bla, simp) 

820 
apply clarsimp 

821 
apply (case_tac blb, clarsimp) 

822 
apply (clarsimp simp: Let_def rbl_add_app2) 

823 
done 

824 

825 
lemma rbl_mult_take2: 

826 
"length blb >= length bla ==> 

827 
rbl_mult bla (take (length bla) blb) = rbl_mult bla blb" 

828 
apply (rule trans) 

829 
apply (rule rbl_mult_app2 [symmetric]) 

830 
apply simp 

831 
apply (rule_tac f = "rbl_mult bla" in arg_cong) 

832 
apply (rule append_take_drop_id) 

833 
done 

834 

835 
lemma rbl_mult_gt1: 

836 
"m >= length bl ==> rbl_mult bl (rev (bin_to_bl m binb)) = 

837 
rbl_mult bl (rev (bin_to_bl (length bl) binb))" 

838 
apply (rule trans) 

839 
apply (rule rbl_mult_take2 [symmetric]) 

840 
apply simp_all 

841 
apply (rule_tac f = "rbl_mult bl" in arg_cong) 

842 
apply (rule rev_swap [THEN iffD1]) 

843 
apply (simp add: rev_take drop_bin2bl) 

844 
done 

845 

846 
lemma rbl_mult_gt: 

847 
"m > n ==> rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = 

848 
rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb))" 

849 
by (auto intro: trans [OF rbl_mult_gt1]) 

850 

851 
lemmas rbl_mult_Suc = lessI [THEN rbl_mult_gt] 

852 

853 
lemma rbbl_Cons: 

37654  854 
"b # rev (bin_to_bl n x) = rev (bin_to_bl (Suc n) (x BIT If b 1 0))" 
24333  855 
apply (unfold bin_to_bl_def) 
856 
apply simp 

857 
apply (simp add: bin_to_bl_aux_alt) 

858 
done 

859 

860 
lemma rbl_mult: "!!bina binb. 

861 
rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = 

862 
rev (bin_to_bl n (bina * binb))" 

863 
apply (induct n) 

864 
apply simp 

865 
apply (unfold bin_to_bl_def) 

866 
apply clarsimp 

867 
apply (case_tac bina rule: bin_exhaust) 

868 
apply (case_tac binb rule: bin_exhaust) 

869 
apply (case_tac b) 

870 
apply (case_tac [!] "ba") 

871 
apply (auto simp: bin_to_bl_aux_alt Let_def) 

872 
apply (auto simp: rbbl_Cons rbl_mult_Suc rbl_add) 

873 
done 

874 

875 
lemma rbl_add_split: 

876 
"P (rbl_add (y # ys) (x # xs)) = 

877 
(ALL ws. length ws = length ys > ws = rbl_add ys xs > 

26008  878 
(y > ((x > P (False # rbl_succ ws)) & (~ x > P (True # ws)))) & 
24333  879 
(~ y > P (x # ws)))" 
880 
apply (auto simp add: Let_def) 

881 
apply (case_tac [!] "y") 

882 
apply auto 

883 
done 

884 

885 
lemma rbl_mult_split: 

886 
"P (rbl_mult (y # ys) xs) = 

887 
(ALL ws. length ws = Suc (length ys) > ws = False # rbl_mult ys xs > 

888 
(y > P (rbl_add ws xs)) & (~ y > P ws))" 

889 
by (clarsimp simp add : Let_def) 

890 

891 
lemma and_len: "xs = ys ==> xs = ys & length xs = length ys" 

892 
by auto 

893 

894 
lemma size_if: "size (if p then xs else ys) = (if p then size xs else size ys)" 

895 
by auto 

896 

897 
lemma tl_if: "tl (if p then xs else ys) = (if p then tl xs else tl ys)" 

898 
by auto 

899 

900 
lemma hd_if: "hd (if p then xs else ys) = (if p then hd xs else hd ys)" 

901 
by auto 

902 

24465  903 
lemma if_Not_x: "(if p then ~ x else x) = (p = (~ x))" 
904 
by auto 

905 

906 
lemma if_x_Not: "(if p then x else ~ x) = (p = x)" 

907 
by auto 

908 

24333  909 
lemma if_same_and: "(If p x y & If p u v) = (if p then x & u else y & v)" 
910 
by auto 

911 

912 
lemma if_same_eq: "(If p x y = (If p u v)) = (if p then x = (u) else y = (v))" 

913 
by auto 

914 

915 
lemma if_same_eq_not: 

916 
"(If p x y = (~ If p u v)) = (if p then x = (~u) else y = (~v))" 

917 
by auto 

918 

919 
(* note  if_Cons can cause blowup in the size, if p is complex, 

920 
so make a simproc *) 

921 
lemma if_Cons: "(if p then x # xs else y # ys) = If p x y # If p xs ys" 

922 
by auto 

923 

924 
lemma if_single: 

925 
"(if xc then [xab] else [an]) = [if xc then xab else an]" 

926 
by auto 

927 

24465  928 
lemma if_bool_simps: 
929 
"If p True y = (p  y) & If p False y = (~p & y) & 

930 
If p y True = (p > y) & If p y False = (p & y)" 

931 
by auto 

932 

933 
lemmas if_simps = if_x_Not if_Not_x if_cancel if_True if_False if_bool_simps 

934 

25350
a5fcf6d12a53
eliminated illegal schematic variables in where/of;
wenzelm
parents:
25134
diff
changeset

935 
lemmas seqr = eq_reflection [where x = "size w", standard] 
24333  936 

937 
lemmas tl_Nil = tl.simps (1) 

938 
lemmas tl_Cons = tl.simps (2) 

939 

940 

24350  941 
subsection "Repeated splitting or concatenation" 
24333  942 

943 
lemma sclem: 

944 
"size (concat (map (bin_to_bl n) xs)) = length xs * n" 

945 
by (induct xs) auto 

946 

947 
lemma bin_cat_foldl_lem [rule_format] : 

948 
"ALL x. foldl (%u. bin_cat u n) x xs = 

949 
bin_cat x (size xs * n) (foldl (%u. bin_cat u n) y xs)" 

950 
apply (induct xs) 

951 
apply simp 

952 
apply clarify 

953 
apply (simp (no_asm)) 

954 
apply (frule asm_rl) 

955 
apply (drule spec) 

956 
apply (erule trans) 

32439  957 
apply (drule_tac x = "bin_cat y n a" in 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

958 
apply (simp add : bin_cat_assoc_sym min_max.inf_absorb2) 
24333  959 
done 
960 

961 
lemma bin_rcat_bl: 

962 
"(bin_rcat n wl) = bl_to_bin (concat (map (bin_to_bl n) wl))" 

963 
apply (unfold bin_rcat_def) 

964 
apply (rule sym) 

965 
apply (induct wl) 

966 
apply (auto simp add : bl_to_bin_append) 

967 
apply (simp add : bl_to_bin_aux_alt sclem) 

968 
apply (simp add : bin_cat_foldl_lem [symmetric]) 

969 
done 

970 

971 
lemmas bin_rsplit_aux_simps = bin_rsplit_aux.simps bin_rsplitl_aux.simps 

972 
lemmas rsplit_aux_simps = bin_rsplit_aux_simps 

973 

25350
a5fcf6d12a53
eliminated illegal schematic variables in where/of;
wenzelm
parents:
25134
diff
changeset

974 
lemmas th_if_simp1 = split_if [where P = "op = l", 
24333  975 
THEN iffD1, THEN conjunct1, THEN mp, standard] 
25350
a5fcf6d12a53
eliminated illegal schematic variables in where/of;
wenzelm
parents:
25134
diff
changeset

976 
lemmas th_if_simp2 = split_if [where P = "op = l", 
24333  977 
THEN iffD1, THEN conjunct2, THEN mp, standard] 
978 

979 
lemmas rsplit_aux_simp1s = rsplit_aux_simps [THEN th_if_simp1] 

980 

981 
lemmas rsplit_aux_simp2ls = rsplit_aux_simps [THEN th_if_simp2] 

982 
(* these safe to [simp add] as require calculating m  n *) 

983 
lemmas bin_rsplit_aux_simp2s [simp] = rsplit_aux_simp2ls [unfolded Let_def] 

984 
lemmas rbscl = bin_rsplit_aux_simp2s (2) 

985 

986 
lemmas rsplit_aux_0_simps [simp] = 

987 
rsplit_aux_simp1s [OF disjI1] rsplit_aux_simp1s [OF disjI2] 

988 

989 
lemma bin_rsplit_aux_append: 

26557  990 
"bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs" 
991 
apply (induct n m c bs rule: bin_rsplit_aux.induct) 

24333  992 
apply (subst bin_rsplit_aux.simps) 
993 
apply (subst bin_rsplit_aux.simps) 

994 
apply (clarsimp split: ls_splits) 

26557  995 
apply auto 
24333  996 
done 
997 

998 
lemma bin_rsplitl_aux_append: 

26557  999 
"bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs" 
1000 
apply (induct n m c bs rule: bin_rsplitl_aux.induct) 

24333  1001 
apply (subst bin_rsplitl_aux.simps) 
1002 
apply (subst bin_rsplitl_aux.simps) 

1003 
apply (clarsimp split: ls_splits) 

26557  1004 
apply auto 
24333  1005 
done 
1006 

1007 
lemmas rsplit_aux_apps [where bs = "[]"] = 

1008 
bin_rsplit_aux_append bin_rsplitl_aux_append 

1009 

1010 
lemmas rsplit_def_auxs = bin_rsplit_def bin_rsplitl_def 

1011 

1012 
lemmas rsplit_aux_alts = rsplit_aux_apps 

1013 
[unfolded append_Nil rsplit_def_auxs [symmetric]] 

1014 

1015 
lemma bin_split_minus: "0 < n ==> bin_split (Suc (n  1)) w = bin_split n w" 

1016 
by auto 

1017 

1018 
lemmas bin_split_minus_simp = 

1019 
bin_split.Suc [THEN [2] bin_split_minus [symmetric, THEN trans], standard] 

1020 

1021 
lemma bin_split_pred_simp [simp]: 

1022 
"(0::nat) < number_of bin \<Longrightarrow> 

1023 
bin_split (number_of bin) w = 

25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25350
diff
changeset

1024 
(let (w1, w2) = bin_split (number_of (Int.pred bin)) (bin_rest w) 
24333  1025 
in (w1, w2 BIT bin_last w))" 
1026 
by (simp only: nobm1 bin_split_minus_simp) 

1027 

24465  1028 
declare bin_split_pred_simp [simp] 
1029 

24333  1030 
lemma bin_rsplit_aux_simp_alt: 
26557  1031 
"bin_rsplit_aux n m c bs = 
24333  1032 
(if m = 0 \<or> n = 0 
1033 
then bs 

1034 
else let (a, b) = bin_split n c in bin_rsplit n (m  n, a) @ b # bs)" 

26557  1035 
unfolding bin_rsplit_aux.simps [of n m c bs] 
1036 
apply simp 

1037 
apply (subst rsplit_aux_alts) 

1038 
apply (simp add: bin_rsplit_def) 

24333  1039 
done 
1040 

1041 
lemmas bin_rsplit_simp_alt = 

26557  1042 
trans [OF bin_rsplit_def 
24333  1043 
bin_rsplit_aux_simp_alt, standard] 
1044 

1045 
lemmas bthrs = bin_rsplit_simp_alt [THEN [2] trans] 

1046 

1047 
lemma bin_rsplit_size_sign' [rule_format] : 

1048 
"n > 0 ==> (ALL nw w. rev sw = bin_rsplit n (nw, w) > 

1049 
(ALL v: set sw. bintrunc n v = v))" 

1050 
apply (induct sw) 

1051 
apply clarsimp 

1052 
apply clarsimp 

1053 
apply (drule bthrs) 

1054 
apply (simp (no_asm_use) add: Let_def split: ls_splits) 

1055 
apply clarify 

1056 
apply (erule impE, rule exI, erule exI) 

1057 
apply (drule split_bintrunc) 

1058 
apply simp 

1059 
done 

1060 

1061 
lemmas bin_rsplit_size_sign = bin_rsplit_size_sign' [OF asm_rl 

1062 
rev_rev_ident [THEN trans] set_rev [THEN equalityD2 [THEN subsetD]], 

1063 
standard] 

1064 

1065 
lemma bin_nth_rsplit [rule_format] : 

1066 
"n > 0 ==> m < n ==> (ALL w k nw. rev sw = bin_rsplit n (nw, w) > 

1067 
k < size sw > bin_nth (sw ! k) m = bin_nth w (k * n + m))" 

1068 
apply (induct sw) 

1069 
apply clarsimp 

1070 
apply clarsimp 

1071 
apply (drule bthrs) 

1072 
apply (simp (no_asm_use) add: Let_def split: ls_splits) 

1073 
apply clarify 

1074 
apply (erule allE, erule impE, erule exI) 

1075 
apply (case_tac k) 

1076 
apply clarsimp 

1077 
prefer 2 

1078 
apply clarsimp 

1079 
apply (erule allE) 

1080 
apply (erule (1) impE) 

1081 
apply (drule bin_nth_split, erule conjE, erule allE, 

1082 
erule trans, simp add : add_ac)+ 

1083 
done 

1084 

1085 
lemma bin_rsplit_all: 

1086 
"0 < nw ==> nw <= n ==> bin_rsplit n (nw, w) = [bintrunc n w]" 

1087 
unfolding bin_rsplit_def 

1088 
by (clarsimp dest!: split_bintrunc simp: rsplit_aux_simp2ls split: ls_splits) 

1089 

1090 
lemma bin_rsplit_l [rule_format] : 

1091 
"ALL bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, bintrunc m bin)" 

1092 
apply (rule_tac a = "m" in wf_less_than [THEN wf_induct]) 

1093 
apply (simp (no_asm) add : bin_rsplitl_def bin_rsplit_def) 

1094 
apply (rule allI) 

1095 
apply (subst bin_rsplitl_aux.simps) 

1096 
apply (subst bin_rsplit_aux.simps) 

26557  1097 
apply (clarsimp simp: Let_def split: ls_splits) 
24333  1098 
apply (drule bin_split_trunc) 
1099 
apply (drule sym [THEN trans], assumption) 

26557  1100 
apply (subst rsplit_aux_alts(1)) 
1101 
apply (subst rsplit_aux_alts(2)) 

1102 
apply clarsimp 

1103 
unfolding bin_rsplit_def bin_rsplitl_def 

1104 
apply simp 

24333  1105 
done 
26557  1106 

24333  1107 
lemma bin_rsplit_rcat [rule_format] : 
1108 
"n > 0 > bin_rsplit n (n * size ws, bin_rcat n ws) = map (bintrunc n) ws" 

1109 
apply (unfold bin_rsplit_def bin_rcat_def) 

1110 
apply (rule_tac xs = "ws" in rev_induct) 

1111 
apply clarsimp 

1112 
apply clarsimp 

26557  1113 
apply (subst rsplit_aux_alts) 
1114 
unfolding bin_split_cat 

1115 
apply simp 

24333  1116 
done 
1117 

1118 
lemma bin_rsplit_aux_len_le [rule_format] : 

26557  1119 
"\<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> 
1120 
length ws \<le> m \<longleftrightarrow> nw + length bs * n \<le> m * n" 

1121 
apply (induct n nw w bs rule: bin_rsplit_aux.induct) 

24333  1122 
apply (subst bin_rsplit_aux.simps) 
26557  1123 
apply (simp add: lrlem Let_def split: ls_splits) 
24333  1124 
done 
1125 

1126 
lemma bin_rsplit_len_le: 

25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset

1127 
"n \<noteq> 0 > ws = bin_rsplit n (nw, w) > (length ws <= m) = (nw <= m * n)" 
24333  1128 
unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len_le) 
1129 

1130 
lemma bin_rsplit_aux_len [rule_format] : 

26557  1131 
"n\<noteq>0 > length (bin_rsplit_aux n nw w cs) = 
24333  1132 
(nw + n  1) div n + length cs" 
26557  1133 
apply (induct n nw w cs rule: bin_rsplit_aux.induct) 
24333  1134 
apply (subst bin_rsplit_aux.simps) 
1135 
apply (clarsimp simp: Let_def split: ls_splits) 

1136 
apply (erule thin_rl) 

27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
27105
diff
changeset

1137 
apply (case_tac m) 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
27105
diff
changeset

1138 
apply simp 
24333  1139 
apply (case_tac "m <= n") 
27677  1140 
apply auto 
24333  1141 
done 
1142 

1143 
lemma bin_rsplit_len: 

25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset

1144 
"n\<noteq>0 ==> length (bin_rsplit n (nw, w)) = (nw + n  1) div n" 
24333  1145 
unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len) 
1146 

26557  1147 
lemma bin_rsplit_aux_len_indep: 
1148 
"n \<noteq> 0 \<Longrightarrow> length bs = length cs \<Longrightarrow> 

1149 
length (bin_rsplit_aux n nw v bs) = 

1150 
length (bin_rsplit_aux n nw w cs)" 

1151 
proof (induct n nw w cs arbitrary: v bs rule: bin_rsplit_aux.induct) 

1152 
case (1 n m w cs v bs) show ?case 

1153 
proof (cases "m = 0") 

28298  1154 
case True then show ?thesis using `length bs = length cs` by simp 
26557  1155 
next 
1156 
case False 

1157 
from "1.hyps" `m \<noteq> 0` `n \<noteq> 0` have hyp: "\<And>v bs. length bs = Suc (length cs) \<Longrightarrow> 

1158 
length (bin_rsplit_aux n (m  n) v bs) = 

1159 
length (bin_rsplit_aux n (m  n) (fst (bin_split n w)) (snd (bin_split n w) # cs))" 

1160 
by auto 

1161 
show ?thesis using `length bs = length cs` `n \<noteq> 0` 

1162 
by (auto simp add: bin_rsplit_aux_simp_alt Let_def bin_rsplit_len 

1163 
split: ls_splits) 

1164 
qed 

1165 
qed 

24333  1166 

1167 
lemma bin_rsplit_len_indep: 

25134
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents:
25112
diff
changeset

1168 
"n\<noteq>0 ==> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))" 
24333  1169 
apply (unfold bin_rsplit_def) 
26557  1170 
apply (simp (no_asm)) 
24333  1171 
apply (erule bin_rsplit_aux_len_indep) 
1172 
apply (rule refl) 

1173 
done 

1174 

1175 
end 