src/HOL/ex/BinEx.ML
author wenzelm
Mon, 29 Nov 1999 15:52:49 +0100
changeset 8039 a901bafe4578
parent 7037 77d596a5ffae
child 8423 3c19160b6432
permissions -rw-r--r--
Goal: tuned pris;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     1
(*  Title:      HOL/ex/BinEx.ML
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     2
    ID:         $Id$
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     4
    Copyright   1998  University of Cambridge
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
     5
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     6
Examples of performing binary arithmetic by simplification
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     7
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     8
Also a proof that binary arithmetic on normalized operands 
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
     9
yields normalized results. 
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
    10
*)
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
    11
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
    12
set proof_timing;
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    13
7037
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
    14
(**** The Integers ****)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
    15
6920
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    16
(*** Addition ***)
5491
22f8331cdf47 revised treatment of integers
paulson
parents: 5199
diff changeset
    17
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    18
Goal "(#13::int)  +  #19 = #32";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    19
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    20
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    21
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    22
Goal "(#1234::int)  +  #5678 = #6912";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    23
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    24
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    25
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    26
Goal "(#1359::int)  +  #-2468 = #-1109";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    27
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    28
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    29
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    30
Goal "(#93746::int) +  #-46375 = #47371";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    31
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    32
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    33
6920
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    34
(*** Negation ***)
5491
22f8331cdf47 revised treatment of integers
paulson
parents: 5199
diff changeset
    35
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    36
Goal "- (#65745::int) = #-65745";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    37
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    38
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    39
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    40
Goal "- (#-54321::int) = #54321";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    41
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    42
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    43
5491
22f8331cdf47 revised treatment of integers
paulson
parents: 5199
diff changeset
    44
6920
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    45
(*** Multiplication ***)
5491
22f8331cdf47 revised treatment of integers
paulson
parents: 5199
diff changeset
    46
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    47
Goal "(#13::int)  *  #19 = #247";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    48
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    49
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    50
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    51
Goal "(#-84::int)  *  #51 = #-4284";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    52
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    53
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    54
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    55
Goal "(#255::int)  *  #255 = #65025";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    56
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    57
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    58
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    59
Goal "(#1359::int)  *  #-2468 = #-3354012";
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    60
by (Simp_tac 1);
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    61
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    62
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    63
Goal "(#89::int) * #10 ~= #889";  
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    64
by (Simp_tac 1); 
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    65
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    66
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    67
Goal "(#13::int) < #18 - #4";  
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    68
by (Simp_tac 1); 
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    69
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    70
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    71
Goal "(#-345::int) < #-242 + #-100";  
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    72
by (Simp_tac 1); 
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    73
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    74
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    75
Goal "(#13557456::int) < #18678654";  
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    76
by (Simp_tac 1); 
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    77
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    78
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    79
Goal "(#999999::int) <= (#1000001 + #1)-#2";  
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    80
by (Simp_tac 1); 
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    81
result();
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    82
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
    83
Goal "(#1234567::int) <= #1234567";  
5199
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    84
by (Simp_tac 1); 
be986f7a6def added ex/MonoidGroups (record example);
wenzelm
parents:
diff changeset
    85
result();
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
    86
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
    87
7037
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
    88
(*** Quotient and Remainder ***)
6920
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    89
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    90
Goal "(#10::int) div #3 = #3";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    91
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    92
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    93
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    94
Goal "(#10::int) mod #3 = #1";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    95
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    96
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    97
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    98
(** A negative divisor **)
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
    99
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   100
Goal "(#10::int) div #-3 = #-4";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   101
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   102
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   103
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   104
Goal "(#10::int) mod #-3 = #-2";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   105
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   106
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   107
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   108
(** A negative dividend
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   109
    [ The definition agrees with mathematical convention but not with
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   110
      the hardware of most computers ]
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   111
**)
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   112
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   113
Goal "(#-10::int) div #3 = #-4";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   114
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   115
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   116
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   117
Goal "(#-10::int) mod #3 = #2";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   118
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   119
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   120
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   121
(** A negative dividend AND divisor **)
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   122
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   123
Goal "(#-10::int) div #-3 = #3";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   124
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   125
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   126
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   127
Goal "(#-10::int) mod #-3 = #-1";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   128
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   129
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   130
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   131
(** A few bigger examples **)
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   132
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   133
Goal "(#8452::int) mod #3 = #1";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   134
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   135
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   136
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   137
Goal "(#59485::int) div #434 = #137";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   138
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   139
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   140
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   141
Goal "(#1000006::int) mod #10 = #6";
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   142
by (Simp_tac 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   143
result();
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   144
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   145
7037
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   146
(** division by shifting **)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   147
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   148
Goal "#10000000 div #2 = (#5000000::int)";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   149
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   150
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   151
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   152
Goal "#10000001 mod #2 = (#1::int)";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   153
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   154
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   155
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   156
Goal "#10000055 div #32 = (#312501::int)";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   157
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   158
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   159
Goal "#10000055 mod #32 = (#23::int)";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   160
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   161
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   162
Goal "#100094 div #144 = (#695::int)";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   163
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   164
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   165
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   166
Goal "#100094 mod #144 = (#14::int)";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   167
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   168
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   169
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   170
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   171
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   172
(**** The Natural Numbers ****)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   173
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   174
(** Successor **)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   175
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   176
Goal "Suc #99999 = #100000";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   177
by (asm_simp_tac (simpset() addsimps [Suc_nat_number_of]) 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   178
	(*not a default rewrite since sometimes we want to have Suc(#nnn)*)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   179
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   180
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   181
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   182
(** Addition **)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   183
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   184
Goal "(#13::nat)  +  #19 = #32";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   185
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   186
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   187
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   188
Goal "(#1234::nat)  +  #5678 = #6912";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   189
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   190
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   191
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   192
Goal "(#973646::nat) +  #6475 = #980121";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   193
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   194
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   195
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   196
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   197
(** Subtraction **)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   198
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   199
Goal "(#32::nat)  -  #14 = #18";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   200
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   201
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   202
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   203
Goal "(#14::nat)  -  #15 = #0";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   204
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   205
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   206
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   207
Goal "(#14::nat)  -  #1576644 = #0";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   208
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   209
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   210
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   211
Goal "(#48273776::nat)  -  #3873737 = #44400039";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   212
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   213
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   214
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   215
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   216
(** Multiplication **)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   217
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   218
Goal "(#12::nat) * #11 = #132";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   219
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   220
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   221
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   222
Goal "(#647::nat) * #3643 = #2357021";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   223
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   224
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   225
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   226
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   227
(** Quotient and Remainder **)
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   228
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   229
Goal "(#10::nat) div #3 = #3";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   230
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   231
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   232
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   233
Goal "(#10::nat) mod #3 = #1";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   234
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   235
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   236
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   237
Goal "(#10000::nat) div #9 = #1111";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   238
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   239
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   240
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   241
Goal "(#10000::nat) mod #9 = #1";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   242
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   243
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   244
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   245
Goal "(#10000::nat) div #16 = #625";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   246
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   247
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   248
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   249
Goal "(#10000::nat) mod #16 = #0";
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   250
by (Simp_tac 1);
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   251
result();
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   252
77d596a5ffae examples of arithmetic on the naturals
paulson
parents: 6920
diff changeset
   253
6920
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   254
(*** Testing the cancellation of complementary terms ***)
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   255
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   256
Goal "y + (x + -x) = (#0::int) + y";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   257
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   258
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   259
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   260
Goal "y + (-x + (- y + x)) = (#0::int)";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   261
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   262
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   263
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   264
Goal "-x + (y + (- y + x)) = (#0::int)";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   265
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   266
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   267
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   268
Goal "x + (x + (- x + (- x + (- y + - z)))) = (#0::int) - y - z";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   269
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   270
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   271
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   272
Goal "x + x - x - x - y - z = (#0::int) - y - z";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   273
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   274
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   275
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   276
Goal "x + y + z - (x + z) = y - (#0::int)";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   277
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   278
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   279
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   280
Goal "x+(y+(y+(y+ (-x + -x)))) = (#0::int) + y - x + y + y";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   281
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   282
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   283
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   284
Goal "x+(y+(y+(y+ (-y + -x)))) = y + (#0::int) + y";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   285
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   286
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   287
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   288
Goal "x + y - x + z - x - y - z + x < (#1::int)";
5601
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   289
by (Simp_tac 1);
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   290
result();
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   291
b6456ccd9e3e revised for new treatment of integers
paulson
parents: 5569
diff changeset
   292
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   293
Addsimps normal.intrs;
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   294
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   295
Goal "(w BIT b): normal ==> (w BIT b BIT c): normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   296
by (case_tac "c" 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   297
by Auto_tac;
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   298
qed "normal_BIT_I";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   299
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   300
Addsimps [normal_BIT_I];
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   301
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   302
Goal "w BIT b: normal ==> w: normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   303
by (etac normal.elim 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   304
by Auto_tac;
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   305
qed "normal_BIT_D";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   306
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   307
Goal "w : normal --> NCons w b : normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   308
by (induct_tac "w" 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   309
by (auto_tac (claset(), simpset() addsimps [NCons_Pls, NCons_Min]));
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   310
qed_spec_mp "NCons_normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   311
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   312
Addsimps [NCons_normal];
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   313
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   314
Goal "NCons w True ~= Pls";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   315
by (induct_tac "w" 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   316
by Auto_tac;
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   317
qed "NCons_True";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   318
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   319
Goal "NCons w False ~= Min";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   320
by (induct_tac "w" 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   321
by Auto_tac;
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   322
qed "NCons_False";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   323
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   324
Goal "w: normal ==> bin_succ w : normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   325
by (etac normal.induct 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   326
by (exhaust_tac "w" 4);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   327
by (auto_tac (claset(), simpset() addsimps [NCons_True, bin_succ_BIT]));
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   328
qed "bin_succ_normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   329
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   330
Goal "w: normal ==> bin_pred w : normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   331
by (etac normal.induct 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   332
by (exhaust_tac "w" 3);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   333
by (auto_tac (claset(), simpset() addsimps [NCons_False, bin_pred_BIT]));
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   334
qed "bin_pred_normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   335
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   336
Addsimps [bin_succ_normal, bin_pred_normal];
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   337
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   338
Goal "w : normal --> (ALL z. z: normal --> bin_add w z : normal)";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   339
by (induct_tac "w" 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   340
by (Simp_tac 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   341
by (Simp_tac 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   342
by (rtac impI 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   343
by (rtac allI 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   344
by (induct_tac "z" 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   345
by (ALLGOALS (asm_simp_tac (simpset() addsimps [bin_add_BIT])));
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   346
by (safe_tac (claset() addSDs [normal_BIT_D]));
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   347
by (ALLGOALS Asm_simp_tac);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   348
qed_spec_mp "bin_add_normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   349
6909
21601bc4f3c2 adapted to generic numerals;
wenzelm
parents: 5747
diff changeset
   350
Goal "w: normal ==> (w = Pls) = (number_of w = (#0::int))";
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   351
by (etac normal.induct 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   352
by Auto_tac;
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   353
qed "normal_Pls_eq_0";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   354
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   355
Goal "w : normal ==> bin_minus w : normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   356
by (etac normal.induct 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   357
by (ALLGOALS (asm_simp_tac (simpset() addsimps [bin_minus_BIT])));
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   358
by (resolve_tac normal.intrs 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   359
by (assume_tac 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   360
by (asm_full_simp_tac (simpset() addsimps [normal_Pls_eq_0]) 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   361
by (asm_full_simp_tac 
6920
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   362
    (simpset_of Int.thy 
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   363
     addsimps [number_of_minus, iszero_def, 
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   364
	       read_instantiate [("y","int 0")] zminus_equation]) 1);
c912740c3545 Introduction of integer division algorithm
paulson
parents: 6909
diff changeset
   365
by (etac not_sym 1);
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   366
qed "bin_minus_normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   367
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   368
Goal "w : normal ==> z: normal --> bin_mult w z : normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   369
by (etac normal.induct 1);
5569
8c7e1190e789 Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents: 5545
diff changeset
   370
by (ALLGOALS
8c7e1190e789 Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents: 5545
diff changeset
   371
    (asm_simp_tac (simpset() addsimps [bin_minus_normal, bin_mult_BIT])));
5545
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   372
by (safe_tac (claset() addSDs [normal_BIT_D]));
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   373
by (asm_simp_tac (simpset() addsimps [bin_add_normal]) 1);
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   374
qed_spec_mp "bin_mult_normal";
9117a0e2bf31 added correctness proofs for arithmetic
paulson
parents: 5513
diff changeset
   375