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