theory Logic = Main: section{*Logic \label{sec:Logic}*} subsection{*Propositional logic*} subsubsection{*Introduction rules*} lemma "A \ A" proof (rule impI) assume a: "A" show "A" by(rule a) qed (* proof *) lemma "A \ A" proof assume a: A show A by(rule a) qed (* . *) lemma "A \ A" proof assume "A" show "A" . qed (* by *) lemma "A \ A \ A" proof assume "A" show "A \ A" by(rule conjI) qed (* .. *) lemma "A \ A \ A" proof assume "A" show "A \ A" .. qed subsubsection{*Elimination rules*} lemma "A \ B \ B \ A" proof assume AB: "A \ B" show "B \ A" proof (rule conjE[OF AB]) assume "A" "B" show ?thesis .. qed qed lemma "A \ B \ B \ A" proof assume AB: "A \ B" from AB show "B \ A" proof assume "A" "B" show ?thesis .. qed qed (* this, then, thus *) lemma "A \ B \ B \ A" proof assume "A \ B" from this show "B \ A" proof assume "A" "B" show ?thesis .. qed qed lemma "A \ B \ B \ A" proof assume ab: "A \ B" from ab have a: "A" .. from ab have b: "B" .. from b a show "B \ A" .. qed subsection{*More constructs*} lemma "A \ B \ B \ A" proof assume ab: "A \ B" from ab have "B" .. moreover from ab have "A" .. ultimately show "B \ A" .. qed (* hence, with *) lemma "\ (A \ B) \ \ A \ \ B" proof assume n: "\ (A \ B)" show "\ A \ \ B" proof (rule ccontr) assume nn: "\ (\ A \ \ B)" have "\ A" proof assume "A" have "\ B" proof assume "B" have "A \ B" .. with n show False .. qed hence "\ A \ \ B" .. with nn show False .. qed hence "\ A \ \ B" .. with nn show False .. qed qed lemma "A & (B | C) \ (A & B) | (A & C)" sorry subsection{*Avoiding duplication*} lemma "A \ B \ B \ A" proof assume "A \ B" thus "B" .. next assume "A \ B" thus "A" .. qed lemma "large_A \ large_B \ large_B \ large_A" (is "?AB \ ?B \ ?A") proof assume "?AB" thus "?B" .. next assume "?AB" thus "?A" .. qed lemma assumes AB: "large_A \ large_B" shows "large_B \ large_A" (is "?B \ ?A") proof from AB show "?B" .. next from AB show "?A" .. qed lemma assumes AB: "large_A \ large_B" shows "large_B \ large_A" (is "?B \ ?A") using AB proof assume "?A" "?B" show ?thesis .. qed lemma assumes AB: "A \ B" shows "B \ A" proof - from AB show ?thesis proof assume A show ?thesis .. next assume B show ?thesis .. qed qed subsection{*Predicate calculus*} (* fix *) lemma assumes P: "\x. P x" shows "\x. P(f x)" proof fix a from P show "P(f a)" .. qed (* Text can only refer to global constants, free variables in the lemma, and local names introduced via "fix"/"obtain" *) lemma assumes Pf: "\x. P(f x)" shows "\y. P y" proof - from Pf show ?thesis proof fix x assume "P(f x)" show ?thesis .. qed qed lemma assumes Pf: "\x. P(f x)" shows "\y. P y" proof - from Pf obtain x where "P(f x)" .. thus "\y. P y" .. qed lemma assumes ex: "\x. \y. P x y" shows "\y. \x. P x y" proof fix y from ex obtain x where "\y. P x y" .. hence "P x y" .. thus "\x. P x y" .. qed lemma "EX x. P x \ (ALL x. P x)" sorry subsection{*Making bigger steps*} theorem "\S. S \ range (f :: 'a \ 'a set)" proof let ?S = "{x. x \ f x}" show "?S \ range f" proof assume "?S \ range f" then obtain y where fy: "?S = f y" .. show False proof cases assume "y \ ?S" with fy show False by blast next assume "y \ ?S" with fy show False by blast qed qed qed theorem "\S. S \ range (f :: 'a \ 'a set)" proof let ?S = "{x. x \ f x}" show "?S \ range f" proof assume "?S \ range f" then obtain y where fy: "?S = f y" .. show False proof cases assume "y \ ?S" hence "y \ f y" by simp hence "y \ ?S" by(simp add:fy) thus False by contradiction next assume "y \ ?S" hence "y \ f y" by simp hence "y \ ?S" by(simp add:fy) thus False by contradiction qed qed qed theorem "\S. S \ range (f :: 'a \ 'a set)" by best (* Of course this only works in the context of HOL's carefully constructed introduction and elimination rules for set theory.*) subsection{*Raw proof blocks*} ML"set quick_and_dirty" lemma "\x y. A x y \ B x y \ C x y" proof fix x show "\y. A x y \ B x y \ C x y" proof fix y show "A x y \ B x y \ C x y" proof assume "A x y \ B x y" show "C x y" sorry qed qed qed lemma "\x y. A x y \ B x y \ C x y" proof - have "\x y. \ A x y; B x y \ \ C x y" proof - fix x y assume "A x y" "B x y" show "C x y" sorry qed thus ?thesis by blast qed lemma "\x y. A x y \ B x y \ C x y" proof - { fix x y assume "A x y" "B x y" have "C x y" sorry } thus ?thesis by blast qed subsection{*Further refinements*} subsubsection{*\isakeyword{obtain}*} lemma assumes A: "\x y. P x y \ Q x y" shows "R" proof - from A obtain x y where P: "P x y" and Q: "Q x y" by blast oops subsubsection{*Combining proof styles*} lemma "A \ (A \ B) \ B" proof assume a: "A" show "(A \B) \ B" apply(rule impI) apply(erule impE) apply(rule a) apply assumption done qed end