src/HOL/Arith.ML
author paulson
Fri, 02 Oct 1998 10:41:35 +0200
changeset 5604 cd17004d09e1
parent 5598 6b8dee1a6ebb
child 5654 8b872d546b9e
permissions -rw-r--r--
tidying
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
4736
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
     4
    Copyright   1998  University of Cambridge
923
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.
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
     7
Some from the Hoare example from Norbert Galm
923
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
(*** Basic rewrite rules for the arithmetic operators ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
3896
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    12
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
(** Difference **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
    15
qed_goal "diff_0_eq_0" thy
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
    "0 - n = 0"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    17
 (fn _ => [induct_tac "n" 1,  ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    19
(*Must simplify BEFORE the induction!  (Else we get a critical pair)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
  Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
    21
qed_goal "diff_Suc_Suc" thy
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
    "Suc(m) - Suc(n) = m - n"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
 (fn _ =>
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    24
  [Simp_tac 1, induct_tac "n" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    26
Addsimps [diff_0_eq_0, diff_Suc_Suc];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    28
(* Could be (and is, below) generalized in various ways;
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    29
   However, none of the generalizations are currently in the simpset,
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    30
   and I dread to think what happens if I put them in *)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
    31
Goal "0 < n ==> Suc(n-1) = n";
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    32
by (asm_simp_tac (simpset() addsplits [nat.split]) 1);
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    33
qed "Suc_pred";
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    34
Addsimps [Suc_pred];
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    35
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    36
Delsimps [diff_Suc];
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    37
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
(**** Inductive properties of the operators ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
(*** Addition ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
    43
qed_goal "add_0_right" thy "m + 0 = m"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    44
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
    46
qed_goal "add_Suc_right" thy "m + Suc(n) = Suc(m+n)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    47
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    49
Addsimps [add_0_right,add_Suc_right];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
(*Associative law for addition*)
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
    52
qed_goal "add_assoc" thy "(m + n) + k = m + ((n + k)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    53
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
(*Commutative law for addition*)  
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
    56
qed_goal "add_commute" thy "m + n = n + (m::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    57
 (fn _ =>  [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
    59
qed_goal "add_left_commute" thy "x+(y+z)=y+((x+z)::nat)"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
 (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
    61
           rtac (add_commute RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
(*Addition is an AC-operator*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
val add_ac = [add_assoc, add_commute, add_left_commute];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    66
Goal "(k + m = k + n) = (m=(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    67
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    68
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    69
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
qed "add_left_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    72
Goal "(m + k = n + k) = (m=(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    73
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    74
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    75
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
qed "add_right_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    78
Goal "(k + m <= k + n) = (m<=(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    79
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    80
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    81
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
qed "add_left_cancel_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    84
Goal "(k + m < k + n) = (m<(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    85
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    86
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    87
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
qed "add_left_cancel_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
    90
Addsimps [add_left_cancel, add_right_cancel,
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
    91
          add_left_cancel_le, add_left_cancel_less];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
    92
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    93
(** Reasoning about m+0=0, etc. **)
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    94
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    95
Goal "(m+n = 0) = (m=0 & n=0)";
5598
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
    96
by (exhaust_tac "m" 1);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
    97
by (Auto_tac);
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
    98
qed "add_is_0";
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    99
AddIffs [add_is_0];
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   100
5598
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   101
Goal "(0 = m+n) = (m=0 & n=0)";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   102
by (exhaust_tac "m" 1);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   103
by (Auto_tac);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   104
qed "zero_is_add";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   105
AddIffs [zero_is_add];
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   106
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   107
Goal "(m+n=1) = (m=1 & n=0 | m=0 & n=1)";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   108
by(exhaust_tac "m" 1);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   109
by(Auto_tac);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   110
qed "add_is_1";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   111
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   112
Goal "(1=m+n) = (m=1 & n=0 | m=0 & n=1)";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   113
by(exhaust_tac "m" 1);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   114
by(Auto_tac);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   115
qed "one_is_add";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   116
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   117
Goal "(0<m+n) = (0<m | 0<n)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   118
by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1);
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   119
qed "add_gr_0";
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   120
AddIffs [add_gr_0];
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   121
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   122
(* FIXME: really needed?? *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   123
Goal "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)";
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   124
by (exhaust_tac "m" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   125
by (ALLGOALS (fast_tac (claset() addss (simpset()))));
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   126
qed "pred_add_is_0";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   127
Addsimps [pred_add_is_0];
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   128
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   129
(* Could be generalized, eg to "k<n ==> m+(n-(Suc k)) = (m+n)-(Suc k)" *)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   130
Goal "0<n ==> m + (n-1) = (m+n)-1";
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   131
by (exhaust_tac "m" 1);
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   132
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc]
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   133
                                      addsplits [nat.split])));
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   134
qed "add_pred";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   135
Addsimps [add_pred];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   136
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   137
Goal "m + n = m ==> n = 0";
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   138
by (dtac (add_0_right RS ssubst) 1);
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   139
by (asm_full_simp_tac (simpset() addsimps [add_assoc]
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   140
                                 delsimps [add_0_right]) 1);
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   141
qed "add_eq_self_zero";
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   142
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   143
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   144
(**** Additional theorems about "less than" ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   146
(*Deleted less_natE; instead use less_eq_Suc_add RS exE*)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   147
Goal "m<n --> (? k. n=Suc(m+k))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   148
by (induct_tac "n" 1);
5604
cd17004d09e1 tidying
paulson
parents: 5598
diff changeset
   149
by (ALLGOALS (simp_tac (simpset() addsimps [order_le_less])));
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   150
by (blast_tac (claset() addSEs [less_SucE] 
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   151
                        addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   152
qed_spec_mp "less_eq_Suc_add";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   153
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   154
Goal "n <= ((m + n)::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   155
by (induct_tac "m" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   156
by (ALLGOALS Simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   157
by (etac le_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   158
by (rtac (lessI RS less_imp_le) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   159
qed "le_add2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   160
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   161
Goal "n <= ((n + m)::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   162
by (simp_tac (simpset() addsimps add_ac) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   163
by (rtac le_add2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
qed "le_add1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   165
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   166
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
   167
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
   168
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   169
Goal "(m<n) = (? k. n=Suc(m+k))";
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   170
by (blast_tac (claset() addSIs [less_add_Suc1, less_eq_Suc_add]) 1);
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   171
qed "less_iff_Suc_add";
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   172
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   173
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   174
(*"i <= j ==> i <= j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   175
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   176
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   177
(*"i <= j ==> i <= m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   178
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   179
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   180
(*"i < j ==> i < j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   181
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
   182
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   183
(*"i < j ==> i < m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   184
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
   185
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   186
Goal "i+j < (k::nat) ==> i<k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   187
by (etac rev_mp 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   188
by (induct_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   189
by (ALLGOALS Asm_simp_tac);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   190
by (blast_tac (claset() addDs [Suc_lessD]) 1);
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   191
qed "add_lessD1";
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   192
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   193
Goal "~ (i+j < (i::nat))";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   194
by (rtac notI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   195
by (etac (add_lessD1 RS less_irrefl) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   196
qed "not_add_less1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   197
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   198
Goal "~ (j+i < (i::nat))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   199
by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   200
qed "not_add_less2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   201
AddIffs [not_add_less1, not_add_less2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   202
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   203
Goal "m+k<=n --> m<=(n::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   204
by (induct_tac "k" 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   205
by (ALLGOALS (asm_simp_tac (simpset() addsimps le_simps)));
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   206
qed_spec_mp "add_leD1";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   207
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   208
Goal "m+k<=n ==> k<=(n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   209
by (full_simp_tac (simpset() addsimps [add_commute]) 1);
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   210
by (etac add_leD1 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   211
qed_spec_mp "add_leD2";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   212
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   213
Goal "m+k<=n ==> m<=n & k<=(n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   214
by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1);
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   215
bind_thm ("add_leE", result() RS conjE);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   216
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   217
(*needs !!k for add_ac to work*)
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   218
Goal "!!k:: nat. [| k<l;  m+l = k+n |] ==> m<n";
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   219
by (auto_tac (claset(),
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   220
	      simpset() delsimps [add_Suc_right]
5537
c2bd39a2c0ee deleted needless parentheses
paulson
parents: 5497
diff changeset
   221
	                addsimps [less_iff_Suc_add,
c2bd39a2c0ee deleted needless parentheses
paulson
parents: 5497
diff changeset
   222
				  add_Suc_right RS sym] @ add_ac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   223
qed "less_add_eq_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   224
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   225
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   226
(*** Monotonicity of Addition ***)
923
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
(*strict, in 1st argument*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   229
Goal "i < j ==> i + k < j + (k::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   230
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   231
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   232
qed "add_less_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   233
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   234
(*strict, in both arguments*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   235
Goal "[|i < j; k < l|] ==> i + k < j + (l::nat)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   236
by (rtac (add_less_mono1 RS less_trans) 1);
1198
23be92d5bf4d tidied proof of add_less_mono
lcp
parents: 1152
diff changeset
   237
by (REPEAT (assume_tac 1));
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   238
by (induct_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   239
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   240
qed "add_less_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   241
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   242
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5270
diff changeset
   243
val [lt_mono,le] = Goal
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   244
     "[| !!i j::nat. i<j ==> f(i) < f(j);       \
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   245
\        i <= j                                 \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   246
\     |] ==> f(i) <= (f(j)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   247
by (cut_facts_tac [le] 1);
5604
cd17004d09e1 tidying
paulson
parents: 5598
diff changeset
   248
by (asm_full_simp_tac (simpset() addsimps [order_le_less]) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   249
by (blast_tac (claset() addSIs [lt_mono]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   250
qed "less_mono_imp_le_mono";
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
(*non-strict, in 1st argument*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   253
Goal "i<=j ==> i + k <= j + (k::nat)";
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3724
diff changeset
   254
by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   255
by (etac add_less_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   256
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   257
qed "add_le_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   258
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   259
(*non-strict, in both arguments*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   260
Goal "[|i<=j;  k<=l |] ==> i + k <= j + (l::nat)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   261
by (etac (add_le_mono1 RS le_trans) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   262
by (simp_tac (simpset() addsimps [add_commute]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   263
qed "add_le_mono";
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   264
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   265
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   266
(*** Multiplication ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   267
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   268
(*right annihilation in product*)
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   269
qed_goal "mult_0_right" thy "m * 0 = 0"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   270
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   271
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   272
(*right successor law for multiplication*)
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   273
qed_goal "mult_Suc_right" thy  "m * Suc(n) = m + (m * n)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   274
 (fn _ => [induct_tac "m" 1,
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   275
           ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   276
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   277
Addsimps [mult_0_right, mult_Suc_right];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   278
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   279
Goal "1 * n = n";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   280
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   281
qed "mult_1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   282
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   283
Goal "n * 1 = n";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   284
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   285
qed "mult_1_right";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   286
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   287
(*Commutative law for multiplication*)
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   288
qed_goal "mult_commute" thy "m * n = n * (m::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   289
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   290
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   291
(*addition distributes over multiplication*)
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   292
qed_goal "add_mult_distrib" thy "(m + n)*k = (m*k) + ((n*k)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   293
 (fn _ => [induct_tac "m" 1,
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   294
           ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   295
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   296
qed_goal "add_mult_distrib2" thy "k*(m + n) = (k*m) + ((k*n)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   297
 (fn _ => [induct_tac "m" 1,
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   298
           ALLGOALS(asm_simp_tac (simpset() addsimps add_ac))]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   299
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   300
(*Associative law for multiplication*)
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   301
qed_goal "mult_assoc" thy "(m * n) * k = m * ((n * k)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   302
  (fn _ => [induct_tac "m" 1, 
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   303
            ALLGOALS (asm_simp_tac (simpset() addsimps [add_mult_distrib]))]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   304
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   305
qed_goal "mult_left_commute" thy "x*(y*z) = y*((x*z)::nat)"
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   306
 (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   307
           rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   308
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   309
val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   310
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   311
Goal "(m*n = 0) = (m=0 | n=0)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   312
by (induct_tac "m" 1);
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   313
by (induct_tac "n" 2);
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   314
by (ALLGOALS Asm_simp_tac);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   315
qed "mult_is_0";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   316
Addsimps [mult_is_0];
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   317
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   318
Goal "m <= m*(m::nat)";
4158
47c7490c74fe Expandshort; new theorem le_square
paulson
parents: 4089
diff changeset
   319
by (induct_tac "m" 1);
47c7490c74fe Expandshort; new theorem le_square
paulson
parents: 4089
diff changeset
   320
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_assoc RS sym])));
47c7490c74fe Expandshort; new theorem le_square
paulson
parents: 4089
diff changeset
   321
by (etac (le_add2 RSN (2,le_trans)) 1);
47c7490c74fe Expandshort; new theorem le_square
paulson
parents: 4089
diff changeset
   322
qed "le_square";
47c7490c74fe Expandshort; new theorem le_square
paulson
parents: 4089
diff changeset
   323
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   324
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   325
(*** Difference ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   326
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   327
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   328
qed_goal "diff_self_eq_0" thy "m - m = 0"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   329
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   330
Addsimps [diff_self_eq_0];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   331
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   332
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   333
Goal "~ m<n --> n+(m-n) = (m::nat)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   334
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   335
by (ALLGOALS Asm_simp_tac);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   336
qed_spec_mp "add_diff_inverse";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   337
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   338
Goal "n<=m ==> n+(m-n) = (m::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   339
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, not_less_iff_le]) 1);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   340
qed "le_add_diff_inverse";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   341
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   342
Goal "n<=m ==> (m-n)+n = (m::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   343
by (asm_simp_tac (simpset() addsimps [le_add_diff_inverse, add_commute]) 1);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   344
qed "le_add_diff_inverse2";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   345
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   346
Addsimps  [le_add_diff_inverse, le_add_diff_inverse2];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   347
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   348
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   349
(*** More results about difference ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   350
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   351
Goal "n <= m ==> Suc(m)-n = Suc(m-n)";
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5270
diff changeset
   352
by (etac rev_mp 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   353
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   354
by (ALLGOALS Asm_simp_tac);
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   355
qed "Suc_diff_le";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   356
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   357
Goal "n<=(l::nat) --> Suc l - n + m = Suc (l - n + m)";
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   358
by (res_inst_tac [("m","n"),("n","l")] diff_induct 1);
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   359
by (ALLGOALS Asm_simp_tac);
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   360
qed_spec_mp "Suc_diff_add_le";
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   361
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   362
Goal "m - n < Suc(m)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   363
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   364
by (etac less_SucE 3);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   365
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq])));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   366
qed "diff_less_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   367
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   368
Goal "m - n <= (m::nat)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   369
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   370
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   371
qed "diff_le_self";
3903
1b29151a1009 New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents: 3896
diff changeset
   372
Addsimps [diff_le_self];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   373
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   374
(* j<k ==> j-n < k *)
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   375
bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans);
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   376
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   377
Goal "!!i::nat. i-j-k = i - (j+k)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   378
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   379
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   380
qed "diff_diff_left";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   381
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   382
Goal "(Suc m - n) - Suc k = m - n - k";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   383
by (simp_tac (simpset() addsimps [diff_diff_left]) 1);
4736
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   384
qed "Suc_diff_diff";
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   385
Addsimps [Suc_diff_diff];
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   386
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   387
Goal "0<n ==> n - Suc i < n";
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   388
by (exhaust_tac "n" 1);
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   389
by Safe_tac;
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   390
by (asm_simp_tac (simpset() addsimps le_simps) 1);
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   391
qed "diff_Suc_less";
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   392
Addsimps [diff_Suc_less];
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   393
5329
1003ddc30299 new theorem diff_Suc_less_diff
paulson
parents: 5316
diff changeset
   394
Goal "i<n ==> n - Suc i < n - i";
1003ddc30299 new theorem diff_Suc_less_diff
paulson
parents: 5316
diff changeset
   395
by (exhaust_tac "n" 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   396
by (auto_tac (claset(),
5537
c2bd39a2c0ee deleted needless parentheses
paulson
parents: 5497
diff changeset
   397
	      simpset() addsimps [Suc_diff_le]@le_simps));
5329
1003ddc30299 new theorem diff_Suc_less_diff
paulson
parents: 5316
diff changeset
   398
qed "diff_Suc_less_diff";
1003ddc30299 new theorem diff_Suc_less_diff
paulson
parents: 5316
diff changeset
   399
3396
aa74c71c3982 eliminated non-ASCII;
wenzelm
parents: 3381
diff changeset
   400
(*This and the next few suggested by Florian Kammueller*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   401
Goal "!!i::nat. i-j-k = i-k-j";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   402
by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   403
qed "diff_commute";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   404
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   405
Goal "k<=j --> j<=i --> i - (j - k) = i - j + (k::nat)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   406
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   407
by (ALLGOALS Asm_simp_tac);
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   408
by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   409
qed_spec_mp "diff_diff_right";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   410
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   411
Goal "k <= (j::nat) --> (i + j) - k = i + (j - k)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   412
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   413
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   414
qed_spec_mp "diff_add_assoc";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   415
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   416
Goal "k <= (j::nat) --> (j + i) - k = i + (j - k)";
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   417
by (asm_simp_tac (simpset() addsimps [add_commute, diff_add_assoc]) 1);
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   418
qed_spec_mp "diff_add_assoc2";
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   419
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   420
Goal "(n+m) - n = (m::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   421
by (induct_tac "n" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   422
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   423
qed "diff_add_inverse";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   424
Addsimps [diff_add_inverse];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   425
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   426
Goal "(m+n) - n = (m::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   427
by (simp_tac (simpset() addsimps [diff_add_assoc]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   428
qed "diff_add_inverse2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   429
Addsimps [diff_add_inverse2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   430
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   431
Goal "i <= (j::nat) ==> (j-i=k) = (j=k+i)";
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   432
by Safe_tac;
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   433
by (ALLGOALS Asm_simp_tac);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents: 3352
diff changeset
   434
qed "le_imp_diff_is_add";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents: 3352
diff changeset
   435
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   436
Goal "(m-n = 0) = (m <= n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   437
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   438
by (ALLGOALS Asm_simp_tac);
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   439
qed "diff_is_0_eq";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   440
Addsimps [diff_is_0_eq RS iffD2];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   441
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5270
diff changeset
   442
Goal "m-n = 0  -->  n-m = 0  -->  m=n";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   443
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   444
by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   445
qed_spec_mp "diffs0_imp_equal";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   446
5333
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   447
Goal "(0<n-m) = (m<n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   448
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   449
by (ALLGOALS Asm_simp_tac);
5333
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   450
qed "zero_less_diff";
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   451
Addsimps [zero_less_diff];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   452
5333
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   453
Goal "i < j  ==> ? k. 0<k & i+k = j";
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   454
by (res_inst_tac [("x","j - i")] exI 1);
5333
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   455
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, less_not_sym]) 1);
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   456
qed "less_imp_add_positive";
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   457
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   458
Goal "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   459
by (simp_tac (simpset() addsimps [leI, Suc_le_eq, Suc_diff_le]) 1);
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   460
qed "if_Suc_diff_le";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   461
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   462
Goal "Suc(m)-n <= Suc(m-n)";
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   463
by (simp_tac (simpset() addsimps [if_Suc_diff_le]) 1);
4672
9d55bc687e1e New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents: 4423
diff changeset
   464
qed "diff_Suc_le_Suc_diff";
9d55bc687e1e New theorem diff_Suc_le_Suc_diff; tidied another proof
paulson
parents: 4423
diff changeset
   465
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   466
Goal "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   467
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3484
diff changeset
   468
by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   469
qed "zero_induct_lemma";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   470
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5270
diff changeset
   471
val prems = Goal "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   472
by (rtac (diff_self_eq_0 RS subst) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   473
by (rtac (zero_induct_lemma RS mp RS mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   474
by (REPEAT (ares_tac ([impI,allI]@prems) 1));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   475
qed "zero_induct";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   476
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   477
Goal "(k+m) - (k+n) = m - (n::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   478
by (induct_tac "k" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   479
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   480
qed "diff_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   481
Addsimps [diff_cancel];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   482
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   483
Goal "(m+k) - (n+k) = m - (n::nat)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   484
val add_commute_k = read_instantiate [("n","k")] add_commute;
5537
c2bd39a2c0ee deleted needless parentheses
paulson
parents: 5497
diff changeset
   485
by (asm_simp_tac (simpset() addsimps [add_commute_k]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   486
qed "diff_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   487
Addsimps [diff_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   488
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   489
(*From Clemens Ballarin, proof by lcp*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   490
Goal "[| k<=n; n<=m |] ==> (m-k) - (n-k) = m-(n::nat)";
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   491
by (REPEAT (etac rev_mp 1));
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   492
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   493
by (ALLGOALS Asm_simp_tac);
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   494
(*a confluence problem*)
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   495
by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   496
qed "diff_right_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   497
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   498
Goal "n - (n+m) = 0";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   499
by (induct_tac "n" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   500
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   501
qed "diff_add_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   502
Addsimps [diff_add_0];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   503
5409
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   504
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   505
(** Difference distributes over multiplication **)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   506
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   507
Goal "!!m::nat. (m - n) * k = (m * k) - (n * k)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   508
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   509
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   510
qed "diff_mult_distrib" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   511
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   512
Goal "!!m::nat. k * (m - n) = (k * m) - (k * n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   513
val mult_commute_k = read_instantiate [("m","k")] mult_commute;
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   514
by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   515
qed "diff_mult_distrib2" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   516
(*NOT added as rewrites, since sometimes they are used from right-to-left*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   517
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   518
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   519
(*** Monotonicity of Multiplication ***)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   520
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   521
Goal "i <= (j::nat) ==> i*k<=j*k";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   522
by (induct_tac "k" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   523
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono])));
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   524
qed "mult_le_mono1";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   525
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   526
(*<=monotonicity, BOTH arguments*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   527
Goal "[| i <= (j::nat); k <= l |] ==> i*k <= j*l";
2007
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   528
by (etac (mult_le_mono1 RS le_trans) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   529
by (rtac le_trans 1);
2007
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   530
by (stac mult_commute 2);
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   531
by (etac mult_le_mono1 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   532
by (simp_tac (simpset() addsimps [mult_commute]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   533
qed "mult_le_mono";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   534
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   535
(*strict, in 1st argument; proof is by induction on k>0*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   536
Goal "[| i<j; 0<k |] ==> k*i < k*j";
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   537
by (eres_inst_tac [("m1","0")] (less_eq_Suc_add RS exE) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   538
by (Asm_simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   539
by (induct_tac "x" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   540
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono])));
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   541
qed "mult_less_mono2";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   542
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   543
Goal "[| i<j; 0<k |] ==> i*k < j*k";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   544
by (dtac mult_less_mono2 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   545
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute])));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   546
qed "mult_less_mono1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   547
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   548
Goal "(0 < m*n) = (0<m & 0<n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   549
by (induct_tac "m" 1);
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   550
by (induct_tac "n" 2);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   551
by (ALLGOALS Asm_simp_tac);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   552
qed "zero_less_mult_iff";
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4297
diff changeset
   553
Addsimps [zero_less_mult_iff];
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   554
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   555
Goal "(m*n = 1) = (m=1 & n=1)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   556
by (induct_tac "m" 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   557
by (Simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   558
by (induct_tac "n" 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   559
by (Simp_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   560
by (fast_tac (claset() addss simpset()) 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   561
qed "mult_eq_1_iff";
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4297
diff changeset
   562
Addsimps [mult_eq_1_iff];
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   563
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   564
Goal "0<k ==> (m*k < n*k) = (m<n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   565
by (safe_tac (claset() addSIs [mult_less_mono1]));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   566
by (cut_facts_tac [less_linear] 1);
4389
1865cb8df116 Faster proof of mult_less_cancel2
paulson
parents: 4378
diff changeset
   567
by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   568
qed "mult_less_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   569
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   570
Goal "0<k ==> (k*m < k*n) = (m<n)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   571
by (dtac mult_less_cancel2 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   572
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   573
qed "mult_less_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   574
Addsimps [mult_less_cancel1, mult_less_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   575
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   576
Goal "(Suc k * m < Suc k * n) = (m < n)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   577
by (rtac mult_less_cancel1 1);
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   578
by (Simp_tac 1);
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   579
qed "Suc_mult_less_cancel1";
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   580
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   581
Goalw [le_def] "(Suc k * m <= Suc k * n) = (m <= n)";
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   582
by (simp_tac (simpset_of HOL.thy) 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   583
by (rtac Suc_mult_less_cancel1 1);
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   584
qed "Suc_mult_le_cancel1";
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   585
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   586
Goal "0<k ==> (m*k = n*k) = (m=n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   587
by (cut_facts_tac [less_linear] 1);
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   588
by Safe_tac;
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   589
by (assume_tac 2);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   590
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   591
by (ALLGOALS Asm_full_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   592
qed "mult_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   593
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   594
Goal "0<k ==> (k*m = k*n) = (m=n)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   595
by (dtac mult_cancel2 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   596
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   597
qed "mult_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   598
Addsimps [mult_cancel1, mult_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   599
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   600
Goal "(Suc k * m = Suc k * n) = (m = n)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   601
by (rtac mult_cancel1 1);
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   602
by (Simp_tac 1);
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   603
qed "Suc_mult_cancel1";
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   604
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   605
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   606
(** Lemma for gcd **)
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   607
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   608
Goal "m = m*n ==> n=1 | m=0";
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   609
by (dtac sym 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   610
by (rtac disjCI 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   611
by (rtac nat_less_cases 1 THEN assume_tac 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   612
by (fast_tac (claset() addSEs [less_SucE] addss simpset()) 1);
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4297
diff changeset
   613
by (best_tac (claset() addDs [mult_less_mono2] addss simpset()) 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   614
qed "mult_eq_self_implies_10";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   615
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   616
4736
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   617
(*** Subtraction laws -- mostly from Clemens Ballarin ***)
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   618
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   619
Goal "[| a < (b::nat); c <= a |] ==> a-c < b-c";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   620
by (subgoal_tac "c+(a-c) < c+(b-c)" 1);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   621
by (Full_simp_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   622
by (subgoal_tac "c <= b" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   623
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 2);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   624
by (Asm_simp_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   625
qed "diff_less_mono";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   626
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   627
Goal "a+b < (c::nat) ==> a < c-b";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   628
by (dtac diff_less_mono 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   629
by (rtac le_add2 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   630
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   631
qed "add_less_imp_less_diff";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   632
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5414
diff changeset
   633
Goal "(i < j-k) = (i+k < (j::nat))";
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   634
by (rtac iffI 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   635
 by (case_tac "k <= j" 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   636
  by (dtac le_add_diff_inverse2 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   637
  by (dres_inst_tac [("k","k")] add_less_mono1 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   638
  by (Asm_full_simp_tac 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   639
 by (rotate_tac 1 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   640
 by (asm_full_simp_tac (simpset() addSolver cut_trans_tac) 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   641
by (etac add_less_imp_less_diff 1);
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5414
diff changeset
   642
qed "less_diff_conv";
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5414
diff changeset
   643
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   644
Goal "(j-k <= (i::nat)) = (j <= i+k)";
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   645
by (simp_tac (simpset() addsimps [less_diff_conv, le_def]) 1);
5485
0cd451e46a20 new theorem le_diff_conv
paulson
parents: 5429
diff changeset
   646
qed "le_diff_conv";
0cd451e46a20 new theorem le_diff_conv
paulson
parents: 5429
diff changeset
   647
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   648
Goal "k <= j ==> (i <= j-k) = (i+k <= (j::nat))";
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   649
by (asm_full_simp_tac
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   650
    (simpset() delsimps [less_Suc_eq_le]
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   651
               addsimps [less_Suc_eq_le RS sym, less_diff_conv,
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   652
			 Suc_diff_le RS sym]) 1);
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   653
qed "le_diff_conv2";
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   654
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   655
Goal "Suc i <= n ==> Suc (n - Suc i) = n - i";
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   656
by (asm_full_simp_tac (simpset() addsimps [Suc_diff_le RS sym]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   657
qed "Suc_diff_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   658
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   659
Goal "i <= (n::nat) ==> n - (n - i) = i";
3903
1b29151a1009 New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents: 3896
diff changeset
   660
by (etac rev_mp 1);
1b29151a1009 New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents: 3896
diff changeset
   661
by (res_inst_tac [("m","n"),("n","i")] diff_induct 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   662
by (ALLGOALS (asm_simp_tac  (simpset() addsimps [Suc_diff_le])));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   663
qed "diff_diff_cancel";
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   664
Addsimps [diff_diff_cancel];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   665
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   666
Goal "k <= (n::nat) ==> m <= n + m - k";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   667
by (etac rev_mp 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   668
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   669
by (Simp_tac 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   670
by (simp_tac (simpset() addsimps [le_add2, less_imp_le]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   671
by (Simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   672
qed "le_add_diff";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   673
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   674
Goal "0<k ==> j<i --> j+k-i < k";
4736
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   675
by (res_inst_tac [("m","j"),("n","i")] diff_induct 1);
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   676
by (ALLGOALS Asm_simp_tac);
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   677
qed_spec_mp "add_diff_less";
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   678
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   679
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   680
Goal "m-1 < n ==> m <= n";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   681
by (exhaust_tac "m" 1);
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   682
by (auto_tac (claset(), simpset() addsimps [Suc_le_eq]));
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   683
qed "pred_less_imp_le";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   684
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   685
Goal "j<=i ==> i - j < Suc i - j";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   686
by (REPEAT (etac rev_mp 1));
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   687
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   688
by Auto_tac;
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   689
qed "diff_less_Suc_diff";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   690
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   691
Goal "i - j <= Suc i - j";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   692
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   693
by Auto_tac;
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   694
qed "diff_le_Suc_diff";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   695
AddIffs [diff_le_Suc_diff];
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   696
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   697
Goal "n - Suc i <= n - i";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   698
by (case_tac "i<n" 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   699
by (dtac diff_Suc_less_diff 1);
5604
cd17004d09e1 tidying
paulson
parents: 5598
diff changeset
   700
by (auto_tac (claset(), simpset() addsimps [less_imp_le, leI]));
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   701
qed "diff_Suc_le_diff";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   702
AddIffs [diff_Suc_le_diff];
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   703
5409
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   704
Goal "0 < n ==> (m <= n-1) = (m<n)";
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   705
by (exhaust_tac "n" 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   706
by (auto_tac (claset(), simpset() addsimps le_simps));
5409
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   707
qed "le_pred_eq";
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   708
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   709
Goal "0 < n ==> (m-1 < n) = (m<=n)";
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   710
by (exhaust_tac "m" 1);
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   711
by (auto_tac (claset(), simpset() addsimps [Suc_le_eq]));
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   712
qed "less_pred_eq";
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   713
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   714
(*In ordinary notation: if 0<n and n<=m then m-n < m *)
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   715
Goal "[| 0<n; ~ m<n |] ==> m - n < m";
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   716
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   717
by (Blast_tac 1);
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   718
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   719
by (ALLGOALS(asm_simp_tac(simpset() addsimps [diff_less_Suc])));
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   720
qed "diff_less";
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   721
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   722
Goal "[| 0<n; n<=m |] ==> m - n < m";
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   723
by (asm_simp_tac (simpset() addsimps [diff_less, not_less_iff_le]) 1);
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   724
qed "le_diff_less";
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   725
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   726
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   727
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   728
(** (Anti)Monotonicity of subtraction -- by Stefan Merz **)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   729
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   730
(* Monotonicity of subtraction in first argument *)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   731
Goal "m <= (n::nat) --> (m-l) <= (n-l)";
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   732
by (induct_tac "n" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   733
by (Simp_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   734
by (simp_tac (simpset() addsimps [le_Suc_eq]) 1);
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   735
by (blast_tac (claset() addIs [diff_le_Suc_diff, le_trans]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   736
qed_spec_mp "diff_le_mono";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   737
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   738
Goal "m <= (n::nat) ==> (l-n) <= (l-m)";
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   739
by (induct_tac "l" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   740
by (Simp_tac 1);
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   741
by (case_tac "n <= na" 1);
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   742
by (subgoal_tac "m <= na" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   743
by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   744
by (fast_tac (claset() addEs [le_trans]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   745
by (dtac not_leE 1);
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   746
by (asm_simp_tac (simpset() addsimps [if_Suc_diff_le]) 1);
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   747
qed_spec_mp "diff_le_mono2";