src/HOL/Arith.ML
author berghofe
Tue, 30 May 2000 18:02:49 +0200
changeset 9001 93af64f54bf2
parent 8935 548901d05a0e
child 9041 3730ae0f513a
permissions -rw-r--r--
the is now defined using primrec, avoiding explicit use of arbitrary.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     1
(*  Title:      HOL/Arith.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
4736
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
     4
    Copyright   1998  University of Cambridge
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Proofs about elementary arithmetic: addition, multiplication, etc.
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
     7
Some from the Hoare example from Norbert Galm
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
(*** Basic rewrite rules for the arithmetic operators ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
3896
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    12
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
(** Difference **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
    15
Goal "0 - n = (0::nat)";
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    16
by (induct_tac "n" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    17
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    18
qed "diff_0_eq_0";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    20
(*Must simplify BEFORE the induction!  (Else we get a critical pair)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
  Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    22
Goal "Suc(m) - Suc(n) = m - n";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    23
by (Simp_tac 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    24
by (induct_tac "n" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    25
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    26
qed "diff_Suc_Suc";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
2682
13cdbf95ed92 minor changes due to new primrec definitions for +,-,*
pusch
parents: 2498
diff changeset
    28
Addsimps [diff_0_eq_0, diff_Suc_Suc];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    30
(* Could be (and is, below) generalized in various ways;
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    31
   However, none of the generalizations are currently in the simpset,
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    32
   and I dread to think what happens if I put them in *)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
    33
Goal "0 < n ==> Suc(n-1) = n";
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    34
by (asm_simp_tac (simpset() addsplits [nat.split]) 1);
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    35
qed "Suc_pred";
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    36
Addsimps [Suc_pred];
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    37
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    38
Delsimps [diff_Suc];
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
    39
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
(**** Inductive properties of the operators ****)
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
(*** Addition ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
    45
Goal "m + 0 = (m::nat)";
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    46
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    47
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    48
qed "add_0_right";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    50
Goal "m + Suc(n) = Suc(m+n)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    51
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    52
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    53
qed "add_Suc_right";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    55
Addsimps [add_0_right,add_Suc_right];
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    57
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
(*Associative law for addition*)
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    59
Goal "(m + n) + k = m + ((n + k)::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    60
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    61
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    62
qed "add_assoc";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
(*Commutative law for addition*)  
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    65
Goal "m + n = n + (m::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    66
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    67
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    68
qed "add_commute";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    70
Goal "x+(y+z)=y+((x+z)::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    71
by (rtac (add_commute RS trans) 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    72
by (rtac (add_assoc RS trans) 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    73
by (rtac (add_commute RS arg_cong) 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
    74
qed "add_left_commute";
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
(*Addition is an AC-operator*)
7428
80838c2af97b bind_thms;
wenzelm
parents: 7131
diff changeset
    77
bind_thms ("add_ac", [add_assoc, add_commute, add_left_commute]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    79
Goal "(k + m = k + n) = (m=(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    80
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    81
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    82
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
qed "add_left_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    85
Goal "(m + k = n + k) = (m=(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    86
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    87
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    88
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
qed "add_right_cancel";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    91
Goal "(k + m <= k + n) = (m<=(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    92
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    93
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    94
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
qed "add_left_cancel_le";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
    97
Goal "(k + m < k + n) = (m<(n::nat))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
    98
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
    99
by (Simp_tac 1);
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   100
by (Asm_simp_tac 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
qed "add_left_cancel_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   103
Addsimps [add_left_cancel, add_right_cancel,
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   104
          add_left_cancel_le, add_left_cancel_less];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   105
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   106
(** Reasoning about m+0=0, etc. **)
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   107
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   108
Goal "!!m::nat. (m+n = 0) = (m=0 & n=0)";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   109
by (case_tac "m" 1);
5598
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   110
by (Auto_tac);
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   111
qed "add_is_0";
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   112
AddIffs [add_is_0];
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   113
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   114
Goal "!!m::nat. (0 = m+n) = (m=0 & n=0)";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   115
by (case_tac "m" 1);
5598
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   116
by (Auto_tac);
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   117
qed "zero_is_add";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   118
AddIffs [zero_is_add];
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   119
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   120
Goal "!!m::nat. (m+n=1) = (m=1 & n=0 | m=0 & n=1)";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   121
by (case_tac "m" 1);
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
   122
by (Auto_tac);
5598
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   123
qed "add_is_1";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   124
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   125
Goal "!!m::nat. (1=m+n) = (m=1 & n=0 | m=0 & n=1)";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   126
by (case_tac "m" 1);
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
   127
by (Auto_tac);
5598
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   128
qed "one_is_add";
6b8dee1a6ebb a few new lemmas.
nipkow
parents: 5537
diff changeset
   129
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   130
Goal "!!m::nat. (0<m+n) = (0<m | 0<n)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   131
by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1);
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   132
qed "add_gr_0";
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   133
AddIffs [add_gr_0];
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   134
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   135
(* Could be generalized, eg to "k<n ==> m+(n-(Suc k)) = (m+n)-(Suc k)" *)
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   136
Goal "!!m::nat. 0<n ==> m + (n-1) = (m+n)-1";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   137
by (case_tac "m" 1);
6075
c148037f53c6 Remoaved a few now redundant rewrite rules.
nipkow
parents: 6073
diff changeset
   138
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc, Suc_n_not_n]
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   139
                                      addsplits [nat.split])));
1327
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   140
qed "add_pred";
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   141
Addsimps [add_pred];
6c29cfab679c added new arithmetic lemmas and the functions take and drop.
nipkow
parents: 1301
diff changeset
   142
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   143
Goal "!!m::nat. m + n = m ==> n = 0";
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   144
by (dtac (add_0_right RS ssubst) 1);
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   145
by (asm_full_simp_tac (simpset() addsimps [add_assoc]
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   146
                                 delsimps [add_0_right]) 1);
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   147
qed "add_eq_self_zero";
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   148
1626
12560b3ebf2c Moved even/odd lemmas from ex/Mutil to Arith
paulson
parents: 1618
diff changeset
   149
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   150
(**** Additional theorems about "less than" ****)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   151
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   152
(*Deleted less_natE; instead use less_eq_Suc_add RS exE*)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   153
Goal "m<n --> (? k. n=Suc(m+k))";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   154
by (induct_tac "n" 1);
5604
cd17004d09e1 tidying
paulson
parents: 5598
diff changeset
   155
by (ALLGOALS (simp_tac (simpset() addsimps [order_le_less])));
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   156
by (blast_tac (claset() addSEs [less_SucE] 
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   157
                        addSIs [add_0_right RS sym, add_Suc_right RS sym]) 1);
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   158
qed_spec_mp "less_eq_Suc_add";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   159
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   160
Goal "n <= ((m + n)::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   161
by (induct_tac "m" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   162
by (ALLGOALS Simp_tac);
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   163
by (etac le_SucI 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
qed "le_add2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   165
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   166
Goal "n <= ((n + m)::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   167
by (simp_tac (simpset() addsimps add_ac) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   168
by (rtac le_add2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   169
qed "le_add1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   170
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   171
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
   172
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
   173
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   174
Goal "(m<n) = (? k. n=Suc(m+k))";
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   175
by (blast_tac (claset() addSIs [less_add_Suc1, less_eq_Suc_add]) 1);
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   176
qed "less_iff_Suc_add";
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   177
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   178
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   179
(*"i <= j ==> i <= j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   180
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans));
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
(*"i <= j ==> i <= m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   183
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   184
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   185
(*"i < j ==> i < j+m"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   186
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
   187
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   188
(*"i < j ==> i < m+j"*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   189
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
   190
5654
8b872d546b9e Installed trans_tac in solver of simpset().
nipkow
parents: 5604
diff changeset
   191
Goal "i+j < (k::nat) --> i<k";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   192
by (induct_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   193
by (ALLGOALS Asm_simp_tac);
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
   194
by (blast_tac (claset() addDs [Suc_lessD]) 1);
5654
8b872d546b9e Installed trans_tac in solver of simpset().
nipkow
parents: 5604
diff changeset
   195
qed_spec_mp "add_lessD1";
1152
b6e1e74695f6 Added add_lessD1
nipkow
parents: 972
diff changeset
   196
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   197
Goal "~ (i+j < (i::nat))";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   198
by (rtac notI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   199
by (etac (add_lessD1 RS less_irrefl) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   200
qed "not_add_less1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   201
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   202
Goal "~ (j+i < (i::nat))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   203
by (simp_tac (simpset() addsimps [add_commute, not_add_less1]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   204
qed "not_add_less2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   205
AddIffs [not_add_less1, not_add_less2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   206
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   207
Goal "m+k<=n --> m<=(n::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   208
by (induct_tac "k" 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   209
by (ALLGOALS (asm_simp_tac (simpset() addsimps le_simps)));
1485
240cc98b94a7 Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents: 1475
diff changeset
   210
qed_spec_mp "add_leD1";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   211
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   212
Goal "m+k<=n ==> k<=(n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   213
by (full_simp_tac (simpset() addsimps [add_commute]) 1);
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   214
by (etac add_leD1 1);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   215
qed_spec_mp "add_leD2";
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   216
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   217
Goal "m+k<=n ==> m<=n & k<=(n::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   218
by (blast_tac (claset() addDs [add_leD1, add_leD2]) 1);
2498
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   219
bind_thm ("add_leE", result() RS conjE);
7914881f47c0 New theorem add_leE
paulson
parents: 2099
diff changeset
   220
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   221
(*needs !!k for add_ac to work*)
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   222
Goal "!!k:: nat. [| k<l;  m+l = k+n |] ==> m<n";
5758
27a2b36efd95 corrected auto_tac (applications of unsafe wrappers)
oheimb
parents: 5654
diff changeset
   223
by (force_tac (claset(),
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   224
	      simpset() delsimps [add_Suc_right]
5537
c2bd39a2c0ee deleted needless parentheses
paulson
parents: 5497
diff changeset
   225
	                addsimps [less_iff_Suc_add,
5758
27a2b36efd95 corrected auto_tac (applications of unsafe wrappers)
oheimb
parents: 5654
diff changeset
   226
				  add_Suc_right RS sym] @ add_ac) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   227
qed "less_add_eq_less";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   228
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   229
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   230
(*** Monotonicity of Addition ***)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   231
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   232
(*strict, in 1st argument*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   233
Goal "i < j ==> i + k < j + (k::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   234
by (induct_tac "k" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   235
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   236
qed "add_less_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   237
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   238
(*strict, in both arguments*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   239
Goal "[|i < j; k < l|] ==> i + k < j + (l::nat)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   240
by (rtac (add_less_mono1 RS less_trans) 1);
1198
23be92d5bf4d tidied proof of add_less_mono
lcp
parents: 1152
diff changeset
   241
by (REPEAT (assume_tac 1));
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   242
by (induct_tac "j" 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1198
diff changeset
   243
by (ALLGOALS Asm_simp_tac);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   244
qed "add_less_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   245
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   246
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5270
diff changeset
   247
val [lt_mono,le] = Goal
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   248
     "[| !!i j::nat. i<j ==> f(i) < f(j);       \
5d7a7e439cec expanded tabs
clasohm
parents: 1398
diff changeset
   249
\        i <= j                                 \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   250
\     |] ==> f(i) <= (f(j)::nat)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   251
by (cut_facts_tac [le] 1);
5604
cd17004d09e1 tidying
paulson
parents: 5598
diff changeset
   252
by (asm_full_simp_tac (simpset() addsimps [order_le_less]) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   253
by (blast_tac (claset() addSIs [lt_mono]) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   254
qed "less_mono_imp_le_mono";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   255
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   256
(*non-strict, in 1st argument*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   257
Goal "i<=j ==> i + k <= j + (k::nat)";
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3724
diff changeset
   258
by (res_inst_tac [("f", "%j. j+k")] less_mono_imp_le_mono 1);
1552
6f71b5d46700 Ran expandshort
paulson
parents: 1496
diff changeset
   259
by (etac add_less_mono1 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   260
by (assume_tac 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   261
qed "add_le_mono1";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   262
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   263
(*non-strict, in both arguments*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   264
Goal "[|i<=j;  k<=l |] ==> i + k <= j + (l::nat)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   265
by (etac (add_le_mono1 RS le_trans) 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   266
by (simp_tac (simpset() addsimps [add_commute]) 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*)
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   273
Goal "!!m::nat. m * 0 = 0";
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   274
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   275
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   276
qed "mult_0_right";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   277
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   278
(*right successor law for multiplication*)
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   279
Goal  "m * Suc(n) = m + (m * n)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   280
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   281
by (ALLGOALS(asm_simp_tac (simpset() addsimps add_ac)));
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   282
qed "mult_Suc_right";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   283
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   284
Addsimps [mult_0_right, mult_Suc_right];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   285
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   286
Goal "1 * n = n";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   287
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   288
qed "mult_1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   289
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   290
Goal "n * 1 = n";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   291
by (Asm_simp_tac 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   292
qed "mult_1_right";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   293
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   294
(*Commutative law for multiplication*)
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   295
Goal "m * n = n * (m::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   296
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   297
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   298
qed "mult_commute";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   299
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   300
(*addition distributes over multiplication*)
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   301
Goal "(m + n)*k = (m*k) + ((n*k)::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   302
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   303
by (ALLGOALS(asm_simp_tac (simpset() addsimps add_ac)));
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   304
qed "add_mult_distrib";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   305
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   306
Goal "k*(m + n) = (k*m) + ((k*n)::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   307
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   308
by (ALLGOALS(asm_simp_tac (simpset() addsimps add_ac)));
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   309
qed "add_mult_distrib2";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   310
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   311
(*Associative law for multiplication*)
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   312
Goal "(m * n) * k = m * ((n * k)::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   313
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   314
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_mult_distrib])));
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   315
qed "mult_assoc";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   316
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   317
Goal "x*(y*z) = y*((x*z)::nat)";
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   318
by (rtac trans 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   319
by (rtac mult_commute 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   320
by (rtac trans 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   321
by (rtac mult_assoc 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   322
by (rtac (mult_commute RS arg_cong) 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   323
qed "mult_left_commute";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   324
7428
80838c2af97b bind_thms;
wenzelm
parents: 7131
diff changeset
   325
bind_thms ("mult_ac", [mult_assoc,mult_commute,mult_left_commute]);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   326
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   327
Goal "!!m::nat. (m*n = 0) = (m=0 | n=0)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   328
by (induct_tac "m" 1);
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   329
by (induct_tac "n" 2);
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   330
by (ALLGOALS Asm_simp_tac);
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   331
qed "mult_is_0";
7622
dcb93b295683 zero_is_mult, by symmetry
paulson
parents: 7582
diff changeset
   332
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   333
Goal "!!m::nat. (0 = m*n) = (0=m | 0=n)";
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   334
by (stac eq_commute 1 THEN stac mult_is_0 1);
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   335
by Auto_tac;
7622
dcb93b295683 zero_is_mult, by symmetry
paulson
parents: 7582
diff changeset
   336
qed "zero_is_mult";
dcb93b295683 zero_is_mult, by symmetry
paulson
parents: 7582
diff changeset
   337
dcb93b295683 zero_is_mult, by symmetry
paulson
parents: 7582
diff changeset
   338
Addsimps [mult_is_0, zero_is_mult];
3293
c05f73cf3227 New lemmas used for ex/Fib
paulson
parents: 3234
diff changeset
   339
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   340
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   341
(*** Difference ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   342
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   343
Goal "!!m::nat. m - m = 0";
7007
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   344
by (induct_tac "m" 1);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   345
by (ALLGOALS Asm_simp_tac);
b46ccfee8e59 qed_goal -> Goal
paulson
parents: 6987
diff changeset
   346
qed "diff_self_eq_0";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   347
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   348
Addsimps [diff_self_eq_0];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   349
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   350
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   351
Goal "~ m<n --> n+(m-n) = (m::nat)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   352
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   353
by (ALLGOALS Asm_simp_tac);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   354
qed_spec_mp "add_diff_inverse";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   355
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   356
Goal "n<=m ==> n+(m-n) = (m::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   357
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, not_less_iff_le]) 1);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   358
qed "le_add_diff_inverse";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   359
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   360
Goal "n<=m ==> (m-n)+n = (m::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   361
by (asm_simp_tac (simpset() addsimps [le_add_diff_inverse, add_commute]) 1);
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   362
qed "le_add_diff_inverse2";
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   363
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
   364
Addsimps  [le_add_diff_inverse, le_add_diff_inverse2];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   365
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   366
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   367
(*** More results about difference ***)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   368
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   369
Goal "n <= m ==> Suc(m)-n = Suc(m-n)";
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5270
diff changeset
   370
by (etac rev_mp 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   371
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   372
by (ALLGOALS Asm_simp_tac);
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
   373
qed "Suc_diff_le";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   374
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   375
Goal "m - n < Suc(m)";
3234
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 (etac less_SucE 3);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   378
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq])));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   379
qed "diff_less_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   380
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   381
Goal "m - n <= (m::nat)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   382
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
6075
c148037f53c6 Remoaved a few now redundant rewrite rules.
nipkow
parents: 6073
diff changeset
   383
by (ALLGOALS (asm_simp_tac (simpset() addsimps [le_SucI])));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   384
qed "diff_le_self";
3903
1b29151a1009 New simprule diff_le_self, requiring a new proof of diff_diff_cancel
paulson
parents: 3896
diff changeset
   385
Addsimps [diff_le_self];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   386
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   387
(* j<k ==> j-n < k *)
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   388
bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans);
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   389
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   390
Goal "!!i::nat. i-j-k = i - (j+k)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   391
by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   392
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   393
qed "diff_diff_left";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   394
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   395
Goal "(Suc m - n) - Suc k = m - n - k";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   396
by (simp_tac (simpset() addsimps [diff_diff_left]) 1);
4736
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   397
qed "Suc_diff_diff";
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
   398
Addsimps [Suc_diff_diff];
4360
40e5c97e988d pred n -> n-1
nipkow
parents: 4356
diff changeset
   399
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
   400
Goal "0<n ==> n - Suc i < n";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   401
by (case_tac "n" 1);
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   402
by Safe_tac;
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   403
by (asm_simp_tac (simpset() addsimps le_simps) 1);
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   404
qed "diff_Suc_less";
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   405
Addsimps [diff_Suc_less];
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   406
3396
aa74c71c3982 eliminated non-ASCII;
wenzelm
parents: 3381
diff changeset
   407
(*This and the next few suggested by Florian Kammueller*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   408
Goal "!!i::nat. i-j-k = i-k-j";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   409
by (simp_tac (simpset() addsimps [diff_diff_left, add_commute]) 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   410
qed "diff_commute";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   411
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   412
Goal "k <= (j::nat) --> (i + j) - k = i + (j - k)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   413
by (res_inst_tac [("m","j"),("n","k")] diff_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   414
by (ALLGOALS Asm_simp_tac);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   415
qed_spec_mp "diff_add_assoc";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   416
8708
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
   417
Goal "k <= (j::nat) --> (j + i) - k = (j - k) + i";
4732
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   418
by (asm_simp_tac (simpset() addsimps [add_commute, diff_add_assoc]) 1);
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   419
qed_spec_mp "diff_add_assoc2";
10af4886b33f Arith.thy -> thy; proved a few new theorems
paulson
parents: 4686
diff changeset
   420
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   421
Goal "(n+m) - n = (m::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   422
by (induct_tac "n" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   423
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   424
qed "diff_add_inverse";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   425
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   426
Goal "(m+n) - n = (m::nat)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   427
by (simp_tac (simpset() addsimps [diff_add_assoc]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   428
qed "diff_add_inverse2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   429
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   430
Goal "i <= (j::nat) ==> (j-i=k) = (j=k+i)";
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   431
by Safe_tac;
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   432
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_add_inverse2])));
3366
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents: 3352
diff changeset
   433
qed "le_imp_diff_is_add";
2402c6ab1561 Moving div and mod from Arith to Divides
paulson
parents: 3352
diff changeset
   434
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   435
Goal "!!m::nat. (m-n = 0) = (m <= n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   436
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
   437
by (ALLGOALS Asm_simp_tac);
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
   438
qed "diff_is_0_eq";
7059
71e9ea2198e0 a stronger diff_less and no more le_diff_less
paulson
parents: 7007
diff changeset
   439
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   440
Goal "!!m::nat. (0 = m-n) = (m <= n)";
7059
71e9ea2198e0 a stronger diff_less and no more le_diff_less
paulson
parents: 7007
diff changeset
   441
by (stac (diff_is_0_eq RS sym) 1);
71e9ea2198e0 a stronger diff_less and no more le_diff_less
paulson
parents: 7007
diff changeset
   442
by (rtac eq_sym_conv 1);
71e9ea2198e0 a stronger diff_less and no more le_diff_less
paulson
parents: 7007
diff changeset
   443
qed "zero_is_diff_eq";
71e9ea2198e0 a stronger diff_less and no more le_diff_less
paulson
parents: 7007
diff changeset
   444
Addsimps [diff_is_0_eq, zero_is_diff_eq];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   445
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   446
Goal "!!m::nat. (0<n-m) = (m<n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   447
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3339
diff changeset
   448
by (ALLGOALS Asm_simp_tac);
5333
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   449
qed "zero_less_diff";
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   450
Addsimps [zero_less_diff];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   451
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   452
Goal "i < j  ==> ? k::nat. 0<k & i+k = j";
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   453
by (res_inst_tac [("x","j - i")] exI 1);
5333
ea33e66dcedd Some new theorems. zero_less_diff replaces less_imp_diff_positive
paulson
parents: 5329
diff changeset
   454
by (asm_simp_tac (simpset() addsimps [add_diff_inverse, less_not_sym]) 1);
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   455
qed "less_imp_add_positive";
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   456
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   457
Goal "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   458
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
3718
d78cf498a88c Minor tidying to use Clarify_tac, etc.
paulson
parents: 3484
diff changeset
   459
by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   460
qed "zero_induct_lemma";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   461
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5270
diff changeset
   462
val prems = Goal "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   463
by (rtac (diff_self_eq_0 RS subst) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   464
by (rtac (zero_induct_lemma RS mp RS mp) 1);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   465
by (REPEAT (ares_tac ([impI,allI]@prems) 1));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   466
qed "zero_induct";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   467
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   468
Goal "(k+m) - (k+n) = m - (n::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   469
by (induct_tac "k" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   470
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   471
qed "diff_cancel";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   472
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   473
Goal "(m+k) - (n+k) = m - (n::nat)";
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   474
by (asm_simp_tac
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   475
    (simpset() addsimps [diff_cancel, inst "n" "k" add_commute]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   476
qed "diff_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   477
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   478
Goal "n - (n+m) = (0::nat)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   479
by (induct_tac "n" 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   480
by (ALLGOALS Asm_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   481
qed "diff_add_0";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   482
5409
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
   483
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   484
(** Difference distributes over multiplication **)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   485
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   486
Goal "!!m::nat. (m - n) * k = (m * k) - (n * k)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   487
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   488
by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_cancel])));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   489
qed "diff_mult_distrib" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   490
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   491
Goal "!!m::nat. k * (m - n) = (k * m) - (k * n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   492
val mult_commute_k = read_instantiate [("m","k")] mult_commute;
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   493
by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   494
qed "diff_mult_distrib2" ;
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   495
(*NOT added as rewrites, since sometimes they are used from right-to-left*)
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   496
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   497
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   498
(*** Monotonicity of Multiplication ***)
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   499
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   500
Goal "i <= (j::nat) ==> i*k<=j*k";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   501
by (induct_tac "k" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   502
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_le_mono])));
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   503
qed "mult_le_mono1";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   504
6987
4e0defe58b42 simplified the <= monotonicity proof
paulson
parents: 6968
diff changeset
   505
Goal "i <= (j::nat) ==> k*i <= k*j";
4e0defe58b42 simplified the <= monotonicity proof
paulson
parents: 6968
diff changeset
   506
by (dtac mult_le_mono1 1);
4e0defe58b42 simplified the <= monotonicity proof
paulson
parents: 6968
diff changeset
   507
by (asm_simp_tac (simpset() addsimps [mult_commute]) 1);
4e0defe58b42 simplified the <= monotonicity proof
paulson
parents: 6968
diff changeset
   508
qed "mult_le_mono2";
4e0defe58b42 simplified the <= monotonicity proof
paulson
parents: 6968
diff changeset
   509
4e0defe58b42 simplified the <= monotonicity proof
paulson
parents: 6968
diff changeset
   510
(* <= monotonicity, BOTH arguments*)
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
   511
Goal "[| i <= (j::nat); k <= l |] ==> i*k <= j*l";
2007
968f78b52540 Proof of mult_le_mono is now more robust
paulson
parents: 1979
diff changeset
   512
by (etac (mult_le_mono1 RS le_trans) 1);
6987
4e0defe58b42 simplified the <= monotonicity proof
paulson
parents: 6968
diff changeset
   513
by (etac mult_le_mono2 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   514
qed "mult_le_mono";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   515
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   516
(*strict, in 1st argument; proof is by induction on k>0*)
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   517
Goal "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
5078
7b5ea59c0275 Installation of target HOL-Real
paulson
parents: 5069
diff changeset
   518
by (eres_inst_tac [("m1","0")] (less_eq_Suc_add RS exE) 1);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   519
by (Asm_simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   520
by (induct_tac "x" 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   521
by (ALLGOALS (asm_simp_tac (simpset() addsimps [add_less_mono])));
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   522
qed "mult_less_mono2";
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   523
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   524
Goal "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   525
by (dtac mult_less_mono2 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   526
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute])));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   527
qed "mult_less_mono1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   528
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   529
Goal "!!m::nat. (0 < m*n) = (0<m & 0<n)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   530
by (induct_tac "m" 1);
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   531
by (case_tac "n" 2);
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   532
by (ALLGOALS Asm_simp_tac);
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   533
qed "zero_less_mult_iff";
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4297
diff changeset
   534
Addsimps [zero_less_mult_iff];
1713
79b4ef7832b5 New cancellation and monotonicity laws, about
paulson
parents: 1660
diff changeset
   535
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   536
Goal "(1 <= m*n) = (1<=m & 1<=n)";
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   537
by (induct_tac "m" 1);
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   538
by (case_tac "n" 2);
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   539
by (ALLGOALS Asm_simp_tac);
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   540
qed "one_le_mult_iff";
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   541
Addsimps [one_le_mult_iff];
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   542
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   543
Goal "(m*n = 1) = (m=1 & n=1)";
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   544
by (induct_tac "m" 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   545
by (Simp_tac 1);
3339
cfa72a70f2b5 Tidying and a couple of useful lemmas
paulson
parents: 3293
diff changeset
   546
by (induct_tac "n" 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   547
by (Simp_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   548
by (fast_tac (claset() addss simpset()) 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   549
qed "mult_eq_1_iff";
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4297
diff changeset
   550
Addsimps [mult_eq_1_iff];
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   551
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   552
Goal "!!m::nat. 0<k ==> (m*k < n*k) = (m<n)";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   553
by (safe_tac (claset() addSIs [mult_less_mono1]));
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   554
by (cut_facts_tac [less_linear] 1);
4389
1865cb8df116 Faster proof of mult_less_cancel2
paulson
parents: 4378
diff changeset
   555
by (blast_tac (claset() addIs [mult_less_mono1] addEs [less_asym]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   556
qed "mult_less_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   557
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   558
Goal "!!m::nat. 0<k ==> (k*m < k*n) = (m<n)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   559
by (dtac mult_less_cancel2 1);
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   560
by (etac subst 1);
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   561
by (simp_tac (simpset() addsimps [mult_commute]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   562
qed "mult_less_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   563
Addsimps [mult_less_cancel1, mult_less_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   564
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   565
Goal "!!m::nat. 0<k ==> (m*k <= n*k) = (m<=n)";
6864
32b5d68196d2 new laws mult_le_cancel1, mult_le_cancel2
paulson
parents: 6394
diff changeset
   566
by (asm_full_simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1);
32b5d68196d2 new laws mult_le_cancel1, mult_le_cancel2
paulson
parents: 6394
diff changeset
   567
qed "mult_le_cancel2";
32b5d68196d2 new laws mult_le_cancel1, mult_le_cancel2
paulson
parents: 6394
diff changeset
   568
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   569
Goal "!!m::nat. 0<k ==> (k*m <= k*n) = (m<=n)";
6864
32b5d68196d2 new laws mult_le_cancel1, mult_le_cancel2
paulson
parents: 6394
diff changeset
   570
by (asm_full_simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1);
32b5d68196d2 new laws mult_le_cancel1, mult_le_cancel2
paulson
parents: 6394
diff changeset
   571
qed "mult_le_cancel1";
32b5d68196d2 new laws mult_le_cancel1, mult_le_cancel2
paulson
parents: 6394
diff changeset
   572
Addsimps [mult_le_cancel1, mult_le_cancel2];
32b5d68196d2 new laws mult_le_cancel1, mult_le_cancel2
paulson
parents: 6394
diff changeset
   573
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   574
Goal "(Suc k * m < Suc k * n) = (m < n)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   575
by (rtac mult_less_cancel1 1);
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   576
by (Simp_tac 1);
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   577
qed "Suc_mult_less_cancel1";
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   578
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   579
Goalw [le_def] "(Suc k * m <= Suc k * n) = (m <= n)";
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   580
by (simp_tac (simpset_of HOL.thy) 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   581
by (rtac Suc_mult_less_cancel1 1);
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   582
qed "Suc_mult_le_cancel1";
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   583
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   584
Goal "0 < (k::nat) ==> (m*k = n*k) = (m=n)";
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   585
by (cut_facts_tac [less_linear] 1);
3724
f33e301a89f5 Step_tac -> Safe_tac
paulson
parents: 3718
diff changeset
   586
by Safe_tac;
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   587
by (assume_tac 2);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   588
by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac));
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   589
by (ALLGOALS Asm_full_simp_tac);
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   590
qed "mult_cancel2";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   591
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   592
Goal "0 < (k::nat) ==> (k*m = k*n) = (m=n)";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3396
diff changeset
   593
by (dtac mult_cancel2 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   594
by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   595
qed "mult_cancel1";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   596
Addsimps [mult_cancel1, mult_cancel2];
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   597
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   598
Goal "(Suc k * m = Suc k * n) = (m = n)";
4423
a129b817b58a expandshort;
wenzelm
parents: 4389
diff changeset
   599
by (rtac mult_cancel1 1);
4297
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   600
by (Simp_tac 1);
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   601
qed "Suc_mult_cancel1";
5defc2105cc8 added Suc_mult_less_cancel1, Suc_mult_le_cancel1, Suc_mult_cancel1;
wenzelm
parents: 4158
diff changeset
   602
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
   603
8352
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
   604
(*Lemma for gcd*)
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
   605
Goal "!!m::nat. m = m*n ==> n=1 | m=0";
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   606
by (dtac sym 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   607
by (rtac disjCI 1);
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   608
by (rtac nat_less_cases 1 THEN assume_tac 2);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   609
by (fast_tac (claset() addSEs [less_SucE] addss simpset()) 1);
4356
0dfd34f0d33d Replaced n ~= 0 by 0 < n
nipkow
parents: 4297
diff changeset
   610
by (best_tac (claset() addDs [mult_less_mono2] addss simpset()) 1);
1795
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   611
qed "mult_eq_self_implies_10";
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   612
0466f9668ba3 New lemmas for gcd example
paulson
parents: 1786
diff changeset
   613
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   614
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   615
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   616
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   617
(* Various arithmetic proof procedures                                       *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   618
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   619
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   620
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   621
(* 1. Cancellation of common terms                                           *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   622
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   623
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   624
(*  Title:      HOL/arith_data.ML
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   625
    ID:         $Id$
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   626
    Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   627
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   628
Setup various arithmetic proof procedures.
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   629
*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   630
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   631
signature ARITH_DATA =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   632
sig
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   633
  val nat_cancel_sums_add: simproc list
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   634
  val nat_cancel_sums: simproc list
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   635
  val nat_cancel_factor: simproc list
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   636
  val nat_cancel: simproc list
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   637
end;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   638
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   639
structure ArithData: ARITH_DATA =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   640
struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   641
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   642
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   643
(** abstract syntax of structure nat: 0, Suc, + **)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   644
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   645
(* mk_sum, mk_norm_sum *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   646
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   647
val one = HOLogic.mk_nat 1;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   648
val mk_plus = HOLogic.mk_binop "op +";
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   649
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   650
fun mk_sum [] = HOLogic.zero
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   651
  | mk_sum [t] = t
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   652
  | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   653
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   654
(*normal form of sums: Suc (... (Suc (a + (b + ...))))*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   655
fun mk_norm_sum ts =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   656
  let val (ones, sums) = partition (equal one) ts in
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   657
    funpow (length ones) HOLogic.mk_Suc (mk_sum sums)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   658
  end;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   659
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   660
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   661
(* dest_sum *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   662
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   663
val dest_plus = HOLogic.dest_bin "op +" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   664
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   665
fun dest_sum tm =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   666
  if HOLogic.is_zero tm then []
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   667
  else
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   668
    (case try HOLogic.dest_Suc tm of
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   669
      Some t => one :: dest_sum t
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   670
    | None =>
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   671
        (case try dest_plus tm of
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   672
          Some (t, u) => dest_sum t @ dest_sum u
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   673
        | None => [tm]));
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   674
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   675
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   676
(** generic proof tools **)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   677
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   678
(* prove conversions *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   679
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   680
val mk_eqv = HOLogic.mk_Trueprop o HOLogic.mk_eq;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   681
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   682
fun prove_conv expand_tac norm_tac sg (t, u) =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   683
  mk_meta_eq (prove_goalw_cterm_nocheck [] (cterm_of sg (mk_eqv (t, u)))
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   684
    (K [expand_tac, norm_tac]))
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   685
  handle ERROR => error ("The error(s) above occurred while trying to prove " ^
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   686
    (string_of_cterm (cterm_of sg (mk_eqv (t, u)))));
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   687
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   688
val subst_equals = prove_goal HOL.thy "[| t = s; u = t |] ==> u = s"
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   689
  (fn prems => [cut_facts_tac prems 1, SIMPSET' asm_simp_tac 1]);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   690
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   691
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   692
(* rewriting *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   693
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   694
fun simp_all rules = ALLGOALS (simp_tac (HOL_ss addsimps rules));
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   695
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   696
val add_rules = [add_Suc, add_Suc_right, add_0, add_0_right];
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   697
val mult_rules = [mult_Suc, mult_Suc_right, mult_0, mult_0_right];
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   698
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   699
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   700
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   701
(** cancel common summands **)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   702
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   703
structure Sum =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   704
struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   705
  val mk_sum = mk_norm_sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   706
  val dest_sum = dest_sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   707
  val prove_conv = prove_conv;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   708
  val norm_tac = simp_all add_rules THEN simp_all add_ac;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   709
end;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   710
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   711
fun gen_uncancel_tac rule ct =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   712
  rtac (instantiate' [] [None, Some ct] (rule RS subst_equals)) 1;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   713
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   714
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   715
(* nat eq *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   716
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   717
structure EqCancelSums = CancelSumsFun
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   718
(struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   719
  open Sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   720
  val mk_bal = HOLogic.mk_eq;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   721
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   722
  val uncancel_tac = gen_uncancel_tac add_left_cancel;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   723
end);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   724
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   725
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   726
(* nat less *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   727
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   728
structure LessCancelSums = CancelSumsFun
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   729
(struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   730
  open Sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   731
  val mk_bal = HOLogic.mk_binrel "op <";
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   732
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   733
  val uncancel_tac = gen_uncancel_tac add_left_cancel_less;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   734
end);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   735
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   736
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   737
(* nat le *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   738
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   739
structure LeCancelSums = CancelSumsFun
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   740
(struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   741
  open Sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   742
  val mk_bal = HOLogic.mk_binrel "op <=";
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   743
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   744
  val uncancel_tac = gen_uncancel_tac add_left_cancel_le;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   745
end);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   746
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   747
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   748
(* nat diff *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   749
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   750
structure DiffCancelSums = CancelSumsFun
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   751
(struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   752
  open Sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   753
  val mk_bal = HOLogic.mk_binop "op -";
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   754
  val dest_bal = HOLogic.dest_bin "op -" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   755
  val uncancel_tac = gen_uncancel_tac diff_cancel;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   756
end);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   757
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   758
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   759
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   760
(** cancel common factor **)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   761
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   762
structure Factor =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   763
struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   764
  val mk_sum = mk_norm_sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   765
  val dest_sum = dest_sum;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   766
  val prove_conv = prove_conv;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   767
  val norm_tac = simp_all (add_rules @ mult_rules) THEN simp_all add_ac;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   768
end;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   769
6394
3d9fd50fcc43 Theory.sign_of;
wenzelm
parents: 6301
diff changeset
   770
fun mk_cnat n = cterm_of (Theory.sign_of Nat.thy) (HOLogic.mk_nat n);
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   771
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   772
fun gen_multiply_tac rule k =
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   773
  if k > 0 then
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   774
    rtac (instantiate' [] [None, Some (mk_cnat (k - 1))] (rule RS subst_equals)) 1
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   775
  else no_tac;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   776
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   777
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   778
(* nat eq *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   779
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   780
structure EqCancelFactor = CancelFactorFun
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   781
(struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   782
  open Factor;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   783
  val mk_bal = HOLogic.mk_eq;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   784
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   785
  val multiply_tac = gen_multiply_tac Suc_mult_cancel1;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   786
end);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   787
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   788
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   789
(* nat less *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   790
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   791
structure LessCancelFactor = CancelFactorFun
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   792
(struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   793
  open Factor;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   794
  val mk_bal = HOLogic.mk_binrel "op <";
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   795
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   796
  val multiply_tac = gen_multiply_tac Suc_mult_less_cancel1;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   797
end);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   798
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   799
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   800
(* nat le *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   801
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   802
structure LeCancelFactor = CancelFactorFun
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   803
(struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   804
  open Factor;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   805
  val mk_bal = HOLogic.mk_binrel "op <=";
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   806
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.natT;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   807
  val multiply_tac = gen_multiply_tac Suc_mult_le_cancel1;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   808
end);
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   809
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   810
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   811
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   812
(** prepare nat_cancel simprocs **)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   813
8100
6186ee807f2e replaced HOLogic.termTVar by HOLogic.termT;
wenzelm
parents: 7945
diff changeset
   814
fun prep_pat s = Thm.read_cterm (Theory.sign_of Arith.thy) (s, HOLogic.termT);
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   815
val prep_pats = map prep_pat;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   816
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   817
fun prep_simproc (name, pats, proc) = Simplifier.mk_simproc name pats proc;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   818
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   819
val eq_pats = prep_pats ["(l::nat) + m = n", "(l::nat) = m + n", "Suc m = n", "m = Suc n"];
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   820
val less_pats = prep_pats ["(l::nat) + m < n", "(l::nat) < m + n", "Suc m < n", "m < Suc n"];
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   821
val le_pats = prep_pats ["(l::nat) + m <= n", "(l::nat) <= m + n", "Suc m <= n", "m <= Suc n"];
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   822
val diff_pats = prep_pats ["((l::nat) + m) - n", "(l::nat) - (m + n)", "Suc m - n", "m - Suc n"];
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   823
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   824
val nat_cancel_sums_add = map prep_simproc
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   825
  [("nateq_cancel_sums", eq_pats, EqCancelSums.proc),
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   826
   ("natless_cancel_sums", less_pats, LessCancelSums.proc),
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   827
   ("natle_cancel_sums", le_pats, LeCancelSums.proc)];
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   828
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   829
val nat_cancel_sums = nat_cancel_sums_add @
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   830
  [prep_simproc("natdiff_cancel_sums", diff_pats, DiffCancelSums.proc)];
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   831
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   832
val nat_cancel_factor = map prep_simproc
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   833
  [("nateq_cancel_factor", eq_pats, EqCancelFactor.proc),
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   834
   ("natless_cancel_factor", less_pats, LessCancelFactor.proc),
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   835
   ("natle_cancel_factor", le_pats, LeCancelFactor.proc)];
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   836
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   837
val nat_cancel = nat_cancel_factor @ nat_cancel_sums;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   838
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   839
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   840
end;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   841
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   842
open ArithData;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   843
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   844
Addsimprocs nat_cancel;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   845
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   846
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   847
(* 2. Linear arithmetic                                                      *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   848
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   849
6101
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   850
(* Parameters data for general linear arithmetic functor *)
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   851
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   852
structure LA_Logic: LIN_ARITH_LOGIC =
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   853
struct
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   854
val ccontr = ccontr;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   855
val conjI = conjI;
6101
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   856
val neqE = linorder_neqE;
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   857
val notI = notI;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   858
val sym = sym;
6109
82b50115564c Simplified arithmetic.
nipkow
parents: 6101
diff changeset
   859
val not_lessD = linorder_not_less RS iffD1;
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   860
val not_leD = linorder_not_le RS iffD1;
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   861
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   862
6968
7f2977e96a5c handle THM/TERM exn;
wenzelm
parents: 6864
diff changeset
   863
fun mk_Eq thm = (thm RS Eq_FalseI) handle THM _ => (thm RS Eq_TrueI);
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   864
6073
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   865
val mk_Trueprop = HOLogic.mk_Trueprop;
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   866
6079
4f7975c74cdf More arith simplifications.
nipkow
parents: 6075
diff changeset
   867
fun neg_prop(TP$(Const("Not",_)$t)) = TP$t
4f7975c74cdf More arith simplifications.
nipkow
parents: 6075
diff changeset
   868
  | neg_prop(TP$t) = TP $ (Const("Not",HOLogic.boolT-->HOLogic.boolT)$t);
6073
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   869
6101
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   870
fun is_False thm =
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   871
  let val _ $ t = #prop(rep_thm thm)
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   872
  in t = Const("False",HOLogic.boolT) end;
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   873
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   874
fun is_nat(t) = fastype_of1 t = HOLogic.natT;
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   875
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   876
fun mk_nat_thm sg t =
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   877
  let val ct = cterm_of sg t  and cn = cterm_of sg (Var(("n",0),HOLogic.natT))
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   878
  in instantiate ([],[(cn,ct)]) le0 end;
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   879
6101
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   880
end;
dde00dc06f0d Restructured Arithmatic
nipkow
parents: 6079
diff changeset
   881
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   882
signature LIN_ARITH_DATA2 =
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   883
sig
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   884
  include LIN_ARITH_DATA
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   885
  val discrete: (string * bool)list ref
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   886
end;
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   887
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   888
structure LA_Data_Ref: LIN_ARITH_DATA2 =
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   889
struct
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   890
  val add_mono_thms = ref ([]:thm list);
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   891
  val lessD = ref ([]:thm list);
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   892
  val ss_ref = ref HOL_basic_ss;
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   893
  val discrete = ref ([]:(string*bool)list);
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   894
7548
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   895
(* Decomposition of terms *)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   896
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   897
fun nT (Type("fun",[N,_])) = N = HOLogic.natT
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   898
  | nT _ = false;
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   899
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   900
fun add_atom(t,m,(p,i)) = (case assoc(p,t) of None => ((t,m)::p,i)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   901
                           | Some n => (overwrite(p,(t,n+m:int)), i));
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   902
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   903
(* Turn term into list of summand * multiplicity plus a constant *)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   904
fun poly(Const("op +",_) $ s $ t, m, pi) = poly(s,m,poly(t,m,pi))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   905
  | poly(all as Const("op -",T) $ s $ t, m, pi) =
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   906
      if nT T then add_atom(all,m,pi)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   907
      else poly(s,m,poly(t,~1*m,pi))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   908
  | poly(Const("uminus",_) $ t, m, pi) = poly(t,~1*m,pi)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   909
  | poly(Const("0",_), _, pi) = pi
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   910
  | poly(Const("Suc",_)$t, m, (p,i)) = poly(t, m, (p,i+m))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   911
  | poly(all as Const("op *",_) $ (Const("Numeral.number_of",_)$c) $ t, m, pi)=
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   912
      (poly(t,m*HOLogic.dest_binum c,pi)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   913
       handle TERM _ => add_atom(all,m,pi))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   914
  | poly(all as Const("op *",_) $ t $ (Const("Numeral.number_of",_)$c), m, pi)=
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   915
      (poly(t,m*HOLogic.dest_binum c,pi)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   916
       handle TERM _ => add_atom(all,m,pi))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   917
  | poly(all as Const("Numeral.number_of",_)$t,m,(p,i)) =
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   918
     ((p,i + m*HOLogic.dest_binum t)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   919
      handle TERM _ => add_atom(all,m,(p,i)))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   920
  | poly x  = add_atom x;
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   921
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   922
fun decomp2(rel,lhs,rhs) =
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   923
  let val (p,i) = poly(lhs,1,([],0)) and (q,j) = poly(rhs,1,([],0))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   924
  in case rel of
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   925
       "op <"  => Some(p,i,"<",q,j)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   926
     | "op <=" => Some(p,i,"<=",q,j)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   927
     | "op ="  => Some(p,i,"=",q,j)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   928
     | _       => None
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   929
  end;
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   930
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   931
fun negate(Some(x,i,rel,y,j,d)) = Some(x,i,"~"^rel,y,j,d)
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   932
  | negate None = None;
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   933
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   934
fun decomp1 (T,xxx) =
7548
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   935
  (case T of
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   936
     Type("fun",[Type(D,[]),_]) =>
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   937
       (case assoc(!discrete,D) of
7548
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   938
          None => None
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   939
        | Some d => (case decomp2 xxx of
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   940
                       None => None
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   941
                     | Some(p,i,rel,q,j) => Some(p,i,rel,q,j,d)))
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   942
   | _ => None);
9e29a3af64ab ROOT: Integ/bin_simprocs.ML now loaded in Integ/Bin.ML
nipkow
parents: 7428
diff changeset
   943
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   944
fun decomp (_$(Const(rel,T)$lhs$rhs)) = decomp1 (T,(rel,lhs,rhs))
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   945
  | decomp (_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) =
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   946
      negate(decomp1 (T,(rel,lhs,rhs)))
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   947
  | decomp _ = None
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   948
end;
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   949
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   950
let
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   951
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   952
(* reduce contradictory <= to False.
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   953
   Most of the work is done by the cancel tactics.
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   954
*)
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   955
val add_rules = [add_0,add_0_right,Zero_not_Suc,Suc_not_Zero,le_0_eq];
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   956
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   957
val add_mono_thms = map (fn s => prove_goal Arith.thy s
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   958
 (fn prems => [cut_facts_tac prems 1,
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   959
               blast_tac (claset() addIs [add_le_mono]) 1]))
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   960
["(i <= j) & (k <= l) ==> i + k <= j + (l::nat)",
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   961
 "(i  = j) & (k <= l) ==> i + k <= j + (l::nat)",
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   962
 "(i <= j) & (k  = l) ==> i + k <= j + (l::nat)",
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   963
 "(i  = j) & (k  = l) ==> i + k  = j + (l::nat)"
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   964
];
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   965
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   966
in
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   967
LA_Data_Ref.add_mono_thms := !LA_Data_Ref.add_mono_thms @ add_mono_thms;
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   968
LA_Data_Ref.lessD := !LA_Data_Ref.lessD @ [Suc_leI];
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   969
LA_Data_Ref.ss_ref := !LA_Data_Ref.ss_ref addsimps add_rules
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   970
                      addsimprocs nat_cancel_sums_add;
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   971
LA_Data_Ref.discrete := !LA_Data_Ref.discrete @ [("nat",true)]
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   972
end;
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   973
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   974
structure Fast_Arith =
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   975
  Fast_Lin_Arith(structure LA_Logic=LA_Logic and LA_Data=LA_Data_Ref);
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   976
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   977
val fast_arith_tac = Fast_Arith.lin_arith_tac;
6073
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   978
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   979
let
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   980
val nat_arith_simproc_pats =
6394
3d9fd50fcc43 Theory.sign_of;
wenzelm
parents: 6301
diff changeset
   981
  map (fn s => Thm.read_cterm (Theory.sign_of Arith.thy) (s, HOLogic.boolT))
6128
2acc5d36610c More arith refinements.
nipkow
parents: 6115
diff changeset
   982
      ["(m::nat) < n","(m::nat) <= n", "(m::nat) = n"];
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
   983
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   984
val fast_nat_arith_simproc = mk_simproc
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   985
  "fast_nat_arith" nat_arith_simproc_pats Fast_Arith.lin_arith_prover;
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   986
in
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   987
Addsimprocs [fast_nat_arith_simproc]
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
   988
end;
6073
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   989
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   990
(* Because of fast_nat_arith_simproc, the arithmetic solver is really only
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   991
useful to detect inconsistencies among the premises for subgoals which are
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   992
*not* themselves (in)equalities, because the latter activate
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   993
fast_nat_arith_simproc anyway. However, it seems cheaper to activate the
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   994
solver all the time rather than add the additional check. *)
fba734ba6894 Refined arith tactic.
nipkow
parents: 6059
diff changeset
   995
7570
a9391550eea1 Mod because of new solver interface.
nipkow
parents: 7548
diff changeset
   996
simpset_ref () := (simpset() addSolver
a9391550eea1 Mod because of new solver interface.
nipkow
parents: 7548
diff changeset
   997
   (mk_solver "lin. arith." Fast_Arith.cut_lin_arith_tac));
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
   998
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
   999
(*Elimination of `-' on nat*)
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1000
Goal "P(a - b::nat) = (ALL d. (a<b --> P 0) & (a = b + d --> P d))";
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1001
by (case_tac "a < b" 1);
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1002
by (auto_tac (claset(), simpset() addsimps [diff_is_0_eq RS iffD2]));
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1003
qed "nat_diff_split";
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1004
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1005
val nat_diff_split = nat_diff_split;
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1006
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1007
(* FIXME: K true should be replaced by a sensible test to speed things up
6157
29942d3a1818 arith_tac for min/max
nipkow
parents: 6151
diff changeset
  1008
   in case there are lots of irrelevant terms involved;
29942d3a1818 arith_tac for min/max
nipkow
parents: 6151
diff changeset
  1009
   elimination of min/max can be optimized:
29942d3a1818 arith_tac for min/max
nipkow
parents: 6151
diff changeset
  1010
   (max m n + k <= r) = (m+k <= r & n+k <= r)
29942d3a1818 arith_tac for min/max
nipkow
parents: 6151
diff changeset
  1011
   (l <= min m n + k) = (l <= m+k & l <= n+k)
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1012
*)
7582
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
  1013
val arith_tac_split_thms = ref [nat_diff_split,split_min,split_max];
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
  1014
fun arith_tac i =
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
  1015
  refute_tac (K true) (REPEAT o split_tac (!arith_tac_split_thms))
2650c9c2ab7f Restructured lin.arith.package.
nipkow
parents: 7570
diff changeset
  1016
             ((REPEAT_DETERM o etac linorder_neqE) THEN' fast_arith_tac) i;
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1017
7131
0b2fe9ec709c 'arith' proof method;
wenzelm
parents: 7128
diff changeset
  1018
0b2fe9ec709c 'arith' proof method;
wenzelm
parents: 7128
diff changeset
  1019
(* proof method setup *)
0b2fe9ec709c 'arith' proof method;
wenzelm
parents: 7128
diff changeset
  1020
8502
75fc67e56440 arith method: bang arg;
wenzelm
parents: 8442
diff changeset
  1021
fun arith_method prems =
8571
c323613e4a47 arith method: HEADGOAL;
wenzelm
parents: 8502
diff changeset
  1022
  Method.METHOD (fn facts => HEADGOAL (Method.insert_tac (prems @ facts) THEN' arith_tac));
7131
0b2fe9ec709c 'arith' proof method;
wenzelm
parents: 7128
diff changeset
  1023
0b2fe9ec709c 'arith' proof method;
wenzelm
parents: 7128
diff changeset
  1024
val arith_setup =
0b2fe9ec709c 'arith' proof method;
wenzelm
parents: 7128
diff changeset
  1025
 [Method.add_methods
8502
75fc67e56440 arith method: bang arg;
wenzelm
parents: 8442
diff changeset
  1026
  [("arith", (arith_method o #2) oo Method.syntax Args.bang_facts , "decide linear arithmethic")]];
7131
0b2fe9ec709c 'arith' proof method;
wenzelm
parents: 7128
diff changeset
  1027
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
  1028
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
  1029
(* End of proof procedures. Now go and USE them!                             *)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
  1030
(*---------------------------------------------------------------------------*)
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
  1031
8833
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1032
Goal "m <= m*(m::nat)";
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1033
by (induct_tac "m" 1);
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1034
by Auto_tac;
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1035
qed "le_square";
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1036
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1037
Goal "(m::nat) <= m*(m*m)";
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1038
by (induct_tac "m" 1);
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1039
by Auto_tac;
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1040
qed "le_cube";
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1041
d6122f13b8a6 moved le_square, proved le_cube
paulson
parents: 8740
diff changeset
  1042
4736
f7d3b9aec7a1 New laws, mostly generalizing old "pred" ones
paulson
parents: 4732
diff changeset
  1043
(*** Subtraction laws -- mostly from Clemens Ballarin ***)
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1044
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
  1045
Goal "[| a < (b::nat); c <= a |] ==> a-c < b-c";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1046
by (arith_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1047
qed "diff_less_mono";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1048
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5414
diff changeset
  1049
Goal "(i < j-k) = (i+k < (j::nat))";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1050
by (arith_tac 1);
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5414
diff changeset
  1051
qed "less_diff_conv";
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5414
diff changeset
  1052
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
  1053
Goal "(j-k <= (i::nat)) = (j <= i+k)";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1054
by (arith_tac 1);
5485
0cd451e46a20 new theorem le_diff_conv
paulson
parents: 5429
diff changeset
  1055
qed "le_diff_conv";
0cd451e46a20 new theorem le_diff_conv
paulson
parents: 5429
diff changeset
  1056
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
  1057
Goal "k <= j ==> (i <= j-k) = (i+k <= (j::nat))";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1058
by (arith_tac 1);
5497
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
  1059
qed "le_diff_conv2";
497215d66441 theorem le_diff_conv2; tidying and expandshort
paulson
parents: 5485
diff changeset
  1060
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5078
diff changeset
  1061
Goal "Suc i <= n ==> Suc (n - Suc i) = n - i";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1062
by (arith_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1063
qed "Suc_diff_Suc";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1064
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
  1065
Goal "i <= (n::nat) ==> n - (n - i) = i";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1066
by (arith_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1067
qed "diff_diff_cancel";
3381
2bac33ec2b0d New theorems le_add_diff_inverse, le_add_diff_inverse2
paulson
parents: 3366
diff changeset
  1068
Addsimps [diff_diff_cancel];
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1069
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
  1070
Goal "k <= (n::nat) ==> m <= n + m - k";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1071
by (arith_tac 1);
3234
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1072
qed "le_add_diff";
503f4c8c29eb New theorems from Hoare/Arith2.ML
paulson
parents: 2922
diff changeset
  1073
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1074
Goal "m-1 < n ==> m <= n";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1075
by (arith_tac 1);
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1076
qed "pred_less_imp_le";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1077
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1078
Goal "j<=i ==> i - j < Suc i - j";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1079
by (arith_tac 1);
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1080
qed "diff_less_Suc_diff";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1081
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1082
Goal "i - j <= Suc i - j";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1083
by (arith_tac 1);
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1084
qed "diff_le_Suc_diff";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1085
AddIffs [diff_le_Suc_diff];
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1086
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1087
Goal "n - Suc i <= n - i";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1088
by (arith_tac 1);
5356
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1089
qed "diff_Suc_le_diff";
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1090
AddIffs [diff_Suc_le_diff];
6ef114ba5b55 new theorems
paulson
parents: 5333
diff changeset
  1091
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
  1092
Goal "!!m::nat. 0 < n ==> (m <= n-1) = (m<n)";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1093
by (arith_tac 1);
5409
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
  1094
qed "le_pred_eq";
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
  1095
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
  1096
Goal "!!m::nat. 0 < n ==> (m-1 < n) = (m<=n)";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1097
by (arith_tac 1);
5409
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
  1098
qed "less_pred_eq";
e97558ee8e76 Two new subtraction lemmas
paulson
parents: 5356
diff changeset
  1099
7059
71e9ea2198e0 a stronger diff_less and no more le_diff_less
paulson
parents: 7007
diff changeset
  1100
(*Replaces the previous diff_less and le_diff_less, which had the stronger
71e9ea2198e0 a stronger diff_less and no more le_diff_less
paulson
parents: 7007
diff changeset
  1101
  second premise n<=m*)
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
  1102
Goal "!!m::nat. [| 0<n; 0<m |] ==> m - n < m";
6301
08245f5a436d expandshort
paulson
parents: 6157
diff changeset
  1103
by (arith_tac 1);
5414
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
  1104
qed "diff_less";
8a458866637c changed Suc_diff_n to Suc_diff_le, with premise n <= m instead of n < Suc(m)
paulson
parents: 5409
diff changeset
  1105
8740
fa6c4e4182d9 replaced obsolete diff_right_cancel by diff_diff_eq
paulson
parents: 8708
diff changeset
  1106
Goal "j <= (k::nat) ==> (j+i)-k = i-(k-j)";
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1107
by (asm_simp_tac (simpset() addsplits [nat_diff_split]) 1);
8740
fa6c4e4182d9 replaced obsolete diff_right_cancel by diff_diff_eq
paulson
parents: 8708
diff changeset
  1108
qed "diff_add_assoc_diff";
fa6c4e4182d9 replaced obsolete diff_right_cancel by diff_diff_eq
paulson
parents: 8708
diff changeset
  1109
fa6c4e4182d9 replaced obsolete diff_right_cancel by diff_diff_eq
paulson
parents: 8708
diff changeset
  1110
8708
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1111
(*** Reducing subtraction to addition ***)
7128
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1112
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1113
Goal "n<=(l::nat) --> Suc l - n + m = Suc (l - n + m)";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1114
by (simp_tac (simpset() addsplits [nat_diff_split]) 1);
7128
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1115
qed_spec_mp "Suc_diff_add_le";
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1116
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1117
Goal "i<n ==> n - Suc i < n - i";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1118
by (asm_simp_tac (simpset() addsplits [nat_diff_split]) 1);
7128
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1119
qed "diff_Suc_less_diff";
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1120
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1121
Goal "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1122
by (simp_tac (simpset() addsplits [nat_diff_split]) 1);
7128
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1123
qed "if_Suc_diff_le";
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1124
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1125
Goal "Suc(m)-n <= Suc(m-n)";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1126
by (simp_tac (simpset() addsplits [nat_diff_split]) 1);
7128
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1127
qed "diff_Suc_le_Suc_diff";
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1128
8740
fa6c4e4182d9 replaced obsolete diff_right_cancel by diff_diff_eq
paulson
parents: 8708
diff changeset
  1129
(** Simplification of relational expressions involving subtraction **)
7128
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1130
8740
fa6c4e4182d9 replaced obsolete diff_right_cancel by diff_diff_eq
paulson
parents: 8708
diff changeset
  1131
Goal "[| k <= m;  k <= (n::nat) |] ==> ((m-k) - (n-k)) = (m-n)";
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1132
by (asm_simp_tac (simpset() addsplits [nat_diff_split]) 1);
8740
fa6c4e4182d9 replaced obsolete diff_right_cancel by diff_diff_eq
paulson
parents: 8708
diff changeset
  1133
qed "diff_diff_eq";
8708
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1134
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1135
Goal "[| k <= m;  k <= (n::nat) |] ==> (m-k = n-k) = (m=n)";
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1136
by (auto_tac (claset(), simpset() addsplits [nat_diff_split]));
8708
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1137
qed "eq_diff_iff";
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1138
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1139
Goal "[| k <= m;  k <= (n::nat) |] ==> (m-k < n-k) = (m<n)";
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1140
by (auto_tac (claset(), simpset() addsplits [nat_diff_split]));
8708
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1141
qed "less_diff_iff";
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1142
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1143
Goal "[| k <= m;  k <= (n::nat) |] ==> (m-k <= n-k) = (m<=n)";
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1144
by (auto_tac (claset(), simpset() addsplits [nat_diff_split]));
8708
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1145
qed "le_diff_iff";
2f2d2b4215d6 added some new iff-lemmas; removed some obsolete thms
paulson
parents: 8571
diff changeset
  1146
7128
468b6c8b8dc4 split_diff and remove_diff_ss
paulson
parents: 7108
diff changeset
  1147
7108
0229ce6735f6 fixed comment;
wenzelm
parents: 7059
diff changeset
  1148
(** (Anti)Monotonicity of subtraction -- by Stephan Merz **)
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
  1149
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
  1150
(* Monotonicity of subtraction in first argument *)
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1151
Goal "m <= (n::nat) ==> (m-l) <= (n-l)";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1152
by (asm_simp_tac (simpset() addsplits [nat_diff_split]) 1);
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1153
qed "diff_le_mono";
3484
1e93eb09ebb9 Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents: 3457
diff changeset
  1154
5429
0833486c23ce tidying
paulson
parents: 5427
diff changeset
  1155
Goal "m <= (n::nat) ==> (l-n) <= (l-m)";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1156
by (asm_simp_tac (simpset() addsplits [nat_diff_split]) 1);
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1157
qed "diff_le_mono2";
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
  1158
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1159
Goal "[| m < (n::nat); m<l |] ==> (l-n) < (l-m)";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1160
by (asm_simp_tac (simpset() addsplits [nat_diff_split]) 1);
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1161
qed "diff_less_mono2";
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5771
diff changeset
  1162
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
  1163
Goal "!!m::nat. [| m-n = 0; n-m = 0 |] ==>  m=n";
7945
3aca6352f063 got rid of split_diff, which duplicated nat_diff_split, and
paulson
parents: 7622
diff changeset
  1164
by (asm_full_simp_tac (simpset() addsplits [nat_diff_split]) 1);
6055
fdf4638bf726 Version 1.0 of linear nat arithmetic.
nipkow
parents: 5983
diff changeset
  1165
qed "diffs0_imp_equal";
8352
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1166
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1167
(** Lemmas for ex/Factorization **)
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1168
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
  1169
Goal "!!m::nat. [| 1<n; 1<m |] ==> 1<m*n";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
  1170
by (case_tac "m" 1);
8352
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1171
by Auto_tac;
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1172
qed "one_less_mult"; 
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1173
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
  1174
Goal "!!m::nat. [| 1<n; 1<m |] ==> n<m*n";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
  1175
by (case_tac "m" 1);
8352
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1176
by Auto_tac;
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1177
qed "n_less_m_mult_n"; 
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1178
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8859
diff changeset
  1179
Goal "!!m::nat. [| 1<n; 1<m |] ==> n<n*m";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
  1180
by (case_tac "m" 1);
8352
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1181
by Auto_tac;
0fda5ba36934 new lemmas
paulson
parents: 8252
diff changeset
  1182
qed "n_less_n_mult_m"; 
8859
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1183
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1184
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1185
(** Rewriting to pull differences out **)
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1186
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1187
Goal "k<=j --> i - (j - k) = i + (k::nat) - j";
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1188
by (arith_tac 1);
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1189
qed "diff_diff_right";
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1190
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1191
Goal "k <= j ==> m - Suc (j - k) = m + k - Suc j";
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1192
by (arith_tac 1);
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1193
qed "diff_Suc_diff_eq1"; 
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1194
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1195
Goal "k <= j ==> Suc (j - k) - m = Suc j - (k + m)";
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1196
by (arith_tac 1);
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1197
qed "diff_Suc_diff_eq2"; 
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1198
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1199
(*The others are
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1200
      i - j - k = i - (j + k),
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1201
      k <= j ==> j - k + i = j + i - k,
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1202
      k <= j ==> i + (j - k) = i + j - k *)
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1203
Addsimps [diff_diff_left, diff_diff_right, diff_add_assoc2 RS sym, 
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1204
	  diff_add_assoc RS sym, diff_Suc_diff_eq1, diff_Suc_diff_eq2];
b1ea21d70c85 deleted some redundant simprules
paulson
parents: 8833
diff changeset
  1205