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