src/ZF/ex/BinEx.ML
author paulson
Mon, 21 May 2001 14:35:54 +0200
changeset 11315 fbca0f74bcef
parent 9570 e16e168984e1
permissions -rw-r--r--
Division examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     1
(*  Title:      ZF/ex/BinEx.ML
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     2
    ID:         $Id$
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     5
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     6
Examples of performing binary arithmetic by simplification
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     7
*)
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
     8
11315
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
     9
context Main.thy;
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    10
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    11
(*All runtimes below are on a 300MHz Pentium*)
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    12
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    13
Goal "#13  $+  #19 = #32";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    14
by (Simp_tac 1);    (*0 secs*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    15
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    16
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    17
Goal "#1234  $+  #5678 = #6912";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    18
by (Simp_tac 1);    (*190 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    19
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    20
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    21
Goal "#1359  $+  #-2468 = #-1109";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    22
by (Simp_tac 1);    (*160 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    23
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    24
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    25
Goal "#93746  $+  #-46375 = #47371";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    26
by (Simp_tac 1);    (*300 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    27
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    28
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9000
diff changeset
    29
Goal "$- #65745 = #-65745";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    30
by (Simp_tac 1);    (*80 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    31
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    32
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    33
(* negation of ~54321 *)
9548
15bee2731e43 instantiated Cancel_Numerals for "nat" in ZF
paulson
parents: 9000
diff changeset
    34
Goal "$- #-54321 = #54321";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    35
by (Simp_tac 1);    (*90 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    36
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    37
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    38
Goal "#13  $*  #19 = #247";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    39
by (Simp_tac 1);    (*110 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    40
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    41
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    42
Goal "#-84  $*  #51 = #-4284";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    43
by (Simp_tac 1);    (*210 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    44
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    45
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    46
(*The worst case for 8-bit operands *)
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    47
Goal "#255  $*  #255 = #65025";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    48
by (Simp_tac 1);    (*730 msec*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    49
result();
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    50
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    51
Goal "#1359  $*  #-2468 = #-3354012";
6153
bff90585cce5 new typechecking solver for the simplifier
paulson
parents: 5533
diff changeset
    52
by (Simp_tac 1);    (*1.04 secs*)
5533
bce36a019b03 re-organized for the new directory Integ
paulson
parents:
diff changeset
    53
result();
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    54
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    55
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    56
(** Comparisons **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    57
11315
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    58
Goal "(#89) $* #10 \\<noteq> #889";  
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    59
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    60
result();
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    61
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    62
Goal "(#13) $< #18 $- #4";  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    63
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    64
result();
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    65
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    66
Goal "(#-345) $< #-242 $+ #-100";  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    67
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    68
result();
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    69
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    70
Goal "(#13557456) $< #18678654";  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    71
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    72
result();
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    73
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    74
Goal "(#999999) $<= (#1000001 $+ #1) $- #2";  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    75
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    76
result();
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    77
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    78
Goal "(#1234567) $<= #1234567";  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    79
by (Simp_tac 1); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents: 9548
diff changeset
    80
result();
11315
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    81
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    82
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    83
(*** Quotient and remainder!! [they could be faster] ***)
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    84
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    85
Goal "#23 zdiv #3 = #7";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    86
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    87
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    88
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    89
Goal "#23 zmod #3 = #2";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    90
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    91
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    92
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    93
(** negative dividend **)
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    94
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    95
Goal "#-23 zdiv #3 = #-8";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    96
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    97
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    98
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
    99
Goal "#-23 zmod #3 = #1";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   100
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   101
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   102
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   103
(** negative divisor **)
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   104
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   105
Goal "#23 zdiv #-3 = #-8";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   106
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   107
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   108
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   109
Goal "#23 zmod #-3 = #-1";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   110
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   111
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   112
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   113
(** Negative dividend and divisor **)
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   114
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   115
Goal "#-23 zdiv #-3 = #7";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   116
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   117
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   118
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   119
Goal "#-23 zmod #-3 = #-2";
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   120
by (Simp_tac 1); 
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   121
result();
fbca0f74bcef Division examples
paulson
parents: 9570
diff changeset
   122