src/ZF/ex/BinFn.ML
changeset 0 a5a9c433f639
child 7 268f93ab3bc4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ZF/ex/BinFn.ML	Thu Sep 16 12:20:38 1993 +0200
     1.3 @@ -0,0 +1,463 @@
     1.4 +(*  Title: 	ZF/ex/bin.ML
     1.5 +    ID:         $Id$
     1.6 +    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
     1.7 +    Copyright   1993  University of Cambridge
     1.8 +
     1.9 +For bin.thy.  Arithmetic on binary integers.
    1.10 +*)
    1.11 +
    1.12 +open BinFn;
    1.13 +
    1.14 +
    1.15 +(** bin_rec -- by Vset recursion **)
    1.16 +
    1.17 +goal BinFn.thy "bin_rec(Plus,a,b,h) = a";
    1.18 +by (rtac (bin_rec_def RS def_Vrec RS trans) 1);
    1.19 +by (rewrite_goals_tac Bin.con_defs);
    1.20 +by (SIMP_TAC rank_ss 1);
    1.21 +val bin_rec_Plus = result();
    1.22 +
    1.23 +goal BinFn.thy "bin_rec(Minus,a,b,h) = b";
    1.24 +by (rtac (bin_rec_def RS def_Vrec RS trans) 1);
    1.25 +by (rewrite_goals_tac Bin.con_defs);
    1.26 +by (SIMP_TAC rank_ss 1);
    1.27 +val bin_rec_Minus = result();
    1.28 +
    1.29 +goal BinFn.thy "bin_rec(w$$x,a,b,h) = h(w, x, bin_rec(w,a,b,h))";
    1.30 +by (rtac (bin_rec_def RS def_Vrec RS trans) 1);
    1.31 +by (rewrite_goals_tac Bin.con_defs);
    1.32 +by (SIMP_TAC (rank_ss addcongs 
    1.33 +	      (mk_typed_congs BinFn.thy [("h", "[i,i,i]=>i")])) 1);
    1.34 +val bin_rec_Bcons = result();
    1.35 +
    1.36 +(*Type checking*)
    1.37 +val prems = goal BinFn.thy
    1.38 +    "[| w: bin;    \
    1.39 +\       a: C(Plus);   b: C(Minus);       \
    1.40 +\       !!w x r. [| w: bin;  x: bool;  r: C(w) |] ==> h(w,x,r): C(w$$x)  \
    1.41 +\    |] ==> bin_rec(w,a,b,h) : C(w)";
    1.42 +by (bin_ind_tac "w" prems 1);
    1.43 +by (ALLGOALS 
    1.44 +    (ASM_SIMP_TAC (ZF_ss addrews (prems@[bin_rec_Plus,bin_rec_Minus,
    1.45 +					 bin_rec_Bcons]))));
    1.46 +val bin_rec_type = result();
    1.47 +
    1.48 +(** Versions for use with definitions **)
    1.49 +
    1.50 +val [rew] = goal BinFn.thy
    1.51 +    "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(Plus) = a";
    1.52 +by (rewtac rew);
    1.53 +by (rtac bin_rec_Plus 1);
    1.54 +val def_bin_rec_Plus = result();
    1.55 +
    1.56 +val [rew] = goal BinFn.thy
    1.57 +    "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(Minus) = b";
    1.58 +by (rewtac rew);
    1.59 +by (rtac bin_rec_Minus 1);
    1.60 +val def_bin_rec_Minus = result();
    1.61 +
    1.62 +val [rew] = goal BinFn.thy
    1.63 +    "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(w$$x) = h(w,x,j(w))";
    1.64 +by (rewtac rew);
    1.65 +by (rtac bin_rec_Bcons 1);
    1.66 +val def_bin_rec_Bcons = result();
    1.67 +
    1.68 +fun bin_recs def = map standard
    1.69 +	([def] RL [def_bin_rec_Plus, def_bin_rec_Minus, def_bin_rec_Bcons]);
    1.70 +
    1.71 +(** Type checking **)
    1.72 +
    1.73 +val bin_typechecks0 = bin_rec_type :: Bin.intrs;
    1.74 +
    1.75 +goalw BinFn.thy [integ_of_bin_def]
    1.76 +    "!!w. w: bin ==> integ_of_bin(w) : integ";
    1.77 +by (typechk_tac (bin_typechecks0@integ_typechecks@
    1.78 +		 nat_typechecks@[bool_into_nat]));
    1.79 +val integ_of_bin_type = result();
    1.80 +
    1.81 +goalw BinFn.thy [bin_succ_def]
    1.82 +    "!!w. w: bin ==> bin_succ(w) : bin";
    1.83 +by (typechk_tac (bin_typechecks0@bool_typechecks));
    1.84 +val bin_succ_type = result();
    1.85 +
    1.86 +goalw BinFn.thy [bin_pred_def]
    1.87 +    "!!w. w: bin ==> bin_pred(w) : bin";
    1.88 +by (typechk_tac (bin_typechecks0@bool_typechecks));
    1.89 +val bin_pred_type = result();
    1.90 +
    1.91 +goalw BinFn.thy [bin_minus_def]
    1.92 +    "!!w. w: bin ==> bin_minus(w) : bin";
    1.93 +by (typechk_tac ([bin_pred_type]@bin_typechecks0@bool_typechecks));
    1.94 +val bin_minus_type = result();
    1.95 +
    1.96 +goalw BinFn.thy [bin_add_def]
    1.97 +    "!!v w. [| v: bin; w: bin |] ==> bin_add(v,w) : bin";
    1.98 +by (typechk_tac ([bin_succ_type,bin_pred_type]@bin_typechecks0@
    1.99 +		 bool_typechecks@ZF_typechecks));
   1.100 +val bin_add_type = result();
   1.101 +
   1.102 +goalw BinFn.thy [bin_mult_def]
   1.103 +    "!!v w. [| v: bin; w: bin |] ==> bin_mult(v,w) : bin";
   1.104 +by (typechk_tac ([bin_minus_type,bin_add_type]@bin_typechecks0@
   1.105 +		 bool_typechecks));
   1.106 +val bin_mult_type = result();
   1.107 +
   1.108 +val bin_typechecks = bin_typechecks0 @
   1.109 +    [integ_of_bin_type, bin_succ_type, bin_pred_type, 
   1.110 +     bin_minus_type, bin_add_type, bin_mult_type];
   1.111 +
   1.112 +val bin_congs = mk_congs BinFn.thy
   1.113 +    ["bin_rec","op $$","integ_of_bin","bin_succ","bin_pred",
   1.114 +     "bin_minus","bin_add","bin_mult"];
   1.115 +
   1.116 +val bin_ss = integ_ss 
   1.117 +    addcongs (bin_congs@bool_congs)
   1.118 +    addrews([bool_1I, bool_0I,
   1.119 +	     bin_rec_Plus, bin_rec_Minus, bin_rec_Bcons] @ 
   1.120 +	     bin_recs integ_of_bin_def @ bool_rews @ bin_typechecks);
   1.121 +
   1.122 +val typechecks = bin_typechecks @ integ_typechecks @ nat_typechecks @
   1.123 +                 [bool_subset_nat RS subsetD];
   1.124 +
   1.125 +(**** The carry/borrow functions, bin_succ and bin_pred ****)
   1.126 +
   1.127 +(** Lemmas **)
   1.128 +
   1.129 +goal Integ.thy 
   1.130 +    "!!z v. [| z $+ v = z' $+ v';  \
   1.131 +\       z: integ; z': integ;  v: integ; v': integ;  w: integ |]   \
   1.132 +\    ==> z $+ (v $+ w) = z' $+ (v' $+ w)";
   1.133 +by (ASM_SIMP_TAC (integ_ss addrews ([zadd_assoc RS sym])) 1);
   1.134 +val zadd_assoc_cong = result();
   1.135 +
   1.136 +goal Integ.thy 
   1.137 +    "!!z v w. [| z: integ;  v: integ;  w: integ |]   \
   1.138 +\    ==> z $+ (v $+ w) = v $+ (z $+ w)";
   1.139 +by (REPEAT (ares_tac [zadd_commute RS zadd_assoc_cong] 1));
   1.140 +val zadd_assoc_swap = result();
   1.141 +
   1.142 +val [zadd_cong] = mk_congs Integ.thy ["op $+"];
   1.143 +
   1.144 +val zadd_kill = (refl RS zadd_cong);
   1.145 +val zadd_assoc_swap_kill = zadd_kill RSN (4, zadd_assoc_swap RS trans);
   1.146 +
   1.147 +(*Pushes 'constants' of the form $#m to the right -- LOOPS if two!*)
   1.148 +val zadd_assoc_znat = standard (znat_type RS zadd_assoc_swap);
   1.149 +
   1.150 +goal Integ.thy 
   1.151 +    "!!z w. [| z: integ;  w: integ |]   \
   1.152 +\    ==> w $+ (z $+ (w $+ z)) = w $+ (w $+ (z $+ z))";
   1.153 +by (REPEAT (ares_tac [zadd_kill, zadd_assoc_swap] 1));
   1.154 +val zadd_swap_pairs = result();
   1.155 +
   1.156 +
   1.157 +val carry_ss = bin_ss addrews 
   1.158 +               (bin_recs bin_succ_def @ bin_recs bin_pred_def);
   1.159 +
   1.160 +goal BinFn.thy
   1.161 +    "!!w. w: bin ==> integ_of_bin(bin_succ(w)) = $#1 $+ integ_of_bin(w)";
   1.162 +by (etac Bin.induct 1);
   1.163 +by (SIMP_TAC (carry_ss addrews [zadd_0_right]) 1);
   1.164 +by (SIMP_TAC (carry_ss addrews [zadd_zminus_inverse]) 1);
   1.165 +by (etac boolE 1);
   1.166 +by (ALLGOALS (ASM_SIMP_TAC (carry_ss addrews [zadd_assoc])));
   1.167 +by (REPEAT (ares_tac (zadd_swap_pairs::typechecks) 1));
   1.168 +val integ_of_bin_succ = result();
   1.169 +
   1.170 +goal BinFn.thy
   1.171 +    "!!w. w: bin ==> integ_of_bin(bin_pred(w)) = $~ ($#1) $+ integ_of_bin(w)";
   1.172 +by (etac Bin.induct 1);
   1.173 +by (SIMP_TAC (carry_ss addrews [zadd_0_right]) 1);
   1.174 +by (SIMP_TAC (carry_ss addrews [zadd_zminus_inverse]) 1);
   1.175 +by (etac boolE 1);
   1.176 +by (ALLGOALS 
   1.177 +    (ASM_SIMP_TAC 
   1.178 +     (carry_ss addrews [zadd_assoc RS sym,
   1.179 +			zadd_zminus_inverse, zadd_zminus_inverse2])));
   1.180 +by (REPEAT (ares_tac ([zadd_commute, zadd_cong, refl]@typechecks) 1));
   1.181 +val integ_of_bin_pred = result();
   1.182 +
   1.183 +(*These two results replace the definitions of bin_succ and bin_pred*)
   1.184 +
   1.185 +
   1.186 +(*** bin_minus: (unary!) negation of binary integers ***)
   1.187 +
   1.188 +val bin_minus_ss =
   1.189 +    bin_ss addrews (bin_recs bin_minus_def @
   1.190 +		    [integ_of_bin_succ, integ_of_bin_pred]);
   1.191 +
   1.192 +goal BinFn.thy
   1.193 +    "!!w. w: bin ==> integ_of_bin(bin_minus(w)) = $~ integ_of_bin(w)";
   1.194 +by (etac Bin.induct 1);
   1.195 +by (SIMP_TAC (bin_minus_ss addrews [zminus_0]) 1);
   1.196 +by (SIMP_TAC (bin_minus_ss addrews [zadd_0_right]) 1);
   1.197 +by (etac boolE 1);
   1.198 +by (ALLGOALS 
   1.199 +    (ASM_SIMP_TAC (bin_minus_ss addrews [zminus_zadd_distrib, zadd_assoc])));
   1.200 +val integ_of_bin_minus = result();
   1.201 +
   1.202 +
   1.203 +(*** bin_add: binary addition ***)
   1.204 +
   1.205 +goalw BinFn.thy [bin_add_def] "!!w. w: bin ==> bin_add(Plus,w) = w";
   1.206 +by (ASM_SIMP_TAC bin_ss 1);
   1.207 +val bin_add_Plus = result();
   1.208 +
   1.209 +goalw BinFn.thy [bin_add_def] "!!w. w: bin ==> bin_add(Minus,w) = bin_pred(w)";
   1.210 +by (ASM_SIMP_TAC bin_ss 1);
   1.211 +val bin_add_Minus = result();
   1.212 +
   1.213 +goalw BinFn.thy [bin_add_def] "bin_add(v$$x,Plus) = v$$x";
   1.214 +by (SIMP_TAC bin_ss 1);
   1.215 +val bin_add_Bcons_Plus = result();
   1.216 +
   1.217 +goalw BinFn.thy [bin_add_def] "bin_add(v$$x,Minus) = bin_pred(v$$x)";
   1.218 +by (SIMP_TAC bin_ss 1);
   1.219 +val bin_add_Bcons_Minus = result();
   1.220 +
   1.221 +goalw BinFn.thy [bin_add_def]
   1.222 +    "!!w y. [| w: bin;  y: bool |] ==> \
   1.223 +\           bin_add(v$$x, w$$y) = \
   1.224 +\           bin_add(v, cond(x and y, bin_succ(w), w)) $$ (x xor y)";
   1.225 +by (ASM_SIMP_TAC bin_ss 1);
   1.226 +val bin_add_Bcons_Bcons = result();
   1.227 +
   1.228 +val bin_add_rews = [bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus,
   1.229 +		    bin_add_Bcons_Minus, bin_add_Bcons_Bcons,
   1.230 +		    integ_of_bin_succ, integ_of_bin_pred];
   1.231 +
   1.232 +val bin_add_ss = bin_ss addrews ([bool_subset_nat RS subsetD] @ bin_add_rews);
   1.233 +
   1.234 +goal BinFn.thy
   1.235 +    "!!v. v: bin ==> \
   1.236 +\         ALL w: bin. integ_of_bin(bin_add(v,w)) = \
   1.237 +\                     integ_of_bin(v) $+ integ_of_bin(w)";
   1.238 +by (etac Bin.induct 1);
   1.239 +by (SIMP_TAC bin_add_ss 1);
   1.240 +by (SIMP_TAC bin_add_ss 1);
   1.241 +by (rtac ballI 1);
   1.242 +by (bin_ind_tac "wa" [] 1);
   1.243 +by (ASM_SIMP_TAC (bin_add_ss addrews [zadd_0_right]) 1);
   1.244 +by (ASM_SIMP_TAC bin_add_ss 1);
   1.245 +by (REPEAT (ares_tac (zadd_commute::typechecks) 1));
   1.246 +by (etac boolE 1);
   1.247 +by (ASM_SIMP_TAC (bin_add_ss addrews [zadd_assoc, zadd_swap_pairs]) 2);
   1.248 +by (REPEAT (ares_tac ([refl, zadd_kill, zadd_assoc_swap_kill]@typechecks) 2));
   1.249 +by (etac boolE 1);
   1.250 +by (ALLGOALS (ASM_SIMP_TAC (bin_add_ss addrews [zadd_assoc,zadd_swap_pairs])));
   1.251 +by (REPEAT (ares_tac ([refl, zadd_kill, zadd_assoc_swap_kill RS sym]@
   1.252 +		      typechecks) 1));
   1.253 +val integ_of_bin_add_lemma = result();
   1.254 +
   1.255 +val integ_of_bin_add = integ_of_bin_add_lemma RS bspec;
   1.256 +
   1.257 +
   1.258 +(*** bin_add: binary multiplication ***)
   1.259 +
   1.260 +val bin_mult_ss =
   1.261 +    bin_ss addrews (bin_recs bin_mult_def @ 
   1.262 +		       [integ_of_bin_minus, integ_of_bin_add]);
   1.263 +
   1.264 +
   1.265 +val major::prems = goal BinFn.thy
   1.266 +    "[| v: bin; w: bin |] ==>	\
   1.267 +\    integ_of_bin(bin_mult(v,w)) = \
   1.268 +\    integ_of_bin(v) $* integ_of_bin(w)";
   1.269 +by (cut_facts_tac prems 1);
   1.270 +by (bin_ind_tac "v" [major] 1);
   1.271 +by (SIMP_TAC (bin_mult_ss addrews [zmult_0]) 1);
   1.272 +by (SIMP_TAC (bin_mult_ss addrews [zmult_1,zmult_zminus]) 1);
   1.273 +by (etac boolE 1);
   1.274 +by (ASM_SIMP_TAC (bin_mult_ss addrews [zadd_zmult_distrib]) 2);
   1.275 +by (ASM_SIMP_TAC 
   1.276 +    (bin_mult_ss addrews [zadd_zmult_distrib, zmult_1, zadd_assoc]) 1);
   1.277 +by (REPEAT (ares_tac ([zadd_commute, zadd_assoc_swap_kill RS sym]@
   1.278 +		      typechecks) 1));
   1.279 +val integ_of_bin_mult = result();
   1.280 +
   1.281 +(**** Computations ****)
   1.282 +
   1.283 +(** extra rules for bin_succ, bin_pred **)
   1.284 +
   1.285 +val [bin_succ_Plus, bin_succ_Minus, _] = bin_recs bin_succ_def;
   1.286 +val [bin_pred_Plus, bin_pred_Minus, _] = bin_recs bin_pred_def;
   1.287 +
   1.288 +goal BinFn.thy "bin_succ(w$$1) = bin_succ(w) $$ 0";
   1.289 +by (SIMP_TAC carry_ss 1);
   1.290 +val bin_succ_Bcons1 = result();
   1.291 +
   1.292 +goal BinFn.thy "bin_succ(w$$0) = w$$1";
   1.293 +by (SIMP_TAC carry_ss 1);
   1.294 +val bin_succ_Bcons0 = result();
   1.295 +
   1.296 +goal BinFn.thy "bin_pred(w$$1) = w$$0";
   1.297 +by (SIMP_TAC carry_ss 1);
   1.298 +val bin_pred_Bcons1 = result();
   1.299 +
   1.300 +goal BinFn.thy "bin_pred(w$$0) = bin_pred(w) $$ 1";
   1.301 +by (SIMP_TAC carry_ss 1);
   1.302 +val bin_pred_Bcons0 = result();
   1.303 +
   1.304 +(** extra rules for bin_minus **)
   1.305 +
   1.306 +val [bin_minus_Plus, bin_minus_Minus, _] = bin_recs bin_minus_def;
   1.307 +
   1.308 +goal BinFn.thy "bin_minus(w$$1) = bin_pred(bin_minus(w) $$ 0)";
   1.309 +by (SIMP_TAC bin_minus_ss 1);
   1.310 +val bin_minus_Bcons1 = result();
   1.311 +
   1.312 +goal BinFn.thy "bin_minus(w$$0) = bin_minus(w) $$ 0";
   1.313 +by (SIMP_TAC bin_minus_ss 1);
   1.314 +val bin_minus_Bcons0 = result();
   1.315 +
   1.316 +(** extra rules for bin_add **)
   1.317 +
   1.318 +goal BinFn.thy 
   1.319 +    "!!w. w: bin ==> bin_add(v$$1, w$$1) = bin_add(v, bin_succ(w)) $$ 0";
   1.320 +by (ASM_SIMP_TAC bin_add_ss 1);
   1.321 +val bin_add_Bcons_Bcons11 = result();
   1.322 +
   1.323 +goal BinFn.thy 
   1.324 +    "!!w. w: bin ==> bin_add(v$$1, w$$0) = bin_add(v,w) $$ 1";
   1.325 +by (ASM_SIMP_TAC bin_add_ss 1);
   1.326 +val bin_add_Bcons_Bcons10 = result();
   1.327 +
   1.328 +goal BinFn.thy 
   1.329 +    "!!w y.[| w: bin;  y: bool |] ==> bin_add(v$$0, w$$y) = bin_add(v,w) $$ y";
   1.330 +by (ASM_SIMP_TAC bin_add_ss 1);
   1.331 +val bin_add_Bcons_Bcons0 = result();
   1.332 +
   1.333 +(** extra rules for bin_mult **)
   1.334 +
   1.335 +val [bin_mult_Plus, bin_mult_Minus, _] = bin_recs bin_mult_def;
   1.336 +
   1.337 +goal BinFn.thy "bin_mult(v$$1, w) = bin_add(bin_mult(v,w)$$0, w)";
   1.338 +by (SIMP_TAC bin_mult_ss 1);
   1.339 +val bin_mult_Bcons1 = result();
   1.340 +
   1.341 +goal BinFn.thy "bin_mult(v$$0, w) = bin_mult(v,w)$$0";
   1.342 +by (SIMP_TAC bin_mult_ss 1);
   1.343 +val bin_mult_Bcons0 = result();
   1.344 +
   1.345 +
   1.346 +(*** The computation simpset ***)
   1.347 +
   1.348 +val bin_comp_ss = carry_ss addrews
   1.349 +    [bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus, bin_add_Bcons_Minus, 
   1.350 +     bin_add_Bcons_Bcons0, bin_add_Bcons_Bcons10, bin_add_Bcons_Bcons11]
   1.351 +    setauto (type_auto_tac bin_typechecks0);
   1.352 +
   1.353 +val bin_comp_ss = integ_ss 
   1.354 +    addcongs bin_congs
   1.355 +    addrews [bin_succ_Plus, bin_succ_Minus,
   1.356 +	     bin_succ_Bcons1, bin_succ_Bcons0,
   1.357 +	     bin_pred_Plus, bin_pred_Minus,
   1.358 +	     bin_pred_Bcons1, bin_pred_Bcons0,
   1.359 +	     bin_minus_Plus, bin_minus_Minus,
   1.360 +	     bin_minus_Bcons1, bin_minus_Bcons0,
   1.361 +	     bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus, 
   1.362 +	     bin_add_Bcons_Minus, bin_add_Bcons_Bcons0, 
   1.363 +	     bin_add_Bcons_Bcons10, bin_add_Bcons_Bcons11,
   1.364 +	     bin_mult_Plus, bin_mult_Minus,
   1.365 +	     bin_mult_Bcons1, bin_mult_Bcons0]
   1.366 +    setauto (type_auto_tac ([bool_1I, bool_0I] @ bin_typechecks0));
   1.367 +
   1.368 +(*** Examples of performing binary arithmetic by simplification ***)
   1.369 +
   1.370 +proof_timing := true;
   1.371 +(*All runtimes below are on a SPARCserver 10*)
   1.372 +
   1.373 +(* 13+19 = 32 *)
   1.374 +goal BinFn.thy
   1.375 +    "bin_add(Plus$$1$$1$$0$$1, Plus$$1$$0$$0$$1$$1) = Plus$$1$$0$$0$$0$$0$$0";
   1.376 +by (SIMP_TAC bin_comp_ss 1);	(*1.9 secs*)
   1.377 +result();
   1.378 +
   1.379 +bin_add(binary_of_int 13, binary_of_int 19);
   1.380 +
   1.381 +(* 1234+5678 = 6912 *)
   1.382 +goal BinFn.thy
   1.383 +    "bin_add(Plus$$1$$0$$0$$1$$1$$0$$1$$0$$0$$1$$0, \
   1.384 +\	     Plus$$1$$0$$1$$1$$0$$0$$0$$1$$0$$1$$1$$1$$0) = \
   1.385 +\    Plus$$1$$1$$0$$1$$1$$0$$0$$0$$0$$0$$0$$0$$0";
   1.386 +by (SIMP_TAC bin_comp_ss 1);	(*8.9 secs*)
   1.387 +result();
   1.388 +
   1.389 +bin_add(binary_of_int 1234, binary_of_int 5678);
   1.390 +
   1.391 +(* 1359-2468 = ~1109 *)
   1.392 +goal BinFn.thy
   1.393 +    "bin_add(Plus$$1$$0$$1$$0$$1$$0$$0$$1$$1$$1$$1,		\
   1.394 +\	     Minus$$0$$1$$1$$0$$0$$1$$0$$1$$1$$1$$0$$0) = 	\
   1.395 +\    Minus$$1$$0$$1$$1$$1$$0$$1$$0$$1$$0$$1$$1";
   1.396 +by (SIMP_TAC bin_comp_ss 1);	(*7.4 secs*)
   1.397 +result();
   1.398 +
   1.399 +bin_add(binary_of_int 1359, binary_of_int ~2468);
   1.400 +
   1.401 +(* 93746-46375 = 47371 *)
   1.402 +goal BinFn.thy
   1.403 +    "bin_add(Plus$$1$$0$$1$$1$$0$$1$$1$$1$$0$$0$$0$$1$$1$$0$$0$$1$$0, \
   1.404 +\	     Minus$$0$$1$$0$$0$$1$$0$$1$$0$$1$$1$$0$$1$$1$$0$$0$$1) = \
   1.405 +\    Plus$$0$$1$$0$$1$$1$$1$$0$$0$$1$$0$$0$$0$$0$$1$$0$$1$$1";
   1.406 +by (SIMP_TAC bin_comp_ss 1);	(*13.7 secs*)
   1.407 +result();
   1.408 +
   1.409 +bin_add(binary_of_int 93746, binary_of_int ~46375);
   1.410 +
   1.411 +(* negation of 65745 *)
   1.412 +goal BinFn.thy
   1.413 +    "bin_minus(Plus$$1$$0$$0$$0$$0$$0$$0$$0$$0$$1$$1$$0$$1$$0$$0$$0$$1) = \
   1.414 +\    Minus$$0$$1$$1$$1$$1$$1$$1$$1$$1$$0$$0$$1$$0$$1$$1$$1$$1";
   1.415 +by (SIMP_TAC bin_comp_ss 1);	(*2.8 secs*)
   1.416 +result();
   1.417 +
   1.418 +bin_minus(binary_of_int 65745);
   1.419 +
   1.420 +(* negation of ~54321 *)
   1.421 +goal BinFn.thy
   1.422 +    "bin_minus(Minus$$0$$0$$1$$0$$1$$0$$1$$1$$1$$1$$0$$0$$1$$1$$1$$1) = \
   1.423 +\    Plus$$0$$1$$1$$0$$1$$0$$1$$0$$0$$0$$0$$1$$1$$0$$0$$0$$1";
   1.424 +by (SIMP_TAC bin_comp_ss 1);	(*3.3 secs*)
   1.425 +result();
   1.426 +
   1.427 +bin_minus(binary_of_int ~54321);
   1.428 +
   1.429 +(* 13*19 = 247 *)
   1.430 +goal BinFn.thy "bin_mult(Plus$$1$$1$$0$$1, Plus$$1$$0$$0$$1$$1) = \
   1.431 +\               Plus$$1$$1$$1$$1$$0$$1$$1$$1";
   1.432 +by (SIMP_TAC bin_comp_ss 1);	(*4.4 secs*)
   1.433 +result();
   1.434 +
   1.435 +bin_mult(binary_of_int 13, binary_of_int 19);
   1.436 +
   1.437 +(* ~84 * 51 = ~4284 *)
   1.438 +goal BinFn.thy
   1.439 +    "bin_mult(Minus$$0$$1$$0$$1$$1$$0$$0, Plus$$1$$1$$0$$0$$1$$1) = \
   1.440 +\    Minus$$0$$1$$1$$1$$1$$0$$1$$0$$0$$0$$1$$0$$0";
   1.441 +by (SIMP_TAC bin_comp_ss 1);	(*9.2 secs*)
   1.442 +result();
   1.443 +
   1.444 +bin_mult(binary_of_int ~84, binary_of_int 51);
   1.445 +
   1.446 +(* 255*255 = 65025;  the worst case for 8-bit operands *)
   1.447 +goal BinFn.thy
   1.448 +    "bin_mult(Plus$$1$$1$$1$$1$$1$$1$$1$$1, \
   1.449 +\             Plus$$1$$1$$1$$1$$1$$1$$1$$1) = \
   1.450 +\        Plus$$1$$1$$1$$1$$1$$1$$1$$0$$0$$0$$0$$0$$0$$0$$0$$1";
   1.451 +by (SIMP_TAC bin_comp_ss 1);	(*38.4 secs*)
   1.452 +result();
   1.453 +
   1.454 +bin_mult(binary_of_int 255, binary_of_int 255);
   1.455 +
   1.456 +(***************** TOO SLOW TO INCLUDE IN TEST RUNS
   1.457 +(* 1359 * ~2468 = ~3354012 *)
   1.458 +goal BinFn.thy
   1.459 +    "bin_mult(Plus$$1$$0$$1$$0$$1$$0$$0$$1$$1$$1$$1, 		\
   1.460 +\	      Minus$$0$$1$$1$$0$$0$$1$$0$$1$$1$$1$$0$$0) = 	\
   1.461 +\    Minus$$0$$0$$1$$1$$0$$0$$1$$1$$0$$1$$0$$0$$1$$0$$0$$1$$1$$0$$0$$1$$0$$0";
   1.462 +by (SIMP_TAC bin_comp_ss 1);	(*54.8 secs*)
   1.463 +result();
   1.464 +****************)
   1.465 +
   1.466 +bin_mult(binary_of_int 1359, binary_of_int ~2468);