src/HOL/Arith.ML
author nipkow
Thu, 16 Oct 1997 14:12:15 +0200
changeset 3896 ee8ebb74ec00
parent 3842 b55686a7b22c
child 3903 1b29151a1009
permissions -rw-r--r--
Various new lemmas. Improved conversion of equations to rewrite rules: (s=t becomes (s=t)==True if s=t loops).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     1
(*  Title:      HOL/Arith.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Proofs about elementary arithmetic: addition, multiplication, etc.
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
2099
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    12
goalw Arith.thy [pred_def] "pred 0 = 0";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
    13
by (Simp_tac 1);
2099
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    14
qed "pred_0";
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    15
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    16
goalw Arith.thy [pred_def] "pred(Suc n) = n";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
    17
by (Simp_tac 1);
2099
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    18
qed "pred_Suc";
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    19
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    20
Addsimps [pred_0,pred_Suc];
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    21
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    22
(** pred **)
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    23
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    24
val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    25
by (res_inst_tac [("n","n")] natE 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    26
by (cut_facts_tac prems 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    27
by (ALLGOALS Asm_full_simp_tac);
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    28
qed "Suc_pred";
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    29
Addsimps [Suc_pred];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    31
goal Arith.thy "pred(n) <= (n::nat)";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    32
by (res_inst_tac [("n","n")] natE 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    33
by (ALLGOALS Asm_simp_tac);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    34
qed "pred_le";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    35
AddIffs [pred_le];
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    36
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    37
goalw Arith.thy [pred_def] "m<=n --> pred(m) <= pred(n)";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    38
by(simp_tac (!simpset setloop (split_tac[expand_nat_case])) 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    39
qed_spec_mp "pred_le_mono";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
    40
3896
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    41
goal Arith.thy "!!n. n ~= 0 ==> pred n < n";
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    42
by(exhaust_tac "n" 1);
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    43
by(ALLGOALS Asm_full_simp_tac);
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    44
qed "pred_less";
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    45
Addsimps [pred_less];
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    46
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
(** Difference **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    49
qed_goalw "diff_0_eq_0" Arith.thy [pred_def]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
    "0 - n = 0"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    51
 (fn _ => [induct_tac "n" 1,  ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
(*Must simplify BEFORE the induction!!  (Else we get a critical pair)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
  Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    55
qed_goalw "diff_Suc_Suc" Arith.thy [pred_def]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
    "Suc(m) - Suc(n) = m - n"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
 (fn _ =>
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    58
  [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
    59
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    60
Addsimps [diff_0_eq_0, diff_Suc_Suc];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
(**** Inductive properties of the operators ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
(*** Addition ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
qed_goal "add_0_right" Arith.thy "m + 0 = m"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    68
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    71
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    73
Addsimps [add_0_right,add_Suc_right];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
(*Associative law for addition*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    77
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
(*Commutative law for addition*)  
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    81
 (fn _ =>  [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
 (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
    85
           rtac (add_commute RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
(*Addition is an AC-operator*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
val add_ac = [add_assoc, add_commute, add_left_commute];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    91
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    92
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    93
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
qed "add_left_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    97
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    98
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    99
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
qed "add_right_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   103
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   104
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   105
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
qed "add_left_cancel_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   109
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   110
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   111
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
qed "add_left_cancel_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   113
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   114
Addsimps [add_left_cancel, add_right_cancel,
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   115
          add_left_cancel_le, add_left_cancel_less];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   116
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   117
(** Reasoning about m+0=0, etc. **)
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   118
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   119
goal Arith.thy "(m+n = 0) = (m=0 & n=0)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   120
by (induct_tac "m" 1);
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   121
by (ALLGOALS Asm_simp_tac);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   122
qed "add_is_0";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   123
Addsimps [add_is_0];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   124
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   125
goal Arith.thy "(pred (m+n) = 0) = (m=0 & pred n = 0 | pred m = 0 & n=0)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   126
by (induct_tac "m" 1);
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   127
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   128
qed "pred_add_is_0";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   129
Addsimps [pred_add_is_0];
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   130
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   131
goal Arith.thy "!!n. n ~= 0 ==> m + pred n = pred(m+n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   132
by (induct_tac "m" 1);
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   133
by (ALLGOALS Asm_simp_tac);
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
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   137
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
(**** Additional theorems about "less than" ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   140
goal Arith.thy "i<j --> (EX k. j = Suc(i+k))";
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   141
by (induct_tac "j" 1);
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   142
by (Simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   143
by (blast_tac (!claset addSEs [less_SucE] 
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   144
                       addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1);
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   145
val lemma = result();
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   146
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   147
(* [| i<j;  !!x. j = Suc(i+x) ==> Q |] ==> Q *)
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   148
bind_thm ("less_natE", lemma RS mp RS exE);
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   149
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   150
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   151
by (induct_tac "n" 1);
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   152
by (ALLGOALS (simp_tac (!simpset addsimps [less_Suc_eq])));
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   153
by (blast_tac (!claset addSEs [less_SucE] 
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   154
                       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
   155
qed_spec_mp "less_eq_Suc_add";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   156
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   157
goal Arith.thy "n <= ((m + n)::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   158
by (induct_tac "m" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   159
by (ALLGOALS Simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   160
by (etac le_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   161
by (rtac (lessI RS less_imp_le) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   162
qed "le_add2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   163
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
goal Arith.thy "n <= ((n + m)::nat)";
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   165
by (simp_tac (!simpset addsimps add_ac) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   166
by (rtac le_add2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   167
qed "le_add1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   168
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   169
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
   170
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
   171
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   172
(*"i <= j ==> i <= j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   173
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   174
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   175
(*"i <= j ==> i <= m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   176
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   177
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   178
(*"i < j ==> i < j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   179
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
   180
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   181
(*"i < j ==> i < m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   182
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
   183
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   184
goal Arith.thy "!!i. i+j < (k::nat) ==> i<k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   185
by (etac rev_mp 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   186
by (induct_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   187
by (ALLGOALS Asm_simp_tac);
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   188
by (blast_tac (!claset addDs [Suc_lessD]) 1);
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   189
qed "add_lessD1";
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   190
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   191
goal Arith.thy "!!i::nat. ~ (i+j < i)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   192
by (rtac notI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   193
by (etac (add_lessD1 RS less_irrefl) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   194
qed "not_add_less1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   195
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   196
goal Arith.thy "!!i::nat. ~ (j+i < i)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   197
by (simp_tac (!simpset addsimps [add_commute, not_add_less1]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   198
qed "not_add_less2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   199
AddIffs [not_add_less1, not_add_less2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   200
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   201
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   202
by (etac le_trans 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   203
by (rtac le_add1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   204
qed "le_imp_add_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   205
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   206
goal Arith.thy "!!k::nat. m < n ==> m < n+k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   207
by (etac less_le_trans 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   208
by (rtac le_add1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   209
qed "less_imp_add_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   210
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   211
goal Arith.thy "m+k<=n --> m<=(n::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   212
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   213
by (ALLGOALS Asm_simp_tac);
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   214
by (blast_tac (!claset addDs [Suc_leD]) 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   215
qed_spec_mp "add_leD1";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   216
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   217
goal Arith.thy "!!n::nat. m+k<=n ==> k<=n";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   218
by (full_simp_tac (!simpset addsimps [add_commute]) 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   219
by (etac add_leD1 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   220
qed_spec_mp "add_leD2";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   221
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   222
goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n";
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   223
by (blast_tac (!claset addDs [add_leD1, add_leD2]) 1);
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   224
bind_thm ("add_leE", result() RS conjE);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   225
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   226
goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n";
1786
8a31d85d27b8 best_tac, deepen_tac and safe_tac now also use default claset.
berghofe
parents: 1767
diff changeset
   227
by (safe_tac (!claset addSDs [less_eq_Suc_add]));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   228
by (asm_full_simp_tac
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   229
    (!simpset delsimps [add_Suc_right]
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   230
                addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   231
by (etac subst 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   232
by (simp_tac (!simpset addsimps [less_add_Suc1]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   233
qed "less_add_eq_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   234
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   235
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   236
(*** Monotonicity of Addition ***)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   237
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   238
(*strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   239
goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   240
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   241
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   242
qed "add_less_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   243
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   244
(*strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   245
goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   246
by (rtac (add_less_mono1 RS less_trans) 1);
1198
23be92d5bf4d tidied proof of add_less_mono
lcp
parents: 1152
diff changeset
   247
by (REPEAT (assume_tac 1));
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   248
by (induct_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   249
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   250
qed "add_less_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
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   253
val [lt_mono,le] = goal Arith.thy
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   254
     "[| !!i j::nat. i<j ==> f(i) < f(j);       \
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   255
\        i <= j                                 \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   256
\     |] ==> f(i) <= (f(j)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   257
by (cut_facts_tac [le] 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   258
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   259
by (blast_tac (!claset addSIs [lt_mono]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   260
qed "less_mono_imp_le_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   261
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   262
(*non-strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   263
goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k";
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3724
diff changeset
   264
by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   265
by (etac add_less_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   266
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   267
qed "add_le_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   268
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   269
(*non-strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   270
goal Arith.thy "!!k l::nat. [|i<=j;  k<=l |] ==> i + k <= j + l";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   271
by (etac (add_le_mono1 RS le_trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   272
by (simp_tac (!simpset addsimps [add_commute]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   273
(*j moves to the end because it is free while k, l are bound*)
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   274
by (etac add_le_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   275
qed "add_le_mono";
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   276
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   277
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   278
(*** Multiplication ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   279
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   280
(*right annihilation in product*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   281
qed_goal "mult_0_right" Arith.thy "m * 0 = 0"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   282
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   283
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   284
(*right successor law for multiplication*)
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   285
qed_goal "mult_Suc_right" Arith.thy  "m * Suc(n) = m + (m * n)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   286
 (fn _ => [induct_tac "m" 1,
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   287
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   288
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   289
Addsimps [mult_0_right, mult_Suc_right];
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
goal Arith.thy "1 * n = n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   292
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   293
qed "mult_1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   294
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   295
goal Arith.thy "n * 1 = n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   296
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   297
qed "mult_1_right";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   298
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   299
(*Commutative law for multiplication*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   300
qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   301
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   302
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   303
(*addition distributes over multiplication*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   304
qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   305
 (fn _ => [induct_tac "m" 1,
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   306
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   307
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   308
qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   309
 (fn _ => [induct_tac "m" 1,
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   310
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   311
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   312
(*Associative law for multiplication*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   313
qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   314
  (fn _ => [induct_tac "m" 1, 
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   315
            ALLGOALS (asm_simp_tac (!simpset addsimps [add_mult_distrib]))]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   316
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   317
qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   318
 (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   319
           rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   320
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   321
val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   322
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   323
goal Arith.thy "(m*n = 0) = (m=0 | n=0)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   324
by (induct_tac "m" 1);
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   325
by (induct_tac "n" 2);
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   326
by (ALLGOALS Asm_simp_tac);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   327
qed "mult_is_0";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   328
Addsimps [mult_is_0];
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   329
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   330
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   331
(*** Difference ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   332
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   333
qed_goal "pred_Suc_diff" Arith.thy "pred(Suc m - n) = m - n"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   334
 (fn _ => [induct_tac "n" 1, ALLGOALS Asm_simp_tac]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   335
Addsimps [pred_Suc_diff];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   336
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   337
qed_goal "diff_self_eq_0" Arith.thy "m - m = 0"
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   338
 (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   339
Addsimps [diff_self_eq_0];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   340
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   341
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   342
goal Arith.thy "~ m<n --> n+(m-n) = (m::nat)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   343
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   344
by (ALLGOALS Asm_simp_tac);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   345
qed_spec_mp "add_diff_inverse";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   346
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   347
goal Arith.thy "!!m. n<=m ==> n+(m-n) = (m::nat)";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   348
by (asm_simp_tac (!simpset addsimps [add_diff_inverse, not_less_iff_le]) 1);
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   349
qed "le_add_diff_inverse";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   350
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   351
goal Arith.thy "!!m. n<=m ==> (m-n)+n = (m::nat)";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   352
by (asm_simp_tac (!simpset addsimps [le_add_diff_inverse, add_commute]) 1);
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   353
qed "le_add_diff_inverse2";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   354
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   355
Addsimps  [le_add_diff_inverse, le_add_diff_inverse2];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   356
Delsimps  [diff_Suc];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   357
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   358
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   359
(*** More results about difference ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   360
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   361
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   362
by (rtac (prem RS rev_mp) 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   363
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   364
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   365
qed "Suc_diff_n";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   366
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   367
goal Arith.thy "m - n < Suc(m)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   368
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   369
by (etac less_SucE 3);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   370
by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq])));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   371
qed "diff_less_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   372
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   373
goal Arith.thy "!!m::nat. m - n <= m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   374
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   375
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   376
qed "diff_le_self";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   377
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   378
goal Arith.thy "!!i::nat. i-j-k = i - (j+k)";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   379
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   380
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   381
qed "diff_diff_left";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   382
3396
aa74c71c3982 eliminated non-ASCII;
wenzelm
parents: 3381
diff changeset
   383
(*This and the next few suggested by Florian Kammueller*)
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   384
goal Arith.thy "!!i::nat. i-j-k = i-k-j";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   385
by (simp_tac (!simpset addsimps [diff_diff_left, add_commute]) 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   386
qed "diff_commute";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   387
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   388
goal Arith.thy "!!i j k:: nat. k<=j --> j<=i --> i - (j - k) = i - j + k";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   389
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   390
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   391
by (asm_simp_tac
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   392
    (!simpset addsimps [Suc_diff_n, le_imp_less_Suc, le_Suc_eq]) 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   393
qed_spec_mp "diff_diff_right";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   394
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   395
goal Arith.thy "!!i j k:: nat. k<=j --> (i + j) - k = i + (j - k)";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   396
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   397
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   398
qed_spec_mp "diff_add_assoc";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   399
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   400
goal Arith.thy "!!n::nat. (n+m) - n = m";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   401
by (induct_tac "n" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   402
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   403
qed "diff_add_inverse";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   404
Addsimps [diff_add_inverse];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   405
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   406
goal Arith.thy "!!n::nat.(m+n) - n = m";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   407
by (simp_tac (!simpset addsimps [diff_add_assoc]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   408
qed "diff_add_inverse2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   409
Addsimps [diff_add_inverse2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   410
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents: 3352
diff changeset
   411
goal Arith.thy "!!i j k::nat. i<=j ==> (j-i=k) = (j=k+i)";
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   412
by Safe_tac;
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   413
by (ALLGOALS Asm_simp_tac);
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents: 3352
diff changeset
   414
qed "le_imp_diff_is_add";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents: 3352
diff changeset
   415
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   416
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   417
by (rtac (prem RS rev_mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   418
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   419
by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   420
by (ALLGOALS Asm_simp_tac);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   421
qed "less_imp_diff_is_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   422
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   423
val prems = goal Arith.thy "m-n = 0  -->  n-m = 0  -->  m=n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   424
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   425
by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   426
qed_spec_mp "diffs0_imp_equal";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   427
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   428
val [prem] = goal Arith.thy "m<n ==> 0<n-m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   429
by (rtac (prem RS rev_mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   430
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   431
by (ALLGOALS Asm_simp_tac);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   432
qed "less_imp_diff_positive";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   433
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   434
goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   435
by (simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   436
                    setloop (split_tac [expand_if])) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   437
qed "if_Suc_diff_n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   438
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   439
goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   440
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
   441
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
   442
qed "zero_induct_lemma";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   443
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   444
val prems = goal Arith.thy "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   445
by (rtac (diff_self_eq_0 RS subst) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   446
by (rtac (zero_induct_lemma RS mp RS mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   447
by (REPEAT (ares_tac ([impI,allI]@prems) 1));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   448
qed "zero_induct";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   449
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   450
goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   451
by (induct_tac "k" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   452
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   453
qed "diff_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   454
Addsimps [diff_cancel];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   455
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   456
goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   457
val add_commute_k = read_instantiate [("n","k")] add_commute;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   458
by (asm_simp_tac (!simpset addsimps ([add_commute_k])) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   459
qed "diff_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   460
Addsimps [diff_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   461
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   462
(*From Clemens Ballarin*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   463
goal Arith.thy "!!n::nat. [| k<=n; n<=m |] ==> (m-k) - (n-k) = m-n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   464
by (subgoal_tac "k<=n --> n<=m --> (m-k) - (n-k) = m-n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   465
by (Asm_full_simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   466
by (induct_tac "k" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   467
by (Simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   468
(* Induction step *)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   469
by (subgoal_tac "Suc na <= m --> n <= m --> Suc na <= n --> \
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   470
\                Suc (m - Suc na) - Suc (n - Suc na) = m-n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   471
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   472
by (blast_tac (!claset addIs [le_trans]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   473
by (auto_tac (!claset addIs [Suc_leD], !simpset delsimps [diff_Suc_Suc]));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   474
by (asm_full_simp_tac (!simpset delsimps [Suc_less_eq] 
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   475
		       addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   476
qed "diff_right_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   477
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   478
goal Arith.thy "!!n::nat. n - (n+m) = 0";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   479
by (induct_tac "n" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   480
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   481
qed "diff_add_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   482
Addsimps [diff_add_0];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   483
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   484
(** Difference distributes over multiplication **)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   485
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   486
goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   487
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   488
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   489
qed "diff_mult_distrib" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   490
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   491
goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   492
val mult_commute_k = read_instantiate [("m","k")] mult_commute;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   493
by (simp_tac (!simpset addsimps [diff_mult_distrib, mult_commute_k]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   494
qed "diff_mult_distrib2" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   495
(*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
   496
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   497
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   498
(*** Monotonicity of Multiplication ***)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   499
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   500
goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   501
by (induct_tac "k" 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   502
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_le_mono])));
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   503
qed "mult_le_mono1";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   504
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   505
(*<=monotonicity, BOTH arguments*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   506
goal Arith.thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l";
2007
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   507
by (etac (mult_le_mono1 RS le_trans) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   508
by (rtac le_trans 1);
2007
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   509
by (stac mult_commute 2);
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   510
by (etac mult_le_mono1 2);
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   511
by (simp_tac (!simpset addsimps [mult_commute]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   512
qed "mult_le_mono";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   513
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   514
(*strict, in 1st argument; proof is by induction on k>0*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   515
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   516
by (eres_inst_tac [("i","0")] less_natE 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   517
by (Asm_simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   518
by (induct_tac "x" 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   519
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_less_mono])));
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   520
qed "mult_less_mono2";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   521
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   522
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   523
by (dtac mult_less_mono2 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   524
by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [mult_commute])));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   525
qed "mult_less_mono1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   526
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   527
goal Arith.thy "(0 < m*n) = (0<m & 0<n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   528
by (induct_tac "m" 1);
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   529
by (induct_tac "n" 2);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   530
by (ALLGOALS Asm_simp_tac);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   531
qed "zero_less_mult_iff";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   532
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   533
goal Arith.thy "(m*n = 1) = (m=1 & n=1)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   534
by (induct_tac "m" 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   535
by (Simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   536
by (induct_tac "n" 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   537
by (Simp_tac 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   538
by (fast_tac (!claset addss !simpset) 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   539
qed "mult_eq_1_iff";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   540
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   541
goal Arith.thy "!!k. 0<k ==> (m*k < n*k) = (m<n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   542
by (safe_tac (!claset addSIs [mult_less_mono1]));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   543
by (cut_facts_tac [less_linear] 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   544
by (blast_tac (!claset addDs [mult_less_mono1] addEs [less_asym]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   545
qed "mult_less_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   546
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   547
goal Arith.thy "!!k. 0<k ==> (k*m < k*n) = (m<n)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   548
by (dtac mult_less_cancel2 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   549
by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   550
qed "mult_less_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   551
Addsimps [mult_less_cancel1, mult_less_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   552
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   553
goal Arith.thy "!!k. 0<k ==> (m*k = n*k) = (m=n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   554
by (cut_facts_tac [less_linear] 1);
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   555
by Safe_tac;
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   556
by (assume_tac 2);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   557
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   558
by (ALLGOALS Asm_full_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   559
qed "mult_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   560
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   561
goal Arith.thy "!!k. 0<k ==> (k*m = k*n) = (m=n)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   562
by (dtac mult_cancel2 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   563
by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   564
qed "mult_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   565
Addsimps [mult_cancel1, mult_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   566
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   567
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   568
(** Lemma for gcd **)
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   569
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   570
goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   571
by (dtac sym 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   572
by (rtac disjCI 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   573
by (rtac nat_less_cases 1 THEN assume_tac 2);
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   574
by (fast_tac (!claset addSEs [less_SucE] addss !simpset) 1);
1979
91c74763c5a3 Change to best_tac required to prevent looping
paulson
parents: 1909
diff changeset
   575
by (best_tac (!claset addDs [mult_less_mono2] 
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   576
                      addss (!simpset addsimps [zero_less_eq RS sym])) 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   577
qed "mult_eq_self_implies_10";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   578
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   579
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   580
(*** Subtraction laws -- from Clemens Ballarin ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   581
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   582
goal Arith.thy "!! a b c::nat. [| a < b; c <= a |] ==> a-c < b-c";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   583
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
   584
by (Full_simp_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   585
by (subgoal_tac "c <= b" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   586
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
   587
by (Asm_simp_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   588
qed "diff_less_mono";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   589
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   590
goal Arith.thy "!! a b c::nat. a+b < c ==> a < c-b";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   591
by (dtac diff_less_mono 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   592
by (rtac le_add2 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   593
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   594
qed "add_less_imp_less_diff";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   595
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   596
goal Arith.thy "!! n. n <= m ==> Suc m - n = Suc (m - n)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   597
by (rtac Suc_diff_n 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   598
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_Suc]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   599
qed "Suc_diff_le";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   600
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   601
goal Arith.thy "!! n. Suc i <= n ==> Suc (n - Suc i) = n - i";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   602
by (asm_full_simp_tac
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   603
    (!simpset addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   604
qed "Suc_diff_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   605
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   606
goal Arith.thy "!! i::nat. i <= n ==> n - (n - i) = i";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   607
by (subgoal_tac "(n-i) + (n - (n-i)) = (n-i) + i" 1);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   608
by (Full_simp_tac 1);
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   609
by (asm_simp_tac (!simpset addsimps [diff_le_self, add_commute]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   610
qed "diff_diff_cancel";
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   611
Addsimps [diff_diff_cancel];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   612
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   613
goal Arith.thy "!!k::nat. k <= n ==> m <= n + m - k";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   614
by (etac rev_mp 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   615
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   616
by (Simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   617
by (simp_tac (!simpset addsimps [less_add_Suc2, less_imp_le]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   618
by (Simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   619
qed "le_add_diff";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   620
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   621
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   622
(** (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
   623
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   624
(* Monotonicity of subtraction in first argument *)
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   625
goal Arith.thy "!!n::nat. m<=n --> (m-l) <= (n-l)";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   626
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
   627
by (Simp_tac 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   628
by (simp_tac (!simpset addsimps [le_Suc_eq]) 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   629
by (rtac impI 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   630
by (etac impE 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   631
by (atac 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   632
by (etac le_trans 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   633
by (res_inst_tac [("m1","n")] (pred_Suc_diff RS subst) 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   634
by (rtac pred_le 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   635
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
   636
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   637
goal Arith.thy "!!n::nat. m<=n ==> (l-n) <= (l-m)";
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   638
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
   639
by (Simp_tac 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   640
by (case_tac "n <= l" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   641
by (subgoal_tac "m <= l" 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   642
by (asm_simp_tac (!simpset addsimps [Suc_diff_le]) 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   643
by (fast_tac (!claset addEs [le_trans]) 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   644
by (dtac not_leE 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   645
by (asm_simp_tac (!simpset addsimps [if_Suc_diff_n]) 1);
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
   646
qed_spec_mp "diff_le_mono2";