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