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