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