src/ZF/ex/Bin.ML
author lcp
Tue Aug 16 18:58:42 1994 +0200 (1994-08-16)
changeset 532 851df239ac8b
parent 515 abcc438e7c27
child 760 f0200e91b272
permissions -rw-r--r--
ZF/Makefile,ROOT.ML, ZF/ex/Integ.thy: updated for EquivClass
lcp@515
     1
(*  Title: 	ZF/ex/Bin.ML
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
lcp@515
     4
    Copyright   1994  University of Cambridge
clasohm@0
     5
lcp@515
     6
For Bin.thy.  Arithmetic on binary integers.
clasohm@0
     7
*)
clasohm@0
     8
lcp@515
     9
open Bin;
clasohm@0
    10
clasohm@0
    11
(*Perform induction on l, then prove the major premise using prems. *)
clasohm@0
    12
fun bin_ind_tac a prems i = 
lcp@515
    13
    EVERY [res_inst_tac [("x",a)] bin.induct i,
clasohm@0
    14
	   rename_last_tac a ["1"] (i+3),
clasohm@0
    15
	   ares_tac prems i];
clasohm@0
    16
lcp@515
    17
lcp@515
    18
(** bin_rec -- by Vset recursion **)
lcp@515
    19
lcp@515
    20
goal Bin.thy "bin_rec(Plus,a,b,h) = a";
lcp@515
    21
by (rtac (bin_rec_def RS def_Vrec RS trans) 1);
lcp@515
    22
by (rewrite_goals_tac bin.con_defs);
lcp@515
    23
by (simp_tac rank_ss 1);
lcp@515
    24
val bin_rec_Plus = result();
lcp@515
    25
lcp@515
    26
goal Bin.thy "bin_rec(Minus,a,b,h) = b";
lcp@515
    27
by (rtac (bin_rec_def RS def_Vrec RS trans) 1);
lcp@515
    28
by (rewrite_goals_tac bin.con_defs);
lcp@515
    29
by (simp_tac rank_ss 1);
lcp@515
    30
val bin_rec_Minus = result();
lcp@515
    31
lcp@515
    32
goal Bin.thy "bin_rec(w$$x,a,b,h) = h(w, x, bin_rec(w,a,b,h))";
lcp@515
    33
by (rtac (bin_rec_def RS def_Vrec RS trans) 1);
lcp@515
    34
by (rewrite_goals_tac bin.con_defs);
lcp@515
    35
by (simp_tac rank_ss 1);
lcp@515
    36
val bin_rec_Bcons = result();
lcp@515
    37
lcp@515
    38
(*Type checking*)
lcp@515
    39
val prems = goal Bin.thy
lcp@515
    40
    "[| w: bin;    \
lcp@515
    41
\       a: C(Plus);   b: C(Minus);       \
lcp@515
    42
\       !!w x r. [| w: bin;  x: bool;  r: C(w) |] ==> h(w,x,r): C(w$$x)  \
lcp@515
    43
\    |] ==> bin_rec(w,a,b,h) : C(w)";
lcp@515
    44
by (bin_ind_tac "w" prems 1);
lcp@515
    45
by (ALLGOALS 
lcp@515
    46
    (asm_simp_tac (ZF_ss addsimps (prems@[bin_rec_Plus,bin_rec_Minus,
lcp@515
    47
					 bin_rec_Bcons]))));
lcp@515
    48
val bin_rec_type = result();
lcp@515
    49
lcp@515
    50
(** Versions for use with definitions **)
lcp@515
    51
lcp@515
    52
val [rew] = goal Bin.thy
lcp@515
    53
    "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(Plus) = a";
lcp@515
    54
by (rewtac rew);
lcp@515
    55
by (rtac bin_rec_Plus 1);
lcp@515
    56
val def_bin_rec_Plus = result();
lcp@515
    57
lcp@515
    58
val [rew] = goal Bin.thy
lcp@515
    59
    "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(Minus) = b";
lcp@515
    60
by (rewtac rew);
lcp@515
    61
by (rtac bin_rec_Minus 1);
lcp@515
    62
val def_bin_rec_Minus = result();
lcp@515
    63
lcp@515
    64
val [rew] = goal Bin.thy
lcp@515
    65
    "[| !!w. j(w)==bin_rec(w,a,b,h) |] ==> j(w$$x) = h(w,x,j(w))";
lcp@515
    66
by (rewtac rew);
lcp@515
    67
by (rtac bin_rec_Bcons 1);
lcp@515
    68
val def_bin_rec_Bcons = result();
lcp@515
    69
lcp@515
    70
fun bin_recs def = map standard
lcp@515
    71
	([def] RL [def_bin_rec_Plus, def_bin_rec_Minus, def_bin_rec_Bcons]);
lcp@515
    72
lcp@515
    73
(** Type checking **)
lcp@515
    74
lcp@515
    75
val bin_typechecks0 = bin_rec_type :: bin.intrs;
lcp@515
    76
lcp@515
    77
goalw Bin.thy [integ_of_bin_def]
lcp@515
    78
    "!!w. w: bin ==> integ_of_bin(w) : integ";
lcp@515
    79
by (typechk_tac (bin_typechecks0@integ_typechecks@
lcp@515
    80
		 nat_typechecks@[bool_into_nat]));
lcp@515
    81
val integ_of_bin_type = result();
lcp@515
    82
lcp@515
    83
goalw Bin.thy [bin_succ_def]
lcp@515
    84
    "!!w. w: bin ==> bin_succ(w) : bin";
lcp@515
    85
by (typechk_tac (bin_typechecks0@bool_typechecks));
lcp@515
    86
val bin_succ_type = result();
lcp@515
    87
lcp@515
    88
goalw Bin.thy [bin_pred_def]
lcp@515
    89
    "!!w. w: bin ==> bin_pred(w) : bin";
lcp@515
    90
by (typechk_tac (bin_typechecks0@bool_typechecks));
lcp@515
    91
val bin_pred_type = result();
lcp@515
    92
lcp@515
    93
goalw Bin.thy [bin_minus_def]
lcp@515
    94
    "!!w. w: bin ==> bin_minus(w) : bin";
lcp@515
    95
by (typechk_tac ([bin_pred_type]@bin_typechecks0@bool_typechecks));
lcp@515
    96
val bin_minus_type = result();
lcp@515
    97
lcp@515
    98
goalw Bin.thy [bin_add_def]
lcp@515
    99
    "!!v w. [| v: bin; w: bin |] ==> bin_add(v,w) : bin";
lcp@515
   100
by (typechk_tac ([bin_succ_type,bin_pred_type]@bin_typechecks0@
lcp@515
   101
		 bool_typechecks@ZF_typechecks));
lcp@515
   102
val bin_add_type = result();
lcp@515
   103
lcp@515
   104
goalw Bin.thy [bin_mult_def]
lcp@515
   105
    "!!v w. [| v: bin; w: bin |] ==> bin_mult(v,w) : bin";
lcp@515
   106
by (typechk_tac ([bin_minus_type,bin_add_type]@bin_typechecks0@
lcp@515
   107
		 bool_typechecks));
lcp@515
   108
val bin_mult_type = result();
lcp@515
   109
lcp@515
   110
val bin_typechecks = bin_typechecks0 @
lcp@515
   111
    [integ_of_bin_type, bin_succ_type, bin_pred_type, 
lcp@515
   112
     bin_minus_type, bin_add_type, bin_mult_type];
lcp@515
   113
lcp@515
   114
val bin_ss = integ_ss 
lcp@515
   115
    addsimps([bool_1I, bool_0I,
lcp@515
   116
	     bin_rec_Plus, bin_rec_Minus, bin_rec_Bcons] @ 
lcp@515
   117
	     bin_recs integ_of_bin_def @ bool_simps @ bin_typechecks);
lcp@515
   118
lcp@515
   119
val typechecks = bin_typechecks @ integ_typechecks @ nat_typechecks @
lcp@515
   120
                 [bool_subset_nat RS subsetD];
lcp@515
   121
lcp@515
   122
(**** The carry/borrow functions, bin_succ and bin_pred ****)
lcp@515
   123
lcp@515
   124
(** Lemmas **)
lcp@515
   125
lcp@515
   126
goal Integ.thy 
lcp@515
   127
    "!!z v. [| z $+ v = z' $+ v';  \
lcp@515
   128
\       z: integ; z': integ;  v: integ; v': integ;  w: integ |]   \
lcp@515
   129
\    ==> z $+ (v $+ w) = z' $+ (v' $+ w)";
lcp@515
   130
by (asm_simp_tac (integ_ss addsimps ([zadd_assoc RS sym])) 1);
lcp@515
   131
val zadd_assoc_cong = result();
lcp@515
   132
lcp@515
   133
goal Integ.thy 
lcp@515
   134
    "!!z v w. [| z: integ;  v: integ;  w: integ |]   \
lcp@515
   135
\    ==> z $+ (v $+ w) = v $+ (z $+ w)";
lcp@515
   136
by (REPEAT (ares_tac [zadd_commute RS zadd_assoc_cong] 1));
lcp@515
   137
val zadd_assoc_swap = result();
lcp@515
   138
lcp@515
   139
val zadd_cong = 
lcp@515
   140
    read_instantiate_sg (sign_of Integ.thy) [("t","op $+")] subst_context2;
lcp@515
   141
lcp@515
   142
val zadd_kill = (refl RS zadd_cong);
lcp@515
   143
val zadd_assoc_swap_kill = zadd_kill RSN (4, zadd_assoc_swap RS trans);
lcp@515
   144
lcp@515
   145
(*Pushes 'constants' of the form $#m to the right -- LOOPS if two!*)
lcp@515
   146
val zadd_assoc_znat = standard (znat_type RS zadd_assoc_swap);
lcp@515
   147
lcp@515
   148
goal Integ.thy 
lcp@515
   149
    "!!z w. [| z: integ;  w: integ |]   \
lcp@515
   150
\    ==> w $+ (z $+ (w $+ z)) = w $+ (w $+ (z $+ z))";
lcp@515
   151
by (REPEAT (ares_tac [zadd_kill, zadd_assoc_swap] 1));
lcp@515
   152
val zadd_swap_pairs = result();
lcp@515
   153
lcp@515
   154
lcp@515
   155
val carry_ss = bin_ss addsimps 
lcp@515
   156
               (bin_recs bin_succ_def @ bin_recs bin_pred_def);
lcp@515
   157
lcp@515
   158
goal Bin.thy
lcp@515
   159
    "!!w. w: bin ==> integ_of_bin(bin_succ(w)) = $#1 $+ integ_of_bin(w)";
lcp@515
   160
by (etac bin.induct 1);
lcp@515
   161
by (simp_tac (carry_ss addsimps [zadd_0_right]) 1);
lcp@515
   162
by (simp_tac (carry_ss addsimps [zadd_zminus_inverse]) 1);
lcp@515
   163
by (etac boolE 1);
lcp@515
   164
by (ALLGOALS (asm_simp_tac (carry_ss addsimps [zadd_assoc])));
lcp@515
   165
by (REPEAT (ares_tac (zadd_swap_pairs::typechecks) 1));
lcp@515
   166
val integ_of_bin_succ = result();
lcp@515
   167
lcp@515
   168
goal Bin.thy
lcp@515
   169
    "!!w. w: bin ==> integ_of_bin(bin_pred(w)) = $~ ($#1) $+ integ_of_bin(w)";
lcp@515
   170
by (etac bin.induct 1);
lcp@515
   171
by (simp_tac (carry_ss addsimps [zadd_0_right]) 1);
lcp@515
   172
by (simp_tac (carry_ss addsimps [zadd_zminus_inverse]) 1);
lcp@515
   173
by (etac boolE 1);
lcp@515
   174
by (ALLGOALS 
lcp@515
   175
    (asm_simp_tac 
lcp@515
   176
     (carry_ss addsimps [zadd_assoc RS sym,
lcp@515
   177
			zadd_zminus_inverse, zadd_zminus_inverse2])));
lcp@515
   178
by (REPEAT (ares_tac ([zadd_commute, zadd_cong, refl]@typechecks) 1));
lcp@515
   179
val integ_of_bin_pred = result();
lcp@515
   180
lcp@515
   181
(*These two results replace the definitions of bin_succ and bin_pred*)
lcp@515
   182
lcp@515
   183
lcp@515
   184
(*** bin_minus: (unary!) negation of binary integers ***)
lcp@515
   185
lcp@515
   186
val bin_minus_ss =
lcp@515
   187
    bin_ss addsimps (bin_recs bin_minus_def @
lcp@515
   188
		    [integ_of_bin_succ, integ_of_bin_pred]);
lcp@515
   189
lcp@515
   190
goal Bin.thy
lcp@515
   191
    "!!w. w: bin ==> integ_of_bin(bin_minus(w)) = $~ integ_of_bin(w)";
lcp@515
   192
by (etac bin.induct 1);
lcp@515
   193
by (simp_tac (bin_minus_ss addsimps [zminus_0]) 1);
lcp@515
   194
by (simp_tac (bin_minus_ss addsimps [zadd_0_right]) 1);
lcp@515
   195
by (etac boolE 1);
lcp@515
   196
by (ALLGOALS 
lcp@515
   197
    (asm_simp_tac (bin_minus_ss addsimps [zminus_zadd_distrib, zadd_assoc])));
lcp@515
   198
val integ_of_bin_minus = result();
lcp@515
   199
lcp@515
   200
lcp@515
   201
(*** bin_add: binary addition ***)
lcp@515
   202
lcp@515
   203
goalw Bin.thy [bin_add_def] "!!w. w: bin ==> bin_add(Plus,w) = w";
lcp@515
   204
by (asm_simp_tac bin_ss 1);
lcp@515
   205
val bin_add_Plus = result();
lcp@515
   206
lcp@515
   207
goalw Bin.thy [bin_add_def] "!!w. w: bin ==> bin_add(Minus,w) = bin_pred(w)";
lcp@515
   208
by (asm_simp_tac bin_ss 1);
lcp@515
   209
val bin_add_Minus = result();
lcp@515
   210
lcp@515
   211
goalw Bin.thy [bin_add_def] "bin_add(v$$x,Plus) = v$$x";
lcp@515
   212
by (simp_tac bin_ss 1);
lcp@515
   213
val bin_add_Bcons_Plus = result();
lcp@515
   214
lcp@515
   215
goalw Bin.thy [bin_add_def] "bin_add(v$$x,Minus) = bin_pred(v$$x)";
lcp@515
   216
by (simp_tac bin_ss 1);
lcp@515
   217
val bin_add_Bcons_Minus = result();
lcp@515
   218
lcp@515
   219
goalw Bin.thy [bin_add_def]
lcp@515
   220
    "!!w y. [| w: bin;  y: bool |] ==> \
lcp@515
   221
\           bin_add(v$$x, w$$y) = \
lcp@515
   222
\           bin_add(v, cond(x and y, bin_succ(w), w)) $$ (x xor y)";
lcp@515
   223
by (asm_simp_tac bin_ss 1);
lcp@515
   224
val bin_add_Bcons_Bcons = result();
lcp@515
   225
lcp@515
   226
val bin_add_rews = [bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus,
lcp@515
   227
		    bin_add_Bcons_Minus, bin_add_Bcons_Bcons,
lcp@515
   228
		    integ_of_bin_succ, integ_of_bin_pred];
lcp@515
   229
lcp@515
   230
val bin_add_ss = bin_ss addsimps ([bool_subset_nat RS subsetD] @ bin_add_rews);
lcp@515
   231
lcp@515
   232
goal Bin.thy
lcp@515
   233
    "!!v. v: bin ==> \
lcp@515
   234
\         ALL w: bin. integ_of_bin(bin_add(v,w)) = \
lcp@515
   235
\                     integ_of_bin(v) $+ integ_of_bin(w)";
lcp@515
   236
by (etac bin.induct 1);
lcp@515
   237
by (simp_tac bin_add_ss 1);
lcp@515
   238
by (simp_tac bin_add_ss 1);
lcp@515
   239
by (rtac ballI 1);
lcp@515
   240
by (bin_ind_tac "wa" [] 1);
lcp@515
   241
by (asm_simp_tac (bin_add_ss addsimps [zadd_0_right]) 1);
lcp@515
   242
by (asm_simp_tac bin_add_ss 1);
lcp@515
   243
by (REPEAT (ares_tac (zadd_commute::typechecks) 1));
lcp@515
   244
by (etac boolE 1);
lcp@515
   245
by (asm_simp_tac (bin_add_ss addsimps [zadd_assoc, zadd_swap_pairs]) 2);
lcp@515
   246
by (REPEAT (ares_tac ([refl, zadd_kill, zadd_assoc_swap_kill]@typechecks) 2));
lcp@515
   247
by (etac boolE 1);
lcp@515
   248
by (ALLGOALS (asm_simp_tac (bin_add_ss addsimps [zadd_assoc,zadd_swap_pairs])));
lcp@515
   249
by (REPEAT (ares_tac ([refl, zadd_kill, zadd_assoc_swap_kill RS sym]@
lcp@515
   250
		      typechecks) 1));
lcp@515
   251
val integ_of_bin_add_lemma = result();
lcp@515
   252
lcp@515
   253
val integ_of_bin_add = integ_of_bin_add_lemma RS bspec;
lcp@515
   254
lcp@515
   255
lcp@515
   256
(*** bin_add: binary multiplication ***)
lcp@515
   257
lcp@515
   258
val bin_mult_ss =
lcp@515
   259
    bin_ss addsimps (bin_recs bin_mult_def @ 
lcp@515
   260
		       [integ_of_bin_minus, integ_of_bin_add]);
lcp@515
   261
lcp@515
   262
lcp@515
   263
val major::prems = goal Bin.thy
lcp@515
   264
    "[| v: bin; w: bin |] ==>	\
lcp@515
   265
\    integ_of_bin(bin_mult(v,w)) = \
lcp@515
   266
\    integ_of_bin(v) $* integ_of_bin(w)";
lcp@515
   267
by (cut_facts_tac prems 1);
lcp@515
   268
by (bin_ind_tac "v" [major] 1);
lcp@515
   269
by (asm_simp_tac (bin_mult_ss addsimps [zmult_0]) 1);
lcp@515
   270
by (asm_simp_tac (bin_mult_ss addsimps [zmult_1,zmult_zminus]) 1);
lcp@515
   271
by (etac boolE 1);
lcp@515
   272
by (asm_simp_tac (bin_mult_ss addsimps [zadd_zmult_distrib]) 2);
lcp@515
   273
by (asm_simp_tac 
lcp@515
   274
    (bin_mult_ss addsimps [zadd_zmult_distrib, zmult_1, zadd_assoc]) 1);
lcp@515
   275
by (REPEAT (ares_tac ([zadd_commute, zadd_assoc_swap_kill RS sym]@
lcp@515
   276
		      typechecks) 1));
lcp@515
   277
val integ_of_bin_mult = result();
lcp@515
   278
lcp@515
   279
(**** Computations ****)
lcp@515
   280
lcp@515
   281
(** extra rules for bin_succ, bin_pred **)
lcp@515
   282
lcp@515
   283
val [bin_succ_Plus, bin_succ_Minus, _] = bin_recs bin_succ_def;
lcp@515
   284
val [bin_pred_Plus, bin_pred_Minus, _] = bin_recs bin_pred_def;
lcp@515
   285
lcp@515
   286
goal Bin.thy "bin_succ(w$$1) = bin_succ(w) $$ 0";
lcp@515
   287
by (simp_tac carry_ss 1);
lcp@515
   288
val bin_succ_Bcons1 = result();
lcp@515
   289
lcp@515
   290
goal Bin.thy "bin_succ(w$$0) = w$$1";
lcp@515
   291
by (simp_tac carry_ss 1);
lcp@515
   292
val bin_succ_Bcons0 = result();
lcp@515
   293
lcp@515
   294
goal Bin.thy "bin_pred(w$$1) = w$$0";
lcp@515
   295
by (simp_tac carry_ss 1);
lcp@515
   296
val bin_pred_Bcons1 = result();
lcp@515
   297
lcp@515
   298
goal Bin.thy "bin_pred(w$$0) = bin_pred(w) $$ 1";
lcp@515
   299
by (simp_tac carry_ss 1);
lcp@515
   300
val bin_pred_Bcons0 = result();
lcp@515
   301
lcp@515
   302
(** extra rules for bin_minus **)
lcp@515
   303
lcp@515
   304
val [bin_minus_Plus, bin_minus_Minus, _] = bin_recs bin_minus_def;
lcp@515
   305
lcp@515
   306
goal Bin.thy "bin_minus(w$$1) = bin_pred(bin_minus(w) $$ 0)";
lcp@515
   307
by (simp_tac bin_minus_ss 1);
lcp@515
   308
val bin_minus_Bcons1 = result();
lcp@515
   309
lcp@515
   310
goal Bin.thy "bin_minus(w$$0) = bin_minus(w) $$ 0";
lcp@515
   311
by (simp_tac bin_minus_ss 1);
lcp@515
   312
val bin_minus_Bcons0 = result();
lcp@515
   313
lcp@515
   314
(** extra rules for bin_add **)
lcp@515
   315
lcp@515
   316
goal Bin.thy 
lcp@515
   317
    "!!w. w: bin ==> bin_add(v$$1, w$$1) = bin_add(v, bin_succ(w)) $$ 0";
lcp@515
   318
by (asm_simp_tac bin_add_ss 1);
lcp@515
   319
val bin_add_Bcons_Bcons11 = result();
lcp@515
   320
lcp@515
   321
goal Bin.thy 
lcp@515
   322
    "!!w. w: bin ==> bin_add(v$$1, w$$0) = bin_add(v,w) $$ 1";
lcp@515
   323
by (asm_simp_tac bin_add_ss 1);
lcp@515
   324
val bin_add_Bcons_Bcons10 = result();
lcp@515
   325
lcp@515
   326
goal Bin.thy 
lcp@515
   327
    "!!w y.[| w: bin;  y: bool |] ==> bin_add(v$$0, w$$y) = bin_add(v,w) $$ y";
lcp@515
   328
by (asm_simp_tac bin_add_ss 1);
lcp@515
   329
val bin_add_Bcons_Bcons0 = result();
lcp@515
   330
lcp@515
   331
(** extra rules for bin_mult **)
lcp@515
   332
lcp@515
   333
val [bin_mult_Plus, bin_mult_Minus, _] = bin_recs bin_mult_def;
lcp@515
   334
lcp@515
   335
goal Bin.thy "bin_mult(v$$1, w) = bin_add(bin_mult(v,w)$$0, w)";
lcp@515
   336
by (simp_tac bin_mult_ss 1);
lcp@515
   337
val bin_mult_Bcons1 = result();
lcp@515
   338
lcp@515
   339
goal Bin.thy "bin_mult(v$$0, w) = bin_mult(v,w)$$0";
lcp@515
   340
by (simp_tac bin_mult_ss 1);
lcp@515
   341
val bin_mult_Bcons0 = result();
lcp@515
   342
lcp@515
   343
lcp@515
   344
(*** The computation simpset ***)
lcp@515
   345
lcp@515
   346
val bin_comp_ss = integ_ss 
lcp@515
   347
    addsimps [bin_succ_Plus, bin_succ_Minus,
lcp@515
   348
	     bin_succ_Bcons1, bin_succ_Bcons0,
lcp@515
   349
	     bin_pred_Plus, bin_pred_Minus,
lcp@515
   350
	     bin_pred_Bcons1, bin_pred_Bcons0,
lcp@515
   351
	     bin_minus_Plus, bin_minus_Minus,
lcp@515
   352
	     bin_minus_Bcons1, bin_minus_Bcons0,
lcp@515
   353
	     bin_add_Plus, bin_add_Minus, bin_add_Bcons_Plus, 
lcp@515
   354
	     bin_add_Bcons_Minus, bin_add_Bcons_Bcons0, 
lcp@515
   355
	     bin_add_Bcons_Bcons10, bin_add_Bcons_Bcons11,
lcp@515
   356
	     bin_mult_Plus, bin_mult_Minus,
lcp@515
   357
	     bin_mult_Bcons1, bin_mult_Bcons0]
lcp@515
   358
    setsolver (type_auto_tac ([bool_1I, bool_0I] @ bin_typechecks0));
lcp@515
   359
lcp@515
   360
(*** Examples of performing binary arithmetic by simplification ***)
lcp@515
   361
lcp@515
   362
proof_timing := true;
lcp@515
   363
(*All runtimes below are on a SPARCserver 10*)
lcp@515
   364
lcp@515
   365
(* 13+19 = 32 *)
lcp@515
   366
goal Bin.thy
lcp@515
   367
    "bin_add(Plus$$1$$1$$0$$1, Plus$$1$$0$$0$$1$$1) = Plus$$1$$0$$0$$0$$0$$0";
lcp@515
   368
by (simp_tac bin_comp_ss 1);	(*0.6 secs*)
lcp@515
   369
result();
lcp@515
   370
lcp@515
   371
bin_add(binary_of_int 13, binary_of_int 19);
lcp@515
   372
lcp@515
   373
(* 1234+5678 = 6912 *)
lcp@515
   374
goal Bin.thy
lcp@515
   375
    "bin_add(Plus$$1$$0$$0$$1$$1$$0$$1$$0$$0$$1$$0, \
lcp@515
   376
\	     Plus$$1$$0$$1$$1$$0$$0$$0$$1$$0$$1$$1$$1$$0) = \
lcp@515
   377
\    Plus$$1$$1$$0$$1$$1$$0$$0$$0$$0$$0$$0$$0$$0";
lcp@515
   378
by (simp_tac bin_comp_ss 1);	(*2.6 secs*)
lcp@515
   379
result();
lcp@515
   380
lcp@515
   381
bin_add(binary_of_int 1234, binary_of_int 5678);
lcp@515
   382
lcp@515
   383
(* 1359-2468 = ~1109 *)
lcp@515
   384
goal Bin.thy
lcp@515
   385
    "bin_add(Plus$$1$$0$$1$$0$$1$$0$$0$$1$$1$$1$$1,		\
lcp@515
   386
\	     Minus$$0$$1$$1$$0$$0$$1$$0$$1$$1$$1$$0$$0) = 	\
lcp@515
   387
\    Minus$$1$$0$$1$$1$$1$$0$$1$$0$$1$$0$$1$$1";
lcp@515
   388
by (simp_tac bin_comp_ss 1);	(*2.3 secs*)
lcp@515
   389
result();
lcp@515
   390
lcp@515
   391
bin_add(binary_of_int 1359, binary_of_int ~2468);
lcp@515
   392
lcp@515
   393
(* 93746-46375 = 47371 *)
lcp@515
   394
goal Bin.thy
lcp@515
   395
    "bin_add(Plus$$1$$0$$1$$1$$0$$1$$1$$1$$0$$0$$0$$1$$1$$0$$0$$1$$0, \
lcp@515
   396
\	     Minus$$0$$1$$0$$0$$1$$0$$1$$0$$1$$1$$0$$1$$1$$0$$0$$1) = \
lcp@515
   397
\    Plus$$0$$1$$0$$1$$1$$1$$0$$0$$1$$0$$0$$0$$0$$1$$0$$1$$1";
lcp@515
   398
by (simp_tac bin_comp_ss 1);	(*3.9 secs*)
lcp@515
   399
result();
lcp@515
   400
lcp@515
   401
bin_add(binary_of_int 93746, binary_of_int ~46375);
lcp@515
   402
lcp@515
   403
(* negation of 65745 *)
lcp@515
   404
goal Bin.thy
lcp@515
   405
    "bin_minus(Plus$$1$$0$$0$$0$$0$$0$$0$$0$$0$$1$$1$$0$$1$$0$$0$$0$$1) = \
lcp@515
   406
\    Minus$$0$$1$$1$$1$$1$$1$$1$$1$$1$$0$$0$$1$$0$$1$$1$$1$$1";
lcp@515
   407
by (simp_tac bin_comp_ss 1);	(*0.6 secs*)
lcp@515
   408
result();
lcp@515
   409
lcp@515
   410
bin_minus(binary_of_int 65745);
lcp@515
   411
lcp@515
   412
(* negation of ~54321 *)
lcp@515
   413
goal Bin.thy
lcp@515
   414
    "bin_minus(Minus$$0$$0$$1$$0$$1$$0$$1$$1$$1$$1$$0$$0$$1$$1$$1$$1) = \
lcp@515
   415
\    Plus$$0$$1$$1$$0$$1$$0$$1$$0$$0$$0$$0$$1$$1$$0$$0$$0$$1";
lcp@515
   416
by (simp_tac bin_comp_ss 1);	(*0.7 secs*)
lcp@515
   417
result();
lcp@515
   418
lcp@515
   419
bin_minus(binary_of_int ~54321);
lcp@515
   420
lcp@515
   421
(* 13*19 = 247 *)
lcp@515
   422
goal Bin.thy "bin_mult(Plus$$1$$1$$0$$1, Plus$$1$$0$$0$$1$$1) = \
lcp@515
   423
\               Plus$$1$$1$$1$$1$$0$$1$$1$$1";
lcp@515
   424
by (simp_tac bin_comp_ss 1);	(*1.5 secs*)
lcp@515
   425
result();
lcp@515
   426
lcp@515
   427
bin_mult(binary_of_int 13, binary_of_int 19);
lcp@515
   428
lcp@515
   429
(* ~84 * 51 = ~4284 *)
lcp@515
   430
goal Bin.thy
lcp@515
   431
    "bin_mult(Minus$$0$$1$$0$$1$$1$$0$$0, Plus$$1$$1$$0$$0$$1$$1) = \
lcp@515
   432
\    Minus$$0$$1$$1$$1$$1$$0$$1$$0$$0$$0$$1$$0$$0";
lcp@515
   433
by (simp_tac bin_comp_ss 1);	(*2.6 secs*)
lcp@515
   434
result();
lcp@515
   435
lcp@515
   436
bin_mult(binary_of_int ~84, binary_of_int 51);
lcp@515
   437
lcp@515
   438
(* 255*255 = 65025;  the worst case for 8-bit operands *)
lcp@515
   439
goal Bin.thy
lcp@515
   440
    "bin_mult(Plus$$1$$1$$1$$1$$1$$1$$1$$1, \
lcp@515
   441
\             Plus$$1$$1$$1$$1$$1$$1$$1$$1) = \
lcp@515
   442
\        Plus$$1$$1$$1$$1$$1$$1$$1$$0$$0$$0$$0$$0$$0$$0$$0$$1";
lcp@515
   443
by (simp_tac bin_comp_ss 1);	(*9.8 secs*)
lcp@515
   444
result();
lcp@515
   445
lcp@515
   446
bin_mult(binary_of_int 255, binary_of_int 255);
lcp@515
   447
lcp@515
   448
(* 1359 * ~2468 = ~3354012 *)
lcp@515
   449
goal Bin.thy
lcp@515
   450
    "bin_mult(Plus$$1$$0$$1$$0$$1$$0$$0$$1$$1$$1$$1, 		\
lcp@515
   451
\	      Minus$$0$$1$$1$$0$$0$$1$$0$$1$$1$$1$$0$$0) = 	\
lcp@515
   452
\    Minus$$0$$0$$1$$1$$0$$0$$1$$1$$0$$1$$0$$0$$1$$0$$0$$1$$1$$0$$0$$1$$0$$0";
lcp@515
   453
by (simp_tac bin_comp_ss 1);	(*13.7 secs*)
lcp@515
   454
result();
lcp@515
   455
lcp@515
   456
bin_mult(binary_of_int 1359, binary_of_int ~2468);