(* $Id: sol.thy,v 1.2 2004/11/23 15:14:35 webertj Exp $ Original Author: Tjark Weber Updated to Isabelle 2016 and additions by Jacques Fleuriot Updated to Isabelle 2020 ({**} to \\) by Jake Palmer *) section \A Riddle: Rich Grandfather\ theory riddle_solution imports Main begin text \ First prove the following formula, which is valid in classical predicate logic, informally with pen and paper. Use case distinctions and/or proof by contradiction. "If every poor man has a rich father, then there is a rich man who has a rich grandfather" \ text \ Proof (1) We first show: "\x. rich x". Proof by contradiction. Assume "\ (\x. rich x)" Then "\x. \ rich x" We consider an arbitrary "y" with "\ rich y" Then "rich (father y)" (2) Now we show the theorem. Proof by cases. Case 1: "rich (father (father x))" We are done. Case 2: "\ rich (father (father x))" Then "rich (father (father (father x))) Also "rich (father x)" because otherwise "rich (father (father x))" qed \ text \ Now prove the formula in Isabelle using a sequence of rule applications (i.e. only using the methods rule, erule and assumption). \ theorem "\x. \ rich x \ rich (father x) \ \x. rich (father (father x)) \ rich x" apply (rule classical) apply (rule exI) apply (rule conjI) apply (rule classical) apply (rule allE) apply assumption apply (erule impE) apply assumption apply (erule notE) apply (rule exI) apply (rule conjI) apply assumption apply (rule classical) apply (erule allE) apply (erule notE) apply (erule impE) apply assumption apply assumption apply (rule classical) apply (rule allE) apply assumption apply (erule impE) apply assumption apply (erule notE) apply (rule exI) apply (rule conjI) apply assumption apply (rule classical) apply (erule allE) apply (erule notE) apply (erule impE) apply assumption apply assumption done text \An alternative proof of the above that does not rely on meta variables and uses additional tactics/methods such as drule and cut_tac. Note the use of rule exCI too. Note also that the order in which the subgoals are tackled are dictated by Isabelle but there are ways of doing the proof in a way closer to the informal one e.g. using "prefer" to change the order of the goals (although this makes the proof potentially more "brittle" to changes in future versions of Isabelle\ theorem "\x. \ rich x \ rich (father x) \ \x. rich (father (father x)) \ rich x" apply (subgoal_tac "\x. rich x") apply (erule exE) (* Tackling (2) first *) apply (cut_tac P="rich (father (father x))" in excluded_middle) apply (erule disjE) (* Case 2 *) apply (subgoal_tac "rich (father x)") apply (drule_tac x="father (father x)" in spec) apply (drule mp, assumption) apply (rule_tac x="father x" in exI) apply (rule conjI) apply assumption apply assumption apply (rule ccontr) apply (drule_tac x="father x" in spec) apply (drule mp, assumption) apply (erule notE, assumption) (* Case 1*) apply (rule_tac x=x in exI) apply (rule conjI) apply assumption apply assumption (* Tackling (1) now *) apply (rule_tac a="father x" in exCI) apply (drule_tac x=x in spec) apply (drule_tac x=x in spec) apply (drule mp, assumption) apply assumption done text \ Here is a proof in Isar that resembles the informal reasoning above: \ theorem rich_grandfather: "\x. \ rich x \ rich (father x) \ \x. rich x \ rich (father (father x))" proof - assume a: "\x. \ rich x \ rich (father x)" have "\x. rich x" proof (rule classical) fix y assume "\ (\x. rich x)" then have "\x. \ rich x" by simp then have "\ rich y" by simp with a have "rich (father y)" by simp then show ?thesis by rule qed then obtain x where x: "rich x" by auto show ?thesis proof cases assume "rich (father (father x))" with x show ?thesis by auto next assume b: "\ rich (father (father x))" with a have "rich (father (father (father x)))" by simp moreover have "rich (father x)" proof (rule classical) assume "\ rich (father x)" with a have "rich (father (father x))" by simp with b show ?thesis by contradiction qed ultimately show ?thesis by auto qed qed text \ An slightly modified proof of the above, with a named assumption right from the beginning: \ theorem rich_grandfather2: assumes a: "\x. \ rich x \ rich (father x)" shows "\x. rich x \ rich (father (father x))" proof - have "\x. rich x" proof (rule classical) fix y assume "\ (\x. rich x)" then have "\x. \ rich x" by simp then have "\ rich y" by simp with a have "rich (father y)" by simp then show ?thesis by rule qed then obtain x where x: "rich x" by auto show ?thesis proof cases assume "rich (father (father x))" with x show ?thesis by auto next assume b: "\ rich (father (father x))" with a have "rich (father (father (father x)))" by simp moreover have "rich (father x)" proof (rule classical) assume "\ rich (father x)" with a have "rich (father (father x))" by simp with b show ?thesis by contradiction qed ultimately show ?thesis by auto qed qed end