src/CTT/Arith.thy
author wenzelm
Mon, 24 Oct 2016 11:10:17 +0200
changeset 64366 e0ab4c0a5a93
parent 63505 42e1dece537a
child 64980 7dc25cf5793e
permissions -rw-r--r--
updated to jedit_build-20161024: Code2HTML 0.7, Navigator 2.7;
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
1474
3f7d67927fe2 expanded tabs
clasohm
parents: 0
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Copyright   1991  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
     6
section \<open>Elementary arithmetic\<close>
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 12110
diff changeset
     7
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 12110
diff changeset
     8
theory Arith
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
     9
  imports Bool
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 12110
diff changeset
    10
begin
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
    12
subsection \<open>Arithmetic operators and their definitions\<close>
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 12110
diff changeset
    13
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    14
definition add :: "[i,i]\<Rightarrow>i"   (infixr "#+" 65)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    15
  where "a#+b \<equiv> rec(a, b, \<lambda>u v. succ(v))"
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    17
definition diff :: "[i,i]\<Rightarrow>i"   (infixr "-" 65)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    18
  where "a-b \<equiv> rec(b, a, \<lambda>u v. rec(v, 0, \<lambda>x y. x))"
19762
wenzelm
parents: 19761
diff changeset
    19
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    20
definition absdiff :: "[i,i]\<Rightarrow>i"   (infixr "|-|" 65)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    21
  where "a|-|b \<equiv> (a-b) #+ (b-a)"
19762
wenzelm
parents: 19761
diff changeset
    22
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    23
definition mult :: "[i,i]\<Rightarrow>i"   (infixr "#*" 70)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    24
  where "a#*b \<equiv> rec(a, 0, \<lambda>u v. b #+ v)"
10467
e6e7205e9e91 x-symbol support for Pi, Sigma, -->, : (membership)
paulson
parents: 3837
diff changeset
    25
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    26
definition mod :: "[i,i]\<Rightarrow>i"   (infixr "mod" 70)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    27
  where "a mod b \<equiv> rec(a, 0, \<lambda>u v. rec(succ(v) |-| b, 0, \<lambda>x y. succ(v)))"
19762
wenzelm
parents: 19761
diff changeset
    28
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    29
definition div :: "[i,i]\<Rightarrow>i"   (infixr "div" 70)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    30
  where "a div b \<equiv> rec(a, 0, \<lambda>u v. rec(succ(u) mod b, succ(v), \<lambda>x y. v))"
17441
5b5feca0344a converted to Isar theory format;
wenzelm
parents: 12110
diff changeset
    31
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    32
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
    33
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    34
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
    35
subsection \<open>Proofs about elementary arithmetic: addition, multiplication, etc.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    36
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    37
subsubsection \<open>Addition\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    38
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    39
text \<open>Typing of \<open>add\<close>: short and long versions.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    40
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    41
lemma add_typing: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a #+ b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    42
  unfolding arith_defs by typechk
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    43
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    44
lemma add_typingL: "\<lbrakk>a = c:N; b = d:N\<rbrakk> \<Longrightarrow> a #+ b = c #+ d : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    45
  unfolding arith_defs by equal
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    46
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    47
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    48
text \<open>Computation for \<open>add\<close>: 0 and successor cases.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    49
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    50
lemma addC0: "b:N \<Longrightarrow> 0 #+ b = b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    51
  unfolding arith_defs by rew
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    52
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    53
lemma addC_succ: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> succ(a) #+ b = succ(a #+ b) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    54
  unfolding arith_defs by rew
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    55
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    56
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    57
subsubsection \<open>Multiplication\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    58
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    59
text \<open>Typing of \<open>mult\<close>: short and long versions.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    60
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    61
lemma mult_typing: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a #* b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    62
  unfolding arith_defs by (typechk add_typing)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    63
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    64
lemma mult_typingL: "\<lbrakk>a = c:N; b = d:N\<rbrakk> \<Longrightarrow> a #* b = c #* d : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    65
  unfolding arith_defs by (equal add_typingL)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    66
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    67
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    68
text \<open>Computation for \<open>mult\<close>: 0 and successor cases.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    69
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    70
lemma multC0: "b:N \<Longrightarrow> 0 #* b = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    71
  unfolding arith_defs by rew
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    72
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    73
lemma multC_succ: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> succ(a) #* b = b #+ (a #* b) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    74
  unfolding arith_defs by rew
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    75
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    76
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    77
subsubsection \<open>Difference\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    78
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    79
text \<open>Typing of difference.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    80
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    81
lemma diff_typing: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a - b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    82
  unfolding arith_defs by typechk
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    83
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    84
lemma diff_typingL: "\<lbrakk>a = c:N; b = d:N\<rbrakk> \<Longrightarrow> a - b = c - d : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    85
  unfolding arith_defs by equal
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    86
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    87
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    88
text \<open>Computation for difference: 0 and successor cases.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    89
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    90
lemma diffC0: "a:N \<Longrightarrow> a - 0 = a : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    91
  unfolding arith_defs by rew
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    92
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    93
text \<open>Note: \<open>rec(a, 0, \<lambda>z w.z)\<close> is \<open>pred(a).\<close>\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
    94
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
    95
lemma diff_0_eq_0: "b:N \<Longrightarrow> 0 - b = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    96
  unfolding arith_defs
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    97
  apply (NE b)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    98
    apply hyp_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
    99
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   100
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   101
text \<open>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   102
  Essential to simplify FIRST!!  (Else we get a critical pair)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   103
  \<open>succ(a) - succ(b)\<close> rewrites to \<open>pred(succ(a) - b)\<close>.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   104
\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   105
lemma diff_succ_succ: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> succ(a) - succ(b) = a - b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   106
  unfolding arith_defs
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   107
  apply hyp_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   108
  apply (NE b)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   109
    apply hyp_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   110
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   111
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   112
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   113
subsection \<open>Simplification\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   114
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   115
lemmas arith_typing_rls = add_typing mult_typing diff_typing
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   116
  and arith_congr_rls = add_typingL mult_typingL diff_typingL
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   117
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   118
lemmas congr_rls = arith_congr_rls intrL2_rls elimL_rls
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   119
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   120
lemmas arithC_rls =
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   121
  addC0 addC_succ
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   122
  multC0 multC_succ
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   123
  diffC0 diff_0_eq_0 diff_succ_succ
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   124
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   125
ML \<open>
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   126
  structure Arith_simp = TSimpFun(
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   127
    val refl = @{thm refl_elem}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   128
    val sym = @{thm sym_elem}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   129
    val trans = @{thm trans_elem}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   130
    val refl_red = @{thm refl_red}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   131
    val trans_red = @{thm trans_red}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   132
    val red_if_equal = @{thm red_if_equal}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   133
    val default_rls = @{thms arithC_rls comp_rls}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   134
    val routine_tac = routine_tac @{thms arith_typing_rls routine_rls}
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   135
  )
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   136
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   137
  fun arith_rew_tac ctxt prems =
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   138
    make_rew_tac ctxt (Arith_simp.norm_tac ctxt (@{thms congr_rls}, prems))
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   139
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   140
  fun hyp_arith_rew_tac ctxt prems =
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   141
    make_rew_tac ctxt
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   142
      (Arith_simp.cond_norm_tac ctxt (prove_cond_tac ctxt, @{thms congr_rls}, prems))
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   143
\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   144
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   145
method_setup arith_rew = \<open>
58972
5b026cfc5f04 more Isar proof methods;
wenzelm
parents: 58963
diff changeset
   146
  Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (arith_rew_tac ctxt ths))
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   147
\<close>
58972
5b026cfc5f04 more Isar proof methods;
wenzelm
parents: 58963
diff changeset
   148
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   149
method_setup hyp_arith_rew = \<open>
58972
5b026cfc5f04 more Isar proof methods;
wenzelm
parents: 58963
diff changeset
   150
  Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD (hyp_arith_rew_tac ctxt ths))
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   151
\<close>
58972
5b026cfc5f04 more Isar proof methods;
wenzelm
parents: 58963
diff changeset
   152
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   153
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   154
subsection \<open>Addition\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   155
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   156
text \<open>Associative law for addition.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   157
lemma add_assoc: "\<lbrakk>a:N; b:N; c:N\<rbrakk> \<Longrightarrow> (a #+ b) #+ c = a #+ (b #+ c) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   158
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   159
    apply hyp_arith_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   160
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   161
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   162
text \<open>Commutative law for addition.  Can be proved using three inductions.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   163
  Must simplify after first induction!  Orientation of rewrites is delicate.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   164
lemma add_commute: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a #+ b = b #+ a : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   165
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   166
    apply hyp_arith_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   167
   apply (rule sym_elem)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   168
   prefer 2
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   169
   apply (NE b)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   170
     prefer 4
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   171
     apply (NE b)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   172
       apply hyp_arith_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   173
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   174
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   175
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   176
subsection \<open>Multiplication\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   177
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   178
text \<open>Right annihilation in product.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   179
lemma mult_0_right: "a:N \<Longrightarrow> a #* 0 = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   180
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   181
    apply hyp_arith_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   182
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   183
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   184
text \<open>Right successor law for multiplication.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   185
lemma mult_succ_right: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a #* succ(b) = a #+ (a #* b) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   186
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   187
    apply (hyp_arith_rew add_assoc [THEN sym_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   188
  apply (assumption | rule add_commute mult_typingL add_typingL intrL_rls refl_elem)+
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   189
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   190
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   191
text \<open>Commutative law for multiplication.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   192
lemma mult_commute: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a #* b = b #* a : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   193
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   194
    apply (hyp_arith_rew mult_0_right mult_succ_right)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   195
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   196
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   197
text \<open>Addition distributes over multiplication.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   198
lemma add_mult_distrib: "\<lbrakk>a:N; b:N; c:N\<rbrakk> \<Longrightarrow> (a #+ b) #* c = (a #* c) #+ (b #* c) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   199
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   200
    apply (hyp_arith_rew add_assoc [THEN sym_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   201
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   202
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   203
text \<open>Associative law for multiplication.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   204
lemma mult_assoc: "\<lbrakk>a:N; b:N; c:N\<rbrakk> \<Longrightarrow> (a #* b) #* c = a #* (b #* c) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   205
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   206
    apply (hyp_arith_rew add_mult_distrib)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   207
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   208
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   209
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   210
subsection \<open>Difference\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   211
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   212
text \<open>
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   213
  Difference on natural numbers, without negative numbers
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   214
  \<^item> \<open>a - b = 0\<close>  iff  \<open>a \<le> b\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   215
  \<^item> \<open>a - b = succ(c)\<close> iff \<open>a > b\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   216
\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   217
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   218
lemma diff_self_eq_0: "a:N \<Longrightarrow> a - a = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   219
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   220
    apply hyp_arith_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   221
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   222
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   223
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   224
lemma add_0_right: "\<lbrakk>c : N; 0 : N; c : N\<rbrakk> \<Longrightarrow> c #+ 0 = c : N"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   225
  by (rule addC0 [THEN [3] add_commute [THEN trans_elem]])
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   226
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   227
text \<open>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   228
  Addition is the inverse of subtraction: if \<open>b \<le> x\<close> then \<open>b #+ (x - b) = x\<close>.
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   229
  An example of induction over a quantified formula (a product).
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   230
  Uses rewriting with a quantified, implicative inductive hypothesis.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   231
\<close>
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60770
diff changeset
   232
schematic_goal add_diff_inverse_lemma:
61391
2332d9be352b tuned syntax -- more symbols;
wenzelm
parents: 61378
diff changeset
   233
  "b:N \<Longrightarrow> ?a : \<Prod>x:N. Eq(N, b-x, 0) \<longrightarrow> Eq(N, b #+ (x-b), x)"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   234
  apply (NE b)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   235
    \<comment> \<open>strip one "universal quantifier" but not the "implication"\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   236
    apply (rule_tac [3] intr_rls)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   237
    \<comment> \<open>case analysis on \<open>x\<close> in \<open>succ(u) \<le> x \<longrightarrow> succ(u) #+ (x - succ(u)) = x\<close>\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   238
     prefer 4
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   239
     apply (NE x)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   240
       apply assumption
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   241
    \<comment> \<open>Prepare for simplification of types -- the antecedent \<open>succ(u) \<le> x\<close>\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   242
      apply (rule_tac [2] replace_type)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   243
       apply (rule_tac [1] replace_type)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   244
        apply arith_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   245
    \<comment> \<open>Solves first 0 goal, simplifies others.  Two sugbgoals remain.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   246
    Both follow by rewriting, (2) using quantified induction hyp.\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   247
   apply intr \<comment> \<open>strips remaining \<open>\<Prod>\<close>s\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   248
    apply (hyp_arith_rew add_0_right)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   249
  apply assumption
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   250
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   251
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   252
text \<open>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   253
  Version of above with premise \<open>b - a = 0\<close> i.e. \<open>a \<ge> b\<close>.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   254
  Using @{thm ProdE} does not work -- for \<open>?B(?a)\<close> is ambiguous.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   255
  Instead, @{thm add_diff_inverse_lemma} states the desired induction scheme;
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   256
  the use of \<open>THEN\<close> below instantiates Vars in @{thm ProdE} automatically.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   257
\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   258
lemma add_diff_inverse: "\<lbrakk>a:N; b:N; b - a = 0 : N\<rbrakk> \<Longrightarrow> b #+ (a-b) = a : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   259
  apply (rule EqE)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   260
  apply (rule add_diff_inverse_lemma [THEN ProdE, THEN ProdE])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   261
    apply (assumption | rule EqI)+
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   262
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   263
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   264
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   265
subsection \<open>Absolute difference\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   266
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   267
text \<open>Typing of absolute difference: short and long versions.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   268
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   269
lemma absdiff_typing: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a |-| b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   270
  unfolding arith_defs by typechk
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   271
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   272
lemma absdiff_typingL: "\<lbrakk>a = c:N; b = d:N\<rbrakk> \<Longrightarrow> a |-| b = c |-| d : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   273
  unfolding arith_defs by equal
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   274
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   275
lemma absdiff_self_eq_0: "a:N \<Longrightarrow> a |-| a = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   276
  unfolding absdiff_def by (arith_rew diff_self_eq_0)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   277
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   278
lemma absdiffC0: "a:N \<Longrightarrow> 0 |-| a = a : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   279
  unfolding absdiff_def by hyp_arith_rew
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   280
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   281
lemma absdiff_succ_succ: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> succ(a) |-| succ(b)  =  a |-| b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   282
  unfolding absdiff_def by hyp_arith_rew
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   283
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   284
text \<open>Note how easy using commutative laws can be?  ...not always...\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   285
lemma absdiff_commute: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a |-| b = b |-| a : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   286
  unfolding absdiff_def
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   287
  apply (rule add_commute)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   288
   apply (typechk diff_typing)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   289
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   290
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   291
text \<open>If \<open>a + b = 0\<close> then \<open>a = 0\<close>. Surprisingly tedious.\<close>
61391
2332d9be352b tuned syntax -- more symbols;
wenzelm
parents: 61378
diff changeset
   292
schematic_goal add_eq0_lemma: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> ?c : \<Prod>u: Eq(N,a#+b,0) .  Eq(N,a,0)"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   293
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   294
    apply (rule_tac [3] replace_type)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   295
     apply arith_rew
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   296
  apply intr  \<comment> \<open>strips remaining \<open>\<Prod>\<close>s\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   297
   apply (rule_tac [2] zero_ne_succ [THEN FE])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   298
     apply (erule_tac [3] EqE [THEN sym_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   299
    apply (typechk add_typing)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   300
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   301
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   302
text \<open>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   303
  Version of above with the premise \<open>a + b = 0\<close>.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   304
  Again, resolution instantiates variables in @{thm ProdE}.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   305
\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   306
lemma add_eq0: "\<lbrakk>a:N; b:N; a #+ b = 0 : N\<rbrakk> \<Longrightarrow> a = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   307
  apply (rule EqE)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   308
  apply (rule add_eq0_lemma [THEN ProdE])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   309
    apply (rule_tac [3] EqI)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   310
    apply typechk
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   311
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   312
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   313
text \<open>Here is a lemma to infer \<open>a - b = 0\<close> and \<open>b - a = 0\<close> from \<open>a |-| b = 0\<close>, below.\<close>
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60770
diff changeset
   314
schematic_goal absdiff_eq0_lem:
61391
2332d9be352b tuned syntax -- more symbols;
wenzelm
parents: 61378
diff changeset
   315
  "\<lbrakk>a:N; b:N; a |-| b = 0 : N\<rbrakk> \<Longrightarrow> ?a : \<Sum>v: Eq(N, a-b, 0) . Eq(N, b-a, 0)"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   316
  apply (unfold absdiff_def)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   317
  apply intr
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   318
   apply eqintr
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   319
   apply (rule_tac [2] add_eq0)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   320
     apply (rule add_eq0)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   321
       apply (rule_tac [6] add_commute [THEN trans_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   322
         apply (typechk diff_typing)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   323
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   324
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   325
text \<open>If \<open>a |-| b = 0\<close> then \<open>a = b\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   326
  proof: \<open>a - b = 0\<close> and \<open>b - a = 0\<close>, so \<open>b = a + (b - a) = a + 0 = a\<close>.
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   327
\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   328
lemma absdiff_eq0: "\<lbrakk>a |-| b = 0 : N; a:N; b:N\<rbrakk> \<Longrightarrow> a = b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   329
  apply (rule EqE)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   330
  apply (rule absdiff_eq0_lem [THEN SumE])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   331
     apply eqintr
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   332
  apply (rule add_diff_inverse [THEN sym_elem, THEN trans_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   333
     apply (erule_tac [3] EqE)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   334
    apply (hyp_arith_rew add_0_right)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   335
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   336
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   337
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59498
diff changeset
   338
subsection \<open>Remainder and Quotient\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   339
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   340
text \<open>Typing of remainder: short and long versions.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   341
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   342
lemma mod_typing: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a mod b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   343
  unfolding mod_def by (typechk absdiff_typing)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   344
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   345
lemma mod_typingL: "\<lbrakk>a = c:N; b = d:N\<rbrakk> \<Longrightarrow> a mod b = c mod d : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   346
  unfolding mod_def by (equal absdiff_typingL)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   347
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   348
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   349
text \<open>Computation for \<open>mod\<close>: 0 and successor cases.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   350
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   351
lemma modC0: "b:N \<Longrightarrow> 0 mod b = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   352
  unfolding mod_def by (rew absdiff_typing)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   353
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   354
lemma modC_succ: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow>
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   355
  succ(a) mod b = rec(succ(a mod b) |-| b, 0, \<lambda>x y. succ(a mod b)) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   356
  unfolding mod_def by (rew absdiff_typing)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   357
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   358
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   359
text \<open>Typing of quotient: short and long versions.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   360
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   361
lemma div_typing: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a div b : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   362
  unfolding div_def by (typechk absdiff_typing mod_typing)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   363
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   364
lemma div_typingL: "\<lbrakk>a = c:N; b = d:N\<rbrakk> \<Longrightarrow> a div b = c div d : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   365
  unfolding div_def by (equal absdiff_typingL mod_typingL)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   366
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   367
lemmas div_typing_rls = mod_typing div_typing absdiff_typing
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   368
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   369
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   370
text \<open>Computation for quotient: 0 and successor cases.\<close>
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   371
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   372
lemma divC0: "b:N \<Longrightarrow> 0 div b = 0 : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   373
  unfolding div_def by (rew mod_typing absdiff_typing)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   374
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   375
lemma divC_succ: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow>
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   376
  succ(a) div b = rec(succ(a) mod b, succ(a div b), \<lambda>x y. a div b) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   377
  unfolding div_def by (rew mod_typing)
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   378
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   379
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   380
text \<open>Version of above with same condition as the \<open>mod\<close> one.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   381
lemma divC_succ2: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow>
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   382
  succ(a) div b =rec(succ(a mod b) |-| b, succ(a div b), \<lambda>x y. a div b) : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   383
  apply (rule divC_succ [THEN trans_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   384
    apply (rew div_typing_rls modC_succ)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   385
  apply (NE "succ (a mod b) |-|b")
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   386
    apply (rew mod_typing div_typing absdiff_typing)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   387
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   388
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   389
text \<open>For case analysis on whether a number is 0 or a successor.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   390
lemma iszero_decidable: "a:N \<Longrightarrow> rec(a, inl(eq), \<lambda>ka kb. inr(<ka, eq>)) :
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   391
  Eq(N,a,0) + (\<Sum>x:N. Eq(N,a, succ(x)))"
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   392
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   393
    apply (rule_tac [3] PlusI_inr)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   394
     apply (rule_tac [2] PlusI_inl)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   395
      apply eqintr
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   396
     apply equal
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   397
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   398
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   399
text \<open>Main Result. Holds when \<open>b\<close> is 0 since \<open>a mod 0 = a\<close> and \<open>a div 0 = 0\<close>.\<close>
58977
9576b510f6a2 more symbols;
wenzelm
parents: 58976
diff changeset
   400
lemma mod_div_equality: "\<lbrakk>a:N; b:N\<rbrakk> \<Longrightarrow> a mod b #+ (a div b) #* b = a : N"
63505
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   401
  apply (NE a)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   402
    apply (arith_rew div_typing_rls modC0 modC_succ divC0 divC_succ2)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   403
  apply (rule EqE)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   404
    \<comment> \<open>case analysis on \<open>succ(u mod b) |-| b\<close>\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   405
  apply (rule_tac a1 = "succ (u mod b) |-| b" in iszero_decidable [THEN PlusE])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   406
    apply (erule_tac [3] SumE)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   407
    apply (hyp_arith_rew div_typing_rls modC0 modC_succ divC0 divC_succ2)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   408
    \<comment> \<open>Replace one occurrence of \<open>b\<close> by \<open>succ(u mod b)\<close>. Clumsy!\<close>
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   409
  apply (rule add_typingL [THEN trans_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   410
    apply (erule EqE [THEN absdiff_eq0, THEN sym_elem])
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   411
     apply (rule_tac [3] refl_elem)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   412
     apply (hyp_arith_rew div_typing_rls)
42e1dece537a misc tuning and modernization;
wenzelm
parents: 61391
diff changeset
   413
  done
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   414
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents: 17441
diff changeset
   415
end