| author | wenzelm | 
| Thu, 29 Aug 2013 15:24:36 +0200 | |
| changeset 53278 | c31532691e55 | 
| parent 53062 | 3af1a6020014 | 
| child 53438 | 6301ed01e34d | 
| permissions | -rw-r--r-- | 
| 24333 | 1 | (* | 
| 2 | Author: Jeremy Dawson, NICTA | |
| 3 | ||
| 44939 
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
 kleing parents: 
41842diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
47219diff
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: 
45997diff
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: 
41842diff
changeset | 63 | text {* 
 | 
| 
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
 kleing parents: 
41842diff
changeset | 64 | Arithmetic operations in terms of the reversed bool list, | 
| 
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
 kleing parents: 
41842diff
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: 
41842diff
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: 
41842diff
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: 
41842diff
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: 
45997diff
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: 
45997diff
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: 
45997diff
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: 
45997diff
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: 
45997diff
changeset | 96 | |
| 46617 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
changeset | 97 | lemma bin_to_bl_aux_minus1_minus_simp [simp]: | 
| 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
changeset | 98 | "0 < n ==> bin_to_bl_aux n -1 bl = | 
| 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
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: 
46240diff
changeset | 102 | lemma bin_to_bl_aux_one_minus_simp [simp]: | 
| 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
changeset | 103 | "0 < n \<Longrightarrow> bin_to_bl_aux n 1 bl = | 
| 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
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: 
26008diff
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: 
26008diff
changeset | 112 | lemma bin_to_bl_aux_Bit0_minus_simp [simp]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
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: 
46655diff
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: 
26008diff
changeset | 115 | by (cases n) auto | 
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26008diff
changeset | 116 | |
| 
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
 huffman parents: 
26008diff
changeset | 117 | lemma bin_to_bl_aux_Bit1_minus_simp [simp]: | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
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: 
46655diff
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: 
26008diff
changeset | 120 | by (cases n) auto | 
| 24333 | 121 | |
| 44939 
5930d35c976d
removed unused legacy lemma names, some comment cleanup.
 kleing parents: 
41842diff
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: 
45854diff
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: 
45854diff
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: 
45854diff
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: 
45854diff
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: 
45854diff
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: 
45997diff
changeset | 186 | unfolding bl_to_bin_def by auto | 
| 45996 
e69d631fe9af
declare simp rules immediately, instead of using 'declare' commands
 huffman parents: 
45854diff
changeset | 187 | |
| 46001 
0b562d564d5f
redefine some binary operations on integers work on abstract numerals instead of Int.Pls and Int.Min
 huffman parents: 
45997diff
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: 
45997diff
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: 
45997diff
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: 
45997diff
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: 
45997diff
changeset | 194 | |
| 46617 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
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: 
46240diff
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: 
46240diff
changeset | 197 | |
| 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
changeset | 198 | lemma bin_to_bl_minus1_aux: | 
| 
8c5d10d41391
make bool list functions respect int/bin distinction
 huffman parents: 
46240diff
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: 
46240diff
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: 
46240diff
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: 
45997diff
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: 
45854diff
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: 
45996diff
changeset | 215 | lemma bin_to_bl_aux_bintr: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
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: 
45996diff
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: 
45997diff
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: 
45847diff
changeset | 228 | lemma bin_to_bl_bintr: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 229 | "bin_to_bl n (bintrunc m bin) = | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 230 | replicate (n - m) False @ bin_to_bl (min n m) bin" | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
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: 
45997diff
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: 
46240diff
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: 
45997diff
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: 
45997diff
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: 
45997diff
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: 
45996diff
changeset | 264 | lemma bin_nth_of_bl_aux: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
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: 
45996diff
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: 
45996diff
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: 
45996diff
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: 
45996diff
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: 
45996diff
changeset | 290 | lemma nth_rev: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
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: 
45996diff
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: 
45996diff
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: 
45847diff
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: 
45847diff
changeset | 300 | by (simp add: nth_rev) | 
| 24465 | 301 | |
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 302 | lemma nth_bin_to_bl_aux: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
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: 
45996diff
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: 
45996diff
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: 
45996diff
changeset | 315 | lemma bl_to_bin_lt2p_aux: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 316 | "bl_to_bin_aux bs w < (w + 1) * (2 ^ length bs)" | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
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: 
47219diff
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: 
47219diff
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: 
45996diff
changeset | 332 | lemma bl_to_bin_ge2p_aux: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 333 | "bl_to_bin_aux bs w >= w * (2 ^ length bs)" | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
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: 
47219diff
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: 
46240diff
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: 
45847diff
changeset | 358 | lemma butlast_bin_rest: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
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: 
45847diff
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: 
45996diff
changeset | 374 | lemma trunc_bl2bin_aux: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
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)" | 
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 377 | apply (induct bl arbitrary: w) | 
| 24333 | 378 | apply clarsimp | 
| 379 | apply clarsimp | |
| 380 | apply safe | |
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 381 | apply (case_tac "m - size bl") | 
| 24333 | 382 | apply (simp add : diff_is_0_eq [THEN iffD1, THEN Suc_diff_le]) | 
| 46652 | 383 | apply simp | 
| 384 | apply (rule_tac f = "%nat. bl_to_bin_aux bl (bintrunc nat w BIT 1)" | |
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 385 | in arg_cong) | 
| 24333 | 386 | apply simp | 
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 387 | apply (case_tac "m - size bl") | 
| 24333 | 388 | apply (simp add: diff_is_0_eq [THEN iffD1, THEN Suc_diff_le]) | 
| 46652 | 389 | apply simp | 
| 390 | apply (rule_tac f = "%nat. bl_to_bin_aux bl (bintrunc nat w BIT 0)" | |
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 391 | in arg_cong) | 
| 24333 | 392 | apply simp | 
| 393 | done | |
| 394 | ||
| 395 | lemma trunc_bl2bin: | |
| 396 | "bintrunc m (bl_to_bin bl) = bl_to_bin (drop (length bl - m) bl)" | |
| 397 | unfolding bl_to_bin_def by (simp add : trunc_bl2bin_aux) | |
| 398 | ||
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 399 | lemma trunc_bl2bin_len [simp]: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 400 | "bintrunc (length bl) (bl_to_bin bl) = bl_to_bin bl" | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 401 | by (simp add: trunc_bl2bin) | 
| 24333 | 402 | |
| 403 | lemma bl2bin_drop: | |
| 404 | "bl_to_bin (drop k bl) = bintrunc (length bl - k) (bl_to_bin bl)" | |
| 405 | apply (rule trans) | |
| 406 | prefer 2 | |
| 407 | apply (rule trunc_bl2bin [symmetric]) | |
| 408 | apply (cases "k <= length bl") | |
| 409 | apply auto | |
| 410 | done | |
| 411 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 412 | lemma nth_rest_power_bin: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 413 | "bin_nth ((bin_rest ^^ k) w) n = bin_nth w (n + k)" | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 414 | apply (induct k arbitrary: n, clarsimp) | 
| 24333 | 415 | apply clarsimp | 
| 416 | apply (simp only: bin_nth.Suc [symmetric] add_Suc) | |
| 417 | done | |
| 418 | ||
| 419 | lemma take_rest_power_bin: | |
| 30971 | 420 | "m <= n ==> take m (bin_to_bl n w) = bin_to_bl m ((bin_rest ^^ (n - m)) w)" | 
| 24333 | 421 | apply (rule nth_equalityI) | 
| 422 | apply simp | |
| 423 | apply (clarsimp simp add: nth_bin_to_bl nth_rest_power_bin) | |
| 424 | done | |
| 425 | ||
| 24465 | 426 | lemma hd_butlast: "size xs > 1 ==> hd (butlast xs) = hd xs" | 
| 427 | by (cases xs) auto | |
| 24333 | 428 | |
| 26557 | 429 | lemma last_bin_last': | 
| 37654 | 430 | "size xs > 0 \<Longrightarrow> last xs = (bin_last (bl_to_bin_aux xs w) = 1)" | 
| 26557 | 431 | by (induct xs arbitrary: w) auto | 
| 24333 | 432 | |
| 433 | lemma last_bin_last: | |
| 37654 | 434 | "size xs > 0 ==> last xs = (bin_last (bl_to_bin xs) = 1)" | 
| 24333 | 435 | unfolding bl_to_bin_def by (erule last_bin_last') | 
| 436 | ||
| 437 | lemma bin_last_last: | |
| 37654 | 438 | "bin_last w = (if last (bin_to_bl (Suc n) w) then 1 else 0)" | 
| 24333 | 439 | apply (unfold bin_to_bl_def) | 
| 440 | apply simp | |
| 441 | apply (auto simp add: bin_to_bl_aux_alt) | |
| 442 | done | |
| 443 | ||
| 24465 | 444 | (** links between bit-wise operations and operations on bool lists **) | 
| 445 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 446 | lemma bl_xor_aux_bin: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 447 | "map2 (%x y. x ~= y) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = | 
| 26557 | 448 | 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: 
45996diff
changeset | 449 | apply (induct n arbitrary: v w bs cs) | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 450 | apply simp | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 451 | apply (case_tac v rule: bin_exhaust) | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 452 | apply (case_tac w rule: bin_exhaust) | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 453 | apply clarsimp | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 454 | apply (case_tac b) | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 455 | apply (case_tac ba, safe, simp_all)+ | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 456 | done | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 457 | |
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 458 | lemma bl_or_aux_bin: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 459 | "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: 
45996diff
changeset | 460 | bin_to_bl_aux n (v OR w) (map2 (op | ) bs cs)" | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 461 | apply (induct n arbitrary: v w bs cs) | 
| 24333 | 462 | apply simp | 
| 463 | apply (case_tac v rule: bin_exhaust) | |
| 464 | apply (case_tac w rule: bin_exhaust) | |
| 465 | apply clarsimp | |
| 466 | apply (case_tac b) | |
| 467 | apply (case_tac ba, safe, simp_all)+ | |
| 468 | done | |
| 469 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 470 | lemma bl_and_aux_bin: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 471 | "map2 (op & ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = | 
| 26557 | 472 | bin_to_bl_aux n (v AND w) (map2 (op & ) bs cs)" | 
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 473 | apply (induct n arbitrary: v w bs cs) | 
| 24333 | 474 | apply simp | 
| 475 | apply (case_tac v rule: bin_exhaust) | |
| 476 | apply (case_tac w rule: bin_exhaust) | |
| 477 | apply clarsimp | |
| 478 | done | |
| 479 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 480 | lemma bl_not_aux_bin: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 481 | "map Not (bin_to_bl_aux n w cs) = | 
| 24353 | 482 | bin_to_bl_aux n (NOT w) (map Not cs)" | 
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 483 | apply (induct n arbitrary: w cs) | 
| 24333 | 484 | apply clarsimp | 
| 485 | apply clarsimp | |
| 486 | done | |
| 487 | ||
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 488 | 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: 
45847diff
changeset | 489 | unfolding bin_to_bl_def by (simp add: bl_not_aux_bin) | 
| 24333 | 490 | |
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 491 | lemma bl_and_bin: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 492 | "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: 
45847diff
changeset | 493 | unfolding bin_to_bl_def by (simp add: bl_and_aux_bin) | 
| 24333 | 494 | |
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 495 | lemma bl_or_bin: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 496 | "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: 
45847diff
changeset | 497 | unfolding bin_to_bl_def by (simp add: bl_or_aux_bin) | 
| 24333 | 498 | |
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 499 | lemma bl_xor_bin: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 500 | "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: 
45847diff
changeset | 501 | unfolding bin_to_bl_def by (simp only: bl_xor_aux_bin map2_Nil) | 
| 24333 | 502 | |
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 503 | lemma drop_bin2bl_aux: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 504 | "drop m (bin_to_bl_aux n bin bs) = | 
| 24333 | 505 | bin_to_bl_aux (n - m) bin (drop (m - n) bs)" | 
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 506 | apply (induct n arbitrary: m bin bs, clarsimp) | 
| 24333 | 507 | apply clarsimp | 
| 508 | apply (case_tac bin rule: bin_exhaust) | |
| 509 | apply (case_tac "m <= n", simp) | |
| 510 | apply (case_tac "m - n", simp) | |
| 511 | apply simp | |
| 512 | apply (rule_tac f = "%nat. drop nat bs" in arg_cong) | |
| 513 | apply simp | |
| 514 | done | |
| 515 | ||
| 516 | lemma drop_bin2bl: "drop m (bin_to_bl n bin) = bin_to_bl (n - m) bin" | |
| 517 | unfolding bin_to_bl_def by (simp add : drop_bin2bl_aux) | |
| 518 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 519 | lemma take_bin2bl_lem1: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 520 | "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: 
45996diff
changeset | 521 | apply (induct m arbitrary: w bs, clarsimp) | 
| 24333 | 522 | apply clarsimp | 
| 523 | apply (simp add: bin_to_bl_aux_alt) | |
| 524 | apply (simp add: bin_to_bl_def) | |
| 525 | apply (simp add: bin_to_bl_aux_alt) | |
| 526 | done | |
| 527 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 528 | lemma take_bin2bl_lem: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 529 | "take m (bin_to_bl_aux (m + n) w bs) = | 
| 24333 | 530 | take m (bin_to_bl (m + n) w)" | 
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 531 | apply (induct n arbitrary: w bs) | 
| 24333 | 532 | apply (simp_all (no_asm) add: bin_to_bl_def take_bin2bl_lem1) | 
| 533 | apply simp | |
| 534 | done | |
| 535 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 536 | lemma bin_split_take: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 537 | "bin_split n c = (a, b) \<Longrightarrow> | 
| 24333 | 538 | 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: 
45996diff
changeset | 539 | apply (induct n arbitrary: b c) | 
| 24333 | 540 | 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: 
47219diff
changeset | 541 | apply (clarsimp simp: Let_def split: prod.split_asm) | 
| 24333 | 542 | apply (simp add: bin_to_bl_def) | 
| 543 | apply (simp add: take_bin2bl_lem) | |
| 544 | done | |
| 545 | ||
| 546 | lemma bin_split_take1: | |
| 547 | "k = m + n ==> bin_split n c = (a, b) ==> | |
| 548 | bin_to_bl m a = take m (bin_to_bl k c)" | |
| 549 | by (auto elim: bin_split_take) | |
| 550 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 551 | lemma nth_takefill: "m < n \<Longrightarrow> | 
| 24333 | 552 | 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: 
45996diff
changeset | 553 | apply (induct n arbitrary: m l, clarsimp) | 
| 24333 | 554 | apply clarsimp | 
| 555 | apply (case_tac m) | |
| 556 | apply (simp split: list.split) | |
| 557 | apply (simp split: list.split) | |
| 558 | done | |
| 559 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 560 | lemma takefill_alt: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 561 | "takefill fill n l = take n l @ replicate (n - length l) fill" | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 562 | by (induct n arbitrary: l) (auto split: list.split) | 
| 24333 | 563 | |
| 564 | lemma takefill_replicate [simp]: | |
| 565 | "takefill fill n (replicate m fill) = replicate n fill" | |
| 566 | by (simp add : takefill_alt replicate_add [symmetric]) | |
| 567 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 568 | lemma takefill_le': | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 569 | "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: 
45996diff
changeset | 570 | by (induct m arbitrary: l n) (auto split: list.split) | 
| 24333 | 571 | |
| 572 | lemma length_takefill [simp]: "length (takefill fill n l) = n" | |
| 573 | by (simp add : takefill_alt) | |
| 574 | ||
| 575 | lemma take_takefill': | |
| 576 | "!!w n. n = k + m ==> take k (takefill fill n w) = takefill fill k w" | |
| 577 | by (induct k) (auto split add : list.split) | |
| 578 | ||
| 579 | lemma drop_takefill: | |
| 580 | "!!w. drop k (takefill fill (m + k) w) = takefill fill m (drop k w)" | |
| 581 | by (induct k) (auto split add : list.split) | |
| 582 | ||
| 583 | lemma takefill_le [simp]: | |
| 584 | "m \<le> n \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l" | |
| 585 | by (auto simp: le_iff_add takefill_le') | |
| 586 | ||
| 587 | lemma take_takefill [simp]: | |
| 588 | "m \<le> n \<Longrightarrow> take m (takefill fill n w) = takefill fill m w" | |
| 589 | by (auto simp: le_iff_add take_takefill') | |
| 590 | ||
| 591 | lemma takefill_append: | |
| 592 | "takefill fill (m + length xs) (xs @ w) = xs @ (takefill fill m w)" | |
| 593 | by (induct xs) auto | |
| 594 | ||
| 595 | lemma takefill_same': | |
| 596 | "l = length xs ==> takefill fill l xs = xs" | |
| 597 | by clarify (induct xs, auto) | |
| 598 | ||
| 599 | lemmas takefill_same [simp] = takefill_same' [OF refl] | |
| 600 | ||
| 601 | lemma takefill_bintrunc: | |
| 602 | "takefill False n bl = rev (bin_to_bl n (bl_to_bin (rev bl)))" | |
| 603 | apply (rule nth_equalityI) | |
| 604 | apply simp | |
| 605 | apply (clarsimp simp: nth_takefill nth_rev nth_bin_to_bl bin_nth_of_bl) | |
| 606 | done | |
| 607 | ||
| 608 | lemma bl_bin_bl_rtf: | |
| 609 | "bin_to_bl n (bl_to_bin bl) = rev (takefill False n (rev bl))" | |
| 610 | by (simp add : takefill_bintrunc) | |
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 611 | |
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 612 | lemma bl_bin_bl_rep_drop: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 613 | "bin_to_bl n (bl_to_bin bl) = | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 614 | replicate (n - length bl) False @ drop (length bl - n) bl" | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 615 | by (simp add: bl_bin_bl_rtf takefill_alt rev_take) | 
| 24333 | 616 | |
| 617 | lemma tf_rev: | |
| 618 | "n + k = m + length bl ==> takefill x m (rev (takefill y n bl)) = | |
| 619 | rev (takefill y m (rev (takefill x k (rev bl))))" | |
| 620 | apply (rule nth_equalityI) | |
| 621 | apply (auto simp add: nth_takefill nth_rev) | |
| 622 | apply (rule_tac f = "%n. bl ! n" in arg_cong) | |
| 623 | apply arith | |
| 624 | done | |
| 625 | ||
| 626 | lemma takefill_minus: | |
| 627 | "0 < n ==> takefill fill (Suc (n - 1)) w = takefill fill n w" | |
| 628 | by auto | |
| 629 | ||
| 630 | lemmas takefill_Suc_cases = | |
| 45604 | 631 | list.cases [THEN takefill.Suc [THEN trans]] | 
| 24333 | 632 | |
| 633 | lemmas takefill_Suc_Nil = takefill_Suc_cases (1) | |
| 634 | lemmas takefill_Suc_Cons = takefill_Suc_cases (2) | |
| 635 | ||
| 636 | lemmas takefill_minus_simps = takefill_Suc_cases [THEN [2] | |
| 45604 | 637 | takefill_minus [symmetric, THEN trans]] | 
| 24333 | 638 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
changeset | 639 | lemma takefill_numeral_Nil [simp]: | 
| 47219 
172c031ad743
restate various simp rules for word operations using pred_numeral
 huffman parents: 
47108diff
changeset | 640 | "takefill fill (numeral k) [] = fill # takefill fill (pred_numeral k) []" | 
| 
172c031ad743
restate various simp rules for word operations using pred_numeral
 huffman parents: 
47108diff
changeset | 641 | by (simp add: numeral_eq_Suc) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
changeset | 642 | |
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
changeset | 643 | lemma takefill_numeral_Cons [simp]: | 
| 47219 
172c031ad743
restate various simp rules for word operations using pred_numeral
 huffman parents: 
47108diff
changeset | 644 | "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: 
47108diff
changeset | 645 | by (simp add: numeral_eq_Suc) | 
| 24333 | 646 | |
| 647 | (* links with function bl_to_bin *) | |
| 648 | ||
| 649 | lemma bl_to_bin_aux_cat: | |
| 26557 | 650 | "!!nv v. bl_to_bin_aux bs (bin_cat w nv v) = | 
| 651 | bin_cat w (nv + length bs) (bl_to_bin_aux bs v)" | |
| 24333 | 652 | apply (induct bs) | 
| 653 | apply simp | |
| 654 | apply (simp add: bin_cat_Suc_Bit [symmetric] del: bin_cat.simps) | |
| 655 | done | |
| 656 | ||
| 657 | lemma bin_to_bl_aux_cat: | |
| 658 | "!!w bs. bin_to_bl_aux (nv + nw) (bin_cat v nw w) bs = | |
| 659 | bin_to_bl_aux nv v (bin_to_bl_aux nw w bs)" | |
| 660 | by (induct nw) auto | |
| 661 | ||
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 662 | lemma bl_to_bin_aux_alt: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 663 | "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: 
45997diff
changeset | 664 | using bl_to_bin_aux_cat [where nv = "0" and v = "0"] | 
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 665 | unfolding bl_to_bin_def [symmetric] by simp | 
| 24333 | 666 | |
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 667 | lemma bin_to_bl_cat: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 668 | "bin_to_bl (nv + nw) (bin_cat v nw w) = | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 669 | bin_to_bl_aux nv v (bin_to_bl nw w)" | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 670 | unfolding bin_to_bl_def by (simp add: bin_to_bl_aux_cat) | 
| 24333 | 671 | |
| 672 | lemmas bl_to_bin_aux_app_cat = | |
| 673 | trans [OF bl_to_bin_aux_append bl_to_bin_aux_alt] | |
| 674 | ||
| 675 | lemmas bin_to_bl_aux_cat_app = | |
| 676 | trans [OF bin_to_bl_aux_cat bin_to_bl_aux_alt] | |
| 677 | ||
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 678 | lemma bl_to_bin_app_cat: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 679 | "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: 
45847diff
changeset | 680 | by (simp only: bl_to_bin_aux_app_cat bl_to_bin_def) | 
| 24333 | 681 | |
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 682 | lemma bin_to_bl_cat_app: | 
| 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 683 | "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: 
45847diff
changeset | 684 | by (simp only: bin_to_bl_def bin_to_bl_aux_cat_app) | 
| 24333 | 685 | |
| 686 | (* bl_to_bin_app_cat_alt and bl_to_bin_app_cat are easily interderivable *) | |
| 687 | lemma bl_to_bin_app_cat_alt: | |
| 688 | "bin_cat (bl_to_bin cs) n w = bl_to_bin (cs @ bin_to_bl n w)" | |
| 689 | by (simp add : bl_to_bin_app_cat) | |
| 690 | ||
| 691 | lemma mask_lem: "(bl_to_bin (True # replicate n False)) = | |
| 46645 
573aff6b9b0a
adapt lemma mask_lem to respect int/bin distinction
 huffman parents: 
46617diff
changeset | 692 | (bl_to_bin (replicate n True)) + 1" | 
| 24333 | 693 | apply (unfold bl_to_bin_def) | 
| 694 | apply (induct n) | |
| 46645 
573aff6b9b0a
adapt lemma mask_lem to respect int/bin distinction
 huffman parents: 
46617diff
changeset | 695 | apply simp | 
| 31790 | 696 | apply (simp only: Suc_eq_plus1 replicate_add | 
| 24333 | 697 | append_Cons [symmetric] bl_to_bin_aux_append) | 
| 46645 
573aff6b9b0a
adapt lemma mask_lem to respect int/bin distinction
 huffman parents: 
46617diff
changeset | 698 | apply (simp add: Bit_B0_2t Bit_B1_2t) | 
| 24333 | 699 | done | 
| 700 | ||
| 24465 | 701 | (* function bl_of_nth *) | 
| 24333 | 702 | lemma length_bl_of_nth [simp]: "length (bl_of_nth n f) = n" | 
| 703 | by (induct n) auto | |
| 704 | ||
| 705 | lemma nth_bl_of_nth [simp]: | |
| 706 | "m < n \<Longrightarrow> rev (bl_of_nth n f) ! m = f m" | |
| 707 | apply (induct n) | |
| 708 | apply simp | |
| 709 | apply (clarsimp simp add : nth_append) | |
| 710 | apply (rule_tac f = "f" in arg_cong) | |
| 711 | apply simp | |
| 712 | done | |
| 713 | ||
| 714 | lemma bl_of_nth_inj: | |
| 715 | "(!!k. k < n ==> f k = g k) ==> bl_of_nth n f = bl_of_nth n g" | |
| 716 | by (induct n) auto | |
| 717 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 718 | lemma bl_of_nth_nth_le: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 719 | "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: 
45996diff
changeset | 720 | apply (induct n arbitrary: xs, clarsimp) | 
| 24333 | 721 | apply clarsimp | 
| 722 | apply (rule trans [OF _ hd_Cons_tl]) | |
| 723 | apply (frule Suc_le_lessD) | |
| 724 | apply (simp add: nth_rev trans [OF drop_Suc drop_tl, symmetric]) | |
| 725 | apply (subst hd_drop_conv_nth) | |
| 726 | apply force | |
| 727 | apply simp_all | |
| 728 | apply (rule_tac f = "%n. drop n xs" in arg_cong) | |
| 729 | apply simp | |
| 730 | done | |
| 731 | ||
| 45854 
40554613b4f0
replace many uses of 'lemmas' with explicit 'lemma'
 huffman parents: 
45847diff
changeset | 732 | 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: 
45847diff
changeset | 733 | by (simp add: bl_of_nth_nth_le) | 
| 24333 | 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 | ||
| 46653 | 755 | lemma rbl_pred: | 
| 756 | "rbl_pred (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin - 1))" | |
| 757 | apply (induct n arbitrary: bin, simp) | |
| 24333 | 758 | apply (unfold bin_to_bl_def) | 
| 759 | apply clarsimp | |
| 760 | apply (case_tac bin rule: bin_exhaust) | |
| 761 | apply (case_tac b) | |
| 46653 | 762 | apply (clarsimp simp: bin_to_bl_aux_alt)+ | 
| 24333 | 763 | done | 
| 764 | ||
| 765 | lemma rbl_succ: | |
| 46653 | 766 | "rbl_succ (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin + 1))" | 
| 767 | apply (induct n arbitrary: bin, simp) | |
| 24333 | 768 | apply (unfold bin_to_bl_def) | 
| 769 | apply clarsimp | |
| 770 | apply (case_tac bin rule: bin_exhaust) | |
| 771 | apply (case_tac b) | |
| 46653 | 772 | apply (clarsimp simp: bin_to_bl_aux_alt)+ | 
| 24333 | 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") | |
| 46655 | 785 | apply (auto simp: rbl_succ bin_to_bl_aux_alt Let_def add_ac) | 
| 24333 | 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 | |
| 46653 | 859 | |
| 24333 | 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") | |
| 46653 | 871 | apply (auto simp: bin_to_bl_aux_alt Let_def) | 
| 872 | apply (auto simp: rbbl_Cons rbl_mult_Suc rbl_add) | |
| 24333 | 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 | ||
| 24350 | 892 | subsection "Repeated splitting or concatenation" | 
| 24333 | 893 | |
| 894 | lemma sclem: | |
| 895 | "size (concat (map (bin_to_bl n) xs)) = length xs * n" | |
| 896 | by (induct xs) auto | |
| 897 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 898 | lemma bin_cat_foldl_lem: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 899 | "foldl (%u. bin_cat u n) x xs = | 
| 24333 | 900 | 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: 
45996diff
changeset | 901 | apply (induct xs arbitrary: x) | 
| 24333 | 902 | apply simp | 
| 903 | apply (simp (no_asm)) | |
| 904 | apply (frule asm_rl) | |
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 905 | apply (drule meta_spec) | 
| 24333 | 906 | apply (erule trans) | 
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 907 | 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: 
32439diff
changeset | 908 | apply (simp add : bin_cat_assoc_sym min_max.inf_absorb2) | 
| 24333 | 909 | done | 
| 910 | ||
| 911 | lemma bin_rcat_bl: | |
| 912 | "(bin_rcat n wl) = bl_to_bin (concat (map (bin_to_bl n) wl))" | |
| 913 | apply (unfold bin_rcat_def) | |
| 914 | apply (rule sym) | |
| 915 | apply (induct wl) | |
| 916 | apply (auto simp add : bl_to_bin_append) | |
| 917 | apply (simp add : bl_to_bin_aux_alt sclem) | |
| 918 | apply (simp add : bin_cat_foldl_lem [symmetric]) | |
| 919 | done | |
| 920 | ||
| 921 | lemmas bin_rsplit_aux_simps = bin_rsplit_aux.simps bin_rsplitl_aux.simps | |
| 922 | lemmas rsplit_aux_simps = bin_rsplit_aux_simps | |
| 923 | ||
| 45604 | 924 | lemmas th_if_simp1 = split_if [where P = "op = l", THEN iffD1, THEN conjunct1, THEN mp] for l | 
| 925 | lemmas th_if_simp2 = split_if [where P = "op = l", THEN iffD1, THEN conjunct2, THEN mp] for l | |
| 24333 | 926 | |
| 927 | lemmas rsplit_aux_simp1s = rsplit_aux_simps [THEN th_if_simp1] | |
| 928 | ||
| 929 | lemmas rsplit_aux_simp2ls = rsplit_aux_simps [THEN th_if_simp2] | |
| 930 | (* these safe to [simp add] as require calculating m - n *) | |
| 931 | lemmas bin_rsplit_aux_simp2s [simp] = rsplit_aux_simp2ls [unfolded Let_def] | |
| 932 | lemmas rbscl = bin_rsplit_aux_simp2s (2) | |
| 933 | ||
| 934 | lemmas rsplit_aux_0_simps [simp] = | |
| 935 | rsplit_aux_simp1s [OF disjI1] rsplit_aux_simp1s [OF disjI2] | |
| 936 | ||
| 937 | lemma bin_rsplit_aux_append: | |
| 26557 | 938 | "bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs" | 
| 939 | apply (induct n m c bs rule: bin_rsplit_aux.induct) | |
| 24333 | 940 | apply (subst bin_rsplit_aux.simps) | 
| 941 | 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: 
47219diff
changeset | 942 | apply (clarsimp split: prod.split) | 
| 26557 | 943 | apply auto | 
| 24333 | 944 | done | 
| 945 | ||
| 946 | lemma bin_rsplitl_aux_append: | |
| 26557 | 947 | "bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs" | 
| 948 | apply (induct n m c bs rule: bin_rsplitl_aux.induct) | |
| 24333 | 949 | apply (subst bin_rsplitl_aux.simps) | 
| 950 | 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: 
47219diff
changeset | 951 | apply (clarsimp split: prod.split) | 
| 26557 | 952 | apply auto | 
| 24333 | 953 | done | 
| 954 | ||
| 955 | lemmas rsplit_aux_apps [where bs = "[]"] = | |
| 956 | bin_rsplit_aux_append bin_rsplitl_aux_append | |
| 957 | ||
| 958 | lemmas rsplit_def_auxs = bin_rsplit_def bin_rsplitl_def | |
| 959 | ||
| 960 | lemmas rsplit_aux_alts = rsplit_aux_apps | |
| 961 | [unfolded append_Nil rsplit_def_auxs [symmetric]] | |
| 962 | ||
| 963 | lemma bin_split_minus: "0 < n ==> bin_split (Suc (n - 1)) w = bin_split n w" | |
| 964 | by auto | |
| 965 | ||
| 966 | lemmas bin_split_minus_simp = | |
| 45604 | 967 | bin_split.Suc [THEN [2] bin_split_minus [symmetric, THEN trans]] | 
| 24333 | 968 | |
| 969 | lemma bin_split_pred_simp [simp]: | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
changeset | 970 | "(0::nat) < numeral bin \<Longrightarrow> | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
changeset | 971 | bin_split (numeral bin) w = | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
changeset | 972 | (let (w1, w2) = bin_split (numeral bin - 1) (bin_rest w) | 
| 24333 | 973 | in (w1, w2 BIT bin_last w))" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46655diff
changeset | 974 | by (simp only: bin_split_minus_simp) | 
| 24333 | 975 | |
| 976 | lemma bin_rsplit_aux_simp_alt: | |
| 26557 | 977 | "bin_rsplit_aux n m c bs = | 
| 24333 | 978 | (if m = 0 \<or> n = 0 | 
| 979 | then bs | |
| 980 | else let (a, b) = bin_split n c in bin_rsplit n (m - n, a) @ b # bs)" | |
| 26557 | 981 | unfolding bin_rsplit_aux.simps [of n m c bs] | 
| 982 | apply simp | |
| 983 | apply (subst rsplit_aux_alts) | |
| 984 | apply (simp add: bin_rsplit_def) | |
| 24333 | 985 | done | 
| 986 | ||
| 987 | lemmas bin_rsplit_simp_alt = | |
| 45604 | 988 | trans [OF bin_rsplit_def bin_rsplit_aux_simp_alt] | 
| 24333 | 989 | |
| 990 | lemmas bthrs = bin_rsplit_simp_alt [THEN [2] trans] | |
| 991 | ||
| 992 | lemma bin_rsplit_size_sign' [rule_format] : | |
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 993 | "\<lbrakk>n > 0; rev sw = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 994 | (ALL v: set sw. bintrunc n v = v)" | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 995 | apply (induct sw arbitrary: nw w v) | 
| 24333 | 996 | apply clarsimp | 
| 997 | apply clarsimp | |
| 998 | 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: 
47219diff
changeset | 999 | apply (simp (no_asm_use) add: Let_def split: prod.split_asm split_if_asm) | 
| 24333 | 1000 | apply clarify | 
| 1001 | apply (drule split_bintrunc) | |
| 1002 | apply simp | |
| 1003 | done | |
| 1004 | ||
| 1005 | lemmas bin_rsplit_size_sign = bin_rsplit_size_sign' [OF asm_rl | |
| 45604 | 1006 | rev_rev_ident [THEN trans] set_rev [THEN equalityD2 [THEN subsetD]]] | 
| 24333 | 1007 | |
| 1008 | lemma bin_nth_rsplit [rule_format] : | |
| 1009 | "n > 0 ==> m < n ==> (ALL w k nw. rev sw = bin_rsplit n (nw, w) --> | |
| 1010 | k < size sw --> bin_nth (sw ! k) m = bin_nth w (k * n + m))" | |
| 1011 | apply (induct sw) | |
| 1012 | apply clarsimp | |
| 1013 | apply clarsimp | |
| 1014 | 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: 
47219diff
changeset | 1015 | apply (simp (no_asm_use) add: Let_def split: prod.split_asm split_if_asm) | 
| 24333 | 1016 | apply clarify | 
| 1017 | apply (erule allE, erule impE, erule exI) | |
| 1018 | apply (case_tac k) | |
| 1019 | apply clarsimp | |
| 1020 | prefer 2 | |
| 1021 | apply clarsimp | |
| 1022 | apply (erule allE) | |
| 1023 | apply (erule (1) impE) | |
| 1024 | apply (drule bin_nth_split, erule conjE, erule allE, | |
| 1025 | erule trans, simp add : add_ac)+ | |
| 1026 | done | |
| 1027 | ||
| 1028 | lemma bin_rsplit_all: | |
| 1029 | "0 < nw ==> nw <= n ==> bin_rsplit n (nw, w) = [bintrunc n w]" | |
| 1030 | 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: 
47219diff
changeset | 1031 | by (clarsimp dest!: split_bintrunc simp: rsplit_aux_simp2ls split: prod.split) | 
| 24333 | 1032 | |
| 1033 | lemma bin_rsplit_l [rule_format] : | |
| 1034 | "ALL bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, bintrunc m bin)" | |
| 1035 | apply (rule_tac a = "m" in wf_less_than [THEN wf_induct]) | |
| 1036 | apply (simp (no_asm) add : bin_rsplitl_def bin_rsplit_def) | |
| 1037 | apply (rule allI) | |
| 1038 | apply (subst bin_rsplitl_aux.simps) | |
| 1039 | 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: 
47219diff
changeset | 1040 | apply (clarsimp simp: Let_def split: prod.split) | 
| 24333 | 1041 | apply (drule bin_split_trunc) | 
| 1042 | apply (drule sym [THEN trans], assumption) | |
| 26557 | 1043 | apply (subst rsplit_aux_alts(1)) | 
| 1044 | apply (subst rsplit_aux_alts(2)) | |
| 1045 | apply clarsimp | |
| 1046 | unfolding bin_rsplit_def bin_rsplitl_def | |
| 1047 | apply simp | |
| 24333 | 1048 | done | 
| 26557 | 1049 | |
| 24333 | 1050 | lemma bin_rsplit_rcat [rule_format] : | 
| 1051 | "n > 0 --> bin_rsplit n (n * size ws, bin_rcat n ws) = map (bintrunc n) ws" | |
| 1052 | apply (unfold bin_rsplit_def bin_rcat_def) | |
| 1053 | apply (rule_tac xs = "ws" in rev_induct) | |
| 1054 | apply clarsimp | |
| 1055 | apply clarsimp | |
| 26557 | 1056 | apply (subst rsplit_aux_alts) | 
| 1057 | unfolding bin_split_cat | |
| 1058 | apply simp | |
| 24333 | 1059 | done | 
| 1060 | ||
| 1061 | lemma bin_rsplit_aux_len_le [rule_format] : | |
| 26557 | 1062 | "\<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> | 
| 1063 | length ws \<le> m \<longleftrightarrow> nw + length bs * n \<le> m * n" | |
| 1064 | apply (induct n nw w bs rule: bin_rsplit_aux.induct) | |
| 24333 | 1065 | 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: 
47219diff
changeset | 1066 | apply (simp add: lrlem Let_def split: prod.split) | 
| 24333 | 1067 | done | 
| 1068 | ||
| 1069 | lemma bin_rsplit_len_le: | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 1070 | "n \<noteq> 0 --> ws = bin_rsplit n (nw, w) --> (length ws <= m) = (nw <= m * n)" | 
| 24333 | 1071 | unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len_le) | 
| 1072 | ||
| 45997 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 1073 | lemma bin_rsplit_aux_len: | 
| 
13392893ea12
use 'induct arbitrary' instead of 'rule_format' attribute
 huffman parents: 
45996diff
changeset | 1074 | "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw w cs) = | 
| 24333 | 1075 | (nw + n - 1) div n + length cs" | 
| 26557 | 1076 | apply (induct n nw w cs rule: bin_rsplit_aux.induct) | 
| 24333 | 1077 | 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: 
47219diff
changeset | 1078 | apply (clarsimp simp: Let_def split: prod.split) | 
| 24333 | 1079 | apply (erule thin_rl) | 
| 27651 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 haftmann parents: 
27105diff
changeset | 1080 | apply (case_tac m) | 
| 
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
 haftmann parents: 
27105diff
changeset | 1081 | apply simp | 
| 24333 | 1082 | apply (case_tac "m <= n") | 
| 27677 | 1083 | apply auto | 
| 24333 | 1084 | done | 
| 1085 | ||
| 1086 | lemma bin_rsplit_len: | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 1087 | "n\<noteq>0 ==> length (bin_rsplit n (nw, w)) = (nw + n - 1) div n" | 
| 24333 | 1088 | unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len) | 
| 1089 | ||
| 26557 | 1090 | lemma bin_rsplit_aux_len_indep: | 
| 1091 | "n \<noteq> 0 \<Longrightarrow> length bs = length cs \<Longrightarrow> | |
| 1092 | length (bin_rsplit_aux n nw v bs) = | |
| 1093 | length (bin_rsplit_aux n nw w cs)" | |
| 1094 | proof (induct n nw w cs arbitrary: v bs rule: bin_rsplit_aux.induct) | |
| 1095 | case (1 n m w cs v bs) show ?case | |
| 1096 | proof (cases "m = 0") | |
| 28298 | 1097 | case True then show ?thesis using `length bs = length cs` by simp | 
| 26557 | 1098 | next | 
| 1099 | case False | |
| 1100 | from "1.hyps" `m \<noteq> 0` `n \<noteq> 0` have hyp: "\<And>v bs. length bs = Suc (length cs) \<Longrightarrow> | |
| 1101 | length (bin_rsplit_aux n (m - n) v bs) = | |
| 1102 | length (bin_rsplit_aux n (m - n) (fst (bin_split n w)) (snd (bin_split n w) # cs))" | |
| 1103 | by auto | |
| 1104 | show ?thesis using `length bs = length cs` `n \<noteq> 0` | |
| 1105 | 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: 
47219diff
changeset | 1106 | split: prod.split) | 
| 26557 | 1107 | qed | 
| 1108 | qed | |
| 24333 | 1109 | |
| 1110 | lemma bin_rsplit_len_indep: | |
| 25134 
3d4953e88449
Eliminated most of the neq0_conv occurrences. As a result, many
 nipkow parents: 
25112diff
changeset | 1111 | "n\<noteq>0 ==> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))" | 
| 24333 | 1112 | apply (unfold bin_rsplit_def) | 
| 26557 | 1113 | apply (simp (no_asm)) | 
| 24333 | 1114 | apply (erule bin_rsplit_aux_len_indep) | 
| 1115 | apply (rule refl) | |
| 1116 | done | |
| 1117 | ||
| 1118 | end |