src/HOL/Arith.ML
author nipkow
Fri, 09 Feb 1996 13:41:18 +0100
changeset 1485 240cc98b94a7
parent 1475 7f5a4cd08209
child 1496 c443b2adaf52
permissions -rw-r--r--
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     1
(*  Title:      HOL/Arith.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Proofs about elementary arithmetic: addition, multiplication, etc.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
Tests definitions and simplifier.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
open Arith;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
(*** Basic rewrite rules for the arithmetic operators ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
val [pred_0, pred_Suc] = nat_recs pred_def;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
val [add_0,add_Suc] = nat_recs add_def; 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
val [mult_0,mult_Suc] = nat_recs mult_def; 
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    17
Addsimps [pred_0,pred_Suc,add_0,add_Suc,mult_0,mult_Suc];
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    18
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    19
(** pred **)
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    20
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    21
val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n";
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    22
by(res_inst_tac [("n","n")] natE 1);
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    23
by(cut_facts_tac prems 1);
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    24
by(ALLGOALS Asm_full_simp_tac);
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    25
qed "Suc_pred";
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    26
Addsimps [Suc_pred];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
(** Difference **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
val diff_0 = diff_def RS def_nat_rec_0;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
qed_goalw "diff_0_eq_0" Arith.thy [diff_def, pred_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
    "0 - n = 0"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    34
 (fn _ => [nat_ind_tac "n" 1,  ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
(*Must simplify BEFORE the induction!!  (Else we get a critical pair)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
  Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
qed_goalw "diff_Suc_Suc" Arith.thy [diff_def, pred_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
    "Suc(m) - Suc(n) = m - n"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
 (fn _ =>
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    41
  [Simp_tac 1, nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    43
Addsimps [diff_0, diff_0_eq_0, diff_Suc_Suc];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
(**** Inductive properties of the operators ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
(*** Addition ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
qed_goal "add_0_right" Arith.thy "m + 0 = m"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    51
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    54
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    56
Addsimps [add_0_right,add_Suc_right];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
(*Associative law for addition*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    60
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
(*Commutative law for addition*)  
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    64
 (fn _ =>  [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
 (fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
           rtac (add_commute RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
(*Addition is an AC-operator*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
val add_ac = [add_assoc, add_commute, add_left_commute];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    75
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    76
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
qed "add_left_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    81
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    82
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
qed "add_right_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    87
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    88
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
qed "add_left_cancel_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    93
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    94
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
qed "add_left_cancel_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
    97
Addsimps [add_left_cancel, add_right_cancel,
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
    98
          add_left_cancel_le, add_left_cancel_less];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
    99
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   100
goal Arith.thy "(m+n = 0) = (m=0 & n=0)";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   101
by (nat_ind_tac "m" 1);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   102
by (ALLGOALS Asm_simp_tac);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   103
qed "add_is_0";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   104
Addsimps [add_is_0];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   105
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   106
goal Arith.thy "!!n. n ~= 0 ==> m + pred n = pred(m+n)";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   107
by (nat_ind_tac "m" 1);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   108
by (ALLGOALS Asm_simp_tac);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   109
qed "add_pred";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   110
Addsimps [add_pred];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   111
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
(*** Multiplication ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   113
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   114
(*right annihilation in product*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   115
qed_goal "mult_0_right" Arith.thy "m * 0 = 0"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   116
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
(*right Sucessor law for multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
qed_goal "mult_Suc_right" Arith.thy  "m * Suc(n) = m + (m * n)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
 (fn _ => [nat_ind_tac "m" 1,
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   121
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   122
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   123
Addsimps [mult_0_right,mult_Suc_right];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   124
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
(*Commutative law for multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   127
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   128
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   129
(*addition distributes over multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   130
qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
 (fn _ => [nat_ind_tac "m" 1,
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   132
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   133
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
 (fn _ => [nat_ind_tac "m" 1,
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   136
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   138
Addsimps [add_mult_distrib,add_mult_distrib2];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
(*Associative law for multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   142
  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   143
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   144
qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
 (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   146
           rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   147
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   148
val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   149
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   150
(*** Difference ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   151
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   152
qed_goal "diff_self_eq_0" Arith.thy "m - m = 0"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   153
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   154
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   155
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   156
val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   157
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   158
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   159
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   160
qed "add_diff_inverse";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   161
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   162
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   163
(*** Remainder ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   165
goal Arith.thy "m - n < Suc(m)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   166
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   167
by (etac less_SucE 3);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   168
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   169
qed "diff_less_Suc";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   170
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   171
goal Arith.thy "!!m::nat. m - n <= m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   172
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   173
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   174
qed "diff_le_self";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   175
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   176
goal Arith.thy "!!n::nat. (n+m) - n = m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   177
by (nat_ind_tac "n" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   178
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   179
qed "diff_add_inverse";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   180
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   181
goal Arith.thy "!!n::nat. n - (n+m) = 0";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   182
by (nat_ind_tac "n" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   183
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   184
qed "diff_add_0";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   185
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   186
(*In ordinary notation: if 0<n and n<=m then m-n < m *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   187
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   188
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   189
by (fast_tac HOL_cs 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   190
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   191
by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc])));
1398
b8de98c2c29c Changed div_termination -> diff_less
nipkow
parents: 1327
diff changeset
   192
qed "diff_less";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   193
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   194
val wf_less_trans = wf_pred_nat RS wf_trancl RSN (2, def_wfrec RS trans);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   195
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 965
diff changeset
   196
goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   197
by (rtac refl 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   198
qed "less_eq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   199
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   200
goal Arith.thy "(%m. m mod n) = wfrec (trancl pred_nat) \
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   201
             \                      (%f j. if j<n then j else f (j-n))";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   202
by (simp_tac (HOL_ss addsimps [mod_def]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   203
val mod_def1 = result() RS eq_reflection;
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   204
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   205
goal Arith.thy "!!m. m<n ==> m mod n = m";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   206
by (rtac (mod_def1 RS wf_less_trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   207
by(Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   208
qed "mod_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   209
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   210
goal Arith.thy "!!m. [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   211
by (rtac (mod_def1 RS wf_less_trans) 1);
1398
b8de98c2c29c Changed div_termination -> diff_less
nipkow
parents: 1327
diff changeset
   212
by(asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   213
qed "mod_geq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   214
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   215
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   216
(*** Quotient ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   217
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   218
goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   219
                        \            (%f j. if j<n then 0 else Suc (f (j-n)))";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   220
by (simp_tac (HOL_ss addsimps [div_def]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   221
val div_def1 = result() RS eq_reflection;
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   222
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   223
goal Arith.thy "!!m. m<n ==> m div n = 0";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   224
by (rtac (div_def1 RS wf_less_trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   225
by(Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   226
qed "div_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   227
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   228
goal Arith.thy "!!M. [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   229
by (rtac (div_def1 RS wf_less_trans) 1);
1398
b8de98c2c29c Changed div_termination -> diff_less
nipkow
parents: 1327
diff changeset
   230
by(asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   231
qed "div_geq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   232
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   233
(*Main Result about quotient and remainder.*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   234
goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   235
by (res_inst_tac [("n","m")] less_induct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   236
by (rename_tac "k" 1);    (*Variable name used in line below*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   237
by (case_tac "k<n" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   238
by (ALLGOALS (asm_simp_tac(!simpset addsimps (add_ac @
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   239
                       [mod_less, mod_geq, div_less, div_geq,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   240
                        add_diff_inverse, diff_less]))));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   241
qed "mod_div_equality";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   242
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   243
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   244
(*** More results about difference ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   245
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   246
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   247
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   248
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   249
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   250
qed "less_imp_diff_is_0";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   251
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   252
val prems = goal Arith.thy "m-n = 0  -->  n-m = 0  -->  m=n";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   253
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   254
by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   255
qed_spec_mp "diffs0_imp_equal";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   256
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   257
val [prem] = goal Arith.thy "m<n ==> 0<n-m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   258
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   259
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   260
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   261
qed "less_imp_diff_positive";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   262
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   263
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   264
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   265
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   266
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   267
qed "Suc_diff_n";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   268
1398
b8de98c2c29c Changed div_termination -> diff_less
nipkow
parents: 1327
diff changeset
   269
goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   270
by(simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   271
                    setloop (split_tac [expand_if])) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   272
qed "if_Suc_diff_n";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   273
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   274
goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   275
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   276
by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o fast_tac HOL_cs));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   277
qed "zero_induct_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   278
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   279
val prems = goal Arith.thy "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   280
by (rtac (diff_self_eq_0 RS subst) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   281
by (rtac (zero_induct_lemma RS mp RS mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   282
by (REPEAT (ares_tac ([impI,allI]@prems) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   283
qed "zero_induct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   284
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   285
(*13 July 1992: loaded in 105.7s*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   286
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   287
(**** Additional theorems about "less than" ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   288
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   289
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   290
by (nat_ind_tac "n" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   291
by (ALLGOALS(Simp_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   292
by (REPEAT_FIRST (ares_tac [conjI, impI]));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   293
by (res_inst_tac [("x","0")] exI 2);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   294
by (Simp_tac 2);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   295
by (safe_tac HOL_cs);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   296
by (res_inst_tac [("x","Suc(k)")] exI 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   297
by (Simp_tac 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   298
qed_spec_mp "less_eq_Suc_add";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   299
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   300
goal Arith.thy "n <= ((m + n)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   301
by (nat_ind_tac "m" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   302
by (ALLGOALS Simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   303
by (etac le_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   304
by (rtac (lessI RS less_imp_le) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   305
qed "le_add2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   306
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   307
goal Arith.thy "n <= ((n + m)::nat)";
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   308
by (simp_tac (!simpset addsimps add_ac) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   309
by (rtac le_add2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   310
qed "le_add1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   311
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   312
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans)));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   313
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans)));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   314
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   315
(*"i <= j ==> i <= j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   316
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   317
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   318
(*"i <= j ==> i <= m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   319
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   320
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   321
(*"i < j ==> i < j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   322
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   323
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   324
(*"i < j ==> i < m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   325
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   326
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   327
goal Arith.thy "!!i. i+j < (k::nat) ==> i<k";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   328
be rev_mp 1;
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   329
by(nat_ind_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   330
by (ALLGOALS Asm_simp_tac);
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   331
by(fast_tac (HOL_cs addDs [Suc_lessD]) 1);
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   332
qed "add_lessD1";
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   333
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   334
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   335
by (eresolve_tac [le_trans] 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   336
by (resolve_tac [le_add1] 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   337
qed "le_imp_add_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   338
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   339
goal Arith.thy "!!k::nat. m < n ==> m < n+k";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   340
by (eresolve_tac [less_le_trans] 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   341
by (resolve_tac [le_add1] 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   342
qed "less_imp_add_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   343
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   344
goal Arith.thy "m+k<=n --> m<=(n::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   345
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   346
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   347
by (fast_tac (HOL_cs addDs [Suc_leD]) 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   348
qed_spec_mp "add_leD1";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   349
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   350
goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   351
by (safe_tac (HOL_cs addSDs [less_eq_Suc_add]));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   352
by (asm_full_simp_tac
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   353
    (!simpset delsimps [add_Suc_right]
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   354
                addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1);
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   355
by (eresolve_tac [subst] 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   356
by (simp_tac (!simpset addsimps [less_add_Suc1]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   357
qed "less_add_eq_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   358
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   359
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   360
(** Monotonicity of addition (from ZF/Arith) **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   361
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   362
(** Monotonicity results **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   363
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   364
(*strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   365
goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   366
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   367
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   368
qed "add_less_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   369
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   370
(*strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   371
goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   372
by (rtac (add_less_mono1 RS less_trans) 1);
1198
23be92d5bf4d tidied proof of add_less_mono
lcp
parents: 1152
diff changeset
   373
by (REPEAT (assume_tac 1));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   374
by (nat_ind_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   375
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   376
qed "add_less_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   377
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   378
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   379
val [lt_mono,le] = goal Arith.thy
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   380
     "[| !!i j::nat. i<j ==> f(i) < f(j);       \
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   381
\        i <= j                                 \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   382
\     |] ==> f(i) <= (f(j)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   383
by (cut_facts_tac [le] 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   384
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   385
by (fast_tac (HOL_cs addSIs [lt_mono]) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   386
qed "less_mono_imp_le_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   387
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   388
(*non-strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   389
goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   390
by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1);
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   391
by (eresolve_tac [add_less_mono1] 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   392
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   393
qed "add_le_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   394
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   395
(*non-strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   396
goal Arith.thy "!!k l::nat. [|i<=j;  k<=l |] ==> i + k <= j + l";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   397
by (etac (add_le_mono1 RS le_trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   398
by (simp_tac (!simpset addsimps [add_commute]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   399
(*j moves to the end because it is free while k, l are bound*)
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   400
by (eresolve_tac [add_le_mono1] 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   401
qed "add_le_mono";