src/HOL/Arith.ML
author paulson
Thu, 22 May 1997 15:07:45 +0200
changeset 3293 c05f73cf3227
parent 3234 503f4c8c29eb
child 3339 cfa72a70f2b5
permissions -rw-r--r--
New lemmas used for ex/Fib
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
open Arith;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
(*** Basic rewrite rules for the arithmetic operators ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
2099
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    14
goalw Arith.thy [pred_def] "pred 0 = 0";
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    15
by(Simp_tac 1);
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    16
qed "pred_0";
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    17
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    18
goalw Arith.thy [pred_def] "pred(Suc n) = n";
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    19
by(Simp_tac 1);
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    20
qed "pred_Suc";
c5f004bfcbab Defined pred using nat_case rather than nat_rec.
nipkow
parents: 2031
diff changeset
    21
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    22
Addsimps [pred_0,pred_Suc];
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    23
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    24
(** pred **)
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    25
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    26
val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    27
by (res_inst_tac [("n","n")] natE 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    28
by (cut_facts_tac prems 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    29
by (ALLGOALS Asm_full_simp_tac);
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    30
qed "Suc_pred";
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    31
Addsimps [Suc_pred];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
(** Difference **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    35
qed_goalw "diff_0_eq_0" Arith.thy [pred_def]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
    "0 - n = 0"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    37
 (fn _ => [nat_ind_tac "n" 1,  ALLGOALS Asm_simp_tac]);
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
(*Must simplify BEFORE the induction!!  (Else we get a critical pair)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
  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
    41
qed_goalw "diff_Suc_Suc" Arith.thy [pred_def]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
    "Suc(m) - Suc(n) = m - n"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
 (fn _ =>
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    44
  [Simp_tac 1, nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    46
Addsimps [diff_0_eq_0, diff_Suc_Suc];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    49
goal Arith.thy "!!k. 0<k ==> EX j. k = Suc(j)";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    50
by (etac rev_mp 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    51
by (nat_ind_tac "k" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    52
by (Simp_tac 1);
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
    53
by (Blast_tac 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    54
val lemma = result();
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    55
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    56
(* [| 0 < k; !!j. [| j: nat; k = succ(j) |] ==> Q |] ==> Q *)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    57
bind_thm ("zero_less_natE", lemma RS exE);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    58
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    59
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    60
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
(**** Inductive properties of the operators ****)
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 ***)
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
qed_goal "add_0_right" Arith.thy "m + 0 = m"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    66
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    69
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    71
Addsimps [add_0_right,add_Suc_right];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
(*Associative law for addition*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    75
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
(*Commutative law for addition*)  
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    79
 (fn _ =>  [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
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
    82
 (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
    83
           rtac (add_commute RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
(*Addition is an AC-operator*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
val add_ac = [add_assoc, add_commute, add_left_commute];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    90
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    91
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
qed "add_left_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    96
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    97
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
qed "add_right_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   102
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   103
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
qed "add_left_cancel_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   105
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   108
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   109
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
qed "add_left_cancel_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   112
Addsimps [add_left_cancel, add_right_cancel,
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   113
          add_left_cancel_le, add_left_cancel_less];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   114
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   115
goal Arith.thy "(m+n = 0) = (m=0 & n=0)";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   116
by (nat_ind_tac "m" 1);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   117
by (ALLGOALS Asm_simp_tac);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   118
qed "add_is_0";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   119
Addsimps [add_is_0];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   120
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   121
goal Arith.thy "(pred (m+n) = 0) = (m=0 & pred n = 0 | pred m = 0 & n=0)";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   122
by (nat_ind_tac "m" 1);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   123
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   124
qed "pred_add_is_0";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   125
Addsimps [pred_add_is_0];
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   126
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   127
goal Arith.thy "!!n. n ~= 0 ==> m + pred n = pred(m+n)";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   128
by (nat_ind_tac "m" 1);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   129
by (ALLGOALS Asm_simp_tac);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   130
qed "add_pred";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   131
Addsimps [add_pred];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   132
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   133
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
(**** Additional theorems about "less than" ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   136
goal Arith.thy "? k::nat. n = n+k";
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   137
by (res_inst_tac [("x","0")] exI 1);
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   138
by (Simp_tac 1);
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   139
val lemma = result();
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   140
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   142
by (nat_ind_tac "n" 1);
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   143
by (ALLGOALS (simp_tac (!simpset addsimps [less_Suc_eq])));
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   144
by (step_tac (!claset addSIs [lemma]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
by (res_inst_tac [("x","Suc(k)")] exI 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   146
by (Simp_tac 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   147
qed_spec_mp "less_eq_Suc_add";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   148
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   149
goal Arith.thy "n <= ((m + n)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   150
by (nat_ind_tac "m" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   151
by (ALLGOALS Simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   152
by (etac le_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   153
by (rtac (lessI RS less_imp_le) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   154
qed "le_add2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   155
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   156
goal Arith.thy "n <= ((n + m)::nat)";
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   157
by (simp_tac (!simpset addsimps add_ac) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   158
by (rtac le_add2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   159
qed "le_add1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   160
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   161
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
   162
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
   163
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
(*"i <= j ==> i <= j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   165
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   166
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   167
(*"i <= j ==> i <= m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   168
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   169
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   170
(*"i < j ==> i < j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   171
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
   172
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   173
(*"i < j ==> i < m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   174
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
   175
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   176
goal Arith.thy "!!i. i+j < (k::nat) ==> i<k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   177
by (etac rev_mp 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   178
by (nat_ind_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   179
by (ALLGOALS Asm_simp_tac);
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   180
by (blast_tac (!claset addDs [Suc_lessD]) 1);
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   181
qed "add_lessD1";
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   182
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   183
goal Arith.thy "!!i::nat. ~ (i+j < i)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   184
br notI 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   185
be (add_lessD1 RS less_irrefl) 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   186
qed "not_add_less1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   187
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   188
goal Arith.thy "!!i::nat. ~ (j+i < i)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   189
by (simp_tac (!simpset addsimps [add_commute, not_add_less1]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   190
qed "not_add_less2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   191
AddIffs [not_add_less1, not_add_less2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   192
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   193
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   194
by (etac le_trans 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   195
by (rtac le_add1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   196
qed "le_imp_add_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   197
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   198
goal Arith.thy "!!k::nat. m < n ==> m < n+k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   199
by (etac less_le_trans 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   200
by (rtac le_add1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   201
qed "less_imp_add_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   202
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   203
goal Arith.thy "m+k<=n --> m<=(n::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   204
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   205
by (ALLGOALS Asm_simp_tac);
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   206
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
   207
qed_spec_mp "add_leD1";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   208
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   209
goal Arith.thy "!!n::nat. m+k<=n ==> k<=n";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   210
by (full_simp_tac (!simpset addsimps [add_commute]) 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   211
by (etac add_leD1 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   212
qed_spec_mp "add_leD2";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   213
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   214
goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n";
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   215
by (blast_tac (!claset addDs [add_leD1, add_leD2]) 1);
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   216
bind_thm ("add_leE", result() RS conjE);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   217
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   218
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
   219
by (safe_tac (!claset addSDs [less_eq_Suc_add]));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   220
by (asm_full_simp_tac
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   221
    (!simpset delsimps [add_Suc_right]
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   222
                addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   223
by (etac subst 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   224
by (simp_tac (!simpset addsimps [less_add_Suc1]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   225
qed "less_add_eq_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   226
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   227
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   228
(*** Monotonicity of Addition ***)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   229
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   230
(*strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   231
goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   232
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   233
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   234
qed "add_less_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   235
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   236
(*strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   237
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
   238
by (rtac (add_less_mono1 RS less_trans) 1);
1198
23be92d5bf4d tidied proof of add_less_mono
lcp
parents: 1152
diff changeset
   239
by (REPEAT (assume_tac 1));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   240
by (nat_ind_tac "j" 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_mono";
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
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   245
val [lt_mono,le] = goal Arith.thy
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   246
     "[| !!i j::nat. i<j ==> f(i) < f(j);       \
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   247
\        i <= j                                 \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   248
\     |] ==> f(i) <= (f(j)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   249
by (cut_facts_tac [le] 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   250
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
2922
580647a879cf Using Blast_tac
paulson
parents: 2682
diff changeset
   251
by (blast_tac (!claset addSIs [lt_mono]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   252
qed "less_mono_imp_le_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   253
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   254
(*non-strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   255
goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   256
by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   257
by (etac add_less_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   258
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   259
qed "add_le_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   260
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   261
(*non-strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   262
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
   263
by (etac (add_le_mono1 RS le_trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   264
by (simp_tac (!simpset addsimps [add_commute]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   265
(*j moves to the end because it is free while k, l are bound*)
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   266
by (etac add_le_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   267
qed "add_le_mono";
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   268
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   269
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   270
(*** Multiplication ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   271
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   272
(*right annihilation in product*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   273
qed_goal "mult_0_right" Arith.thy "m * 0 = 0"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   274
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   275
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   276
(*right successor law for multiplication*)
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   277
qed_goal "mult_Suc_right" Arith.thy  "m * Suc(n) = m + (m * n)"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   278
 (fn _ => [nat_ind_tac "m" 1,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   279
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   280
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   281
Addsimps [mult_0_right, mult_Suc_right];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   282
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   283
goal Arith.thy "1 * n = n";
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";
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
goal Arith.thy "n * 1 = n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   288
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   289
qed "mult_1_right";
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
(*Commutative law for multiplication*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   292
qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   293
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
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
(*addition distributes over multiplication*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   296
qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   297
 (fn _ => [nat_ind_tac "m" 1,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   298
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
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
qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   301
 (fn _ => [nat_ind_tac "m" 1,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   302
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   303
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   304
(*Associative law for multiplication*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   305
qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   306
  (fn _ => [nat_ind_tac "m" 1, 
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   307
            ALLGOALS (asm_simp_tac (!simpset addsimps [add_mult_distrib]))]);
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
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
   310
 (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   311
           rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   312
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   313
val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   314
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   315
goal Arith.thy "(m*n = 0) = (m=0 | n=0)";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   316
by (nat_ind_tac "m" 1);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   317
by (nat_ind_tac "n" 2);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   318
by (ALLGOALS Asm_simp_tac);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   319
qed "mult_is_0";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   320
Addsimps [mult_is_0];
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   321
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   322
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   323
(*** Difference ***)
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
qed_goal "pred_Suc_diff" Arith.thy "pred(Suc m - n) = m - n"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   326
 (fn _ => [nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   327
Addsimps [pred_Suc_diff];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   328
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   329
qed_goal "diff_self_eq_0" Arith.thy "m - m = 0"
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   330
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   331
Addsimps [diff_self_eq_0];
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
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   334
val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   335
by (rtac (prem RS rev_mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   336
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   337
by (ALLGOALS (Asm_simp_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   338
qed "add_diff_inverse";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   339
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   340
Delsimps  [diff_Suc];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   341
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   342
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   343
(*** More results about difference ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   344
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   345
goal Arith.thy "m - n < Suc(m)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   346
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   347
by (etac less_SucE 3);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   348
by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq])));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   349
qed "diff_less_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   350
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   351
goal Arith.thy "!!m::nat. m - n <= m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   352
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   353
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   354
qed "diff_le_self";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   355
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   356
goal Arith.thy "!!n::nat. (n+m) - n = m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   357
by (nat_ind_tac "n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   358
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   359
qed "diff_add_inverse";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   360
Addsimps [diff_add_inverse];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   361
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   362
goal Arith.thy "!!n::nat.(m+n) - n = m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   363
by (res_inst_tac [("m1","m")] (add_commute RS ssubst) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   364
by (REPEAT (ares_tac [diff_add_inverse] 1));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   365
qed "diff_add_inverse2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   366
Addsimps [diff_add_inverse2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   367
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   368
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   369
by (rtac (prem RS rev_mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   370
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   371
by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   372
by (ALLGOALS (Asm_simp_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   373
qed "less_imp_diff_is_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   374
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   375
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
   376
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   377
by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   378
qed_spec_mp "diffs0_imp_equal";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   379
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   380
val [prem] = goal Arith.thy "m<n ==> 0<n-m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   381
by (rtac (prem RS rev_mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   382
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   383
by (ALLGOALS (Asm_simp_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   384
qed "less_imp_diff_positive";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   385
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   386
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   387
by (rtac (prem RS rev_mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   388
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   389
by (ALLGOALS (Asm_simp_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   390
qed "Suc_diff_n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   391
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   392
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
   393
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
   394
                    setloop (split_tac [expand_if])) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   395
qed "if_Suc_diff_n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   396
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   397
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
   398
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   399
by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o Blast_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   400
qed "zero_induct_lemma";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   401
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   402
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
   403
by (rtac (diff_self_eq_0 RS subst) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   404
by (rtac (zero_induct_lemma RS mp RS mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   405
by (REPEAT (ares_tac ([impI,allI]@prems) 1));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   406
qed "zero_induct";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   407
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   408
goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   409
by (nat_ind_tac "k" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   410
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   411
qed "diff_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   412
Addsimps [diff_cancel];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   413
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   414
goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   415
val add_commute_k = read_instantiate [("n","k")] add_commute;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   416
by (asm_simp_tac (!simpset addsimps ([add_commute_k])) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   417
qed "diff_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   418
Addsimps [diff_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   419
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   420
(*From Clemens Ballarin*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   421
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
   422
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
   423
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   424
by (nat_ind_tac "k" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   425
by (Simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   426
(* Induction step *)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   427
by (subgoal_tac "Suc na <= m --> n <= m --> Suc na <= n --> \
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   428
\                Suc (m - Suc na) - Suc (n - Suc na) = m-n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   429
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   430
by (blast_tac (!claset addIs [le_trans]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   431
by (auto_tac (!claset addIs [Suc_leD], !simpset delsimps [diff_Suc_Suc]));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   432
by (asm_full_simp_tac (!simpset delsimps [Suc_less_eq] 
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   433
		       addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   434
qed "diff_right_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   435
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   436
goal Arith.thy "!!n::nat. n - (n+m) = 0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   437
by (nat_ind_tac "n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   438
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   439
qed "diff_add_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   440
Addsimps [diff_add_0];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   441
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   442
(** Difference distributes over multiplication **)
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
goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   445
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   446
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   447
qed "diff_mult_distrib" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   448
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   449
goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   450
val mult_commute_k = read_instantiate [("m","k")] mult_commute;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   451
by (simp_tac (!simpset addsimps [diff_mult_distrib, mult_commute_k]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   452
qed "diff_mult_distrib2" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   453
(*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
   454
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
(** Less-then properties **)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   457
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   458
(*In ordinary notation: if 0<n and n<=m then m-n < m *)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   459
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   460
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   461
by (Blast_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   462
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   463
by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc])));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   464
qed "diff_less";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   465
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   466
val wf_less_trans = [eq_reflection, wf_pred_nat RS wf_trancl] MRS 
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   467
                    def_wfrec RS trans;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   468
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   469
goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   470
by (rtac refl 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   471
qed "less_eq";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   472
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   473
(*** Remainder ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   474
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   475
goal Arith.thy "(%m. m mod n) = wfrec (trancl pred_nat) \
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   476
             \                      (%f j. if j<n then j else f (j-n))";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   477
by (simp_tac (!simpset addsimps [mod_def]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   478
qed "mod_eq";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   479
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   480
goal Arith.thy "!!m. m<n ==> m mod n = m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   481
by (rtac (mod_eq RS wf_less_trans) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   482
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   483
qed "mod_less";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   484
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   485
goal Arith.thy "!!m. [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   486
by (rtac (mod_eq RS wf_less_trans) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   487
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   488
qed "mod_geq";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   489
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   490
goal thy "!!n. 0<n ==> n mod n = 0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   491
by (rtac (mod_eq RS wf_less_trans) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   492
by (asm_simp_tac (!simpset addsimps [mod_less, diff_self_eq_0,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   493
				     cut_def, less_eq]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   494
qed "mod_nn_is_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   495
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   496
goal thy "!!n. 0<n ==> (m+n) mod n = m mod n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   497
by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   498
by (stac (mod_geq RS sym) 2);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   499
by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [add_commute])));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   500
qed "mod_eq_add";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   501
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   502
goal thy "!!n. 0<n ==> m*n mod n = 0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   503
by (nat_ind_tac "m" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   504
by (asm_simp_tac (!simpset addsimps [mod_less]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   505
by (dres_inst_tac [("m","m*n")] mod_eq_add 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   506
by (asm_full_simp_tac (!simpset addsimps [add_commute]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   507
qed "mod_prod_nn_is_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   508
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   509
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   510
(*** Quotient ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   511
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   512
goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   513
                        \            (%f j. if j<n then 0 else Suc (f (j-n)))";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   514
by (simp_tac (!simpset addsimps [div_def]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   515
qed "div_eq";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   516
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   517
goal Arith.thy "!!m. m<n ==> m div n = 0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   518
by (rtac (div_eq RS wf_less_trans) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   519
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   520
qed "div_less";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   521
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   522
goal Arith.thy "!!M. [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   523
by (rtac (div_eq RS wf_less_trans) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   524
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   525
qed "div_geq";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   526
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   527
(*Main Result about quotient and remainder.*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   528
goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   529
by (res_inst_tac [("n","m")] less_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   530
by (rename_tac "k" 1);    (*Variable name used in line below*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   531
by (case_tac "k<n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   532
by (ALLGOALS (asm_simp_tac(!simpset addsimps ([add_assoc] @
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   533
                       [mod_less, mod_geq, div_less, div_geq,
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   534
                        add_diff_inverse, diff_less]))));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   535
qed "mod_div_equality";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   536
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   537
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   538
(*** Further facts about mod (mainly for the mutilated chess board ***)
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   539
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   540
goal Arith.thy
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   541
    "!!m n. 0<n ==> \
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   542
\           Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   543
by (res_inst_tac [("n","m")] less_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   544
by (excluded_middle_tac "Suc(na)<n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   545
(* case Suc(na) < n *)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   546
by (forward_tac [lessI RS less_trans] 2);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   547
by (asm_simp_tac (!simpset addsimps [mod_less, less_not_refl2 RS not_sym]) 2);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   548
(* case n <= Suc(na) *)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   549
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, mod_geq]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   550
by (etac (le_imp_less_or_eq RS disjE) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   551
by (asm_simp_tac (!simpset addsimps [Suc_diff_n]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   552
by (asm_full_simp_tac (!simpset addsimps [not_less_eq RS sym, 
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   553
                                          diff_less, mod_geq]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   554
by (asm_simp_tac (!simpset addsimps [mod_less]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   555
qed "mod_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   556
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   557
goal Arith.thy "!!m n. 0<n ==> m mod n < n";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   558
by (res_inst_tac [("n","m")] less_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   559
by (excluded_middle_tac "na<n" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   560
(*case na<n*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   561
by (asm_simp_tac (!simpset addsimps [mod_less]) 2);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   562
(*case n le na*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   563
by (asm_full_simp_tac (!simpset addsimps [mod_geq, diff_less]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   564
qed "mod_less_divisor";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   565
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
(** Evens and Odds **)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   568
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   569
(*With less_zeroE, causes case analysis on b<2*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   570
AddSEs [less_SucE];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   571
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   572
goal thy "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   573
by (subgoal_tac "k mod 2 < 2" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   574
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   575
by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   576
by (Blast_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   577
qed "mod2_cases";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   578
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   579
goal thy "Suc(Suc(m)) mod 2 = m mod 2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   580
by (subgoal_tac "m mod 2 < 2" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   581
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   582
by (Step_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   583
by (ALLGOALS (asm_simp_tac (!simpset addsimps [mod_Suc])));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   584
qed "mod2_Suc_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   585
Addsimps [mod2_Suc_Suc];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   586
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   587
goal Arith.thy "!!m. m mod 2 ~= 0 ==> m mod 2 = 1";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   588
by (subgoal_tac "m mod 2 < 2" 1);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   589
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   590
by (safe_tac (!claset addSEs [lessE]));
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   591
by (ALLGOALS (blast_tac (!claset addIs [sym])));
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   592
qed "mod2_neq_0";
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   593
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   594
goal thy "(m+m) mod 2 = 0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   595
by (nat_ind_tac "m" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   596
by (simp_tac (!simpset addsimps [mod_less]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   597
by (asm_simp_tac (!simpset addsimps [mod2_Suc_Suc, add_Suc_right]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   598
qed "mod2_add_self";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   599
Addsimps [mod2_add_self];
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
Delrules [less_SucE];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   602
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   603
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   604
(*** Monotonicity of Multiplication ***)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   605
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   606
goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   607
by (nat_ind_tac "k" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   608
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_le_mono])));
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   609
qed "mult_le_mono1";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   610
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   611
(*<=monotonicity, BOTH arguments*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   612
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
   613
by (etac (mult_le_mono1 RS le_trans) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   614
by (rtac le_trans 1);
2007
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   615
by (stac mult_commute 2);
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   616
by (etac mult_le_mono1 2);
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   617
by (simp_tac (!simpset addsimps [mult_commute]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   618
qed "mult_le_mono";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   619
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   620
(*strict, in 1st argument; proof is by induction on k>0*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   621
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   622
by (etac zero_less_natE 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   623
by (Asm_simp_tac 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   624
by (nat_ind_tac "x" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   625
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_less_mono])));
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   626
qed "mult_less_mono2";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   627
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   628
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   629
bd mult_less_mono2 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   630
by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [mult_commute])));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   631
qed "mult_less_mono1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   632
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   633
goal Arith.thy "(0 < m*n) = (0<m & 0<n)";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   634
by (nat_ind_tac "m" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   635
by (nat_ind_tac "n" 2);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   636
by (ALLGOALS Asm_simp_tac);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   637
qed "zero_less_mult_iff";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   638
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   639
goal Arith.thy "(m*n = 1) = (m=1 & n=1)";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   640
by (nat_ind_tac "m" 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   641
by (Simp_tac 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   642
by (nat_ind_tac "n" 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   643
by (Simp_tac 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   644
by (fast_tac (!claset addss !simpset) 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   645
qed "mult_eq_1_iff";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   646
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   647
goal Arith.thy "!!k. 0<k ==> (m*k < n*k) = (m<n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   648
by (safe_tac (!claset addSIs [mult_less_mono1]));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   649
by (cut_facts_tac [less_linear] 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   650
by (blast_tac (!claset addDs [mult_less_mono1] addEs [less_asym]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   651
qed "mult_less_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   652
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   653
goal Arith.thy "!!k. 0<k ==> (k*m < k*n) = (m<n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   654
bd mult_less_cancel2 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   655
by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   656
qed "mult_less_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   657
Addsimps [mult_less_cancel1, mult_less_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   658
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   659
goal Arith.thy "!!k. 0<k ==> (m*k = n*k) = (m=n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   660
by (cut_facts_tac [less_linear] 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   661
by(Step_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   662
ba 2;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   663
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   664
by (ALLGOALS Asm_full_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   665
qed "mult_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   666
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   667
goal Arith.thy "!!k. 0<k ==> (k*m = k*n) = (m=n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   668
bd mult_cancel2 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   669
by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   670
qed "mult_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   671
Addsimps [mult_cancel1, mult_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   672
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   673
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   674
(*** More division laws ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   675
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   676
goal thy "!!n. 0<n ==> m*n div n = m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   677
by (cut_inst_tac [("m", "m*n")] mod_div_equality 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   678
ba 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   679
by (asm_full_simp_tac (!simpset addsimps [mod_prod_nn_is_0]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   680
qed "div_prod_nn_is_m";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   681
Addsimps [div_prod_nn_is_m];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   682
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   683
(*Cancellation law for division*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   684
goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) div (k*n) = m div n";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   685
by (res_inst_tac [("n","m")] less_induct 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   686
by (case_tac "na<n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   687
by (asm_simp_tac (!simpset addsimps [div_less, zero_less_mult_iff, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   688
                                     mult_less_mono2]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   689
by (subgoal_tac "~ k*na < k*n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   690
by (asm_simp_tac
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   691
     (!simpset addsimps [zero_less_mult_iff, div_geq,
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   692
                         diff_mult_distrib2 RS sym, diff_less]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   693
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   694
                                          le_refl RS mult_le_mono]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   695
qed "div_cancel";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   696
Addsimps [div_cancel];
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   697
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   698
goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) mod (k*n) = k * (m mod n)";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   699
by (res_inst_tac [("n","m")] less_induct 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   700
by (case_tac "na<n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   701
by (asm_simp_tac (!simpset addsimps [mod_less, zero_less_mult_iff, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   702
                                     mult_less_mono2]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   703
by (subgoal_tac "~ k*na < k*n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   704
by (asm_simp_tac
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   705
     (!simpset addsimps [zero_less_mult_iff, mod_geq,
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   706
                         diff_mult_distrib2 RS sym, diff_less]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   707
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   708
                                          le_refl RS mult_le_mono]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   709
qed "mult_mod_distrib";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   710
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   711
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   712
(** Lemma for gcd **)
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   713
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   714
goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   715
by (dtac sym 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   716
by (rtac disjCI 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   717
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
   718
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
   719
by (best_tac (!claset addDs [mult_less_mono2] 
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   720
                      addss (!simpset addsimps [zero_less_eq RS sym])) 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   721
qed "mult_eq_self_implies_10";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   722
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   723
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   724
(*** Subtraction laws -- from Clemens Ballarin ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   725
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   726
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
   727
by (subgoal_tac "c+(a-c) < c+(b-c)" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   728
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   729
by (subgoal_tac "c <= b" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   730
by (blast_tac (!claset addIs [less_imp_le, le_trans]) 2);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   731
by (asm_simp_tac (!simpset addsimps [leD RS add_diff_inverse]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   732
qed "diff_less_mono";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   733
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   734
goal Arith.thy "!! a b c::nat. a+b < c ==> a < c-b";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   735
bd diff_less_mono 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   736
br le_add2 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   737
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   738
qed "add_less_imp_less_diff";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   739
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   740
goal Arith.thy "!! n. n <= m ==> Suc m - n = Suc (m - n)";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   741
br Suc_diff_n 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   742
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_Suc]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   743
qed "Suc_diff_le";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   744
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   745
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
   746
by (asm_full_simp_tac
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   747
    (!simpset addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   748
qed "Suc_diff_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   749
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   750
goal Arith.thy "!! i::nat. i <= n ==> n - (n - i) = i";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   751
by (subgoal_tac "(n-i) + (n - (n-i)) = (n-i) + i" 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   752
by (Asm_full_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   753
by (asm_simp_tac (!simpset addsimps [leD RS add_diff_inverse, diff_le_self, 
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   754
				     add_commute]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   755
qed "diff_diff_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   756
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   757
goal Arith.thy "!!k::nat. k <= n ==> m <= n + m - k";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   758
be rev_mp 1;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   759
by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   760
by (Simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   761
by (simp_tac (!simpset addsimps [less_add_Suc2, less_imp_le]) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   762
by (Simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   763
qed "le_add_diff";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   764
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   765