author | wenzelm |
Tue, 14 Jun 2005 22:08:53 +0200 | |
changeset 16392 | 7212040b71f2 |
parent 13756 | 41abb61ecce9 |
child 16417 | 9bc16273c2d4 |
permissions | -rw-r--r-- |
10341 | 1 |
(* ID: $Id$ *) |
10295 | 2 |
theory Basic = Main: |
3 |
||
4 |
lemma conj_rule: "\<lbrakk> P; Q \<rbrakk> \<Longrightarrow> P \<and> (Q \<and> P)" |
|
5 |
apply (rule conjI) |
|
6 |
apply assumption |
|
7 |
apply (rule conjI) |
|
8 |
apply assumption |
|
9 |
apply assumption |
|
10 |
done |
|
11 |
||
12 |
||
13 |
lemma disj_swap: "P | Q \<Longrightarrow> Q | P" |
|
14 |
apply (erule disjE) |
|
15 |
apply (rule disjI2) |
|
16 |
apply assumption |
|
17 |
apply (rule disjI1) |
|
18 |
apply assumption |
|
19 |
done |
|
20 |
||
21 |
lemma conj_swap: "P \<and> Q \<Longrightarrow> Q \<and> P" |
|
22 |
apply (rule conjI) |
|
23 |
apply (drule conjunct2) |
|
24 |
apply assumption |
|
25 |
apply (drule conjunct1) |
|
26 |
apply assumption |
|
27 |
done |
|
28 |
||
29 |
lemma imp_uncurry: "P \<longrightarrow> Q \<longrightarrow> R \<Longrightarrow> P \<and> Q \<longrightarrow> R" |
|
30 |
apply (rule impI) |
|
31 |
apply (erule conjE) |
|
32 |
apply (drule mp) |
|
33 |
apply assumption |
|
34 |
apply (drule mp) |
|
35 |
apply assumption |
|
36 |
apply assumption |
|
37 |
done |
|
38 |
||
10957 | 39 |
text {* |
10843 | 40 |
by eliminates uses of assumption and done |
41 |
*} |
|
42 |
||
13550 | 43 |
lemma imp_uncurry': "P \<longrightarrow> Q \<longrightarrow> R \<Longrightarrow> P \<and> Q \<longrightarrow> R" |
10843 | 44 |
apply (rule impI) |
45 |
apply (erule conjE) |
|
46 |
apply (drule mp) |
|
47 |
apply assumption |
|
48 |
by (drule mp) |
|
49 |
||
50 |
||
10295 | 51 |
text {* |
52 |
substitution |
|
53 |
||
54 |
@{thm[display] ssubst} |
|
55 |
\rulename{ssubst} |
|
56 |
*}; |
|
57 |
||
58 |
lemma "\<lbrakk> x = f x; P(f x) \<rbrakk> \<Longrightarrow> P x" |
|
10843 | 59 |
by (erule ssubst) |
10295 | 60 |
|
61 |
text {* |
|
62 |
also provable by simp (re-orients) |
|
63 |
*}; |
|
64 |
||
11182 | 65 |
text {* |
66 |
the subst method |
|
67 |
||
68 |
@{thm[display] mult_commute} |
|
69 |
\rulename{mult_commute} |
|
70 |
||
71 |
this would fail: |
|
72 |
apply (simp add: mult_commute) |
|
73 |
*}; |
|
74 |
||
75 |
||
76 |
lemma "\<lbrakk>P x y z; Suc x < y\<rbrakk> \<Longrightarrow> f z = x*y" |
|
77 |
txt{* |
|
78 |
@{subgoals[display,indent=0,margin=65]} |
|
79 |
*}; |
|
80 |
apply (subst mult_commute) |
|
81 |
txt{* |
|
82 |
@{subgoals[display,indent=0,margin=65]} |
|
83 |
*}; |
|
84 |
oops |
|
85 |
||
86 |
(*exercise involving THEN*) |
|
87 |
lemma "\<lbrakk>P x y z; Suc x < y\<rbrakk> \<Longrightarrow> f z = x*y" |
|
88 |
apply (rule mult_commute [THEN ssubst]) |
|
89 |
oops |
|
90 |
||
91 |
||
92 |
lemma "\<lbrakk>x = f x; triple (f x) (f x) x\<rbrakk> \<Longrightarrow> triple x x x" |
|
10957 | 93 |
apply (erule ssubst) |
94 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
95 |
back --{* @{subgoals[display,indent=0,margin=65]} *} |
|
96 |
back --{* @{subgoals[display,indent=0,margin=65]} *} |
|
97 |
back --{* @{subgoals[display,indent=0,margin=65]} *} |
|
98 |
back --{* @{subgoals[display,indent=0,margin=65]} *} |
|
10295 | 99 |
apply assumption |
100 |
done |
|
101 |
||
11182 | 102 |
lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x" |
10295 | 103 |
apply (erule ssubst, assumption) |
104 |
done |
|
105 |
||
10843 | 106 |
text{* |
10957 | 107 |
or better still |
10843 | 108 |
*} |
109 |
||
11182 | 110 |
lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x" |
10843 | 111 |
by (erule ssubst) |
112 |
||
113 |
||
11182 | 114 |
lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x" |
115 |
apply (erule_tac P="\<lambda>u. triple u u x" in ssubst) |
|
10843 | 116 |
apply (assumption) |
10295 | 117 |
done |
118 |
||
119 |
||
11182 | 120 |
lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x" |
121 |
by (erule_tac P="\<lambda>u. triple u u x" in ssubst) |
|
10843 | 122 |
|
123 |
||
10295 | 124 |
text {* |
125 |
negation |
|
126 |
||
127 |
@{thm[display] notI} |
|
128 |
\rulename{notI} |
|
129 |
||
130 |
@{thm[display] notE} |
|
131 |
\rulename{notE} |
|
132 |
||
133 |
@{thm[display] classical} |
|
134 |
\rulename{classical} |
|
135 |
||
136 |
@{thm[display] contrapos_pp} |
|
137 |
\rulename{contrapos_pp} |
|
138 |
||
11407 | 139 |
@{thm[display] contrapos_pn} |
140 |
\rulename{contrapos_pn} |
|
141 |
||
10295 | 142 |
@{thm[display] contrapos_np} |
143 |
\rulename{contrapos_np} |
|
144 |
||
145 |
@{thm[display] contrapos_nn} |
|
146 |
\rulename{contrapos_nn} |
|
147 |
*}; |
|
148 |
||
149 |
||
150 |
lemma "\<lbrakk>\<not>(P\<longrightarrow>Q); \<not>(R\<longrightarrow>Q)\<rbrakk> \<Longrightarrow> R" |
|
151 |
apply (erule_tac Q="R\<longrightarrow>Q" in contrapos_np) |
|
10957 | 152 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
12390 | 153 |
apply (intro impI) |
10957 | 154 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
10843 | 155 |
by (erule notE) |
10295 | 156 |
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
157 |
text {* |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
158 |
@{thm[display] disjCI} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
159 |
\rulename{disjCI} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
160 |
*}; |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
161 |
|
10295 | 162 |
lemma "(P \<or> Q) \<and> R \<Longrightarrow> P \<or> Q \<and> R" |
12408 | 163 |
apply (intro disjCI conjI) |
10957 | 164 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
10295 | 165 |
|
166 |
apply (elim conjE disjE) |
|
167 |
apply assumption |
|
10957 | 168 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
10295 | 169 |
|
10843 | 170 |
by (erule contrapos_np, rule conjI) |
10957 | 171 |
text{* |
10295 | 172 |
proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{6}}\isanewline |
173 |
\isanewline |
|
174 |
goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline |
|
175 |
{\isacharparenleft}P\ {\isasymor}\ Q{\isacharparenright}\ {\isasymand}\ R\ {\isasymLongrightarrow}\ P\ {\isasymor}\ Q\ {\isasymand}\ R\isanewline |
|
176 |
\ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}R{\isacharsemicolon}\ Q{\isacharsemicolon}\ {\isasymnot}\ P{\isasymrbrakk}\ {\isasymLongrightarrow}\ Q\isanewline |
|
177 |
\ {\isadigit{2}}{\isachardot}\ {\isasymlbrakk}R{\isacharsemicolon}\ Q{\isacharsemicolon}\ {\isasymnot}\ P{\isasymrbrakk}\ {\isasymLongrightarrow}\ R |
|
178 |
*} |
|
179 |
||
180 |
||
11182 | 181 |
text{*rule_tac, etc.*} |
182 |
||
183 |
||
184 |
lemma "P&Q" |
|
185 |
apply (rule_tac P=P and Q=Q in conjI) |
|
186 |
oops |
|
187 |
||
188 |
||
13756 | 189 |
text{*unification failure trace *} |
190 |
||
191 |
ML "set trace_unify_fail" |
|
192 |
||
193 |
lemma "P(a, f(b, g(e,a), b), a) \<Longrightarrow> P(a, f(b, g(c,a), b), a)" |
|
194 |
txt{* |
|
195 |
@{subgoals[display,indent=0,margin=65]} |
|
196 |
apply assumption |
|
197 |
Clash: e =/= c |
|
198 |
||
199 |
Clash: == =/= Trueprop |
|
200 |
*} |
|
201 |
oops |
|
202 |
||
203 |
lemma "\<forall>x y. P(x,y) --> P(y,x)" |
|
204 |
apply auto |
|
205 |
txt{* |
|
206 |
@{subgoals[display,indent=0,margin=65]} |
|
207 |
apply assumption |
|
208 |
||
209 |
Clash: bound variable x (depth 1) =/= bound variable y (depth 0) |
|
210 |
||
211 |
Clash: == =/= Trueprop |
|
212 |
Clash: == =/= Trueprop |
|
213 |
*} |
|
214 |
oops |
|
215 |
||
216 |
ML "reset trace_unify_fail" |
|
217 |
||
218 |
||
10295 | 219 |
text{*Quantifiers*} |
220 |
||
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
221 |
text {* |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
222 |
@{thm[display] allI} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
223 |
\rulename{allI} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
224 |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
225 |
@{thm[display] allE} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
226 |
\rulename{allE} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
227 |
|
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
228 |
@{thm[display] spec} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
229 |
\rulename{spec} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
230 |
*}; |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
231 |
|
10295 | 232 |
lemma "\<forall>x. P x \<longrightarrow> P x" |
233 |
apply (rule allI) |
|
10843 | 234 |
by (rule impI) |
10295 | 235 |
|
236 |
lemma "(\<forall>x. P \<longrightarrow> Q x) \<Longrightarrow> P \<longrightarrow> (\<forall>x. Q x)" |
|
10843 | 237 |
apply (rule impI, rule allI) |
10295 | 238 |
apply (drule spec) |
10843 | 239 |
by (drule mp) |
10957 | 240 |
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
241 |
text{*rename_tac*} |
10957 | 242 |
lemma "x < y \<Longrightarrow> \<forall>x y. P x (f y)" |
12390 | 243 |
apply (intro allI) |
10957 | 244 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
245 |
apply (rename_tac v w) |
|
246 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
247 |
oops |
|
248 |
||
10295 | 249 |
|
10843 | 250 |
lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (h x); P a\<rbrakk> \<Longrightarrow> P(h (h a))" |
10295 | 251 |
apply (frule spec) |
10957 | 252 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
10295 | 253 |
apply (drule mp, assumption) |
254 |
apply (drule spec) |
|
10957 | 255 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
10843 | 256 |
by (drule mp) |
10295 | 257 |
|
258 |
lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (f x); P a\<rbrakk> \<Longrightarrow> P(f (f a))" |
|
259 |
by blast |
|
260 |
||
11234 | 261 |
|
262 |
text{* |
|
263 |
the existential quantifier*} |
|
264 |
||
265 |
text {* |
|
266 |
@{thm[display]"exI"} |
|
267 |
\rulename{exI} |
|
268 |
||
269 |
@{thm[display]"exE"} |
|
270 |
\rulename{exE} |
|
271 |
*}; |
|
272 |
||
273 |
||
274 |
text{* |
|
275 |
instantiating quantifiers explicitly by rule_tac and erule_tac*} |
|
276 |
||
277 |
lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (h x); P a\<rbrakk> \<Longrightarrow> P(h (h a))" |
|
278 |
apply (frule spec) |
|
279 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
280 |
apply (drule mp, assumption) |
|
281 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
282 |
apply (drule_tac x = "h a" in spec) |
|
283 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
284 |
by (drule mp) |
|
285 |
||
286 |
text {* |
|
287 |
@{thm[display]"dvd_def"} |
|
288 |
\rulename{dvd_def} |
|
289 |
*}; |
|
290 |
||
291 |
lemma mult_dvd_mono: "\<lbrakk>i dvd m; j dvd n\<rbrakk> \<Longrightarrow> i*j dvd (m*n :: nat)" |
|
292 |
apply (simp add: dvd_def) |
|
293 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
294 |
apply (erule exE) |
|
295 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
296 |
apply (erule exE) |
|
297 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
11407 | 298 |
apply (rename_tac l) |
299 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
|
300 |
apply (rule_tac x="k*l" in exI) |
|
11244 | 301 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
11234 | 302 |
apply simp |
303 |
done |
|
304 |
||
10957 | 305 |
text{* |
10843 | 306 |
Hilbert-epsilon theorems*} |
307 |
||
308 |
text{* |
|
11458 | 309 |
@{thm[display] the_equality[no_vars]} |
310 |
\rulename{the_equality} |
|
311 |
||
10843 | 312 |
@{thm[display] some_equality[no_vars]} |
313 |
\rulename{some_equality} |
|
314 |
||
315 |
@{thm[display] someI[no_vars]} |
|
316 |
\rulename{someI} |
|
317 |
||
318 |
@{thm[display] someI2[no_vars]} |
|
319 |
\rulename{someI2} |
|
320 |
||
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
321 |
@{thm[display] someI_ex[no_vars]} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
322 |
\rulename{someI_ex} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
323 |
|
10843 | 324 |
needed for examples |
325 |
||
326 |
@{thm[display] inv_def[no_vars]} |
|
327 |
\rulename{inv_def} |
|
328 |
||
329 |
@{thm[display] Least_def[no_vars]} |
|
330 |
\rulename{Least_def} |
|
331 |
||
332 |
@{thm[display] order_antisym[no_vars]} |
|
333 |
\rulename{order_antisym} |
|
334 |
*} |
|
335 |
||
336 |
||
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
337 |
lemma "inv Suc (Suc n) = n" |
10843 | 338 |
by (simp add: inv_def) |
339 |
||
340 |
text{*but we know nothing about inv Suc 0*} |
|
341 |
||
342 |
theorem Least_equality: |
|
343 |
"\<lbrakk> P (k::nat); \<forall>x. P x \<longrightarrow> k \<le> x \<rbrakk> \<Longrightarrow> (LEAST x. P(x)) = k" |
|
11456 | 344 |
apply (simp add: Least_def) |
10843 | 345 |
|
11458 | 346 |
txt{* |
10843 | 347 |
@{subgoals[display,indent=0,margin=65]} |
348 |
*}; |
|
349 |
||
11456 | 350 |
apply (rule the_equality) |
10843 | 351 |
|
352 |
txt{* |
|
353 |
@{subgoals[display,indent=0,margin=65]} |
|
354 |
||
355 |
first subgoal is existence; second is uniqueness |
|
356 |
*}; |
|
357 |
by (auto intro: order_antisym) |
|
358 |
||
359 |
||
360 |
theorem axiom_of_choice: |
|
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
361 |
"(\<forall>x. \<exists>y. P x y) \<Longrightarrow> \<exists>f. \<forall>x. P x (f x)" |
10843 | 362 |
apply (rule exI, rule allI) |
363 |
||
364 |
txt{* |
|
365 |
@{subgoals[display,indent=0,margin=65]} |
|
366 |
||
367 |
state after intro rules |
|
368 |
*}; |
|
369 |
apply (drule spec, erule exE) |
|
370 |
||
371 |
txt{* |
|
372 |
@{subgoals[display,indent=0,margin=65]} |
|
373 |
||
374 |
applying @text{someI} automatically instantiates |
|
375 |
@{term f} to @{term "\<lambda>x. SOME y. P x y"} |
|
376 |
*}; |
|
377 |
||
378 |
by (rule someI) |
|
379 |
||
380 |
(*both can be done by blast, which however hasn't been introduced yet*) |
|
381 |
lemma "[| P (k::nat); \<forall>x. P x \<longrightarrow> k \<le> x |] ==> (LEAST x. P(x)) = k"; |
|
11154 | 382 |
apply (simp add: Least_def LeastM_def) |
10843 | 383 |
by (blast intro: some_equality order_antisym); |
384 |
||
13550 | 385 |
theorem axiom_of_choice': "(\<forall>x. \<exists>y. P x y) \<Longrightarrow> \<exists>f. \<forall>x. P x (f x)" |
10843 | 386 |
apply (rule exI [of _ "\<lambda>x. SOME y. P x y"]) |
387 |
by (blast intro: someI); |
|
388 |
||
10957 | 389 |
text{*end of Epsilon section*} |
390 |
||
10843 | 391 |
|
10295 | 392 |
lemma "(\<exists>x. P x) \<or> (\<exists>x. Q x) \<Longrightarrow> \<exists>x. P x \<or> Q x" |
12390 | 393 |
apply (elim exE disjE) |
12408 | 394 |
apply (intro exI disjI1) |
10295 | 395 |
apply assumption |
12408 | 396 |
apply (intro exI disjI2) |
10295 | 397 |
apply assumption |
398 |
done |
|
399 |
||
400 |
lemma "(P\<longrightarrow>Q) \<or> (Q\<longrightarrow>P)" |
|
12390 | 401 |
apply (intro disjCI impI) |
402 |
apply (elim notE) |
|
403 |
apply (intro impI) |
|
10295 | 404 |
apply assumption |
405 |
done |
|
406 |
||
407 |
lemma "(P\<or>Q)\<and>(P\<or>R) \<Longrightarrow> P \<or> (Q\<and>R)" |
|
12390 | 408 |
apply (intro disjCI conjI) |
10295 | 409 |
apply (elim conjE disjE) |
410 |
apply blast |
|
411 |
apply blast |
|
412 |
apply blast |
|
413 |
apply blast |
|
414 |
(*apply elim*) |
|
415 |
done |
|
416 |
||
417 |
lemma "(\<exists>x. P \<and> Q x) \<Longrightarrow> P \<and> (\<exists>x. Q x)" |
|
418 |
apply (erule exE) |
|
419 |
apply (erule conjE) |
|
420 |
apply (rule conjI) |
|
421 |
apply assumption |
|
422 |
apply (rule exI) |
|
423 |
apply assumption |
|
424 |
done |
|
425 |
||
426 |
lemma "(\<exists>x. P x) \<and> (\<exists>x. Q x) \<Longrightarrow> \<exists>x. P x \<and> Q x" |
|
427 |
apply (erule conjE) |
|
428 |
apply (erule exE) |
|
429 |
apply (erule exE) |
|
430 |
apply (rule exI) |
|
431 |
apply (rule conjI) |
|
432 |
apply assumption |
|
433 |
oops |
|
434 |
||
11407 | 435 |
lemma "\<forall>y. R y y \<Longrightarrow> \<exists>x. \<forall>y. R x y" |
11080
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
436 |
apply (rule exI) |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
437 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
438 |
apply (rule allI) |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
439 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
440 |
apply (drule spec) |
22855d091249
various revisions in response to comments from Tobias
paulson
parents:
10957
diff
changeset
|
441 |
--{* @{subgoals[display,indent=0,margin=65]} *} |
10295 | 442 |
oops |
443 |
||
11407 | 444 |
lemma "\<forall>x. \<exists>y. x=y" |
10295 | 445 |
apply (rule allI) |
446 |
apply (rule exI) |
|
447 |
apply (rule refl) |
|
448 |
done |
|
449 |
||
11407 | 450 |
lemma "\<exists>x. \<forall>y. x=y" |
10295 | 451 |
apply (rule exI) |
452 |
apply (rule allI) |
|
453 |
oops |
|
454 |
||
455 |
end |