author | paulson |
Wed, 06 Mar 1996 12:52:11 +0100 | |
changeset 1552 | 6f71b5d46700 |
parent 1496 | c443b2adaf52 |
child 1618 | 372880456b5b |
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. |
|
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"; |
|
1552 | 22 |
by (res_inst_tac [("n","n")] natE 1); |
23 |
by (cut_facts_tac prems 1); |
|
24 |
by (ALLGOALS Asm_full_simp_tac); |
|
1301 | 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]); |
1496 | 154 |
Addsimps [diff_self_eq_0]; |
923 | 155 |
|
156 |
(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) |
|
157 |
val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)"; |
|
158 |
by (rtac (prem RS rev_mp) 1); |
|
159 |
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
|
160 |
by (ALLGOALS Asm_simp_tac); |
923 | 161 |
qed "add_diff_inverse"; |
162 |
||
163 |
||
164 |
(*** Remainder ***) |
|
165 |
||
166 |
goal Arith.thy "m - n < Suc(m)"; |
|
167 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
168 |
by (etac less_SucE 3); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
169 |
by (ALLGOALS Asm_simp_tac); |
923 | 170 |
qed "diff_less_Suc"; |
171 |
||
172 |
goal Arith.thy "!!m::nat. m - n <= m"; |
|
173 |
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
|
174 |
by (ALLGOALS Asm_simp_tac); |
923 | 175 |
qed "diff_le_self"; |
176 |
||
177 |
goal Arith.thy "!!n::nat. (n+m) - n = m"; |
|
178 |
by (nat_ind_tac "n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
179 |
by (ALLGOALS Asm_simp_tac); |
923 | 180 |
qed "diff_add_inverse"; |
181 |
||
182 |
goal Arith.thy "!!n::nat. n - (n+m) = 0"; |
|
183 |
by (nat_ind_tac "n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
184 |
by (ALLGOALS Asm_simp_tac); |
923 | 185 |
qed "diff_add_0"; |
186 |
||
187 |
(*In ordinary notation: if 0<n and n<=m then m-n < m *) |
|
188 |
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m"; |
|
189 |
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1); |
|
190 |
by (fast_tac HOL_cs 1); |
|
191 |
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
|
192 |
by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc]))); |
1398 | 193 |
qed "diff_less"; |
923 | 194 |
|
195 |
val wf_less_trans = wf_pred_nat RS wf_trancl RSN (2, def_wfrec RS trans); |
|
196 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
965
diff
changeset
|
197 |
goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)"; |
923 | 198 |
by (rtac refl 1); |
199 |
qed "less_eq"; |
|
200 |
||
1475 | 201 |
goal Arith.thy "(%m. m mod n) = wfrec (trancl pred_nat) \ |
202 |
\ (%f j. if j<n then j else f (j-n))"; |
|
203 |
by (simp_tac (HOL_ss addsimps [mod_def]) 1); |
|
204 |
val mod_def1 = result() RS eq_reflection; |
|
205 |
||
923 | 206 |
goal Arith.thy "!!m. m<n ==> m mod n = m"; |
1475 | 207 |
by (rtac (mod_def1 RS wf_less_trans) 1); |
1552 | 208 |
by (Asm_simp_tac 1); |
923 | 209 |
qed "mod_less"; |
210 |
||
211 |
goal Arith.thy "!!m. [| 0<n; ~m<n |] ==> m mod n = (m-n) mod n"; |
|
1475 | 212 |
by (rtac (mod_def1 RS wf_less_trans) 1); |
1552 | 213 |
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1); |
923 | 214 |
qed "mod_geq"; |
215 |
||
216 |
||
217 |
(*** Quotient ***) |
|
218 |
||
1475 | 219 |
goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \ |
220 |
\ (%f j. if j<n then 0 else Suc (f (j-n)))"; |
|
221 |
by (simp_tac (HOL_ss addsimps [div_def]) 1); |
|
222 |
val div_def1 = result() RS eq_reflection; |
|
223 |
||
923 | 224 |
goal Arith.thy "!!m. m<n ==> m div n = 0"; |
1475 | 225 |
by (rtac (div_def1 RS wf_less_trans) 1); |
1552 | 226 |
by (Asm_simp_tac 1); |
923 | 227 |
qed "div_less"; |
228 |
||
229 |
goal Arith.thy "!!M. [| 0<n; ~m<n |] ==> m div n = Suc((m-n) div n)"; |
|
1475 | 230 |
by (rtac (div_def1 RS wf_less_trans) 1); |
1552 | 231 |
by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1); |
923 | 232 |
qed "div_geq"; |
233 |
||
234 |
(*Main Result about quotient and remainder.*) |
|
235 |
goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m"; |
|
236 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
237 |
by (rename_tac "k" 1); (*Variable name used in line below*) |
|
238 |
by (case_tac "k<n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
239 |
by (ALLGOALS (asm_simp_tac(!simpset addsimps (add_ac @ |
923 | 240 |
[mod_less, mod_geq, div_less, div_geq, |
1465 | 241 |
add_diff_inverse, diff_less])))); |
923 | 242 |
qed "mod_div_equality"; |
243 |
||
244 |
||
245 |
(*** More results about difference ***) |
|
246 |
||
247 |
val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0"; |
|
248 |
by (rtac (prem RS rev_mp) 1); |
|
249 |
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
|
250 |
by (ALLGOALS Asm_simp_tac); |
923 | 251 |
qed "less_imp_diff_is_0"; |
252 |
||
253 |
val prems = goal Arith.thy "m-n = 0 --> n-m = 0 --> m=n"; |
|
254 |
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
|
255 |
by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset
|
256 |
qed_spec_mp "diffs0_imp_equal"; |
923 | 257 |
|
258 |
val [prem] = goal Arith.thy "m<n ==> 0<n-m"; |
|
259 |
by (rtac (prem RS rev_mp) 1); |
|
260 |
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
|
261 |
by (ALLGOALS Asm_simp_tac); |
923 | 262 |
qed "less_imp_diff_positive"; |
263 |
||
264 |
val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)"; |
|
265 |
by (rtac (prem RS rev_mp) 1); |
|
266 |
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
|
267 |
by (ALLGOALS Asm_simp_tac); |
923 | 268 |
qed "Suc_diff_n"; |
269 |
||
1398 | 270 |
goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))"; |
1552 | 271 |
by (simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n] |
923 | 272 |
setloop (split_tac [expand_if])) 1); |
273 |
qed "if_Suc_diff_n"; |
|
274 |
||
275 |
goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)"; |
|
276 |
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
|
277 |
by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o fast_tac HOL_cs)); |
923 | 278 |
qed "zero_induct_lemma"; |
279 |
||
280 |
val prems = goal Arith.thy "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; |
|
281 |
by (rtac (diff_self_eq_0 RS subst) 1); |
|
282 |
by (rtac (zero_induct_lemma RS mp RS mp) 1); |
|
283 |
by (REPEAT (ares_tac ([impI,allI]@prems) 1)); |
|
284 |
qed "zero_induct"; |
|
285 |
||
286 |
(*13 July 1992: loaded in 105.7s*) |
|
287 |
||
288 |
(**** Additional theorems about "less than" ****) |
|
289 |
||
290 |
goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))"; |
|
291 |
by (nat_ind_tac "n" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
292 |
by (ALLGOALS(Simp_tac)); |
923 | 293 |
by (REPEAT_FIRST (ares_tac [conjI, impI])); |
294 |
by (res_inst_tac [("x","0")] exI 2); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
295 |
by (Simp_tac 2); |
923 | 296 |
by (safe_tac HOL_cs); |
297 |
by (res_inst_tac [("x","Suc(k)")] exI 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
298 |
by (Simp_tac 1); |
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset
|
299 |
qed_spec_mp "less_eq_Suc_add"; |
923 | 300 |
|
301 |
goal Arith.thy "n <= ((m + n)::nat)"; |
|
302 |
by (nat_ind_tac "m" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
303 |
by (ALLGOALS Simp_tac); |
923 | 304 |
by (etac le_trans 1); |
305 |
by (rtac (lessI RS less_imp_le) 1); |
|
306 |
qed "le_add2"; |
|
307 |
||
308 |
goal Arith.thy "n <= ((n + m)::nat)"; |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
309 |
by (simp_tac (!simpset addsimps add_ac) 1); |
923 | 310 |
by (rtac le_add2 1); |
311 |
qed "le_add1"; |
|
312 |
||
313 |
bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); |
|
314 |
bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); |
|
315 |
||
316 |
(*"i <= j ==> i <= j+m"*) |
|
317 |
bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); |
|
318 |
||
319 |
(*"i <= j ==> i <= m+j"*) |
|
320 |
bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); |
|
321 |
||
322 |
(*"i < j ==> i < j+m"*) |
|
323 |
bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); |
|
324 |
||
325 |
(*"i < j ==> i < m+j"*) |
|
326 |
bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); |
|
327 |
||
1152 | 328 |
goal Arith.thy "!!i. i+j < (k::nat) ==> i<k"; |
1552 | 329 |
by (etac rev_mp 1); |
330 |
by (nat_ind_tac "j" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
331 |
by (ALLGOALS Asm_simp_tac); |
1552 | 332 |
by (fast_tac (HOL_cs addDs [Suc_lessD]) 1); |
1152 | 333 |
qed "add_lessD1"; |
334 |
||
923 | 335 |
goal Arith.thy "!!k::nat. m <= n ==> m <= n+k"; |
1552 | 336 |
by (etac le_trans 1); |
337 |
by (rtac le_add1 1); |
|
923 | 338 |
qed "le_imp_add_le"; |
339 |
||
340 |
goal Arith.thy "!!k::nat. m < n ==> m < n+k"; |
|
1552 | 341 |
by (etac less_le_trans 1); |
342 |
by (rtac le_add1 1); |
|
923 | 343 |
qed "less_imp_add_less"; |
344 |
||
345 |
goal Arith.thy "m+k<=n --> m<=(n::nat)"; |
|
346 |
by (nat_ind_tac "k" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
347 |
by (ALLGOALS Asm_simp_tac); |
923 | 348 |
by (fast_tac (HOL_cs 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
|
349 |
qed_spec_mp "add_leD1"; |
923 | 350 |
|
351 |
goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n"; |
|
352 |
by (safe_tac (HOL_cs addSDs [less_eq_Suc_add])); |
|
353 |
by (asm_full_simp_tac |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
354 |
(!simpset delsimps [add_Suc_right] |
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
355 |
addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1); |
1552 | 356 |
by (etac subst 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
357 |
by (simp_tac (!simpset addsimps [less_add_Suc1]) 1); |
923 | 358 |
qed "less_add_eq_less"; |
359 |
||
360 |
||
361 |
(** Monotonicity of addition (from ZF/Arith) **) |
|
362 |
||
363 |
(** Monotonicity results **) |
|
364 |
||
365 |
(*strict, in 1st argument*) |
|
366 |
goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k"; |
|
367 |
by (nat_ind_tac "k" 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
368 |
by (ALLGOALS Asm_simp_tac); |
923 | 369 |
qed "add_less_mono1"; |
370 |
||
371 |
(*strict, in both arguments*) |
|
372 |
goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l"; |
|
373 |
by (rtac (add_less_mono1 RS less_trans) 1); |
|
1198 | 374 |
by (REPEAT (assume_tac 1)); |
923 | 375 |
by (nat_ind_tac "j" 1); |
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
376 |
by (ALLGOALS Asm_simp_tac); |
923 | 377 |
qed "add_less_mono"; |
378 |
||
379 |
(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) |
|
380 |
val [lt_mono,le] = goal Arith.thy |
|
1465 | 381 |
"[| !!i j::nat. i<j ==> f(i) < f(j); \ |
382 |
\ i <= j \ |
|
923 | 383 |
\ |] ==> f(i) <= (f(j)::nat)"; |
384 |
by (cut_facts_tac [le] 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
385 |
by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1); |
923 | 386 |
by (fast_tac (HOL_cs addSIs [lt_mono]) 1); |
387 |
qed "less_mono_imp_le_mono"; |
|
388 |
||
389 |
(*non-strict, in 1st argument*) |
|
390 |
goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k"; |
|
391 |
by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1); |
|
1552 | 392 |
by (etac add_less_mono1 1); |
923 | 393 |
by (assume_tac 1); |
394 |
qed "add_le_mono1"; |
|
395 |
||
396 |
(*non-strict, in both arguments*) |
|
397 |
goal Arith.thy "!!k l::nat. [|i<=j; k<=l |] ==> i + k <= j + l"; |
|
398 |
by (etac (add_le_mono1 RS le_trans) 1); |
|
1264
3eb91524b938
added local simpsets; removed IOA from 'make test'
clasohm
parents:
1198
diff
changeset
|
399 |
by (simp_tac (!simpset addsimps [add_commute]) 1); |
923 | 400 |
(*j moves to the end because it is free while k, l are bound*) |
1552 | 401 |
by (etac add_le_mono1 1); |
923 | 402 |
qed "add_le_mono"; |