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