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