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