src/HOL/Arith.ML
author paulson
Thu, 09 Jan 1997 10:22:42 +0100
changeset 2498 7914881f47c0
parent 2099 c5f004bfcbab
child 2682 13cdbf95ed92
permissions -rw-r--r--
New theorem add_leE
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     1
(*  Title:      HOL/Arith.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Proofs about elementary arithmetic: addition, multiplication, etc.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
Tests definitions and simplifier.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
open Arith;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
(*** Basic rewrite rules for the arithmetic operators ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
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
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
val [add_0,add_Suc] = nat_recs add_def; 
1767
0c8f131eac40 Rules pred_0, pred_Suc etc. are now stored in theorem database.
berghofe
parents: 1760
diff changeset
    23
val [mult_0,mult_Suc] = nat_recs mult_def;
0c8f131eac40 Rules pred_0, pred_Suc etc. are now stored in theorem database.
berghofe
parents: 1760
diff changeset
    24
store_thm("add_0",add_0);
0c8f131eac40 Rules pred_0, pred_Suc etc. are now stored in theorem database.
berghofe
parents: 1760
diff changeset
    25
store_thm("add_Suc",add_Suc);
0c8f131eac40 Rules pred_0, pred_Suc etc. are now stored in theorem database.
berghofe
parents: 1760
diff changeset
    26
store_thm("mult_0",mult_0);
0c8f131eac40 Rules pred_0, pred_Suc etc. are now stored in theorem database.
berghofe
parents: 1760
diff changeset
    27
store_thm("mult_Suc",mult_Suc);
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    28
Addsimps [pred_0,pred_Suc,add_0,add_Suc,mult_0,mult_Suc];
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    29
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    30
(** pred **)
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    31
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    32
val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    33
by (res_inst_tac [("n","n")] natE 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    34
by (cut_facts_tac prems 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
    35
by (ALLGOALS Asm_full_simp_tac);
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    36
qed "Suc_pred";
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    37
Addsimps [Suc_pred];
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
(** Difference **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
1655
5be64540f275 Added a number of lemmas
nipkow
parents: 1626
diff changeset
    41
bind_thm("diff_0", diff_def RS def_nat_rec_0);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
qed_goalw "diff_0_eq_0" Arith.thy [diff_def, pred_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
    "0 - n = 0"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    45
 (fn _ => [nat_ind_tac "n" 1,  ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
(*Must simplify BEFORE the induction!!  (Else we get a critical pair)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
  Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
qed_goalw "diff_Suc_Suc" Arith.thy [diff_def, pred_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
    "Suc(m) - Suc(n) = m - n"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
 (fn _ =>
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    52
  [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
    53
1301
42782316d510 Added various thms and tactics.
nipkow
parents: 1264
diff changeset
    54
Addsimps [diff_0, diff_0_eq_0, diff_Suc_Suc];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    57
goal Arith.thy "!!k. 0<k ==> EX j. k = Suc(j)";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    58
by (etac rev_mp 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    59
by (nat_ind_tac "k" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    60
by (Simp_tac 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
    61
by (Fast_tac 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    62
val lemma = result();
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    63
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    64
(* [| 0 < k; !!j. [| j: nat; k = succ(j) |] ==> Q |] ==> Q *)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    65
bind_thm ("zero_less_natE", lemma RS exE);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    66
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    67
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
    68
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
(**** Inductive properties of the operators ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
(*** Addition ***)
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
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
    74
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
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
    77
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    79
Addsimps [add_0_right,add_Suc_right];
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
(*Associative law for addition*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
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
    83
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
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
(*Commutative law for addition*)  
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
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
    87
 (fn _ =>  [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
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
    90
 (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
    91
           rtac (add_commute RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
(*Addition is an AC-operator*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
val add_ac = [add_assoc, add_commute, add_left_commute];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    98
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    99
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
qed "add_left_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   104
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   105
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
qed "add_right_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   110
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   111
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
qed "add_left_cancel_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   113
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   114
goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   115
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   116
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   117
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
qed "add_left_cancel_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   120
Addsimps [add_left_cancel, add_right_cancel,
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   121
          add_left_cancel_le, add_left_cancel_less];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   122
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   123
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
   124
by (nat_ind_tac "m" 1);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   125
by (ALLGOALS Asm_simp_tac);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   126
qed "add_is_0";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   127
Addsimps [add_is_0];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   128
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   129
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
   130
by (nat_ind_tac "m" 1);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   131
by (ALLGOALS Asm_simp_tac);
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   132
qed "add_pred";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   133
Addsimps [add_pred];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   134
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
(*** Multiplication ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
(*right annihilation in product*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
qed_goal "mult_0_right" Arith.thy "m * 0 = 0"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   139
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
(*right Sucessor law for multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   142
qed_goal "mult_Suc_right" Arith.thy  "m * Suc(n) = m + (m * n)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   143
 (fn _ => [nat_ind_tac "m" 1,
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   144
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   146
Addsimps [mult_0_right,mult_Suc_right];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   147
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   148
goal Arith.thy "1 * n = n";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   149
by (Asm_simp_tac 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   150
qed "mult_1";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   151
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   152
goal Arith.thy "n * 1 = n";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   153
by (Asm_simp_tac 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   154
qed "mult_1_right";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   155
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   156
(*Commutative law for multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   157
qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   158
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   159
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   160
(*addition distributes over multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   161
qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   162
 (fn _ => [nat_ind_tac "m" 1,
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   163
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   165
qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   166
 (fn _ => [nat_ind_tac "m" 1,
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   167
           ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   168
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   169
(*Associative law for multiplication*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   170
qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)"
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   171
  (fn _ => [nat_ind_tac "m" 1, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   172
            ALLGOALS (asm_simp_tac (!simpset addsimps [add_mult_distrib]))]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   173
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   174
qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   175
 (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   176
           rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   177
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   178
val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   179
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   180
(*** Difference ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   181
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   182
qed_goal "diff_self_eq_0" Arith.thy "m - m = 0"
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   183
 (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
1496
c443b2adaf52 Added a few thms and the new theory RelPow.
nipkow
parents: 1485
diff changeset
   184
Addsimps [diff_self_eq_0];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   185
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   186
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   187
val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   188
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   189
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1660
8cb42cd97579 *** empty log message ***
oheimb
parents: 1655
diff changeset
   190
by (ALLGOALS (Asm_simp_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   191
qed "add_diff_inverse";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   192
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   193
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   194
(*** Remainder ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   195
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   196
goal Arith.thy "m - n < Suc(m)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   197
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   198
by (etac less_SucE 3);
1660
8cb42cd97579 *** empty log message ***
oheimb
parents: 1655
diff changeset
   199
by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq])));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   200
qed "diff_less_Suc";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   201
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   202
goal Arith.thy "!!m::nat. m - n <= m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   203
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   204
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   205
qed "diff_le_self";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   206
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   207
goal Arith.thy "!!n::nat. (n+m) - n = m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   208
by (nat_ind_tac "n" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   209
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   210
qed "diff_add_inverse";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   211
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   212
goal Arith.thy "!!n::nat.(m+n) - n = m";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   213
by (res_inst_tac [("m1","m")] (add_commute RS ssubst) 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   214
by (REPEAT (ares_tac [diff_add_inverse] 1));
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   215
qed "diff_add_inverse2";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   216
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   217
goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   218
by (nat_ind_tac "k" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   219
by (ALLGOALS Asm_simp_tac);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   220
qed "diff_cancel";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   221
Addsimps [diff_cancel];
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   222
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   223
goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   224
val add_commute_k = read_instantiate [("n","k")] add_commute;
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   225
by (asm_simp_tac (!simpset addsimps ([add_commute_k])) 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   226
qed "diff_cancel2";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   227
Addsimps [diff_cancel2];
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   228
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   229
goal Arith.thy "!!n::nat. n - (n+m) = 0";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   230
by (nat_ind_tac "n" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   231
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   232
qed "diff_add_0";
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   233
Addsimps [diff_add_0];
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   234
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   235
(** Difference distributes over multiplication **)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   236
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   237
goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   238
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   239
by (ALLGOALS Asm_simp_tac);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   240
qed "diff_mult_distrib" ;
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   241
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   242
goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   243
val mult_commute_k = read_instantiate [("m","k")] mult_commute;
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   244
by (simp_tac (!simpset addsimps [diff_mult_distrib, mult_commute_k]) 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   245
qed "diff_mult_distrib2" ;
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   246
(*NOT added as rewrites, since sometimes they are used from right-to-left*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   247
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   248
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   249
(** Less-then properties **)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   250
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   251
(*In ordinary notation: if 0<n and n<=m then m-n < m *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   252
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   253
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
   254
by (Fast_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   255
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   256
by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc])));
1398
b8de98c2c29c Changed div_termination -> diff_less
nipkow
parents: 1327
diff changeset
   257
qed "diff_less";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   258
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   259
val wf_less_trans = wf_pred_nat RS wf_trancl RSN (2, def_wfrec RS trans);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   260
972
e61b058d58d2 changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents: 965
diff changeset
   261
goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   262
by (rtac refl 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   263
qed "less_eq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   264
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   265
goal Arith.thy "(%m. m mod n) = wfrec (trancl pred_nat) \
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   266
             \                      (%f j. if j<n then j else f (j-n))";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   267
by (simp_tac (HOL_ss addsimps [mod_def]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   268
val mod_def1 = result() RS eq_reflection;
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   269
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   270
goal Arith.thy "!!m. m<n ==> m mod n = m";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   271
by (rtac (mod_def1 RS wf_less_trans) 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   272
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   273
qed "mod_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   274
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   275
goal Arith.thy "!!m. [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   276
by (rtac (mod_def1 RS wf_less_trans) 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   277
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   278
qed "mod_geq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   279
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   280
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   281
(*** Quotient ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   282
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   283
goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   284
                        \            (%f j. if j<n then 0 else Suc (f (j-n)))";
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   285
by (simp_tac (HOL_ss addsimps [div_def]) 1);
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   286
val div_def1 = result() RS eq_reflection;
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   287
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   288
goal Arith.thy "!!m. m<n ==> m div n = 0";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   289
by (rtac (div_def1 RS wf_less_trans) 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   290
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   291
qed "div_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   292
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   293
goal Arith.thy "!!M. [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
1475
7f5a4cd08209 expanded tabs; renamed subtype to typedef;
clasohm
parents: 1465
diff changeset
   294
by (rtac (div_def1 RS wf_less_trans) 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   295
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   296
qed "div_geq";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   297
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   298
(*Main Result about quotient and remainder.*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   299
goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   300
by (res_inst_tac [("n","m")] less_induct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   301
by (rename_tac "k" 1);    (*Variable name used in line below*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   302
by (case_tac "k<n" 1);
1660
8cb42cd97579 *** empty log message ***
oheimb
parents: 1655
diff changeset
   303
by (ALLGOALS (asm_simp_tac(!simpset addsimps ([add_assoc] @
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   304
                       [mod_less, mod_geq, div_less, div_geq,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   305
                        add_diff_inverse, diff_less]))));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   306
qed "mod_div_equality";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   307
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   308
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   309
(*** More results about difference ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   310
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   311
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   312
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   313
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1660
8cb42cd97579 *** empty log message ***
oheimb
parents: 1655
diff changeset
   314
by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
8cb42cd97579 *** empty log message ***
oheimb
parents: 1655
diff changeset
   315
by (ALLGOALS (Asm_simp_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   316
qed "less_imp_diff_is_0";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   317
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   318
val prems = goal Arith.thy "m-n = 0  -->  n-m = 0  -->  m=n";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   319
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   320
by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   321
qed_spec_mp "diffs0_imp_equal";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   322
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   323
val [prem] = goal Arith.thy "m<n ==> 0<n-m";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   324
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   325
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1660
8cb42cd97579 *** empty log message ***
oheimb
parents: 1655
diff changeset
   326
by (ALLGOALS (Asm_simp_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   327
qed "less_imp_diff_positive";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   328
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   329
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   330
by (rtac (prem RS rev_mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   331
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
1660
8cb42cd97579 *** empty log message ***
oheimb
parents: 1655
diff changeset
   332
by (ALLGOALS (Asm_simp_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   333
qed "Suc_diff_n";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   334
1398
b8de98c2c29c Changed div_termination -> diff_less
nipkow
parents: 1327
diff changeset
   335
goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   336
by (simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   337
                    setloop (split_tac [expand_if])) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   338
qed "if_Suc_diff_n";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   339
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   340
goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   341
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
   342
by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o Fast_tac));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   343
qed "zero_induct_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   344
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   345
val prems = goal Arith.thy "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   346
by (rtac (diff_self_eq_0 RS subst) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   347
by (rtac (zero_induct_lemma RS mp RS mp) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   348
by (REPEAT (ares_tac ([impI,allI]@prems) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   349
qed "zero_induct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   350
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   351
(*13 July 1992: loaded in 105.7s*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   352
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   353
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   354
(*** Further facts about mod (mainly for mutilated checkerboard ***)
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   355
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   356
goal Arith.thy
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   357
    "!!m n. 0<n ==> \
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   358
\           Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))";
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   359
by (res_inst_tac [("n","m")] less_induct 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   360
by (excluded_middle_tac "Suc(na)<n" 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   361
(* case Suc(na) < n *)
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   362
by (forward_tac [lessI RS less_trans] 2);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   363
by (asm_simp_tac (!simpset addsimps [mod_less, less_not_refl2 RS not_sym]) 2);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   364
(* case n <= Suc(na) *)
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   365
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, mod_geq]) 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   366
by (etac (le_imp_less_or_eq RS disjE) 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   367
by (asm_simp_tac (!simpset addsimps [Suc_diff_n]) 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   368
by (asm_full_simp_tac (!simpset addsimps [not_less_eq RS sym, 
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   369
                                          diff_less, mod_geq]) 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   370
by (asm_simp_tac (!simpset addsimps [mod_less]) 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   371
qed "mod_Suc";
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   372
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   373
goal Arith.thy "!!m n. 0<n ==> m mod n < n";
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   374
by (res_inst_tac [("n","m")] less_induct 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   375
by (excluded_middle_tac "na<n" 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   376
(*case na<n*)
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   377
by (asm_simp_tac (!simpset addsimps [mod_less]) 2);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   378
(*case n le na*)
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   379
by (asm_full_simp_tac (!simpset addsimps [mod_geq, diff_less]) 1);
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   380
qed "mod_less_divisor";
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   381
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1552
diff changeset
   382
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   383
(** Evens and Odds **)
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   384
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   385
(*With less_zeroE, causes case analysis on b<2*)
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   386
AddSEs [less_SucE];
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
   387
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   388
goal thy "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)";
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   389
by (subgoal_tac "k mod 2 < 2" 1);
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   390
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   391
by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
   392
by (Fast_tac 1);
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   393
qed "mod2_cases";
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   394
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   395
goal thy "Suc(Suc(m)) mod 2 = m mod 2";
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   396
by (subgoal_tac "m mod 2 < 2" 1);
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   397
by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   398
by (Step_tac 1);
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   399
by (ALLGOALS (asm_simp_tac (!simpset addsimps [mod_Suc])));
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   400
qed "mod2_Suc_Suc";
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   401
Addsimps [mod2_Suc_Suc];
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   402
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   403
goal thy "(m+m) mod 2 = 0";
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   404
by (nat_ind_tac "m" 1);
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   405
by (simp_tac (!simpset addsimps [mod_less]) 1);
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   406
by (asm_simp_tac (!simpset addsimps [mod2_Suc_Suc, add_Suc_right]) 1);
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   407
qed "mod2_add_self";
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   408
Addsimps [mod2_add_self];
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   409
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   410
Delrules [less_SucE];
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   411
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   412
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   413
(**** Additional theorems about "less than" ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   414
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   415
goal Arith.thy "? k::nat. n = n+k";
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   416
by (res_inst_tac [("x","0")] exI 1);
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   417
by (Simp_tac 1);
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   418
val lemma = result();
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   419
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   420
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   421
by (nat_ind_tac "n" 1);
1909
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   422
by (ALLGOALS (simp_tac (!simpset addsimps [less_Suc_eq])));
f535276171d1 Removal of less_SucE as default SE rule
paulson
parents: 1795
diff changeset
   423
by (step_tac (!claset addSIs [lemma]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   424
by (res_inst_tac [("x","Suc(k)")] exI 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   425
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
   426
qed_spec_mp "less_eq_Suc_add";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   427
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   428
goal Arith.thy "n <= ((m + n)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   429
by (nat_ind_tac "m" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   430
by (ALLGOALS Simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   431
by (etac le_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   432
by (rtac (lessI RS less_imp_le) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   433
qed "le_add2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   434
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   435
goal Arith.thy "n <= ((n + m)::nat)";
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   436
by (simp_tac (!simpset addsimps add_ac) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   437
by (rtac le_add2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   438
qed "le_add1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   439
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   440
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
   441
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
   442
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   443
(*"i <= j ==> i <= j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   444
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   445
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   446
(*"i <= j ==> i <= m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   447
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   448
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   449
(*"i < j ==> i < j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   450
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
   451
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   452
(*"i < j ==> i < m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   453
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
   454
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   455
goal Arith.thy "!!i. i+j < (k::nat) ==> i<k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   456
by (etac rev_mp 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   457
by (nat_ind_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   458
by (ALLGOALS Asm_simp_tac);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
   459
by (fast_tac (!claset addDs [Suc_lessD]) 1);
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   460
qed "add_lessD1";
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   461
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   462
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   463
by (etac le_trans 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   464
by (rtac le_add1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   465
qed "le_imp_add_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   466
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   467
goal Arith.thy "!!k::nat. m < n ==> m < n+k";
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   468
by (etac less_le_trans 1);
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   469
by (rtac le_add1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   470
qed "less_imp_add_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   471
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   472
goal Arith.thy "m+k<=n --> m<=(n::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   473
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   474
by (ALLGOALS Asm_simp_tac);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
   475
by (fast_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
   476
qed_spec_mp "add_leD1";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   477
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   478
goal Arith.thy "!!n::nat. m+k<=n ==> k<=n";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   479
by (full_simp_tac (!simpset addsimps [add_commute]) 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   480
by (etac add_leD1 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   481
qed_spec_mp "add_leD2";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   482
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   483
goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   484
by (fast_tac (!claset addDs [add_leD1, add_leD2]) 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   485
bind_thm ("add_leE", result() RS conjE);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   486
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   487
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
   488
by (safe_tac (!claset addSDs [less_eq_Suc_add]));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   489
by (asm_full_simp_tac
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   490
    (!simpset delsimps [add_Suc_right]
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   491
                addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   492
by (etac subst 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   493
by (simp_tac (!simpset addsimps [less_add_Suc1]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   494
qed "less_add_eq_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   495
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   496
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   497
(*** Monotonicity of Addition ***)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   498
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   499
(*strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   500
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
   501
by (nat_ind_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   502
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   503
qed "add_less_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   504
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   505
(*strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   506
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
   507
by (rtac (add_less_mono1 RS less_trans) 1);
1198
23be92d5bf4d tidied proof of add_less_mono
lcp
parents: 1152
diff changeset
   508
by (REPEAT (assume_tac 1));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   509
by (nat_ind_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   510
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   511
qed "add_less_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   512
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   513
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   514
val [lt_mono,le] = goal Arith.thy
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   515
     "[| !!i j::nat. i<j ==> f(i) < f(j);       \
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   516
\        i <= j                                 \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   517
\     |] ==> f(i) <= (f(j)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   518
by (cut_facts_tac [le] 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   519
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
1760
6f41a494f3b1 Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents: 1713
diff changeset
   520
by (fast_tac (!claset addSIs [lt_mono]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   521
qed "less_mono_imp_le_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   522
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   523
(*non-strict, in 1st argument*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   524
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
   525
by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   526
by (etac add_less_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   527
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   528
qed "add_le_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   529
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   530
(*non-strict, in both arguments*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   531
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
   532
by (etac (add_le_mono1 RS le_trans) 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   533
by (simp_tac (!simpset addsimps [add_commute]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   534
(*j moves to the end because it is free while k, l are bound*)
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   535
by (etac add_le_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   536
qed "add_le_mono";
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   537
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   538
(*** Monotonicity of Multiplication ***)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   539
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   540
goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   541
by (nat_ind_tac "k" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   542
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_le_mono])));
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   543
qed "mult_le_mono1";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   544
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   545
(*<=monotonicity, BOTH arguments*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   546
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
   547
by (etac (mult_le_mono1 RS le_trans) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   548
by (rtac le_trans 1);
2007
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   549
by (stac mult_commute 2);
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   550
by (etac mult_le_mono1 2);
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   551
by (simp_tac (!simpset addsimps [mult_commute]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   552
qed "mult_le_mono";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   553
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   554
(*strict, in 1st argument; proof is by induction on k>0*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   555
goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   556
by (etac zero_less_natE 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   557
by (Asm_simp_tac 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   558
by (nat_ind_tac "x" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   559
by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_less_mono])));
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   560
qed "mult_less_mono2";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   561
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   562
goal Arith.thy "(0 < m*n) = (0<m & 0<n)";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   563
by (nat_ind_tac "m" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   564
by (nat_ind_tac "n" 2);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   565
by (ALLGOALS Asm_simp_tac);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   566
qed "zero_less_mult_iff";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   567
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   568
goal Arith.thy "(m*n = 1) = (m=1 & n=1)";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   569
by (nat_ind_tac "m" 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   570
by (Simp_tac 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   571
by (nat_ind_tac "n" 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   572
by (Simp_tac 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   573
by (fast_tac (!claset addss !simpset) 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   574
qed "mult_eq_1_iff";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   575
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   576
(*Cancellation law for division*)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   577
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
   578
by (res_inst_tac [("n","m")] less_induct 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   579
by (case_tac "na<n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   580
by (asm_simp_tac (!simpset addsimps [div_less, zero_less_mult_iff, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   581
                                     mult_less_mono2]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   582
by (subgoal_tac "~ k*na < k*n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   583
by (asm_simp_tac
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   584
     (!simpset addsimps [zero_less_mult_iff, div_geq,
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   585
                         diff_mult_distrib2 RS sym, diff_less]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   586
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   587
                                          le_refl RS mult_le_mono]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   588
qed "div_cancel";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   589
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   590
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
   591
by (res_inst_tac [("n","m")] less_induct 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   592
by (case_tac "na<n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   593
by (asm_simp_tac (!simpset addsimps [mod_less, zero_less_mult_iff, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   594
                                     mult_less_mono2]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   595
by (subgoal_tac "~ k*na < k*n" 1);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   596
by (asm_simp_tac
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   597
     (!simpset addsimps [zero_less_mult_iff, mod_geq,
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   598
                         diff_mult_distrib2 RS sym, diff_less]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   599
by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, 
2031
03a843f0f447 Ran expandshort
paulson
parents: 2007
diff changeset
   600
                                          le_refl RS mult_le_mono]) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   601
qed "mult_mod_distrib";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   602
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   603
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   604
(** Lemma for gcd **)
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   605
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   606
goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   607
by (dtac sym 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   608
by (rtac disjCI 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   609
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
   610
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
   611
by (best_tac (!claset addDs [mult_less_mono2] 
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   612
                      addss (!simpset addsimps [zero_less_eq RS sym])) 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   613
qed "mult_eq_self_implies_10";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   614
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   615