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