theory Demo85 imports Main begin -- -------------------------------------------- section "More Isar" text {* . = by assumption, .. = by rule *} lemma "\ A; B \ \ B \ A" proof assume "A" and "B" show "A" . show "B" . qed lemma "\ A; B \ \ B \ A" proof - assume "A" and "B" show "B \ A" .. qed text {* backward/forward *} lemma "A \ B \ B \ A" proof assume AB: "A \ B" from AB show "B \ A" proof assume "A" "B" show "B \ A" .. qed qed text{* fix *} lemma assumes P: "\x. P x" shows "\x. P (f x)" proof fix a from P show "P (f a)" .. qed text{* Proof text can only refer to global constants, free variables in the lemma, and local names introduced via fix or 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 text {* obtain *} 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 assumes A: "\x y. P x y \ Q x y" shows "\x y. P x y \ Q x y" proof - from A obtain x y where P: "P x y" and Q: "Q x y" by blast thus ?thesis by blast qed text {* moreover *} thm mono_def monoI lemma assumes mono_f: "mono (f::int\int)" and mono_g: "mono (g::int\int)" shows "mono (\i. f i + g i)" proof fix i and j :: "int" assume A: "i \ j" from A mono_f have "f i \ f j" by (simp add: mono_def) moreover from A mono_g have "g i \ g j" by (simp add: mono_def) ultimately show "f i + g i \ f j + g j" by simp qed -- --------------------------------------- text{*A manual proof in set theory:*} thm equalityI subsetI thm UnI1 UnI2 UnE lemma "A \ B = B \ A" apply(rule equalityI) apply(rule subsetI) apply(erule UnE) apply(rule UnI2) apply(assumption) apply(rule UnI1) apply(assumption) apply(rule subsetI) apply(erule UnE) apply(rule UnI2) apply(assumption) apply(rule UnI1) apply(assumption) done text{* Most simple proofs in set theory are automatic: *} lemma "-(A \ B) = (-A \ -B)" by blast lemma "{x. P x \ Q x} = {x. P x} \ {x. Q x}" by blast -- ------------------------------------------------------------------------ end