author | clasohm |
Wed, 29 Nov 1995 16:44:59 +0100 | |
changeset 1370 | 7361ac9b024d |
parent 1327 | 6c29cfab679c |
child 1398 | b8de98c2c29c |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/Arith.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
Proofs about elementary arithmetic: addition, multiplication, etc. |
|
7 |
Tests definitions and simplifier. |
|
8 |
*) |
|
9 |
||
10 |
open Arith; |
|
11 |
||
12 |
(*** Basic rewrite rules for the arithmetic operators ***) |
|
13 |
||
14 |
val [pred_0, pred_Suc] = nat_recs pred_def; |
|
15 |
val [add_0,add_Suc] = nat_recs add_def; |
|
16 |
val [mult_0,mult_Suc] = nat_recs mult_def; |
|
1301 | 17 |
Addsimps [pred_0,pred_Suc,add_0,add_Suc,mult_0,mult_Suc]; |
18 |
||
19 |
(** pred **) |
|
20 |
||
21 |
val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n"; |
|
22 |
by(res_inst_tac [("n","n")] natE 1); |
|
23 |
by(cut_facts_tac prems 1); |
|
24 |
by(ALLGOALS Asm_full_simp_tac); |
|
25 |
qed "Suc_pred"; |
|
26 |
Addsimps [Suc_pred]; |
|
923 | 27 |
|
28 |
(** Difference **) |
|
29 |
||
30 |
val diff_0 = diff_def RS def_nat_rec_0; |
|
31 |
||
32 |
qed_goalw "diff_0_eq_0" Arith.thy [diff_def, pred_def] |
|
33 |
"0 - n = 0" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
34 |
(fn _ => [nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]); |
923 | 35 |
|
36 |
(*Must simplify BEFORE the induction!! (Else we get a critical pair) |
|
37 |
Suc(m) - Suc(n) rewrites to pred(Suc(m) - n) *) |
|
38 |
qed_goalw "diff_Suc_Suc" Arith.thy [diff_def, pred_def] |
|
39 |
"Suc(m) - Suc(n) = m - n" |
|
40 |
(fn _ => |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
41 |
[Simp_tac 1, nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]); |
923 | 42 |
|
1301 | 43 |
Addsimps [diff_0, diff_0_eq_0, diff_Suc_Suc]; |
923 | 44 |
|
45 |
||
46 |
(**** Inductive properties of the operators ****) |
|
47 |
||
48 |
(*** Addition ***) |
|
49 |
||
50 |
qed_goal "add_0_right" Arith.thy "m + 0 = m" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
51 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 52 |
|
53 |
qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
54 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 55 |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
56 |
Addsimps [add_0_right,add_Suc_right]; |
923 | 57 |
|
58 |
(*Associative law for addition*) |
|
59 |
qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
60 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 61 |
|
62 |
(*Commutative law for addition*) |
|
63 |
qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
64 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 65 |
|
66 |
qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)" |
|
67 |
(fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1, |
|
68 |
rtac (add_commute RS arg_cong) 1]); |
|
69 |
||
70 |
(*Addition is an AC-operator*) |
|
71 |
val add_ac = [add_assoc, add_commute, add_left_commute]; |
|
72 |
||
73 |
goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)"; |
|
74 |
by (nat_ind_tac "k" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
75 |
by (Simp_tac 1); |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
76 |
by (Asm_simp_tac 1); |
923 | 77 |
qed "add_left_cancel"; |
78 |
||
79 |
goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)"; |
|
80 |
by (nat_ind_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 | 83 |
qed "add_right_cancel"; |
84 |
||
85 |
goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)"; |
|
86 |
by (nat_ind_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 | 89 |
qed "add_left_cancel_le"; |
90 |
||
91 |
goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)"; |
|
92 |
by (nat_ind_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 | 95 |
qed "add_left_cancel_less"; |
96 |
||
1327
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
97 |
Addsimps [add_left_cancel, add_right_cancel, |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
98 |
add_left_cancel_le, add_left_cancel_less]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
99 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
100 |
goal Arith.thy "(m+n = 0) = (m=0 & n=0)"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
101 |
by (nat_ind_tac "m" 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
102 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
103 |
qed "add_is_0"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
104 |
Addsimps [add_is_0]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
105 |
|
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
106 |
goal Arith.thy "!!n. n ~= 0 ==> m + pred n = pred(m+n)"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
107 |
by (nat_ind_tac "m" 1); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
108 |
by (ALLGOALS Asm_simp_tac); |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
109 |
qed "add_pred"; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
110 |
Addsimps [add_pred]; |
6c29cfab679c
added new arithmetic lemmas and the functions take and drop.
nipkow
parents:
1301
diff
changeset
|
111 |
|
923 | 112 |
(*** Multiplication ***) |
113 |
||
114 |
(*right annihilation in product*) |
|
115 |
qed_goal "mult_0_right" Arith.thy "m * 0 = 0" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
116 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 117 |
|
118 |
(*right Sucessor law for multiplication*) |
|
119 |
qed_goal "mult_Suc_right" Arith.thy "m * Suc(n) = m + (m * n)" |
|
120 |
(fn _ => [nat_ind_tac "m" 1, |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
121 |
ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); |
923 | 122 |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
123 |
Addsimps [mult_0_right,mult_Suc_right]; |
923 | 124 |
|
125 |
(*Commutative law for multiplication*) |
|
126 |
qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
127 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 128 |
|
129 |
(*addition distributes over multiplication*) |
|
130 |
qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)" |
|
131 |
(fn _ => [nat_ind_tac "m" 1, |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
132 |
ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); |
923 | 133 |
|
134 |
qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)" |
|
135 |
(fn _ => [nat_ind_tac "m" 1, |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
136 |
ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); |
923 | 137 |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
138 |
Addsimps [add_mult_distrib,add_mult_distrib2]; |
923 | 139 |
|
140 |
(*Associative law for multiplication*) |
|
141 |
qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
142 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 143 |
|
144 |
qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)" |
|
145 |
(fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1, |
|
146 |
rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]); |
|
147 |
||
148 |
val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; |
|
149 |
||
150 |
(*** Difference ***) |
|
151 |
||
152 |
qed_goal "diff_self_eq_0" Arith.thy "m - m = 0" |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
153 |
(fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); |
923 | 154 |
|
155 |
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) |
|
156 |
val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)"; |
|
157 |
by (rtac (prem RS rev_mp) 1); |
|
158 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
159 |
by (ALLGOALS Asm_simp_tac); |
923 | 160 |
qed "add_diff_inverse"; |
161 |
||
162 |
||
163 |
(*** Remainder ***) |
|
164 |
||
165 |
goal Arith.thy "m - n < Suc(m)"; |
|
166 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
167 |
by (etac less_SucE 3); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
168 |
by (ALLGOALS Asm_simp_tac); |
923 | 169 |
qed "diff_less_Suc"; |
170 |
||
171 |
goal Arith.thy "!!m::nat. m - n <= m"; |
|
172 |
by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
173 |
by (ALLGOALS Asm_simp_tac); |
923 | 174 |
qed "diff_le_self"; |
175 |
||
176 |
goal Arith.thy "!!n::nat. (n+m) - n = m"; |
|
177 |
by (nat_ind_tac "n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
178 |
by (ALLGOALS Asm_simp_tac); |
923 | 179 |
qed "diff_add_inverse"; |
180 |
||
181 |
goal Arith.thy "!!n::nat. n - (n+m) = 0"; |
|
182 |
by (nat_ind_tac "n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
183 |
by (ALLGOALS Asm_simp_tac); |
923 | 184 |
qed "diff_add_0"; |
185 |
||
186 |
(*In ordinary notation: if 0<n and n<=m then m-n < m *) |
|
187 |
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m"; |
|
188 |
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1); |
|
189 |
by (fast_tac HOL_cs 1); |
|
190 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
191 |
by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc]))); |
923 | 192 |
qed "div_termination"; |
193 |
||
194 |
val wf_less_trans = wf_pred_nat RS wf_trancl RSN (2, def_wfrec RS trans); |
|
195 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
965
diff
changeset
|
196 |
goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)"; |
923 | 197 |
by (rtac refl 1); |
198 |
qed "less_eq"; |
|
199 |
||
200 |
goal Arith.thy "!!m. m<n ==> m mod n = m"; |
|
201 |
by (rtac (mod_def RS wf_less_trans) 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
202 |
by(Asm_simp_tac 1); |
923 | 203 |
qed "mod_less"; |
204 |
||
205 |
goal Arith.thy "!!m. [| 0<n; ~m<n |] ==> m mod n = (m-n) mod n"; |
|
206 |
by (rtac (mod_def RS wf_less_trans) 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
207 |
by(asm_simp_tac (!simpset addsimps [div_termination, cut_apply, less_eq]) 1); |
923 | 208 |
qed "mod_geq"; |
209 |
||
210 |
||
211 |
(*** Quotient ***) |
|
212 |
||
213 |
goal Arith.thy "!!m. m<n ==> m div n = 0"; |
|
214 |
by (rtac (div_def RS wf_less_trans) 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
215 |
by(Asm_simp_tac 1); |
923 | 216 |
qed "div_less"; |
217 |
||
218 |
goal Arith.thy "!!M. [| 0<n; ~m<n |] ==> m div n = Suc((m-n) div n)"; |
|
219 |
by (rtac (div_def RS wf_less_trans) 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
220 |
by(asm_simp_tac (!simpset addsimps [div_termination, cut_apply, less_eq]) 1); |
923 | 221 |
qed "div_geq"; |
222 |
||
223 |
(*Main Result about quotient and remainder.*) |
|
224 |
goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m"; |
|
225 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
226 |
by (rename_tac "k" 1); (*Variable name used in line below*) |
|
227 |
by (case_tac "k<n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
228 |
by (ALLGOALS (asm_simp_tac(!simpset addsimps (add_ac @ |
923 | 229 |
[mod_less, mod_geq, div_less, div_geq, |
230 |
add_diff_inverse, div_termination])))); |
|
231 |
qed "mod_div_equality"; |
|
232 |
||
233 |
||
234 |
(*** More results about difference ***) |
|
235 |
||
236 |
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0"; |
|
237 |
by (rtac (prem RS rev_mp) 1); |
|
238 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
239 |
by (ALLGOALS Asm_simp_tac); |
923 | 240 |
qed "less_imp_diff_is_0"; |
241 |
||
242 |
val prems = goal Arith.thy "m-n = 0 --> n-m = 0 --> m=n"; |
|
243 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
244 |
by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); |
923 | 245 |
qed "diffs0_imp_equal_lemma"; |
246 |
||
247 |
(* [| m-n = 0; n-m = 0 |] ==> m=n *) |
|
248 |
bind_thm ("diffs0_imp_equal", (diffs0_imp_equal_lemma RS mp RS mp)); |
|
249 |
||
250 |
val [prem] = goal Arith.thy "m<n ==> 0<n-m"; |
|
251 |
by (rtac (prem RS rev_mp) 1); |
|
252 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
253 |
by (ALLGOALS Asm_simp_tac); |
923 | 254 |
qed "less_imp_diff_positive"; |
255 |
||
256 |
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)"; |
|
257 |
by (rtac (prem RS rev_mp) 1); |
|
258 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
259 |
by (ALLGOALS Asm_simp_tac); |
923 | 260 |
qed "Suc_diff_n"; |
261 |
||
965 | 262 |
goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc m-n)"; |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
263 |
by(simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n] |
923 | 264 |
setloop (split_tac [expand_if])) 1); |
265 |
qed "if_Suc_diff_n"; |
|
266 |
||
267 |
goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
|
268 |
by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
269 |
by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o fast_tac HOL_cs)); |
923 | 270 |
qed "zero_induct_lemma"; |
271 |
||
272 |
val prems = goal Arith.thy "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
|
273 |
by (rtac (diff_self_eq_0 RS subst) 1); |
|
274 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
275 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
276 |
qed "zero_induct"; |
|
277 |
||
278 |
(*13 July 1992: loaded in 105.7s*) |
|
279 |
||
280 |
(**** Additional theorems about "less than" ****) |
|
281 |
||
282 |
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))"; |
|
283 |
by (nat_ind_tac "n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
284 |
by (ALLGOALS(Simp_tac)); |
923 | 285 |
by (REPEAT_FIRST (ares_tac [conjI, impI])); |
286 |
by (res_inst_tac [("x","0")] exI 2); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
287 |
by (Simp_tac 2); |
923 | 288 |
by (safe_tac HOL_cs); |
289 |
by (res_inst_tac [("x","Suc(k)")] exI 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
290 |
by (Simp_tac 1); |
923 | 291 |
val less_eq_Suc_add_lemma = result(); |
292 |
||
293 |
(*"m<n ==> ? k. n = Suc(m+k)"*) |
|
294 |
bind_thm ("less_eq_Suc_add", less_eq_Suc_add_lemma RS mp); |
|
295 |
||
296 |
||
297 |
goal Arith.thy "n <= ((m + n)::nat)"; |
|
298 |
by (nat_ind_tac "m" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
299 |
by (ALLGOALS Simp_tac); |
923 | 300 |
by (etac le_trans 1); |
301 |
by (rtac (lessI RS less_imp_le) 1); |
|
302 |
qed "le_add2"; |
|
303 |
||
304 |
goal Arith.thy "n <= ((n + m)::nat)"; |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
305 |
by (simp_tac (!simpset addsimps add_ac) 1); |
923 | 306 |
by (rtac le_add2 1); |
307 |
qed "le_add1"; |
|
308 |
||
309 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
310 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
311 |
||
312 |
(*"i <= j ==> i <= j+m"*) |
|
313 |
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); |
|
314 |
||
315 |
(*"i <= j ==> i <= m+j"*) |
|
316 |
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); |
|
317 |
||
318 |
(*"i < j ==> i < j+m"*) |
|
319 |
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); |
|
320 |
||
321 |
(*"i < j ==> i < m+j"*) |
|
322 |
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); |
|
323 |
||
1152 | 324 |
goal Arith.thy "!!i. i+j < (k::nat) ==> i<k"; |
325 |
be rev_mp 1; |
|
326 |
by(nat_ind_tac "j" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
327 |
by (ALLGOALS Asm_simp_tac); |
1152 | 328 |
by(fast_tac (HOL_cs addDs [Suc_lessD]) 1); |
329 |
qed "add_lessD1"; |
|
330 |
||
923 | 331 |
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k"; |
332 |
by (eresolve_tac [le_trans] 1); |
|
333 |
by (resolve_tac [le_add1] 1); |
|
334 |
qed "le_imp_add_le"; |
|
335 |
||
336 |
goal Arith.thy "!!k::nat. m < n ==> m < n+k"; |
|
337 |
by (eresolve_tac [less_le_trans] 1); |
|
338 |
by (resolve_tac [le_add1] 1); |
|
339 |
qed "less_imp_add_less"; |
|
340 |
||
341 |
goal Arith.thy "m+k<=n --> m<=(n::nat)"; |
|
342 |
by (nat_ind_tac "k" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
343 |
by (ALLGOALS Asm_simp_tac); |
923 | 344 |
by (fast_tac (HOL_cs addDs [Suc_leD]) 1); |
345 |
val add_leD1_lemma = result(); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
346 |
bind_thm ("add_leD1", add_leD1_lemma RS mp); |
923 | 347 |
|
348 |
goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n"; |
|
349 |
by (safe_tac (HOL_cs addSDs [less_eq_Suc_add])); |
|
350 |
by (asm_full_simp_tac |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
351 |
(!simpset delsimps [add_Suc_right] |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
352 |
addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1); |
923 | 353 |
by (eresolve_tac [subst] 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
354 |
by (simp_tac (!simpset addsimps [less_add_Suc1]) 1); |
923 | 355 |
qed "less_add_eq_less"; |
356 |
||
357 |
||
358 |
(** Monotonicity of addition (from ZF/Arith) **) |
|
359 |
||
360 |
(** Monotonicity results **) |
|
361 |
||
362 |
(*strict, in 1st argument*) |
|
363 |
goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k"; |
|
364 |
by (nat_ind_tac "k" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
365 |
by (ALLGOALS Asm_simp_tac); |
923 | 366 |
qed "add_less_mono1"; |
367 |
||
368 |
(*strict, in both arguments*) |
|
369 |
goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l"; |
|
370 |
by (rtac (add_less_mono1 RS less_trans) 1); |
|
1198 | 371 |
by (REPEAT (assume_tac 1)); |
923 | 372 |
by (nat_ind_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
373 |
by (ALLGOALS Asm_simp_tac); |
923 | 374 |
qed "add_less_mono"; |
375 |
||
376 |
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) |
|
377 |
val [lt_mono,le] = goal Arith.thy |
|
378 |
"[| !!i j::nat. i<j ==> f(i) < f(j); \ |
|
379 |
\ i <= j \ |
|
380 |
\ |] ==> f(i) <= (f(j)::nat)"; |
|
381 |
by (cut_facts_tac [le] 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
382 |
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1); |
923 | 383 |
by (fast_tac (HOL_cs addSIs [lt_mono]) 1); |
384 |
qed "less_mono_imp_le_mono"; |
|
385 |
||
386 |
(*non-strict, in 1st argument*) |
|
387 |
goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k"; |
|
388 |
by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1); |
|
389 |
by (eresolve_tac [add_less_mono1] 1); |
|
390 |
by (assume_tac 1); |
|
391 |
qed "add_le_mono1"; |
|
392 |
||
393 |
(*non-strict, in both arguments*) |
|
394 |
goal Arith.thy "!!k l::nat. [|i<=j; k<=l |] ==> i + k <= j + l"; |
|
395 |
by (etac (add_le_mono1 RS le_trans) 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
396 |
by (simp_tac (!simpset addsimps [add_commute]) 1); |
923 | 397 |
(*j moves to the end because it is free while k, l are bound*) |
398 |
by (eresolve_tac [add_le_mono1] 1); |
|
399 |
qed "add_le_mono"; |