1 theory Basic imports Main begin
3 lemma conj_rule: "\<lbrakk> P; Q \<rbrakk> \<Longrightarrow> P \<and> (Q \<and> P)"
12 lemma disj_swap: "P | Q \<Longrightarrow> Q | P"
20 lemma conj_swap: "P \<and> Q \<Longrightarrow> Q \<and> P"
22 apply (drule conjunct2)
24 apply (drule conjunct1)
28 lemma imp_uncurry: "P \<longrightarrow> Q \<longrightarrow> R \<Longrightarrow> P \<and> Q \<longrightarrow> R"
39 by eliminates uses of assumption and done
42 lemma imp_uncurry': "P \<longrightarrow> Q \<longrightarrow> R \<Longrightarrow> P \<and> Q \<longrightarrow> R"
53 @{thm[display] ssubst}
57 lemma "\<lbrakk> x = f x; P(f x) \<rbrakk> \<Longrightarrow> P x"
61 also provable by simp (re-orients)
67 @{thm[display] mult_commute}
68 \rulename{mult_commute}
71 apply (simp add: mult_commute)
75 lemma "\<lbrakk>P x y z; Suc x < y\<rbrakk> \<Longrightarrow> f z = x*y"
77 @{subgoals[display,indent=0,margin=65]}
79 apply (subst mult_commute)
81 @{subgoals[display,indent=0,margin=65]}
85 (*exercise involving THEN*)
86 lemma "\<lbrakk>P x y z; Suc x < y\<rbrakk> \<Longrightarrow> f z = x*y"
87 apply (rule mult_commute [THEN ssubst])
91 lemma "\<lbrakk>x = f x; triple (f x) (f x) x\<rbrakk> \<Longrightarrow> triple x x x"
93 --{* @{subgoals[display,indent=0,margin=65]} *}
94 back --{* @{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]} *}
101 lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x"
102 apply (erule ssubst, assumption)
109 lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x"
113 lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x"
114 apply (erule_tac P="\<lambda>u. triple u u x" in ssubst)
119 lemma "\<lbrakk> x = f x; triple (f x) (f x) x \<rbrakk> \<Longrightarrow> triple x x x"
120 by (erule_tac P="\<lambda>u. triple u u x" in ssubst)
132 @{thm[display] classical}
135 @{thm[display] contrapos_pp}
136 \rulename{contrapos_pp}
138 @{thm[display] contrapos_pn}
139 \rulename{contrapos_pn}
141 @{thm[display] contrapos_np}
142 \rulename{contrapos_np}
144 @{thm[display] contrapos_nn}
145 \rulename{contrapos_nn}
149 lemma "\<lbrakk>\<not>(P\<longrightarrow>Q); \<not>(R\<longrightarrow>Q)\<rbrakk> \<Longrightarrow> R"
150 apply (erule_tac Q="R\<longrightarrow>Q" in contrapos_np)
151 --{* @{subgoals[display,indent=0,margin=65]} *}
153 --{* @{subgoals[display,indent=0,margin=65]} *}
157 @{thm[display] disjCI}
161 lemma "(P \<or> Q) \<and> R \<Longrightarrow> P \<or> Q \<and> R"
162 apply (intro disjCI conjI)
163 --{* @{subgoals[display,indent=0,margin=65]} *}
165 apply (elim conjE disjE)
167 --{* @{subgoals[display,indent=0,margin=65]} *}
169 by (erule contrapos_np, rule conjI)
171 proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{6}}\isanewline
173 goal\ {\isacharparenleft}lemma{\isacharparenright}{\isacharcolon}\isanewline
174 {\isacharparenleft}P\ {\isasymor}\ Q{\isacharparenright}\ {\isasymand}\ R\ {\isasymLongrightarrow}\ P\ {\isasymor}\ Q\ {\isasymand}\ R\isanewline
175 \ {\isadigit{1}}{\isachardot}\ {\isasymlbrakk}R{\isacharsemicolon}\ Q{\isacharsemicolon}\ {\isasymnot}\ P{\isasymrbrakk}\ {\isasymLongrightarrow}\ Q\isanewline
176 \ {\isadigit{2}}{\isachardot}\ {\isasymlbrakk}R{\isacharsemicolon}\ Q{\isacharsemicolon}\ {\isasymnot}\ P{\isasymrbrakk}\ {\isasymLongrightarrow}\ R
180 text{*rule_tac, etc.*}
184 apply (rule_tac P=P and Q=Q in conjI)
188 text{*unification failure trace *}
190 ML "Unsynchronized.set trace_unify_fail"
192 lemma "P(a, f(b, g(e,a), b), a) \<Longrightarrow> P(a, f(b, g(c,a), b), a)"
194 @{subgoals[display,indent=0,margin=65]}
198 Clash: == =/= Trueprop
202 lemma "\<forall>x y. P(x,y) --> P(y,x)"
205 @{subgoals[display,indent=0,margin=65]}
208 Clash: bound variable x (depth 1) =/= bound variable y (depth 0)
210 Clash: == =/= Trueprop
211 Clash: == =/= Trueprop
215 ML "Unsynchronized.reset trace_unify_fail"
231 lemma "\<forall>x. P x \<longrightarrow> P x"
235 lemma "(\<forall>x. P \<longrightarrow> Q x) \<Longrightarrow> P \<longrightarrow> (\<forall>x. Q x)"
236 apply (rule impI, rule allI)
241 lemma "x < y \<Longrightarrow> \<forall>x y. P x (f y)"
243 --{* @{subgoals[display,indent=0,margin=65]} *}
244 apply (rename_tac v w)
245 --{* @{subgoals[display,indent=0,margin=65]} *}
249 lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (h x); P a\<rbrakk> \<Longrightarrow> P(h (h a))"
251 --{* @{subgoals[display,indent=0,margin=65]} *}
252 apply (drule mp, assumption)
254 --{* @{subgoals[display,indent=0,margin=65]} *}
257 lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (f x); P a\<rbrakk> \<Longrightarrow> P(f (f a))"
262 the existential quantifier*}
274 instantiating quantifiers explicitly by rule_tac and erule_tac*}
276 lemma "\<lbrakk>\<forall>x. P x \<longrightarrow> P (h x); P a\<rbrakk> \<Longrightarrow> P(h (h a))"
278 --{* @{subgoals[display,indent=0,margin=65]} *}
279 apply (drule mp, assumption)
280 --{* @{subgoals[display,indent=0,margin=65]} *}
281 apply (drule_tac x = "h a" in spec)
282 --{* @{subgoals[display,indent=0,margin=65]} *}
286 @{thm[display]"dvd_def"}
290 lemma mult_dvd_mono: "\<lbrakk>i dvd m; j dvd n\<rbrakk> \<Longrightarrow> i*j dvd (m*n :: nat)"
291 apply (simp add: dvd_def)
292 --{* @{subgoals[display,indent=0,margin=65]} *}
294 --{* @{subgoals[display,indent=0,margin=65]} *}
296 --{* @{subgoals[display,indent=0,margin=65]} *}
298 --{* @{subgoals[display,indent=0,margin=65]} *}
299 apply (rule_tac x="k*l" in exI)
300 --{* @{subgoals[display,indent=0,margin=65]} *}
305 Hilbert-epsilon theorems*}
308 @{thm[display] the_equality[no_vars]}
309 \rulename{the_equality}
311 @{thm[display] some_equality[no_vars]}
312 \rulename{some_equality}
314 @{thm[display] someI[no_vars]}
317 @{thm[display] someI2[no_vars]}
320 @{thm[display] someI_ex[no_vars]}
325 @{thm[display] inv_def[no_vars]}
328 @{thm[display] Least_def[no_vars]}
331 @{thm[display] order_antisym[no_vars]}
332 \rulename{order_antisym}
336 lemma "inv Suc (Suc n) = n"
337 by (simp add: inv_def)
339 text{*but we know nothing about inv Suc 0*}
341 theorem Least_equality:
342 "\<lbrakk> P (k::nat); \<forall>x. P x \<longrightarrow> k \<le> x \<rbrakk> \<Longrightarrow> (LEAST x. P(x)) = k"
343 apply (simp add: Least_def)
346 @{subgoals[display,indent=0,margin=65]}
349 apply (rule the_equality)
352 @{subgoals[display,indent=0,margin=65]}
354 first subgoal is existence; second is uniqueness
356 by (auto intro: order_antisym)
359 theorem axiom_of_choice:
360 "(\<forall>x. \<exists>y. P x y) \<Longrightarrow> \<exists>f. \<forall>x. P x (f x)"
361 apply (rule exI, rule allI)
364 @{subgoals[display,indent=0,margin=65]}
366 state after intro rules
368 apply (drule spec, erule exE)
371 @{subgoals[display,indent=0,margin=65]}
373 applying @text{someI} automatically instantiates
374 @{term f} to @{term "\<lambda>x. SOME y. P x y"}
379 (*both can be done by blast, which however hasn't been introduced yet*)
380 lemma "[| P (k::nat); \<forall>x. P x \<longrightarrow> k \<le> x |] ==> (LEAST x. P(x)) = k";
381 apply (simp add: Least_def LeastM_def)
382 by (blast intro: some_equality order_antisym);
384 theorem axiom_of_choice': "(\<forall>x. \<exists>y. P x y) \<Longrightarrow> \<exists>f. \<forall>x. P x (f x)"
385 apply (rule exI [of _ "\<lambda>x. SOME y. P x y"])
386 by (blast intro: someI);
388 text{*end of Epsilon section*}
391 lemma "(\<exists>x. P x) \<or> (\<exists>x. Q x) \<Longrightarrow> \<exists>x. P x \<or> Q x"
392 apply (elim exE disjE)
393 apply (intro exI disjI1)
395 apply (intro exI disjI2)
399 lemma "(P\<longrightarrow>Q) \<or> (Q\<longrightarrow>P)"
400 apply (intro disjCI impI)
406 lemma "(P\<or>Q)\<and>(P\<or>R) \<Longrightarrow> P \<or> (Q\<and>R)"
407 apply (intro disjCI conjI)
408 apply (elim conjE disjE)
416 lemma "(\<exists>x. P \<and> Q x) \<Longrightarrow> P \<and> (\<exists>x. Q x)"
425 lemma "(\<exists>x. P x) \<and> (\<exists>x. Q x) \<Longrightarrow> \<exists>x. P x \<and> Q x"
434 lemma "\<forall>y. R y y \<Longrightarrow> \<exists>x. \<forall>y. R x y"
436 --{* @{subgoals[display,indent=0,margin=65]} *}
438 --{* @{subgoals[display,indent=0,margin=65]} *}
440 --{* @{subgoals[display,indent=0,margin=65]} *}
443 lemma "\<forall>x. \<exists>y. x=y"
449 lemma "\<exists>x. \<forall>y. x=y"