9 |
9 |
10 header "Bool lists and integers" |
10 header "Bool lists and integers" |
11 |
11 |
12 theory BinBoolList imports BinOperations begin |
12 theory BinBoolList imports BinOperations begin |
13 |
13 |
14 subsection "Lemmas about standard list operations" |
14 subsection "Arithmetic in terms of bool lists" |
|
15 |
|
16 consts (* arithmetic operations in terms of the reversed bool list, |
|
17 assuming input list(s) the same length, and don't extend them *) |
|
18 rbl_succ :: "bool list => bool list" |
|
19 rbl_pred :: "bool list => bool list" |
|
20 rbl_add :: "bool list => bool list => bool list" |
|
21 rbl_mult :: "bool list => bool list => bool list" |
|
22 |
|
23 primrec |
|
24 Nil: "rbl_succ Nil = Nil" |
|
25 Cons: "rbl_succ (x # xs) = (if x then False # rbl_succ xs else True # xs)" |
|
26 |
|
27 primrec |
|
28 Nil : "rbl_pred Nil = Nil" |
|
29 Cons : "rbl_pred (x # xs) = (if x then False # xs else True # rbl_pred xs)" |
|
30 |
|
31 primrec (* result is length of first arg, second arg may be longer *) |
|
32 Nil : "rbl_add Nil x = Nil" |
|
33 Cons : "rbl_add (y # ys) x = (let ws = rbl_add ys (tl x) in |
|
34 (y ~= hd x) # (if hd x & y then rbl_succ ws else ws))" |
|
35 |
|
36 primrec (* result is length of first arg, second arg may be longer *) |
|
37 Nil : "rbl_mult Nil x = Nil" |
|
38 Cons : "rbl_mult (y # ys) x = (let ws = False # rbl_mult ys x in |
|
39 if y then rbl_add ws x else ws)" |
15 |
40 |
16 lemma tl_take: "tl (take n l) = take (n - 1) (tl l)" |
41 lemma tl_take: "tl (take n l) = take (n - 1) (tl l)" |
17 apply (cases n, clarsimp) |
42 apply (cases n, clarsimp) |
18 apply (cases l, auto) |
43 apply (cases l, auto) |
19 done |
44 done |
48 |
73 |
49 lemma butlast_power: |
74 lemma butlast_power: |
50 "(butlast ^ n) bl = take (length bl - n) bl" |
75 "(butlast ^ n) bl = take (length bl - n) bl" |
51 by (induct n) (auto simp: butlast_take) |
76 by (induct n) (auto simp: butlast_take) |
52 |
77 |
53 lemma nth_rev [rule_format] : |
|
54 "n < length xs --> rev xs ! n = xs ! (length xs - 1 - n)" |
|
55 apply (induct_tac "xs") |
|
56 apply simp |
|
57 apply (clarsimp simp add : nth_append nth.simps split add : nat.split) |
|
58 apply (rule_tac f = "%n. list ! n" in arg_cong) |
|
59 apply arith |
|
60 done |
|
61 |
|
62 lemmas nth_rev_alt = nth_rev [where xs = "rev ?ys", simplified] |
|
63 |
|
64 lemma hd_butlast: "size xs > 1 ==> hd (butlast xs) = hd xs" |
|
65 by (cases xs) auto |
|
66 |
|
67 subsection "From integers to bool lists" |
|
68 |
|
69 consts |
|
70 bin_to_bl :: "nat => int => bool list" |
|
71 bin_to_bl_aux :: "nat => int => bool list => bool list" |
|
72 |
|
73 primrec |
|
74 Z : "bin_to_bl_aux 0 w bl = bl" |
|
75 Suc : "bin_to_bl_aux (Suc n) w bl = |
|
76 bin_to_bl_aux n (bin_rest w) ((bin_last w = bit.B1) # bl)" |
|
77 |
|
78 defs |
|
79 bin_to_bl_def : "bin_to_bl n w == bin_to_bl_aux n w []" |
|
80 |
|
81 lemma bin_to_bl_aux_Pls_minus_simp: |
78 lemma bin_to_bl_aux_Pls_minus_simp: |
82 "0 < n ==> bin_to_bl_aux n Numeral.Pls bl = |
79 "0 < n ==> bin_to_bl_aux n Numeral.Pls bl = |
83 bin_to_bl_aux (n - 1) Numeral.Pls (False # bl)" |
80 bin_to_bl_aux (n - 1) Numeral.Pls (False # bl)" |
84 by (cases n) auto |
81 by (cases n) auto |
85 |
82 |
95 |
92 |
96 declare bin_to_bl_aux_Pls_minus_simp [simp] |
93 declare bin_to_bl_aux_Pls_minus_simp [simp] |
97 bin_to_bl_aux_Min_minus_simp [simp] |
94 bin_to_bl_aux_Min_minus_simp [simp] |
98 bin_to_bl_aux_Bit_minus_simp [simp] |
95 bin_to_bl_aux_Bit_minus_simp [simp] |
99 |
96 |
|
97 (** link between bin and bool list **) |
|
98 |
|
99 lemma bl_to_bin_aux_append [rule_format] : |
|
100 "ALL w. bl_to_bin_aux w (bs @ cs) = bl_to_bin_aux (bl_to_bin_aux w bs) cs" |
|
101 by (induct bs) auto |
|
102 |
100 lemma bin_to_bl_aux_append [rule_format] : |
103 lemma bin_to_bl_aux_append [rule_format] : |
101 "ALL w bs. bin_to_bl_aux n w bs @ cs = bin_to_bl_aux n w (bs @ cs)" |
104 "ALL w bs. bin_to_bl_aux n w bs @ cs = bin_to_bl_aux n w (bs @ cs)" |
102 by (induct n) auto |
105 by (induct n) auto |
103 |
106 |
|
107 lemma bl_to_bin_append: |
|
108 "bl_to_bin (bs @ cs) = bl_to_bin_aux (bl_to_bin bs) cs" |
|
109 unfolding bl_to_bin_def by (rule bl_to_bin_aux_append) |
|
110 |
104 lemma bin_to_bl_aux_alt: |
111 lemma bin_to_bl_aux_alt: |
105 "bin_to_bl_aux n w bs = bin_to_bl n w @ bs" |
112 "bin_to_bl_aux n w bs = bin_to_bl n w @ bs" |
106 unfolding bin_to_bl_def by (simp add : bin_to_bl_aux_append) |
113 unfolding bin_to_bl_def by (simp add : bin_to_bl_aux_append) |
107 |
114 |
108 lemma bin_to_bl_0 [simp]: "bin_to_bl 0 bs = []" |
115 lemma bin_to_bl_0: "bin_to_bl 0 bs = []" |
109 unfolding bin_to_bl_def by auto |
116 unfolding bin_to_bl_def by auto |
110 |
117 |
111 lemma size_bin_to_bl_aux [rule_format] : |
118 lemma size_bin_to_bl_aux [rule_format] : |
112 "ALL w bs. size (bin_to_bl_aux n w bs) = n + length bs" |
119 "ALL w bs. size (bin_to_bl_aux n w bs) = n + length bs" |
113 by (induct n) auto |
120 by (induct n) auto |
114 |
121 |
115 lemma size_bin_to_bl [simp]: "size (bin_to_bl n w) = n" |
122 lemma size_bin_to_bl: "size (bin_to_bl n w) = n" |
116 unfolding bin_to_bl_def by (simp add : size_bin_to_bl_aux) |
123 unfolding bin_to_bl_def by (simp add : size_bin_to_bl_aux) |
117 |
|
118 lemma bin_to_bl_Pls_aux [rule_format] : |
|
119 "ALL bl. bin_to_bl_aux n Numeral.Pls bl = replicate n False @ bl" |
|
120 by (induct n) (auto simp: replicate_app_Cons_same) |
|
121 |
|
122 lemma bin_to_bl_Pls: "bin_to_bl n Numeral.Pls = replicate n False" |
|
123 unfolding bin_to_bl_def by (simp add : bin_to_bl_Pls_aux) |
|
124 |
|
125 lemma bin_to_bl_Min_aux [rule_format] : |
|
126 "ALL bl. bin_to_bl_aux n Numeral.Min bl = replicate n True @ bl" |
|
127 by (induct n) (auto simp: replicate_app_Cons_same) |
|
128 |
|
129 lemma bin_to_bl_Min: "bin_to_bl n Numeral.Min = replicate n True" |
|
130 unfolding bin_to_bl_def by (simp add : bin_to_bl_Min_aux) |
|
131 |
|
132 lemma bin_to_bl_aux_bintr [rule_format] : |
|
133 "ALL m bin bl. bin_to_bl_aux n (bintrunc m bin) bl = |
|
134 replicate (n - m) False @ bin_to_bl_aux (min n m) bin bl" |
|
135 apply (induct_tac "n") |
|
136 apply clarsimp |
|
137 apply clarsimp |
|
138 apply (case_tac "m") |
|
139 apply (clarsimp simp: bin_to_bl_Pls_aux) |
|
140 apply (erule thin_rl) |
|
141 apply (induct_tac n) |
|
142 apply auto |
|
143 done |
|
144 |
|
145 lemmas bin_to_bl_bintr = |
|
146 bin_to_bl_aux_bintr [where bl = "[]", folded bin_to_bl_def] |
|
147 |
|
148 lemma len_bin_to_bl_aux [rule_format] : |
|
149 "ALL w bs. length (bin_to_bl_aux n w bs) = n + length bs" |
|
150 by (induct "n") auto |
|
151 |
|
152 lemma len_bin_to_bl [simp]: "length (bin_to_bl n w) = n" |
|
153 unfolding bin_to_bl_def len_bin_to_bl_aux by auto |
|
154 |
|
155 |
|
156 subsection "From bool lists to integers" |
|
157 |
|
158 consts |
|
159 bl_to_bin :: "bool list => int" |
|
160 bl_to_bin_aux :: "int => bool list => int" |
|
161 |
|
162 primrec |
|
163 Nil : "bl_to_bin_aux w [] = w" |
|
164 Cons : "bl_to_bin_aux w (b # bs) = |
|
165 bl_to_bin_aux (w BIT (if b then bit.B1 else bit.B0)) bs" |
|
166 |
|
167 defs |
|
168 bl_to_bin_def : "bl_to_bin bs == bl_to_bin_aux Numeral.Pls bs" |
|
169 |
|
170 (** link between bin and bool list **) |
|
171 |
|
172 lemma bl_to_bin_aux_append [rule_format] : |
|
173 "ALL w. bl_to_bin_aux w (bs @ cs) = bl_to_bin_aux (bl_to_bin_aux w bs) cs" |
|
174 by (induct bs) auto |
|
175 |
|
176 lemma bl_to_bin_append: |
|
177 "bl_to_bin (bs @ cs) = bl_to_bin_aux (bl_to_bin bs) cs" |
|
178 unfolding bl_to_bin_def by (rule bl_to_bin_aux_append) |
|
179 |
|
180 lemma bl_to_bin_False [simp]: "bl_to_bin (False # bl) = bl_to_bin bl" |
|
181 unfolding bl_to_bin_def by auto |
|
182 |
|
183 lemma bl_to_bin_Nil [simp]: "bl_to_bin [] = Numeral.Pls" |
|
184 unfolding bl_to_bin_def by auto |
|
185 |
|
186 lemma bl_to_bin_rep_F: |
|
187 "bl_to_bin (replicate n False @ bl) = bl_to_bin bl" |
|
188 by (induct n) auto |
|
189 |
|
190 lemma bl_to_bin_rep_False: "bl_to_bin (replicate n False) = Numeral.Pls" |
|
191 by (induct n) auto |
|
192 |
|
193 |
|
194 subsection "Converting between bool lists and integers" |
|
195 |
124 |
196 lemma bin_bl_bin' [rule_format] : |
125 lemma bin_bl_bin' [rule_format] : |
197 "ALL w bs. bl_to_bin (bin_to_bl_aux n w bs) = |
126 "ALL w bs. bl_to_bin (bin_to_bl_aux n w bs) = |
198 bl_to_bin_aux (bintrunc n w) bs" |
127 bl_to_bin_aux (bintrunc n w) bs" |
199 by (induct n) (auto simp add : bl_to_bin_def) |
128 by (induct n) (auto simp add : bl_to_bin_def) |
200 |
129 |
201 lemma bin_bl_bin [simp]: "bl_to_bin (bin_to_bl n w) = bintrunc n w" |
130 lemma bin_bl_bin: "bl_to_bin (bin_to_bl n w) = bintrunc n w" |
202 unfolding bin_to_bl_def bin_bl_bin' by auto |
131 unfolding bin_to_bl_def bin_bl_bin' by auto |
203 |
132 |
204 lemma bl_bin_bl' [rule_format] : |
133 lemma bl_bin_bl' [rule_format] : |
205 "ALL w n. bin_to_bl (n + length bs) (bl_to_bin_aux w bs) = |
134 "ALL w n. bin_to_bl (n + length bs) (bl_to_bin_aux w bs) = |
206 bin_to_bl_aux n w bs" |
135 bin_to_bl_aux n w bs" |
208 apply auto |
137 apply auto |
209 apply (simp_all only : add_Suc [symmetric]) |
138 apply (simp_all only : add_Suc [symmetric]) |
210 apply (auto simp add : bin_to_bl_def) |
139 apply (auto simp add : bin_to_bl_def) |
211 done |
140 done |
212 |
141 |
213 lemma bl_bin_bl [simp]: "bin_to_bl (length bs) (bl_to_bin bs) = bs" |
142 lemma bl_bin_bl: "bin_to_bl (length bs) (bl_to_bin bs) = bs" |
214 unfolding bl_to_bin_def |
143 unfolding bl_to_bin_def |
215 apply (rule box_equals) |
144 apply (rule box_equals) |
216 apply (rule bl_bin_bl') |
145 apply (rule bl_bin_bl') |
217 prefer 2 |
146 prefer 2 |
218 apply (rule bin_to_bl_aux.Z) |
147 apply (rule bin_to_bl_aux.Z) |
219 apply simp |
148 apply simp |
220 done |
149 done |
221 |
150 |
|
151 declare |
|
152 bin_to_bl_0 [simp] |
|
153 size_bin_to_bl [simp] |
|
154 bin_bl_bin [simp] |
|
155 bl_bin_bl [simp] |
|
156 |
222 lemma bl_to_bin_inj: |
157 lemma bl_to_bin_inj: |
223 "bl_to_bin bs = bl_to_bin cs ==> length bs = length cs ==> bs = cs" |
158 "bl_to_bin bs = bl_to_bin cs ==> length bs = length cs ==> bs = cs" |
224 apply (rule_tac box_equals) |
159 apply (rule_tac box_equals) |
225 defer |
160 defer |
226 apply (rule bl_bin_bl) |
161 apply (rule bl_bin_bl) |
227 apply (rule bl_bin_bl) |
162 apply (rule bl_bin_bl) |
228 apply simp |
163 apply simp |
229 done |
164 done |
230 |
165 |
231 lemma bin_to_bl_trunc [simp]: |
166 lemma bl_to_bin_False: "bl_to_bin (False # bl) = bl_to_bin bl" |
|
167 unfolding bl_to_bin_def by auto |
|
168 |
|
169 lemma bl_to_bin_Nil: "bl_to_bin [] = Numeral.Pls" |
|
170 unfolding bl_to_bin_def by auto |
|
171 |
|
172 lemma bin_to_bl_Pls_aux [rule_format] : |
|
173 "ALL bl. bin_to_bl_aux n Numeral.Pls bl = replicate n False @ bl" |
|
174 by (induct n) (auto simp: replicate_app_Cons_same) |
|
175 |
|
176 lemma bin_to_bl_Pls: "bin_to_bl n Numeral.Pls = replicate n False" |
|
177 unfolding bin_to_bl_def by (simp add : bin_to_bl_Pls_aux) |
|
178 |
|
179 lemma bin_to_bl_Min_aux [rule_format] : |
|
180 "ALL bl. bin_to_bl_aux n Numeral.Min bl = replicate n True @ bl" |
|
181 by (induct n) (auto simp: replicate_app_Cons_same) |
|
182 |
|
183 lemma bin_to_bl_Min: "bin_to_bl n Numeral.Min = replicate n True" |
|
184 unfolding bin_to_bl_def by (simp add : bin_to_bl_Min_aux) |
|
185 |
|
186 lemma bl_to_bin_rep_F: |
|
187 "bl_to_bin (replicate n False @ bl) = bl_to_bin bl" |
|
188 apply (simp add: bin_to_bl_Pls_aux [symmetric] bin_bl_bin') |
|
189 apply (simp add: bl_to_bin_def) |
|
190 done |
|
191 |
|
192 lemma bin_to_bl_trunc: |
232 "n <= m ==> bin_to_bl n (bintrunc m w) = bin_to_bl n w" |
193 "n <= m ==> bin_to_bl n (bintrunc m w) = bin_to_bl n w" |
233 by (auto intro: bl_to_bin_inj) |
194 by (auto intro: bl_to_bin_inj) |
234 |
195 |
235 subsection "@{term bin_sign} with bool list operations" |
196 declare |
236 |
197 bin_to_bl_trunc [simp] |
|
198 bl_to_bin_False [simp] |
|
199 bl_to_bin_Nil [simp] |
|
200 |
|
201 lemma bin_to_bl_aux_bintr [rule_format] : |
|
202 "ALL m bin bl. bin_to_bl_aux n (bintrunc m bin) bl = |
|
203 replicate (n - m) False @ bin_to_bl_aux (min n m) bin bl" |
|
204 apply (induct_tac "n") |
|
205 apply clarsimp |
|
206 apply clarsimp |
|
207 apply (case_tac "m") |
|
208 apply (clarsimp simp: bin_to_bl_Pls_aux) |
|
209 apply (erule thin_rl) |
|
210 apply (induct_tac n) |
|
211 apply auto |
|
212 done |
|
213 |
|
214 lemmas bin_to_bl_bintr = |
|
215 bin_to_bl_aux_bintr [where bl = "[]", folded bin_to_bl_def] |
|
216 |
|
217 lemma bl_to_bin_rep_False: "bl_to_bin (replicate n False) = Numeral.Pls" |
|
218 by (induct n) auto |
|
219 |
|
220 lemma len_bin_to_bl_aux [rule_format] : |
|
221 "ALL w bs. length (bin_to_bl_aux n w bs) = n + length bs" |
|
222 by (induct "n") auto |
|
223 |
|
224 lemma len_bin_to_bl [simp]: "length (bin_to_bl n w) = n" |
|
225 unfolding bin_to_bl_def len_bin_to_bl_aux by auto |
|
226 |
237 lemma sign_bl_bin' [rule_format] : |
227 lemma sign_bl_bin' [rule_format] : |
238 "ALL w. bin_sign (bl_to_bin_aux w bs) = bin_sign w" |
228 "ALL w. bin_sign (bl_to_bin_aux w bs) = bin_sign w" |
239 by (induct bs) auto |
229 by (induct bs) auto |
240 |
230 |
241 lemma sign_bl_bin: "bin_sign (bl_to_bin bs) = Numeral.Pls" |
231 lemma sign_bl_bin: "bin_sign (bl_to_bin bs) = Numeral.Pls" |
282 apply (case_tac m, clarsimp) |
270 apply (case_tac m, clarsimp) |
283 apply (clarsimp simp: bin_to_bl_def) |
271 apply (clarsimp simp: bin_to_bl_def) |
284 apply (simp add: bin_to_bl_aux_alt) |
272 apply (simp add: bin_to_bl_aux_alt) |
285 done |
273 done |
286 |
274 |
|
275 lemma nth_rev [rule_format] : |
|
276 "n < length xs --> rev xs ! n = xs ! (length xs - 1 - n)" |
|
277 apply (induct_tac "xs") |
|
278 apply simp |
|
279 apply (clarsimp simp add : nth_append nth.simps split add : nat.split) |
|
280 apply (rule_tac f = "%n. list ! n" in arg_cong) |
|
281 apply arith |
|
282 done |
|
283 |
|
284 lemmas nth_rev_alt = nth_rev [where xs = "rev ?ys", simplified] |
|
285 |
287 lemma nth_bin_to_bl_aux [rule_format] : |
286 lemma nth_bin_to_bl_aux [rule_format] : |
288 "ALL w n bl. n < m + length bl --> (bin_to_bl_aux m w bl) ! n = |
287 "ALL w n bl. n < m + length bl --> (bin_to_bl_aux m w bl) ! n = |
289 (if n < m then bin_nth w (m - 1 - n) else bl ! (n - m))" |
288 (if n < m then bin_nth w (m - 1 - n) else bl ! (n - m))" |
290 apply (induct_tac "m") |
289 apply (induct_tac "m") |
291 apply clarsimp |
290 apply clarsimp |
564 lemma bin_split_take1: |
547 lemma bin_split_take1: |
565 "k = m + n ==> bin_split n c = (a, b) ==> |
548 "k = m + n ==> bin_split n c = (a, b) ==> |
566 bin_to_bl m a = take m (bin_to_bl k c)" |
549 bin_to_bl m a = take m (bin_to_bl k c)" |
567 by (auto elim: bin_split_take) |
550 by (auto elim: bin_split_take) |
568 |
551 |
569 subsection "@{term takefill}" |
|
570 |
|
571 consts |
|
572 takefill :: "'a => nat => 'a list => 'a list" |
|
573 |
|
574 -- "takefill - like take but if argument list too short," |
|
575 -- "extends result to get requested length" |
|
576 primrec |
|
577 Z : "takefill fill 0 xs = []" |
|
578 Suc : "takefill fill (Suc n) xs = ( |
|
579 case xs of [] => fill # takefill fill n xs |
|
580 | y # ys => y # takefill fill n ys)" |
|
581 |
|
582 lemma nth_takefill [rule_format] : "ALL m l. m < n --> |
552 lemma nth_takefill [rule_format] : "ALL m l. m < n --> |
583 takefill fill n l ! m = (if m < length l then l ! m else fill)" |
553 takefill fill n l ! m = (if m < length l then l ! m else fill)" |
584 apply (induct n, clarsimp) |
554 apply (induct n, clarsimp) |
585 apply clarsimp |
555 apply clarsimp |
586 apply (case_tac m) |
556 apply (case_tac m) |
761 apply (rule_tac f = "%n. drop n xs" in arg_cong) |
721 apply (rule_tac f = "%n. drop n xs" in arg_cong) |
762 apply simp |
722 apply simp |
763 done |
723 done |
764 |
724 |
765 lemmas bl_of_nth_nth [simp] = order_refl [THEN bl_of_nth_nth_le, simplified] |
725 lemmas bl_of_nth_nth [simp] = order_refl [THEN bl_of_nth_nth_le, simplified] |
766 |
|
767 subsection "Arithmetic in terms of bool lists" |
|
768 |
|
769 consts (* arithmetic operations in terms of the reversed bool list, |
|
770 assuming input list(s) the same length, and don't extend them *) |
|
771 rbl_succ :: "bool list => bool list" |
|
772 rbl_pred :: "bool list => bool list" |
|
773 rbl_add :: "bool list => bool list => bool list" |
|
774 rbl_mult :: "bool list => bool list => bool list" |
|
775 |
|
776 primrec |
|
777 Nil: "rbl_succ Nil = Nil" |
|
778 Cons: "rbl_succ (x # xs) = (if x then False # rbl_succ xs else True # xs)" |
|
779 |
|
780 primrec |
|
781 Nil : "rbl_pred Nil = Nil" |
|
782 Cons : "rbl_pred (x # xs) = (if x then False # xs else True # rbl_pred xs)" |
|
783 |
|
784 primrec (* result is length of first arg, second arg may be longer *) |
|
785 Nil : "rbl_add Nil x = Nil" |
|
786 Cons : "rbl_add (y # ys) x = (let ws = rbl_add ys (tl x) in |
|
787 (y ~= hd x) # (if hd x & y then rbl_succ ws else ws))" |
|
788 |
|
789 primrec (* result is length of first arg, second arg may be longer *) |
|
790 Nil : "rbl_mult Nil x = Nil" |
|
791 Cons : "rbl_mult (y # ys) x = (let ws = False # rbl_mult ys x in |
|
792 if y then rbl_add ws x else ws)" |
|
793 |
726 |
794 lemma size_rbl_pred: "length (rbl_pred bl) = length bl" |
727 lemma size_rbl_pred: "length (rbl_pred bl) = length bl" |
795 by (induct bl) auto |
728 by (induct bl) auto |
796 |
729 |
797 lemma size_rbl_succ: "length (rbl_succ bl) = length bl" |
730 lemma size_rbl_succ: "length (rbl_succ bl) = length bl" |
945 "P (rbl_mult (y # ys) xs) = |
878 "P (rbl_mult (y # ys) xs) = |
946 (ALL ws. length ws = Suc (length ys) --> ws = False # rbl_mult ys xs --> |
879 (ALL ws. length ws = Suc (length ys) --> ws = False # rbl_mult ys xs --> |
947 (y --> P (rbl_add ws xs)) & (~ y --> P ws))" |
880 (y --> P (rbl_add ws xs)) & (~ y --> P ws))" |
948 by (clarsimp simp add : Let_def) |
881 by (clarsimp simp add : Let_def) |
949 |
882 |
950 subsection "Miscellaneous lemmas" |
|
951 |
|
952 lemma and_len: "xs = ys ==> xs = ys & length xs = length ys" |
883 lemma and_len: "xs = ys ==> xs = ys & length xs = length ys" |
953 by auto |
884 by auto |
954 |
885 |
955 lemma size_if: "size (if p then xs else ys) = (if p then size xs else size ys)" |
886 lemma size_if: "size (if p then xs else ys) = (if p then size xs else size ys)" |
956 by auto |
887 by auto |
957 |
888 |
958 lemma tl_if: "tl (if p then xs else ys) = (if p then tl xs else tl ys)" |
889 lemma tl_if: "tl (if p then xs else ys) = (if p then tl xs else tl ys)" |
959 by auto |
890 by auto |
960 |
891 |
961 lemma hd_if: "hd (if p then xs else ys) = (if p then hd xs else hd ys)" |
892 lemma hd_if: "hd (if p then xs else ys) = (if p then hd xs else hd ys)" |
|
893 by auto |
|
894 |
|
895 lemma if_Not_x: "(if p then ~ x else x) = (p = (~ x))" |
|
896 by auto |
|
897 |
|
898 lemma if_x_Not: "(if p then x else ~ x) = (p = x)" |
962 by auto |
899 by auto |
963 |
900 |
964 lemma if_same_and: "(If p x y & If p u v) = (if p then x & u else y & v)" |
901 lemma if_same_and: "(If p x y & If p u v) = (if p then x & u else y & v)" |
965 by auto |
902 by auto |
966 |
903 |
1068 "(0::nat) < number_of bin \<Longrightarrow> |
1012 "(0::nat) < number_of bin \<Longrightarrow> |
1069 bin_split (number_of bin) w = |
1013 bin_split (number_of bin) w = |
1070 (let (w1, w2) = bin_split (number_of (Numeral.pred bin)) (bin_rest w) |
1014 (let (w1, w2) = bin_split (number_of (Numeral.pred bin)) (bin_rest w) |
1071 in (w1, w2 BIT bin_last w))" |
1015 in (w1, w2 BIT bin_last w))" |
1072 by (simp only: nobm1 bin_split_minus_simp) |
1016 by (simp only: nobm1 bin_split_minus_simp) |
|
1017 |
|
1018 declare bin_split_pred_simp [simp] |
1073 |
1019 |
1074 lemma bin_rsplit_aux_simp_alt: |
1020 lemma bin_rsplit_aux_simp_alt: |
1075 "bin_rsplit_aux (n, bs, m, c) = |
1021 "bin_rsplit_aux (n, bs, m, c) = |
1076 (if m = 0 \<or> n = 0 |
1022 (if m = 0 \<or> n = 0 |
1077 then bs |
1023 then bs |