| author | paulson | 
| Fri, 24 May 2002 16:55:28 +0200 | |
| changeset 13178 | bc54319f6875 | 
| parent 13175 | 81082cfa5618 | 
| child 13535 | 007559e981c7 | 
| permissions | -rw-r--r-- | 
| 5528 | 1 | (* Title: ZF/ex/Bin.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | |
| 4 | Copyright 1994 University of Cambridge | |
| 5 | ||
| 6 | Arithmetic on binary integers. | |
| 7 | *) | |
| 8 | ||
| 6046 | 9 | |
| 13175 
81082cfa5618
new definition of "apply" and new simprule "beta_if"
 paulson parents: 
12152diff
changeset | 10 | Addsimps bin.intrs; | 
| 6153 | 11 | AddTCs bin.intrs; | 
| 5528 | 12 | |
| 6046 | 13 | Goal "NCons(Pls,0) = Pls"; | 
| 5528 | 14 | by (Asm_simp_tac 1); | 
| 15 | qed "NCons_Pls_0"; | |
| 16 | ||
| 6153 | 17 | Goal "NCons(Pls,1) = Pls BIT 1"; | 
| 5528 | 18 | by (Asm_simp_tac 1); | 
| 19 | qed "NCons_Pls_1"; | |
| 20 | ||
| 6153 | 21 | Goal "NCons(Min,0) = Min BIT 0"; | 
| 5528 | 22 | by (Asm_simp_tac 1); | 
| 23 | qed "NCons_Min_0"; | |
| 24 | ||
| 6046 | 25 | Goal "NCons(Min,1) = Min"; | 
| 5528 | 26 | by (Asm_simp_tac 1); | 
| 27 | qed "NCons_Min_1"; | |
| 28 | ||
| 6153 | 29 | Goal "NCons(w BIT x,b) = w BIT x BIT b"; | 
| 5528 | 30 | by (asm_simp_tac (simpset() addsimps bin.case_eqns) 1); | 
| 6153 | 31 | qed "NCons_BIT"; | 
| 5528 | 32 | |
| 9909 | 33 | bind_thms ("NCons_simps",
 | 
| 34 | [NCons_Pls_0, NCons_Pls_1, | |
| 35 | NCons_Min_0, NCons_Min_1, | |
| 36 | NCons_BIT]); | |
| 6046 | 37 | Addsimps NCons_simps; | 
| 38 | ||
| 5528 | 39 | |
| 40 | (** Type checking **) | |
| 41 | ||
| 6046 | 42 | Goal "w: bin ==> integ_of(w) : int"; | 
| 6065 | 43 | by (induct_tac "w" 1); | 
| 6153 | 44 | by (ALLGOALS (asm_simp_tac (simpset() addsimps [bool_into_nat]))); | 
| 5528 | 45 | qed "integ_of_type"; | 
| 6153 | 46 | AddTCs [integ_of_type]; | 
| 5528 | 47 | |
| 6046 | 48 | Goal "[| w: bin; b: bool |] ==> NCons(w,b) : bin"; | 
| 6065 | 49 | by (induct_tac "w" 1); | 
| 6046 | 50 | by Auto_tac; | 
| 5528 | 51 | qed "NCons_type"; | 
| 6153 | 52 | AddTCs [NCons_type]; | 
| 5528 | 53 | |
| 6046 | 54 | Goal "w: bin ==> bin_succ(w) : bin"; | 
| 6065 | 55 | by (induct_tac "w" 1); | 
| 6046 | 56 | by Auto_tac; | 
| 5528 | 57 | qed "bin_succ_type"; | 
| 6153 | 58 | AddTCs [bin_succ_type]; | 
| 5528 | 59 | |
| 6046 | 60 | Goal "w: bin ==> bin_pred(w) : bin"; | 
| 6065 | 61 | by (induct_tac "w" 1); | 
| 6046 | 62 | by Auto_tac; | 
| 63 | qed "bin_pred_type"; | |
| 6153 | 64 | AddTCs [bin_pred_type]; | 
| 5528 | 65 | |
| 6046 | 66 | Goal "w: bin ==> bin_minus(w) : bin"; | 
| 6065 | 67 | by (induct_tac "w" 1); | 
| 6046 | 68 | by Auto_tac; | 
| 69 | qed "bin_minus_type"; | |
| 6153 | 70 | AddTCs [bin_minus_type]; | 
| 5528 | 71 | |
| 6046 | 72 | (*This proof is complicated by the mutual recursion*) | 
| 9207 | 73 | Goalw [bin_add_def] "v: bin ==> ALL w: bin. bin_add(v,w) : bin"; | 
| 6065 | 74 | by (induct_tac "v" 1); | 
| 6046 | 75 | by (rtac ballI 3); | 
| 6065 | 76 | by (rename_tac "w'" 3); | 
| 77 | by (induct_tac "w'" 3); | |
| 6153 | 78 | by (ALLGOALS (asm_simp_tac (simpset() addsimps [NCons_type]))); | 
| 6112 | 79 | qed_spec_mp "bin_add_type"; | 
| 6153 | 80 | AddTCs [bin_add_type]; | 
| 5528 | 81 | |
| 6046 | 82 | Goal "[| v: bin; w: bin |] ==> bin_mult(v,w) : bin"; | 
| 6065 | 83 | by (induct_tac "v" 1); | 
| 6046 | 84 | by Auto_tac; | 
| 85 | qed "bin_mult_type"; | |
| 6153 | 86 | AddTCs [bin_mult_type]; | 
| 5528 | 87 | |
| 88 | ||
| 89 | (**** The carry/borrow functions, bin_succ and bin_pred ****) | |
| 90 | ||
| 91 | (*NCons preserves the integer value of its argument*) | |
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 92 | Goal "[| w: bin; b: bool |] ==> integ_of(NCons(w,b)) = integ_of(w BIT b)"; | 
| 5528 | 93 | by (etac bin.elim 1); | 
| 6046 | 94 | by (Asm_simp_tac 3); | 
| 5528 | 95 | by (ALLGOALS (etac boolE)); | 
| 6046 | 96 | by (ALLGOALS Asm_simp_tac); | 
| 5528 | 97 | qed "integ_of_NCons"; | 
| 98 | ||
| 99 | Addsimps [integ_of_NCons]; | |
| 100 | ||
| 101 | Goal "w: bin ==> integ_of(bin_succ(w)) = $#1 $+ integ_of(w)"; | |
| 102 | by (etac bin.induct 1); | |
| 103 | by (Simp_tac 1); | |
| 104 | by (Simp_tac 1); | |
| 105 | by (etac boolE 1); | |
| 106 | by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac))); | |
| 107 | qed "integ_of_succ"; | |
| 108 | ||
| 9548 | 109 | Goal "w: bin ==> integ_of(bin_pred(w)) = $- ($#1) $+ integ_of(w)"; | 
| 5528 | 110 | by (etac bin.induct 1); | 
| 111 | by (Simp_tac 1); | |
| 112 | by (Simp_tac 1); | |
| 113 | by (etac boolE 1); | |
| 114 | by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac))); | |
| 115 | qed "integ_of_pred"; | |
| 116 | ||
| 6046 | 117 | Addsimps [integ_of_succ, integ_of_pred]; | 
| 5528 | 118 | |
| 119 | ||
| 120 | (*** bin_minus: (unary!) negation of binary integers ***) | |
| 121 | ||
| 9548 | 122 | Goal "w: bin ==> integ_of(bin_minus(w)) = $- integ_of(w)"; | 
| 5528 | 123 | by (etac bin.induct 1); | 
| 124 | by (Simp_tac 1); | |
| 125 | by (Simp_tac 1); | |
| 126 | by (etac boolE 1); | |
| 127 | by (ALLGOALS | |
| 128 | (asm_simp_tac (simpset() addsimps zadd_ac@[zminus_zadd_distrib]))); | |
| 129 | qed "integ_of_minus"; | |
| 130 | ||
| 131 | ||
| 132 | (*** bin_add: binary addition ***) | |
| 133 | ||
| 9207 | 134 | Goalw [bin_add_def] "w: bin ==> bin_add(Pls,w) = w"; | 
| 5528 | 135 | by (Asm_simp_tac 1); | 
| 136 | qed "bin_add_Pls"; | |
| 137 | ||
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 138 | Goalw [bin_add_def] "w: bin ==> bin_add(w,Pls) = w"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 139 | by (etac bin.induct 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 140 | by Auto_tac; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 141 | qed "bin_add_Pls_right"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 142 | |
| 9207 | 143 | Goalw [bin_add_def] "w: bin ==> bin_add(Min,w) = bin_pred(w)"; | 
| 5528 | 144 | by (Asm_simp_tac 1); | 
| 145 | qed "bin_add_Min"; | |
| 146 | ||
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 147 | Goalw [bin_add_def] "w: bin ==> bin_add(w,Min) = bin_pred(w)"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 148 | by (etac bin.induct 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 149 | by Auto_tac; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 150 | qed "bin_add_Min_right"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 151 | |
| 9207 | 152 | Goalw [bin_add_def] "bin_add(v BIT x,Pls) = v BIT x"; | 
| 5528 | 153 | by (Simp_tac 1); | 
| 6153 | 154 | qed "bin_add_BIT_Pls"; | 
| 5528 | 155 | |
| 9207 | 156 | Goalw [bin_add_def] "bin_add(v BIT x,Min) = bin_pred(v BIT x)"; | 
| 5528 | 157 | by (Simp_tac 1); | 
| 6153 | 158 | qed "bin_add_BIT_Min"; | 
| 5528 | 159 | |
| 9207 | 160 | Goalw [bin_add_def] "[| w: bin; y: bool |] \ | 
| 6153 | 161 | \ ==> bin_add(v BIT x, w BIT y) = \ | 
| 6046 | 162 | \ NCons(bin_add(v, cond(x and y, bin_succ(w), w)), x xor y)"; | 
| 5528 | 163 | by (Asm_simp_tac 1); | 
| 6153 | 164 | qed "bin_add_BIT_BIT"; | 
| 5528 | 165 | |
| 6153 | 166 | Addsimps [bin_add_Pls, bin_add_Min, bin_add_BIT_Pls, | 
| 167 | bin_add_BIT_Min, bin_add_BIT_BIT, | |
| 5528 | 168 | integ_of_succ, integ_of_pred]; | 
| 169 | ||
| 170 | Goal "v: bin ==> \ | |
| 6046 | 171 | \ ALL w: bin. integ_of(bin_add(v,w)) = integ_of(v) $+ integ_of(w)"; | 
| 5528 | 172 | by (etac bin.induct 1); | 
| 173 | by (Simp_tac 1); | |
| 174 | by (Simp_tac 1); | |
| 175 | by (rtac ballI 1); | |
| 6065 | 176 | by (induct_tac "wa" 1); | 
| 5528 | 177 | by (ALLGOALS (asm_simp_tac (simpset() addsimps zadd_ac setloop (etac boolE)))); | 
| 6112 | 178 | qed_spec_mp "integ_of_add"; | 
| 5528 | 179 | |
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 180 | (*Subtraction*) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 181 | Goalw [zdiff_def] | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 182 | "[| v: bin; w: bin |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 183 | \ ==> integ_of(v) $- integ_of(w) = integ_of(bin_add (v, bin_minus(w)))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 184 | by (asm_simp_tac (simpset() addsimps [integ_of_add, integ_of_minus]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 185 | qed "diff_integ_of_eq"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 186 | |
| 5528 | 187 | |
| 9207 | 188 | (*** bin_mult: binary multiplication ***) | 
| 5528 | 189 | |
| 6046 | 190 | Goal "[| v: bin; w: bin |] \ | 
| 191 | \ ==> integ_of(bin_mult(v,w)) = integ_of(v) $* integ_of(w)"; | |
| 6065 | 192 | by (induct_tac "v" 1); | 
| 5528 | 193 | by (Asm_simp_tac 1); | 
| 6153 | 194 | by (asm_simp_tac (simpset() addsimps [integ_of_minus]) 1); | 
| 5528 | 195 | by (etac boolE 1); | 
| 196 | by (asm_simp_tac (simpset() addsimps [zadd_zmult_distrib]) 2); | |
| 6153 | 197 | by (asm_simp_tac (simpset() addsimps [integ_of_add, | 
| 198 | zadd_zmult_distrib] @ zadd_ac) 1); | |
| 5528 | 199 | qed "integ_of_mult"; | 
| 200 | ||
| 201 | (**** Computations ****) | |
| 202 | ||
| 203 | (** extra rules for bin_succ, bin_pred **) | |
| 204 | ||
| 6153 | 205 | Goal "bin_succ(w BIT 1) = bin_succ(w) BIT 0"; | 
| 5528 | 206 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 207 | qed "bin_succ_1"; | 
| 5528 | 208 | |
| 6153 | 209 | Goal "bin_succ(w BIT 0) = NCons(w,1)"; | 
| 5528 | 210 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 211 | qed "bin_succ_0"; | 
| 5528 | 212 | |
| 6153 | 213 | Goal "bin_pred(w BIT 1) = NCons(w,0)"; | 
| 5528 | 214 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 215 | qed "bin_pred_1"; | 
| 5528 | 216 | |
| 6153 | 217 | Goal "bin_pred(w BIT 0) = bin_pred(w) BIT 1"; | 
| 5528 | 218 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 219 | qed "bin_pred_0"; | 
| 5528 | 220 | |
| 221 | (** extra rules for bin_minus **) | |
| 222 | ||
| 6153 | 223 | Goal "bin_minus(w BIT 1) = bin_pred(NCons(bin_minus(w), 0))"; | 
| 5528 | 224 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 225 | qed "bin_minus_1"; | 
| 5528 | 226 | |
| 6153 | 227 | Goal "bin_minus(w BIT 0) = bin_minus(w) BIT 0"; | 
| 5528 | 228 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 229 | qed "bin_minus_0"; | 
| 5528 | 230 | |
| 231 | (** extra rules for bin_add **) | |
| 232 | ||
| 6153 | 233 | Goal "w: bin ==> bin_add(v BIT 1, w BIT 1) = \ | 
| 5528 | 234 | \ NCons(bin_add(v, bin_succ(w)), 0)"; | 
| 235 | by (Asm_simp_tac 1); | |
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 236 | qed "bin_add_BIT_11"; | 
| 5528 | 237 | |
| 6153 | 238 | Goal "w: bin ==> bin_add(v BIT 1, w BIT 0) = \ | 
| 5528 | 239 | \ NCons(bin_add(v,w), 1)"; | 
| 240 | by (Asm_simp_tac 1); | |
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 241 | qed "bin_add_BIT_10"; | 
| 5528 | 242 | |
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 243 | Goal "[| w: bin; y: bool |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 244 | \ ==> bin_add(v BIT 0, w BIT y) = NCons(bin_add(v,w), y)"; | 
| 5528 | 245 | by (Asm_simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 246 | qed "bin_add_BIT_0"; | 
| 5528 | 247 | |
| 248 | (** extra rules for bin_mult **) | |
| 249 | ||
| 6153 | 250 | Goal "bin_mult(v BIT 1, w) = bin_add(NCons(bin_mult(v,w),0), w)"; | 
| 5528 | 251 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 252 | qed "bin_mult_1"; | 
| 5528 | 253 | |
| 6153 | 254 | Goal "bin_mult(v BIT 0, w) = NCons(bin_mult(v,w),0)"; | 
| 5528 | 255 | by (Simp_tac 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 256 | qed "bin_mult_0"; | 
| 5528 | 257 | |
| 258 | ||
| 9548 | 259 | (** Simplification rules with integer constants **) | 
| 260 | ||
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 261 | Goal "$#0 = #0"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 262 | by (Simp_tac 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 263 | qed "int_of_0"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 264 | |
| 9576 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 265 | Goal "$# succ(n) = #1 $+ $#n"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 266 | by (simp_tac (simpset() addsimps [int_of_add RS sym, natify_succ]) 1); | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 267 | qed "int_of_succ"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 268 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 269 | Goal "$- #0 = #0"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 270 | by (Simp_tac 1); | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 271 | qed "zminus_0"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 272 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 273 | Addsimps [zminus_0]; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 274 | |
| 9548 | 275 | Goal "#0 $+ z = intify(z)"; | 
| 276 | by (Simp_tac 1); | |
| 277 | qed "zadd_0_intify"; | |
| 278 | ||
| 279 | Goal "z $+ #0 = intify(z)"; | |
| 280 | by (Simp_tac 1); | |
| 281 | qed "zadd_0_right_intify"; | |
| 282 | ||
| 283 | Addsimps [zadd_0_intify, zadd_0_right_intify]; | |
| 284 | ||
| 285 | Goal "#1 $* z = intify(z)"; | |
| 286 | by (Simp_tac 1); | |
| 287 | qed "zmult_1_intify"; | |
| 288 | ||
| 289 | Goal "z $* #1 = intify(z)"; | |
| 290 | by (stac zmult_commute 1); | |
| 291 | by (Simp_tac 1); | |
| 292 | qed "zmult_1_right_intify"; | |
| 293 | ||
| 294 | Addsimps [zmult_1_intify, zmult_1_right_intify]; | |
| 295 | ||
| 296 | Goal "#0 $* z = #0"; | |
| 297 | by (Simp_tac 1); | |
| 298 | qed "zmult_0"; | |
| 299 | ||
| 300 | Goal "z $* #0 = #0"; | |
| 301 | by (stac zmult_commute 1); | |
| 302 | by (Simp_tac 1); | |
| 303 | qed "zmult_0_right"; | |
| 304 | ||
| 305 | Addsimps [zmult_0, zmult_0_right]; | |
| 306 | ||
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 307 | Goal "#-1 $* z = $-z"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 308 | by (simp_tac (simpset() addsimps zcompare_rls) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 309 | qed "zmult_minus1"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 310 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 311 | Goal "z $* #-1 = $-z"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 312 | by (stac zmult_commute 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 313 | by (rtac zmult_minus1 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 314 | qed "zmult_minus1_right"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 315 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 316 | Addsimps [zmult_minus1, zmult_minus1_right]; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 317 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 318 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 319 | (*** Simplification rules for comparison of binary numbers (N Voelker) ***) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 320 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 321 | (** Equals (=) **) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 322 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 323 | Goalw [iszero_def] | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 324 | "[| v: bin; w: bin |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 325 | \ ==> ((integ_of(v)) = integ_of(w)) <-> \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 326 | \ iszero (integ_of (bin_add (v, bin_minus(w))))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 327 | by (asm_simp_tac (simpset() addsimps | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 328 | (zcompare_rls @ [integ_of_add, integ_of_minus])) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 329 | qed "eq_integ_of_eq"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 330 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 331 | Goalw [iszero_def] "iszero (integ_of(Pls))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 332 | by (Simp_tac 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 333 | qed "iszero_integ_of_Pls"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 334 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 335 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 336 | Goalw [iszero_def] "~ iszero (integ_of(Min))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 337 | by (simp_tac (simpset() addsimps [zminus_equation]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 338 | qed "nonzero_integ_of_Min"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 339 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 340 | Goalw [iszero_def] | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 341 | "[| w: bin; x: bool |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 342 | \ ==> iszero (integ_of (w BIT x)) <-> (x=0 & iszero (integ_of(w)))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 343 | by (Simp_tac 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 344 | by (subgoal_tac "integ_of(w) : int" 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 345 | by (Asm_simp_tac 2); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 346 | by (dtac int_cases 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 347 | by (auto_tac (claset() addSEs [boolE], | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 348 | simpset() addsimps [int_of_add RS sym])); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 349 | by (ALLGOALS (asm_full_simp_tac | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 350 | (simpset() addsimps zcompare_rls @ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 351 | [zminus_zadd_distrib RS sym, int_of_add RS sym]))); | 
| 12152 
46f128d8133c
Renamed some bound variables due to changes in simplifier.
 berghofe parents: 
11381diff
changeset | 352 | by (subgoal_tac "znegative ($- $# succ(n)) <-> znegative ($# succ(n))" 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 353 | by (Asm_simp_tac 2); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 354 | by (Full_simp_tac 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 355 | qed "iszero_integ_of_BIT"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 356 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 357 | Goal "w: bin ==> iszero (integ_of (w BIT 0)) <-> iszero (integ_of(w))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 358 | by (asm_simp_tac (ZF_ss addsimps [iszero_integ_of_BIT]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 359 | qed "iszero_integ_of_0"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 360 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 361 | Goal "w: bin ==> ~ iszero (integ_of (w BIT 1))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 362 | by (asm_simp_tac (ZF_ss addsimps [iszero_integ_of_BIT]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 363 | qed "iszero_integ_of_1"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 364 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 365 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 366 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 367 | (** Less-than (<) **) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 368 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 369 | Goalw [zless_def,zdiff_def] | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 370 | "[| v: bin; w: bin |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 371 | \ ==> integ_of(v) $< integ_of(w) \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 372 | \ <-> znegative (integ_of (bin_add (v, bin_minus(w))))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 373 | by (asm_simp_tac (simpset() addsimps [integ_of_minus, integ_of_add]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 374 | qed "less_integ_of_eq_neg"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 375 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 376 | Goal "~ znegative (integ_of(Pls))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 377 | by (Simp_tac 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 378 | qed "not_neg_integ_of_Pls"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 379 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 380 | Goal "znegative (integ_of(Min))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 381 | by (Simp_tac 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 382 | qed "neg_integ_of_Min"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 383 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 384 | Goal "[| w: bin; x: bool |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 385 | \ ==> znegative (integ_of (w BIT x)) <-> znegative (integ_of(w))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 386 | by (Asm_simp_tac 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 387 | by (subgoal_tac "integ_of(w) : int" 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 388 | by (Asm_simp_tac 2); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 389 | by (dtac int_cases 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 390 | by (auto_tac (claset() addSEs [boolE], | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 391 | simpset() addsimps [int_of_add RS sym] @ zcompare_rls)); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 392 | by (ALLGOALS (asm_full_simp_tac | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 393 | (simpset() addsimps [zminus_zadd_distrib RS sym, zdiff_def, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 394 | int_of_add RS sym]))); | 
| 12152 
46f128d8133c
Renamed some bound variables due to changes in simplifier.
 berghofe parents: 
11381diff
changeset | 395 | by (subgoal_tac "$#1 $- $# succ(succ(n #+ n)) = $- $# succ(n #+ n)" 1); | 
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 396 | by (asm_full_simp_tac (simpset() addsimps [zdiff_def])1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 397 | by (asm_simp_tac (simpset() addsimps [equation_zminus, int_of_diff RS sym])1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 398 | qed "neg_integ_of_BIT"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 399 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 400 | (** Less-than-or-equals (<=) **) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 401 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 402 | Goal "(integ_of(x) $<= (integ_of(w))) <-> ~ (integ_of(w) $< (integ_of(x)))"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 403 | by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 404 | qed "le_integ_of_eq_not_less"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 405 | |
| 9548 | 406 | |
| 6153 | 407 | (*Delete the original rewrites, with their clumsy conditional expressions*) | 
| 408 | Delsimps [bin_succ_BIT, bin_pred_BIT, bin_minus_BIT, | |
| 9207 | 409 | NCons_Pls, NCons_Min, bin_adder_BIT, bin_mult_BIT]; | 
| 6153 | 410 | |
| 411 | (*Hide the binary representation of integer constants*) | |
| 412 | Delsimps [integ_of_Pls, integ_of_Min, integ_of_BIT]; | |
| 413 | ||
| 5528 | 414 | |
| 9570 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 415 | bind_thms ("NCons_simps", 
 | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 416 | [NCons_Pls_0, NCons_Pls_1, NCons_Min_0, NCons_Min_1, NCons_BIT]); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 417 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 418 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 419 | bind_thms ("bin_arith_extra_simps",
 | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 420 | [integ_of_add RS sym, (*invoke bin_add*) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 421 | integ_of_minus RS sym, (*invoke bin_minus*) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 422 | integ_of_mult RS sym, (*invoke bin_mult*) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 423 | bin_succ_1, bin_succ_0, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 424 | bin_pred_1, bin_pred_0, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 425 | bin_minus_1, bin_minus_0, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 426 | bin_add_Pls_right, bin_add_Min_right, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 427 | bin_add_BIT_0, bin_add_BIT_10, bin_add_BIT_11, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 428 | diff_integ_of_eq, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 429 | bin_mult_1, bin_mult_0] @ NCons_simps); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 430 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 431 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 432 | (*For making a minimal simpset, one must include these default simprules | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 433 | of thy. Also include simp_thms, or at least (~False)=True*) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 434 | bind_thms ("bin_arith_simps",
 | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 435 | [bin_pred_Pls, bin_pred_Min, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 436 | bin_succ_Pls, bin_succ_Min, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 437 | bin_add_Pls, bin_add_Min, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 438 | bin_minus_Pls, bin_minus_Min, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 439 | bin_mult_Pls, bin_mult_Min] @ bin_arith_extra_simps); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 440 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 441 | (*Simplification of relational operations*) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 442 | bind_thms ("bin_rel_simps",
 | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 443 | [eq_integ_of_eq, iszero_integ_of_Pls, nonzero_integ_of_Min, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 444 | iszero_integ_of_0, iszero_integ_of_1, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 445 | less_integ_of_eq_neg, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 446 | not_neg_integ_of_Pls, neg_integ_of_Min, neg_integ_of_BIT, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 447 | le_integ_of_eq_not_less]); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 448 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 449 | Addsimps bin_arith_simps; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 450 | Addsimps bin_rel_simps; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 451 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 452 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 453 | (** Simplification of arithmetic when nested to the right **) | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 454 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 455 | Goal "[| v: bin; w: bin |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 456 | \ ==> integ_of(v) $+ (integ_of(w) $+ z) = (integ_of(bin_add(v,w)) $+ z)"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 457 | by (asm_simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 458 | qed "add_integ_of_left"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 459 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 460 | Goal "[| v: bin; w: bin |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 461 | \ ==> integ_of(v) $* (integ_of(w) $* z) = (integ_of(bin_mult(v,w)) $* z)"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 462 | by (asm_simp_tac (simpset() addsimps [zmult_assoc RS sym]) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 463 | qed "mult_integ_of_left"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 464 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 465 | Goalw [zdiff_def] | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 466 | "[| v: bin; w: bin |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 467 | \ ==> integ_of(v) $+ (integ_of(w) $- c) = integ_of(bin_add(v,w)) $- (c)"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 468 | by (rtac add_integ_of_left 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 469 | by Auto_tac; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 470 | qed "add_integ_of_diff1"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 471 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 472 | Goal "[| v: bin; w: bin |] \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 473 | \ ==> integ_of(v) $+ (c $- integ_of(w)) = \ | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 474 | \ integ_of (bin_add (v, bin_minus(w))) $+ (c)"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 475 | by (stac (diff_integ_of_eq RS sym) 1); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 476 | by (ALLGOALS (asm_simp_tac (simpset() addsimps zdiff_def::zadd_ac))); | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 477 | qed "add_integ_of_diff2"; | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 478 | |
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 479 | Addsimps [add_integ_of_left, mult_integ_of_left, | 
| 
e16e168984e1
installation of cancellation simprocs for the integers
 paulson parents: 
9548diff
changeset | 480 | add_integ_of_diff1, add_integ_of_diff2]; | 
| 9576 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 481 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 482 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 483 | (** More for integer constants **) | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 484 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 485 | Addsimps [int_of_0, int_of_succ]; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 486 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 487 | Goal "#0 $- x = $-x"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 488 | by (simp_tac (simpset() addsimps [zdiff_def]) 1); | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 489 | qed "zdiff0"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 490 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 491 | Goal "x $- #0 = intify(x)"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 492 | by (simp_tac (simpset() addsimps [zdiff_def]) 1); | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 493 | qed "zdiff0_right"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 494 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 495 | Goal "x $- x = #0"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 496 | by (simp_tac (simpset() addsimps [zdiff_def]) 1); | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 497 | qed "zdiff_self"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 498 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 499 | Addsimps [zdiff0, zdiff0_right, zdiff_self]; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 500 | |
| 9883 | 501 | Goal "k: int ==> znegative(k) <-> k $< #0"; | 
| 9576 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 502 | by (asm_simp_tac (simpset() addsimps [zless_def]) 1); | 
| 9883 | 503 | qed "znegative_iff_zless_0"; | 
| 9576 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 504 | |
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 505 | Goal "[| #0 $< k; k: int |] ==> znegative($-k)"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 506 | by (asm_full_simp_tac (simpset() addsimps [zless_def]) 1); | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 507 | qed "zero_zless_imp_znegative_zminus"; | 
| 
3df14e0a3a51
interim working version: more improvements to the integers
 paulson parents: 
9570diff
changeset | 508 | |
| 9883 | 509 | Goal "#0 $<= $# n"; | 
| 510 | by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym, | |
| 511 | znegative_iff_zless_0 RS iff_sym]) 1); | |
| 512 | qed "zero_zle_int_of"; | |
| 11321 | 513 | Addsimps [zero_zle_int_of]; | 
| 9883 | 514 | |
| 515 | Goal "nat_of(#0) = 0"; | |
| 516 | by (simp_tac (ZF_ss addsimps [natify_0, int_of_0 RS sym, nat_of_int_of]) 1); | |
| 517 | qed "nat_of_0"; | |
| 518 | Addsimps [nat_of_0]; | |
| 519 | ||
| 520 | Goal "[| z $<= $#0; z: int |] ==> nat_of(z) = 0"; | |
| 521 | by (auto_tac (claset(), | |
| 522 | simpset() addsimps [znegative_iff_zless_0 RS iff_sym, | |
| 523 | zle_def, zneg_nat_of])); | |
| 524 | val lemma = result(); | |
| 525 | ||
| 526 | Goal "z $<= $#0 ==> nat_of(z) = 0"; | |
| 527 | by (subgoal_tac "nat_of(intify(z)) = 0" 1); | |
| 528 | by (rtac lemma 2); | |
| 529 | by Auto_tac; | |
| 530 | qed "nat_le_int0"; | |
| 531 | ||
| 10635 | 532 | Goal "$# n = #0 ==> natify(n) = 0"; | 
| 9883 | 533 | by (rtac not_znegative_imp_zero 1); | 
| 534 | by Auto_tac; | |
| 535 | qed "int_of_eq_0_imp_natify_eq_0"; | |
| 536 | ||
| 537 | Goalw [nat_of_def, raw_nat_of_def] "nat_of($- $# n) = 0"; | |
| 538 | by (auto_tac((claset() addSDs [not_znegative_imp_zero, natify_int_of_eq], | |
| 539 | simpset()) delIffs [int_of_eq])); | |
| 540 | by (rtac the_equality 1); | |
| 541 | by Auto_tac; | |
| 542 | by (blast_tac (claset() addIs [int_of_eq_0_imp_natify_eq_0, sym]) 1); | |
| 543 | qed "nat_of_zminus_int_of"; | |
| 544 | ||
| 10635 | 545 | Goal "#0 $<= z ==> $# nat_of(z) = intify(z)"; | 
| 9883 | 546 | by (rtac not_zneg_nat_of_intify 1); | 
| 547 | by (asm_simp_tac (simpset() addsimps [znegative_iff_zless_0, | |
| 548 | not_zless_iff_zle]) 1); | |
| 549 | qed "int_of_nat_of"; | |
| 550 | ||
| 551 | Addsimps [int_of_nat_of, nat_of_zminus_int_of]; | |
| 552 | ||
| 553 | Goal "$# nat_of(z) = (if #0 $<= z then intify(z) else #0)"; | |
| 554 | by (simp_tac (simpset() addsimps [int_of_nat_of, | |
| 555 | znegative_iff_zless_0, not_zle_iff_zless]) 1); | |
| 556 | qed "int_of_nat_of_if"; | |
| 557 | ||
| 558 | Goal "[| m: nat; z: int |] ==> (m < nat_of(z)) <-> ($#m $< z)"; | |
| 559 | by (case_tac "znegative(z)" 1); | |
| 560 | by (etac (not_zneg_nat_of RS subst) 2); | |
| 561 | by (auto_tac (claset() addDs [zless_trans] | |
| 562 | addSDs [zero_zle_int_of RS zle_zless_trans], | |
| 563 | simpset() addsimps [znegative_iff_zless_0])); | |
| 564 | qed "zless_nat_iff_int_zless"; | |
| 565 | ||
| 566 | ||
| 567 | (** nat_of and zless **) | |
| 568 | ||
| 569 | (*An alternative condition is $#0 <= w *) | |
| 570 | Goal "$#0 $< z ==> (nat_of(w) < nat_of(z)) <-> (w $< z)"; | |
| 571 | by (rtac iff_trans 1); | |
| 572 | by (rtac (zless_int_of RS iff_sym) 1); | |
| 573 | by (auto_tac (claset(), | |
| 574 | simpset() addsimps [int_of_nat_of_if] delsimps [zless_int_of])); | |
| 575 | by (auto_tac (claset() addEs [zless_asym], | |
| 576 | simpset() addsimps [not_zle_iff_zless])); | |
| 577 | by (blast_tac (claset() addIs [zless_zle_trans]) 1); | |
| 578 | val lemma = result(); | |
| 579 | ||
| 580 | Goal "(nat_of(w) < nat_of(z)) <-> ($#0 $< z & w $< z)"; | |
| 581 | by (case_tac "$#0 $< z" 1); | |
| 582 | by (auto_tac (claset(), | |
| 583 | simpset() addsimps [lemma, nat_le_int0, not_zless_iff_zle])); | |
| 584 | qed "zless_nat_conj"; | |
| 585 | ||
| 10716 | 586 | (*This simprule cannot be added unless we can find a way to make eq_integ_of_eq | 
| 587 | unconditional! | |
| 588 | ||
| 589 | (*The condition "True" is a hack to prevent looping. | |
| 590 | Conditional rewrite rules are tried after unconditional ones, so a rule | |
| 591 | like eq_nat_number_of will be tried first to eliminate #mm=#nn. *) | |
| 592 | Goal "True ==> (integ_of(w) = x) <-> (x = integ_of(w))"; | |
| 593 | by Auto_tac; | |
| 594 | qed "integ_of_reorient"; | |
| 595 | Addsimps [integ_of_reorient]; | |
| 596 | *) | |
| 597 | ||
| 598 | Goal "(integ_of(w) = $- x) <-> ($- x = integ_of(w))"; | |
| 599 | by Auto_tac; | |
| 600 | qed "integ_of_minus_reorient"; | |
| 601 | Addsimps [integ_of_minus_reorient]; | |
| 602 | ||
| 603 | Goal "(integ_of(w) = x $+ y) <-> (x $+ y = integ_of(w))"; | |
| 604 | by Auto_tac; | |
| 605 | qed "integ_of_add_reorient"; | |
| 606 | Addsimps [integ_of_add_reorient]; | |
| 607 | ||
| 608 | Goal "(integ_of(w) = x $- y) <-> (x $- y = integ_of(w))"; | |
| 609 | by Auto_tac; | |
| 610 | qed "integ_of_diff_reorient"; | |
| 611 | Addsimps [integ_of_diff_reorient]; | |
| 612 | ||
| 613 | Goal "(integ_of(w) = x $* y) <-> (x $* y = integ_of(w))"; | |
| 614 | by Auto_tac; | |
| 615 | qed "integ_of_mult_reorient"; | |
| 616 | Addsimps [integ_of_mult_reorient]; |