src/CTT/Arith.ML
author kleing
Wed Apr 14 14:13:05 2004 +0200 (2004-04-14)
changeset 14565 c6dc17aab88a
parent 9251 bd57acd44fc1
child 17441 5b5feca0344a
permissions -rw-r--r--
use more symbols in HTML output
paulson@9251
     1
(*  Title:      CTT/Arith
clasohm@0
     2
    ID:         $Id$
clasohm@1459
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1991  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Proofs about elementary arithmetic: addition, multiplication, etc.
clasohm@0
     7
Tests definitions and simplifier.
clasohm@0
     8
*)
clasohm@0
     9
clasohm@0
    10
val arith_defs = [add_def, diff_def, absdiff_def, mult_def, mod_def, div_def];
clasohm@0
    11
clasohm@0
    12
clasohm@0
    13
(** Addition *)
clasohm@0
    14
clasohm@0
    15
(*typing of add: short and long versions*)
clasohm@0
    16
paulson@9251
    17
Goalw arith_defs "[| a:N;  b:N |] ==> a #+ b : N";
paulson@9251
    18
by (typechk_tac []) ;
paulson@9249
    19
qed "add_typing";
clasohm@0
    20
paulson@9251
    21
Goalw arith_defs "[| a=c:N;  b=d:N |] ==> a #+ b = c #+ d : N";
paulson@9251
    22
by (equal_tac []) ;
paulson@9249
    23
qed "add_typingL";
clasohm@0
    24
clasohm@0
    25
clasohm@0
    26
(*computation for add: 0 and successor cases*)
clasohm@0
    27
paulson@9251
    28
Goalw arith_defs "b:N ==> 0 #+ b = b : N";
paulson@9251
    29
by (rew_tac []) ;
paulson@9249
    30
qed "addC0";
clasohm@0
    31
paulson@9251
    32
Goalw arith_defs "[| a:N;  b:N |] ==> succ(a) #+ b = succ(a #+ b) : N";
paulson@9251
    33
by (rew_tac []) ;
paulson@9249
    34
qed "addC_succ"; 
clasohm@0
    35
clasohm@0
    36
clasohm@0
    37
(** Multiplication *)
clasohm@0
    38
clasohm@0
    39
(*typing of mult: short and long versions*)
clasohm@0
    40
paulson@9251
    41
Goalw arith_defs "[| a:N;  b:N |] ==> a #* b : N";
paulson@9251
    42
by (typechk_tac [add_typing]) ;
paulson@9249
    43
qed "mult_typing";
clasohm@0
    44
paulson@9251
    45
Goalw arith_defs "[| a=c:N;  b=d:N |] ==> a #* b = c #* d : N";
paulson@9251
    46
by (equal_tac [add_typingL]) ;
paulson@9249
    47
qed "mult_typingL";
clasohm@0
    48
clasohm@0
    49
(*computation for mult: 0 and successor cases*)
clasohm@0
    50
paulson@9251
    51
Goalw arith_defs "b:N ==> 0 #* b = 0 : N";
paulson@9251
    52
by (rew_tac []) ;
paulson@9249
    53
qed "multC0";
clasohm@0
    54
paulson@9251
    55
Goalw arith_defs "[| a:N;  b:N |] ==> succ(a) #* b = b #+ (a #* b) : N";
paulson@9251
    56
by (rew_tac []) ;
paulson@9249
    57
qed "multC_succ";
clasohm@0
    58
clasohm@0
    59
clasohm@0
    60
(** Difference *)
clasohm@0
    61
clasohm@0
    62
(*typing of difference*)
clasohm@0
    63
paulson@9251
    64
Goalw arith_defs "[| a:N;  b:N |] ==> a - b : N";
paulson@9251
    65
by (typechk_tac []) ;
paulson@9249
    66
qed "diff_typing";
clasohm@0
    67
paulson@9251
    68
Goalw arith_defs "[| a=c:N;  b=d:N |] ==> a - b = c - d : N";
paulson@9251
    69
by (equal_tac []) ;
paulson@9249
    70
qed "diff_typingL";
clasohm@0
    71
clasohm@0
    72
clasohm@0
    73
clasohm@0
    74
(*computation for difference: 0 and successor cases*)
clasohm@0
    75
paulson@9251
    76
Goalw arith_defs "a:N ==> a - 0 = a : N";
paulson@9251
    77
by (rew_tac []) ;
paulson@9249
    78
qed "diffC0";
clasohm@0
    79
clasohm@0
    80
(*Note: rec(a, 0, %z w.z) is pred(a). *)
clasohm@0
    81
paulson@9251
    82
Goalw arith_defs "b:N ==> 0 - b = 0 : N";
paulson@9249
    83
by (NE_tac "b" 1);
paulson@9251
    84
by (hyp_rew_tac []) ;
paulson@9249
    85
qed "diff_0_eq_0";
clasohm@0
    86
clasohm@0
    87
clasohm@0
    88
(*Essential to simplify FIRST!!  (Else we get a critical pair)
clasohm@0
    89
  succ(a) - succ(b) rewrites to   pred(succ(a) - b)  *)
paulson@9251
    90
Goalw arith_defs "[| a:N;  b:N |] ==> succ(a) - succ(b) = a - b : N";
paulson@9251
    91
by (hyp_rew_tac []);
paulson@9249
    92
by (NE_tac "b" 1);
paulson@9251
    93
by (hyp_rew_tac []) ;
paulson@9249
    94
qed "diff_succ_succ";
clasohm@0
    95
clasohm@0
    96
clasohm@0
    97
clasohm@0
    98
(*** Simplification *)
clasohm@0
    99
clasohm@0
   100
val arith_typing_rls =
clasohm@0
   101
  [add_typing, mult_typing, diff_typing];
clasohm@0
   102
clasohm@0
   103
val arith_congr_rls =
clasohm@0
   104
  [add_typingL, mult_typingL, diff_typingL];
clasohm@0
   105
clasohm@0
   106
val congr_rls = arith_congr_rls@standard_congr_rls;
clasohm@0
   107
clasohm@0
   108
val arithC_rls =
clasohm@0
   109
  [addC0, addC_succ,
clasohm@0
   110
   multC0, multC_succ,
clasohm@0
   111
   diffC0, diff_0_eq_0, diff_succ_succ];
clasohm@0
   112
clasohm@0
   113
clasohm@0
   114
structure Arith_simp_data: TSIMP_DATA =
clasohm@0
   115
  struct
clasohm@1459
   116
  val refl              = refl_elem
clasohm@1459
   117
  val sym               = sym_elem
clasohm@1459
   118
  val trans             = trans_elem
clasohm@1459
   119
  val refl_red          = refl_red
clasohm@1459
   120
  val trans_red         = trans_red
clasohm@1459
   121
  val red_if_equal      = red_if_equal
clasohm@1459
   122
  val default_rls       = arithC_rls @ comp_rls
clasohm@1459
   123
  val routine_tac       = routine_tac (arith_typing_rls @ routine_rls)
clasohm@0
   124
  end;
clasohm@0
   125
clasohm@0
   126
structure Arith_simp = TSimpFun (Arith_simp_data);
clasohm@0
   127
clasohm@0
   128
fun arith_rew_tac prems = make_rew_tac
clasohm@0
   129
    (Arith_simp.norm_tac(congr_rls, prems));
clasohm@0
   130
clasohm@0
   131
fun hyp_arith_rew_tac prems = make_rew_tac
clasohm@0
   132
    (Arith_simp.cond_norm_tac(prove_cond_tac, congr_rls, prems));
clasohm@0
   133
clasohm@0
   134
clasohm@0
   135
(**********
clasohm@0
   136
  Addition
clasohm@0
   137
 **********)
clasohm@0
   138
clasohm@0
   139
(*Associative law for addition*)
paulson@9251
   140
Goal "[| a:N;  b:N;  c:N |] ==> (a #+ b) #+ c = a #+ (b #+ c) : N";
paulson@9249
   141
by (NE_tac "a" 1);
paulson@9251
   142
by (hyp_arith_rew_tac []) ;
paulson@9249
   143
qed "add_assoc";
clasohm@0
   144
clasohm@0
   145
clasohm@0
   146
(*Commutative law for addition.  Can be proved using three inductions.
clasohm@0
   147
  Must simplify after first induction!  Orientation of rewrites is delicate*)  
paulson@9251
   148
Goal "[| a:N;  b:N |] ==> a #+ b = b #+ a : N";
paulson@9249
   149
by (NE_tac "a" 1);
paulson@9251
   150
by (hyp_arith_rew_tac []);
paulson@9249
   151
by (NE_tac "b" 2);
paulson@9249
   152
by (rtac sym_elem 1);
paulson@9249
   153
by (NE_tac "b" 1);
paulson@9251
   154
by (hyp_arith_rew_tac []) ;
paulson@9249
   155
qed "add_commute";
clasohm@0
   156
clasohm@0
   157
clasohm@0
   158
(****************
clasohm@0
   159
  Multiplication
clasohm@0
   160
 ****************)
clasohm@0
   161
clasohm@0
   162
(*Commutative law for multiplication
paulson@9251
   163
Goal "[| a:N;  b:N |] ==> a #* b = b #* a : N";
paulson@9249
   164
by (NE_tac "a" 1);
paulson@9251
   165
by (hyp_arith_rew_tac []);
paulson@9249
   166
by (NE_tac "b" 2);
paulson@9249
   167
by (rtac sym_elem 1);
paulson@9249
   168
by (NE_tac "b" 1);
paulson@9251
   169
by (hyp_arith_rew_tac []) ;
paulson@9249
   170
qed "mult_commute";   NEEDS COMMUTATIVE MATCHING
clasohm@0
   171
***************)
clasohm@0
   172
clasohm@0
   173
(*right annihilation in product*)
paulson@9251
   174
Goal "a:N ==> a #* 0 = 0 : N";
paulson@9249
   175
by (NE_tac "a" 1);
paulson@9251
   176
by (hyp_arith_rew_tac []) ;
paulson@9249
   177
qed "mult_0_right";
clasohm@0
   178
clasohm@0
   179
(*right successor law for multiplication*)
paulson@9251
   180
Goal "[| a:N;  b:N |] ==> a #* succ(b) = a #+ (a #* b) : N";
paulson@9249
   181
by (NE_tac "a" 1);
paulson@9251
   182
by (hyp_arith_rew_tac [add_assoc RS sym_elem]);
paulson@9251
   183
by (REPEAT (assume_tac 1
paulson@9251
   184
     ORELSE resolve_tac ([add_commute,mult_typingL,add_typingL]@ intrL_rls@
paulson@9251
   185
			 [refl_elem])   1)) ;
paulson@9249
   186
qed "mult_succ_right";
clasohm@0
   187
clasohm@0
   188
(*Commutative law for multiplication*)
paulson@9251
   189
Goal "[| a:N;  b:N |] ==> a #* b = b #* a : N";
paulson@9249
   190
by (NE_tac "a" 1);
paulson@9251
   191
by (hyp_arith_rew_tac [mult_0_right, mult_succ_right]) ;
paulson@9249
   192
qed "mult_commute";
clasohm@0
   193
clasohm@0
   194
(*addition distributes over multiplication*)
paulson@9251
   195
Goal "[| a:N;  b:N;  c:N |] ==> (a #+ b) #* c = (a #* c) #+ (b #* c) : N";
paulson@9249
   196
by (NE_tac "a" 1);
paulson@9251
   197
by (hyp_arith_rew_tac [add_assoc RS sym_elem]) ;
paulson@9249
   198
qed "add_mult_distrib";
clasohm@0
   199
clasohm@0
   200
clasohm@0
   201
(*Associative law for multiplication*)
paulson@9251
   202
Goal "[| a:N;  b:N;  c:N |] ==> (a #* b) #* c = a #* (b #* c) : N";
paulson@9249
   203
by (NE_tac "a" 1);
paulson@9251
   204
by (hyp_arith_rew_tac [add_mult_distrib]) ;
paulson@9249
   205
qed "mult_assoc";
clasohm@0
   206
clasohm@0
   207
clasohm@0
   208
(************
clasohm@0
   209
  Difference
clasohm@0
   210
 ************
clasohm@0
   211
clasohm@0
   212
Difference on natural numbers, without negative numbers
clasohm@0
   213
  a - b = 0  iff  a<=b    a - b = succ(c) iff a>b   *)
clasohm@0
   214
paulson@9251
   215
Goal "a:N ==> a - a = 0 : N";
paulson@9249
   216
by (NE_tac "a" 1);
paulson@9251
   217
by (hyp_arith_rew_tac []) ;
paulson@9249
   218
qed "diff_self_eq_0";
clasohm@0
   219
clasohm@0
   220
clasohm@0
   221
(*  [| c : N; 0 : N; c : N |] ==> c #+ 0 = c : N  *)
clasohm@0
   222
val add_0_right = addC0 RSN (3, add_commute RS trans_elem);
clasohm@0
   223
clasohm@0
   224
(*Addition is the inverse of subtraction: if b<=x then b#+(x-b) = x.
clasohm@0
   225
  An example of induction over a quantified formula (a product).
clasohm@0
   226
  Uses rewriting with a quantified, implicative inductive hypothesis.*)
paulson@9251
   227
Goal "b:N ==> ?a : PROD x:N. Eq(N, b-x, 0) --> Eq(N, b #+ (x-b), x)";
clasohm@0
   228
by (NE_tac "b" 1);
clasohm@0
   229
(*strip one "universal quantifier" but not the "implication"*)
clasohm@0
   230
by (resolve_tac intr_rls 3);  
clasohm@0
   231
(*case analysis on x in
clasohm@0
   232
    (succ(u) <= x) --> (succ(u)#+(x-succ(u)) = x) *)
clasohm@0
   233
by (NE_tac "x" 4 THEN assume_tac 4); 
clasohm@0
   234
(*Prepare for simplification of types -- the antecedent succ(u)<=x *)
clasohm@1459
   235
by (rtac replace_type 5);
clasohm@1459
   236
by (rtac replace_type 4);
paulson@9251
   237
by (arith_rew_tac []); 
clasohm@0
   238
(*Solves first 0 goal, simplifies others.  Two sugbgoals remain.
clasohm@0
   239
  Both follow by rewriting, (2) using quantified induction hyp*)
clasohm@0
   240
by (intr_tac[]);  (*strips remaining PRODs*)
paulson@9251
   241
by (hyp_arith_rew_tac [add_0_right]);  
clasohm@0
   242
by (assume_tac 1);
clasohm@1294
   243
qed "add_diff_inverse_lemma";
clasohm@0
   244
clasohm@0
   245
clasohm@0
   246
(*Version of above with premise   b-a=0   i.e.    a >= b.
clasohm@0
   247
  Using ProdE does not work -- for ?B(?a) is ambiguous.
clasohm@0
   248
  Instead, add_diff_inverse_lemma states the desired induction scheme;
clasohm@0
   249
    the use of RS below instantiates Vars in ProdE automatically. *)
paulson@9251
   250
Goal "[| a:N;  b:N;  b-a = 0 : N |] ==> b #+ (a-b) = a : N";
clasohm@1459
   251
by (rtac EqE 1);
clasohm@0
   252
by (resolve_tac [ add_diff_inverse_lemma RS ProdE RS ProdE ] 1);
paulson@9251
   253
by (REPEAT (ares_tac [EqI] 1));
clasohm@1294
   254
qed "add_diff_inverse";
clasohm@0
   255
clasohm@0
   256
clasohm@0
   257
(********************
clasohm@0
   258
  Absolute difference
clasohm@0
   259
 ********************)
clasohm@0
   260
clasohm@0
   261
(*typing of absolute difference: short and long versions*)
clasohm@0
   262
paulson@9251
   263
Goalw arith_defs "[| a:N;  b:N |] ==> a |-| b : N";
paulson@9251
   264
by (typechk_tac []) ;
paulson@9249
   265
qed "absdiff_typing";
clasohm@0
   266
paulson@9251
   267
Goalw arith_defs "[| a=c:N;  b=d:N |] ==> a |-| b = c |-| d : N";
paulson@9251
   268
by (equal_tac []) ;
paulson@9249
   269
qed "absdiff_typingL";
clasohm@0
   270
paulson@9251
   271
Goalw [absdiff_def] "a:N ==> a |-| a = 0 : N";
paulson@9251
   272
by (arith_rew_tac [diff_self_eq_0]) ;
paulson@9249
   273
qed "absdiff_self_eq_0";
clasohm@0
   274
paulson@9251
   275
Goalw [absdiff_def] "a:N ==> 0 |-| a = a : N";
paulson@9249
   276
by (hyp_arith_rew_tac []);
paulson@9249
   277
qed "absdiffC0";
clasohm@0
   278
clasohm@0
   279
paulson@9251
   280
Goalw [absdiff_def] "[| a:N;  b:N |] ==> succ(a) |-| succ(b)  =  a |-| b : N";
paulson@9249
   281
by (hyp_arith_rew_tac []) ;
paulson@9249
   282
qed "absdiff_succ_succ";
clasohm@0
   283
clasohm@0
   284
(*Note how easy using commutative laws can be?  ...not always... *)
paulson@9251
   285
Goalw [absdiff_def] "[| a:N;  b:N |] ==> a |-| b = b |-| a : N";
clasohm@1459
   286
by (rtac add_commute 1);
paulson@9251
   287
by (typechk_tac [diff_typing]);
clasohm@1294
   288
qed "absdiff_commute";
clasohm@0
   289
clasohm@0
   290
(*If a+b=0 then a=0.   Surprisingly tedious*)
paulson@9251
   291
Goal "[| a:N;  b:N |] ==> ?c : PROD u: Eq(N,a#+b,0) .  Eq(N,a,0)";
clasohm@0
   292
by (NE_tac "a" 1);
clasohm@1459
   293
by (rtac replace_type 3);
paulson@9251
   294
by (arith_rew_tac []);
clasohm@0
   295
by (intr_tac[]);  (*strips remaining PRODs*)
clasohm@0
   296
by (resolve_tac [ zero_ne_succ RS FE ] 2);
clasohm@0
   297
by (etac (EqE RS sym_elem) 3);
paulson@9251
   298
by (typechk_tac [add_typing]);
clasohm@1294
   299
qed "add_eq0_lemma";
clasohm@0
   300
clasohm@0
   301
(*Version of above with the premise  a+b=0.
clasohm@0
   302
  Again, resolution instantiates variables in ProdE *)
paulson@9251
   303
Goal "[| a:N;  b:N;  a #+ b = 0 : N |] ==> a = 0 : N";
clasohm@1459
   304
by (rtac EqE 1);
clasohm@0
   305
by (resolve_tac [add_eq0_lemma RS ProdE] 1);
clasohm@1459
   306
by (rtac EqI 3);
paulson@9251
   307
by (typechk_tac []) ;
clasohm@1294
   308
qed "add_eq0";
clasohm@0
   309
clasohm@0
   310
(*Here is a lemma to infer a-b=0 and b-a=0 from a|-|b=0, below. *)
paulson@9251
   311
Goalw [absdiff_def]
clasohm@0
   312
    "[| a:N;  b:N;  a |-| b = 0 : N |] ==> \
clasohm@0
   313
\    ?a : SUM v: Eq(N, a-b, 0) . Eq(N, b-a, 0)";
clasohm@0
   314
by (intr_tac[]);
clasohm@0
   315
by eqintr_tac;
clasohm@1459
   316
by (rtac add_eq0 2);
clasohm@1459
   317
by (rtac add_eq0 1);
clasohm@0
   318
by (resolve_tac [add_commute RS trans_elem] 6);
paulson@9251
   319
by (typechk_tac [diff_typing]);
clasohm@1294
   320
qed "absdiff_eq0_lem";
clasohm@0
   321
clasohm@0
   322
(*if  a |-| b = 0  then  a = b  
clasohm@0
   323
  proof: a-b=0 and b-a=0, so b = a+(b-a) = a+0 = a*)
paulson@9251
   324
Goal "[| a |-| b = 0 : N;  a:N;  b:N |] ==> a = b : N";
clasohm@1459
   325
by (rtac EqE 1);
clasohm@0
   326
by (resolve_tac [absdiff_eq0_lem RS SumE] 1);
paulson@9251
   327
by (TRYALL assume_tac);
clasohm@0
   328
by eqintr_tac;
clasohm@0
   329
by (resolve_tac [add_diff_inverse RS sym_elem RS trans_elem] 1);
clasohm@1459
   330
by (rtac EqE 3  THEN  assume_tac 3);
paulson@9251
   331
by (hyp_arith_rew_tac [add_0_right]);
clasohm@1294
   332
qed "absdiff_eq0";
clasohm@0
   333
clasohm@0
   334
(***********************
clasohm@0
   335
  Remainder and Quotient
clasohm@0
   336
 ***********************)
clasohm@0
   337
clasohm@0
   338
(*typing of remainder: short and long versions*)
clasohm@0
   339
paulson@9251
   340
Goalw [mod_def] "[| a:N;  b:N |] ==> a mod b : N";
paulson@9251
   341
by (typechk_tac [absdiff_typing]) ;
paulson@9249
   342
qed "mod_typing";
clasohm@0
   343
 
paulson@9251
   344
Goalw [mod_def] "[| a=c:N;  b=d:N |] ==> a mod b = c mod d : N";
paulson@9249
   345
by (equal_tac [absdiff_typingL]) ;
paulson@9249
   346
qed "mod_typingL";
clasohm@0
   347
 
clasohm@0
   348
clasohm@0
   349
(*computation for  mod : 0 and successor cases*)
clasohm@0
   350
paulson@9249
   351
Goalw [mod_def]   "b:N ==> 0 mod b = 0 : N";
paulson@9251
   352
by (rew_tac [absdiff_typing]) ;
paulson@9249
   353
qed "modC0";
clasohm@0
   354
paulson@9249
   355
Goalw [mod_def]   
paulson@9249
   356
"[| a:N; b:N |] ==> succ(a) mod b = rec(succ(a mod b) |-| b, 0, %x y. succ(a mod b)) : N";
paulson@9251
   357
by (rew_tac [absdiff_typing]) ;
paulson@9249
   358
qed "modC_succ";
clasohm@0
   359
clasohm@0
   360
clasohm@0
   361
(*typing of quotient: short and long versions*)
clasohm@0
   362
paulson@9249
   363
Goalw [div_def]   "[| a:N;  b:N |] ==> a div b : N";
paulson@9251
   364
by (typechk_tac [absdiff_typing,mod_typing]) ;
paulson@9249
   365
qed "div_typing";
clasohm@0
   366
paulson@9251
   367
Goalw [div_def] "[| a=c:N;  b=d:N |] ==> a div b = c div d : N";
paulson@9249
   368
by (equal_tac [absdiff_typingL, mod_typingL]);
paulson@9249
   369
qed "div_typingL";
clasohm@0
   370
clasohm@0
   371
val div_typing_rls = [mod_typing, div_typing, absdiff_typing];
clasohm@0
   372
clasohm@0
   373
clasohm@0
   374
(*computation for quotient: 0 and successor cases*)
clasohm@0
   375
paulson@9249
   376
Goalw [div_def]   "b:N ==> 0 div b = 0 : N";
paulson@9251
   377
by (rew_tac [mod_typing, absdiff_typing]) ;
paulson@9249
   378
qed "divC0";
clasohm@0
   379
paulson@9249
   380
Goalw [div_def] 
paulson@9249
   381
 "[| a:N;  b:N |] ==> succ(a) div b = \
paulson@9249
   382
\    rec(succ(a) mod b, succ(a div b), %x y. a div b) : N";
paulson@9251
   383
by (rew_tac [mod_typing]) ;
paulson@9249
   384
qed "divC_succ";
clasohm@0
   385
clasohm@0
   386
clasohm@0
   387
(*Version of above with same condition as the  mod  one*)
paulson@9251
   388
Goal "[| a:N;  b:N |] ==> \
paulson@9249
   389
\    succ(a) div b =rec(succ(a mod b) |-| b, succ(a div b), %x y. a div b) : N";
paulson@9249
   390
by (resolve_tac [ divC_succ RS trans_elem ] 1);
paulson@9251
   391
by (rew_tac(div_typing_rls @ [modC_succ]));
paulson@9249
   392
by (NE_tac "succ(a mod b)|-|b" 1);
paulson@9251
   393
by (rew_tac [mod_typing, div_typing, absdiff_typing]);
paulson@9249
   394
qed "divC_succ2";
clasohm@0
   395
clasohm@0
   396
(*for case analysis on whether a number is 0 or a successor*)
paulson@9251
   397
Goal "a:N ==> rec(a, inl(eq), %ka kb. inr(<ka, eq>)) : \
paulson@9249
   398
\                     Eq(N,a,0) + (SUM x:N. Eq(N,a, succ(x)))";
paulson@9249
   399
by (NE_tac "a" 1);
paulson@9249
   400
by (rtac PlusI_inr 3);
paulson@9249
   401
by (rtac PlusI_inl 2);
paulson@9249
   402
by eqintr_tac;
paulson@9251
   403
by (equal_tac []) ;
paulson@9249
   404
qed "iszero_decidable";
clasohm@0
   405
clasohm@0
   406
(*Main Result.  Holds when b is 0 since   a mod 0 = a     and    a div 0 = 0  *)
paulson@9251
   407
Goal "[| a:N;  b:N |] ==> a mod b  #+  (a div b) #* b = a : N";
clasohm@0
   408
by (NE_tac "a" 1);
paulson@9251
   409
by (arith_rew_tac (div_typing_rls@[modC0,modC_succ,divC0,divC_succ2])); 
clasohm@1459
   410
by (rtac EqE 1);
clasohm@0
   411
(*case analysis on   succ(u mod b)|-|b  *)
clasohm@0
   412
by (res_inst_tac [("a1", "succ(u mod b) |-| b")] 
clasohm@0
   413
                 (iszero_decidable RS PlusE) 1);
clasohm@0
   414
by (etac SumE 3);
paulson@9251
   415
by (hyp_arith_rew_tac (div_typing_rls @
clasohm@1459
   416
        [modC0,modC_succ, divC0, divC_succ2])); 
clasohm@0
   417
(*Replace one occurence of  b  by succ(u mod b).  Clumsy!*)
clasohm@0
   418
by (resolve_tac [ add_typingL RS trans_elem ] 1);
clasohm@0
   419
by (eresolve_tac [EqE RS absdiff_eq0 RS sym_elem] 1);
clasohm@1459
   420
by (rtac refl_elem 3);
paulson@9251
   421
by (hyp_arith_rew_tac (div_typing_rls)); 
clasohm@1294
   422
qed "mod_div_equality";
clasohm@0
   423
clasohm@0
   424
writeln"Reached end of file.";