src/HOL/ex/Classical.thy
changeset 69420 85b0df070afe
parent 67443 3abf6a722518
child 69597 ff784d5a5bfb
equal deleted inserted replaced
69346:3c29edccf739 69420:85b0df070afe
    12 text\<open>The machine "griffon" mentioned below is a 2.5GHz Power Mac G5.\<close>
    12 text\<open>The machine "griffon" mentioned below is a 2.5GHz Power Mac G5.\<close>
    13 
    13 
    14 text\<open>Taken from \<open>FOL/Classical.thy\<close>. When porting examples from
    14 text\<open>Taken from \<open>FOL/Classical.thy\<close>. When porting examples from
    15 first-order logic, beware of the precedence of \<open>=\<close> versus \<open>\<leftrightarrow>\<close>.\<close>
    15 first-order logic, beware of the precedence of \<open>=\<close> versus \<open>\<leftrightarrow>\<close>.\<close>
    16 
    16 
    17 lemma "(P --> Q | R) --> (P-->Q) | (P-->R)"
    17 lemma "(P \<longrightarrow> Q \<or> R) \<longrightarrow> (P\<longrightarrow>Q) \<or> (P\<longrightarrow>R)"
    18 by blast
    18 by blast
    19 
    19 
    20 text\<open>If and only if\<close>
    20 text\<open>If and only if\<close>
    21 
    21 
    22 lemma "(P=Q) = (Q = (P::bool))"
    22 lemma "(P=Q) = (Q = (P::bool))"
    23 by blast
    23 by blast
    24 
    24 
    25 lemma "~ (P = (~P))"
    25 lemma "\<not> (P = (\<not>P))"
    26 by blast
    26 by blast
    27 
    27 
    28 
    28 
    29 text\<open>Sample problems from
    29 text\<open>Sample problems from
    30   F. J. Pelletier,
    30   F. J. Pelletier,
    37 \<close>
    37 \<close>
    38 
    38 
    39 subsubsection\<open>Pelletier's examples\<close>
    39 subsubsection\<open>Pelletier's examples\<close>
    40 
    40 
    41 text\<open>1\<close>
    41 text\<open>1\<close>
    42 lemma "(P-->Q)  =  (~Q --> ~P)"
    42 lemma "(P\<longrightarrow>Q)  =  (\<not>Q \<longrightarrow> \<not>P)"
    43 by blast
    43 by blast
    44 
    44 
    45 text\<open>2\<close>
    45 text\<open>2\<close>
    46 lemma "(~ ~ P) =  P"
    46 lemma "(\<not> \<not> P) =  P"
    47 by blast
    47 by blast
    48 
    48 
    49 text\<open>3\<close>
    49 text\<open>3\<close>
    50 lemma "~(P-->Q) --> (Q-->P)"
    50 lemma "\<not>(P\<longrightarrow>Q) \<longrightarrow> (Q\<longrightarrow>P)"
    51 by blast
    51 by blast
    52 
    52 
    53 text\<open>4\<close>
    53 text\<open>4\<close>
    54 lemma "(~P-->Q)  =  (~Q --> P)"
    54 lemma "(\<not>P\<longrightarrow>Q)  =  (\<not>Q \<longrightarrow> P)"
    55 by blast
    55 by blast
    56 
    56 
    57 text\<open>5\<close>
    57 text\<open>5\<close>
    58 lemma "((P|Q)-->(P|R)) --> (P|(Q-->R))"
    58 lemma "((P\<or>Q)\<longrightarrow>(P\<or>R)) \<longrightarrow> (P\<or>(Q\<longrightarrow>R))"
    59 by blast
    59 by blast
    60 
    60 
    61 text\<open>6\<close>
    61 text\<open>6\<close>
    62 lemma "P | ~ P"
    62 lemma "P \<or> \<not> P"
    63 by blast
    63 by blast
    64 
    64 
    65 text\<open>7\<close>
    65 text\<open>7\<close>
    66 lemma "P | ~ ~ ~ P"
    66 lemma "P \<or> \<not> \<not> \<not> P"
    67 by blast
    67 by blast
    68 
    68 
    69 text\<open>8.  Peirce's law\<close>
    69 text\<open>8.  Peirce's law\<close>
    70 lemma "((P-->Q) --> P)  -->  P"
    70 lemma "((P\<longrightarrow>Q) \<longrightarrow> P)  \<longrightarrow>  P"
    71 by blast
    71 by blast
    72 
    72 
    73 text\<open>9\<close>
    73 text\<open>9\<close>
    74 lemma "((P|Q) & (~P|Q) & (P| ~Q)) --> ~ (~P | ~Q)"
    74 lemma "((P\<or>Q) \<and> (\<not>P\<or>Q) \<and> (P\<or> \<not>Q)) \<longrightarrow> \<not> (\<not>P \<or> \<not>Q)"
    75 by blast
    75 by blast
    76 
    76 
    77 text\<open>10\<close>
    77 text\<open>10\<close>
    78 lemma "(Q-->R) & (R-->P&Q) & (P-->Q|R) --> (P=Q)"
    78 lemma "(Q\<longrightarrow>R) \<and> (R\<longrightarrow>P\<and>Q) \<and> (P\<longrightarrow>Q\<or>R) \<longrightarrow> (P=Q)"
    79 by blast
    79 by blast
    80 
    80 
    81 text\<open>11.  Proved in each direction (incorrectly, says Pelletier!!)\<close>
    81 text\<open>11.  Proved in each direction (incorrectly, says Pelletier!!)\<close>
    82 lemma "P=(P::bool)"
    82 lemma "P=(P::bool)"
    83 by blast
    83 by blast
    85 text\<open>12.  "Dijkstra's law"\<close>
    85 text\<open>12.  "Dijkstra's law"\<close>
    86 lemma "((P = Q) = R) = (P = (Q = R))"
    86 lemma "((P = Q) = R) = (P = (Q = R))"
    87 by blast
    87 by blast
    88 
    88 
    89 text\<open>13.  Distributive law\<close>
    89 text\<open>13.  Distributive law\<close>
    90 lemma "(P | (Q & R)) = ((P | Q) & (P | R))"
    90 lemma "(P \<or> (Q \<and> R)) = ((P \<or> Q) \<and> (P \<or> R))"
    91 by blast
    91 by blast
    92 
    92 
    93 text\<open>14\<close>
    93 text\<open>14\<close>
    94 lemma "(P = Q) = ((Q | ~P) & (~Q|P))"
    94 lemma "(P = Q) = ((Q \<or> \<not>P) \<and> (\<not>Q\<or>P))"
    95 by blast
    95 by blast
    96 
    96 
    97 text\<open>15\<close>
    97 text\<open>15\<close>
    98 lemma "(P --> Q) = (~P | Q)"
    98 lemma "(P \<longrightarrow> Q) = (\<not>P \<or> Q)"
    99 by blast
    99 by blast
   100 
   100 
   101 text\<open>16\<close>
   101 text\<open>16\<close>
   102 lemma "(P-->Q) | (Q-->P)"
   102 lemma "(P\<longrightarrow>Q) \<or> (Q\<longrightarrow>P)"
   103 by blast
   103 by blast
   104 
   104 
   105 text\<open>17\<close>
   105 text\<open>17\<close>
   106 lemma "((P & (Q-->R))-->S)  =  ((~P | Q | S) & (~P | ~R | S))"
   106 lemma "((P \<and> (Q\<longrightarrow>R))\<longrightarrow>S)  =  ((\<not>P \<or> Q \<or> S) \<and> (\<not>P \<or> \<not>R \<or> S))"
   107 by blast
   107 by blast
   108 
   108 
   109 subsubsection\<open>Classical Logic: examples with quantifiers\<close>
   109 subsubsection\<open>Classical Logic: examples with quantifiers\<close>
   110 
   110 
   111 lemma "(\<forall>x. P(x) & Q(x)) = ((\<forall>x. P(x)) & (\<forall>x. Q(x)))"
   111 lemma "(\<forall>x. P(x) \<and> Q(x)) = ((\<forall>x. P(x)) \<and> (\<forall>x. Q(x)))"
   112 by blast
   112 by blast
   113 
   113 
   114 lemma "(\<exists>x. P-->Q(x))  =  (P --> (\<exists>x. Q(x)))"
   114 lemma "(\<exists>x. P\<longrightarrow>Q(x))  =  (P \<longrightarrow> (\<exists>x. Q(x)))"
   115 by blast
   115 by blast
   116 
   116 
   117 lemma "(\<exists>x. P(x)-->Q) = ((\<forall>x. P(x)) --> Q)"
   117 lemma "(\<exists>x. P(x)\<longrightarrow>Q) = ((\<forall>x. P(x)) \<longrightarrow> Q)"
   118 by blast
   118 by blast
   119 
   119 
   120 lemma "((\<forall>x. P(x)) | Q)  =  (\<forall>x. P(x) | Q)"
   120 lemma "((\<forall>x. P(x)) \<or> Q)  =  (\<forall>x. P(x) \<or> Q)"
   121 by blast
   121 by blast
   122 
   122 
   123 text\<open>From Wishnu Prasetya\<close>
   123 text\<open>From Wishnu Prasetya\<close>
   124 lemma "(\<forall>s. q(s) --> r(s)) & ~r(s) & (\<forall>s. ~r(s) & ~q(s) --> p(t) | q(t))
   124 lemma "(\<forall>x. Q(x) \<longrightarrow> R(x)) \<and> \<not>R(a) \<and> (\<forall>x. \<not>R(x) \<and> \<not>Q(x) \<longrightarrow> P(b) \<or> Q(b))
   125     --> p(t) | r(t)"
   125     \<longrightarrow> P(b) \<or> R(b)"
   126 by blast
   126 by blast
   127 
   127 
   128 
   128 
   129 subsubsection\<open>Problems requiring quantifier duplication\<close>
   129 subsubsection\<open>Problems requiring quantifier duplication\<close>
   130 
   130 
   131 text\<open>Theorem B of Peter Andrews, Theorem Proving via General Matings,
   131 text\<open>Theorem B of Peter Andrews, Theorem Proving via General Matings,
   132   JACM 28 (1981).\<close>
   132   JACM 28 (1981).\<close>
   133 lemma "(\<exists>x. \<forall>y. P(x) = P(y)) --> ((\<exists>x. P(x)) = (\<forall>y. P(y)))"
   133 lemma "(\<exists>x. \<forall>y. P(x) = P(y)) \<longrightarrow> ((\<exists>x. P(x)) = (\<forall>y. P(y)))"
   134 by blast
   134 by blast
   135 
   135 
   136 text\<open>Needs multiple instantiation of the quantifier.\<close>
   136 text\<open>Needs multiple instantiation of the quantifier.\<close>
   137 lemma "(\<forall>x. P(x)-->P(f(x)))  &  P(d)-->P(f(f(f(d))))"
   137 lemma "(\<forall>x. P(x)\<longrightarrow>P(f(x)))  \<and>  P(d)\<longrightarrow>P(f(f(f(d))))"
   138 by blast
   138 by blast
   139 
   139 
   140 text\<open>Needs double instantiation of the quantifier\<close>
   140 text\<open>Needs double instantiation of the quantifier\<close>
   141 lemma "\<exists>x. P(x) --> P(a) & P(b)"
   141 lemma "\<exists>x. P(x) \<longrightarrow> P(a) \<and> P(b)"
   142 by blast
   142 by blast
   143 
   143 
   144 lemma "\<exists>z. P(z) --> (\<forall>x. P(x))"
   144 lemma "\<exists>z. P(z) \<longrightarrow> (\<forall>x. P(x))"
   145 by blast
   145 by blast
   146 
   146 
   147 lemma "\<exists>x. (\<exists>y. P(y)) --> P(x)"
   147 lemma "\<exists>x. (\<exists>y. P(y)) \<longrightarrow> P(x)"
   148 by blast
   148 by blast
   149 
   149 
   150 subsubsection\<open>Hard examples with quantifiers\<close>
   150 subsubsection\<open>Hard examples with quantifiers\<close>
   151 
   151 
   152 text\<open>Problem 18\<close>
   152 text\<open>Problem 18\<close>
   153 lemma "\<exists>y. \<forall>x. P(y)-->P(x)"
   153 lemma "\<exists>y. \<forall>x. P(y)\<longrightarrow>P(x)"
   154 by blast
   154 by blast
   155 
   155 
   156 text\<open>Problem 19\<close>
   156 text\<open>Problem 19\<close>
   157 lemma "\<exists>x. \<forall>y z. (P(y)-->Q(z)) --> (P(x)-->Q(x))"
   157 lemma "\<exists>x. \<forall>y z. (P(y)\<longrightarrow>Q(z)) \<longrightarrow> (P(x)\<longrightarrow>Q(x))"
   158 by blast
   158 by blast
   159 
   159 
   160 text\<open>Problem 20\<close>
   160 text\<open>Problem 20\<close>
   161 lemma "(\<forall>x y. \<exists>z. \<forall>w. (P(x)&Q(y)-->R(z)&S(w)))
   161 lemma "(\<forall>x y. \<exists>z. \<forall>w. (P(x)\<and>Q(y)\<longrightarrow>R(z)\<and>S(w)))
   162     --> (\<exists>x y. P(x) & Q(y)) --> (\<exists>z. R(z))"
   162     \<longrightarrow> (\<exists>x y. P(x) \<and> Q(y)) \<longrightarrow> (\<exists>z. R(z))"
   163 by blast
   163 by blast
   164 
   164 
   165 text\<open>Problem 21\<close>
   165 text\<open>Problem 21\<close>
   166 lemma "(\<exists>x. P-->Q(x)) & (\<exists>x. Q(x)-->P) --> (\<exists>x. P=Q(x))"
   166 lemma "(\<exists>x. P\<longrightarrow>Q(x)) \<and> (\<exists>x. Q(x)\<longrightarrow>P) \<longrightarrow> (\<exists>x. P=Q(x))"
   167 by blast
   167 by blast
   168 
   168 
   169 text\<open>Problem 22\<close>
   169 text\<open>Problem 22\<close>
   170 lemma "(\<forall>x. P = Q(x))  -->  (P = (\<forall>x. Q(x)))"
   170 lemma "(\<forall>x. P = Q(x))  \<longrightarrow>  (P = (\<forall>x. Q(x)))"
   171 by blast
   171 by blast
   172 
   172 
   173 text\<open>Problem 23\<close>
   173 text\<open>Problem 23\<close>
   174 lemma "(\<forall>x. P | Q(x))  =  (P | (\<forall>x. Q(x)))"
   174 lemma "(\<forall>x. P \<or> Q(x))  =  (P \<or> (\<forall>x. Q(x)))"
   175 by blast
   175 by blast
   176 
   176 
   177 text\<open>Problem 24\<close>
   177 text\<open>Problem 24\<close>
   178 lemma "~(\<exists>x. S(x)&Q(x)) & (\<forall>x. P(x) --> Q(x)|R(x)) &
   178 lemma "\<not>(\<exists>x. S(x)\<and>Q(x)) \<and> (\<forall>x. P(x) \<longrightarrow> Q(x)\<or>R(x)) \<and>
   179      (~(\<exists>x. P(x)) --> (\<exists>x. Q(x))) & (\<forall>x. Q(x)|R(x) --> S(x))
   179      (\<not>(\<exists>x. P(x)) \<longrightarrow> (\<exists>x. Q(x))) \<and> (\<forall>x. Q(x)\<or>R(x) \<longrightarrow> S(x))
   180     --> (\<exists>x. P(x)&R(x))"
   180     \<longrightarrow> (\<exists>x. P(x)\<and>R(x))"
   181 by blast
   181 by blast
   182 
   182 
   183 text\<open>Problem 25\<close>
   183 text\<open>Problem 25\<close>
   184 lemma "(\<exists>x. P(x)) &
   184 lemma "(\<exists>x. P(x)) \<and>
   185         (\<forall>x. L(x) --> ~ (M(x) & R(x))) &
   185         (\<forall>x. L(x) \<longrightarrow> \<not> (M(x) \<and> R(x))) \<and>
   186         (\<forall>x. P(x) --> (M(x) & L(x))) &
   186         (\<forall>x. P(x) \<longrightarrow> (M(x) \<and> L(x))) \<and>
   187         ((\<forall>x. P(x)-->Q(x)) | (\<exists>x. P(x)&R(x)))
   187         ((\<forall>x. P(x)\<longrightarrow>Q(x)) \<or> (\<exists>x. P(x)\<and>R(x)))
   188     --> (\<exists>x. Q(x)&P(x))"
   188     \<longrightarrow> (\<exists>x. Q(x)\<and>P(x))"
   189 by blast
   189 by blast
   190 
   190 
   191 text\<open>Problem 26\<close>
   191 text\<open>Problem 26\<close>
   192 lemma "((\<exists>x. p(x)) = (\<exists>x. q(x))) &
   192 lemma "((\<exists>x. p(x)) = (\<exists>x. q(x))) \<and>
   193       (\<forall>x. \<forall>y. p(x) & q(y) --> (r(x) = s(y)))
   193       (\<forall>x. \<forall>y. p(x) \<and> q(y) \<longrightarrow> (r(x) = s(y)))
   194   --> ((\<forall>x. p(x)-->r(x)) = (\<forall>x. q(x)-->s(x)))"
   194   \<longrightarrow> ((\<forall>x. p(x)\<longrightarrow>r(x)) = (\<forall>x. q(x)\<longrightarrow>s(x)))"
   195 by blast
   195 by blast
   196 
   196 
   197 text\<open>Problem 27\<close>
   197 text\<open>Problem 27\<close>
   198 lemma "(\<exists>x. P(x) & ~Q(x)) &
   198 lemma "(\<exists>x. P(x) \<and> \<not>Q(x)) \<and>
   199               (\<forall>x. P(x) --> R(x)) &
   199               (\<forall>x. P(x) \<longrightarrow> R(x)) \<and>
   200               (\<forall>x. M(x) & L(x) --> P(x)) &
   200               (\<forall>x. M(x) \<and> L(x) \<longrightarrow> P(x)) \<and>
   201               ((\<exists>x. R(x) & ~ Q(x)) --> (\<forall>x. L(x) --> ~ R(x)))
   201               ((\<exists>x. R(x) \<and> \<not> Q(x)) \<longrightarrow> (\<forall>x. L(x) \<longrightarrow> \<not> R(x)))
   202           --> (\<forall>x. M(x) --> ~L(x))"
   202           \<longrightarrow> (\<forall>x. M(x) \<longrightarrow> \<not>L(x))"
   203 by blast
   203 by blast
   204 
   204 
   205 text\<open>Problem 28.  AMENDED\<close>
   205 text\<open>Problem 28.  AMENDED\<close>
   206 lemma "(\<forall>x. P(x) --> (\<forall>x. Q(x))) &
   206 lemma "(\<forall>x. P(x) \<longrightarrow> (\<forall>x. Q(x))) \<and>
   207         ((\<forall>x. Q(x)|R(x)) --> (\<exists>x. Q(x)&S(x))) &
   207         ((\<forall>x. Q(x)\<or>R(x)) \<longrightarrow> (\<exists>x. Q(x)\<and>S(x))) \<and>
   208         ((\<exists>x. S(x)) --> (\<forall>x. L(x) --> M(x)))
   208         ((\<exists>x. S(x)) \<longrightarrow> (\<forall>x. L(x) \<longrightarrow> M(x)))
   209     --> (\<forall>x. P(x) & L(x) --> M(x))"
   209     \<longrightarrow> (\<forall>x. P(x) \<and> L(x) \<longrightarrow> M(x))"
   210 by blast
   210 by blast
   211 
   211 
   212 text\<open>Problem 29.  Essentially the same as Principia Mathematica *11.71\<close>
   212 text\<open>Problem 29.  Essentially the same as Principia Mathematica *11.71\<close>
   213 lemma "(\<exists>x. F(x)) & (\<exists>y. G(y))
   213 lemma "(\<exists>x. F(x)) \<and> (\<exists>y. G(y))
   214     --> ( ((\<forall>x. F(x)-->H(x)) & (\<forall>y. G(y)-->J(y)))  =
   214     \<longrightarrow> ( ((\<forall>x. F(x)\<longrightarrow>H(x)) \<and> (\<forall>y. G(y)\<longrightarrow>J(y)))  =
   215           (\<forall>x y. F(x) & G(y) --> H(x) & J(y)))"
   215           (\<forall>x y. F(x) \<and> G(y) \<longrightarrow> H(x) \<and> J(y)))"
   216 by blast
   216 by blast
   217 
   217 
   218 text\<open>Problem 30\<close>
   218 text\<open>Problem 30\<close>
   219 lemma "(\<forall>x. P(x) | Q(x) --> ~ R(x)) &
   219 lemma "(\<forall>x. P(x) \<or> Q(x) \<longrightarrow> \<not> R(x)) \<and>
   220         (\<forall>x. (Q(x) --> ~ S(x)) --> P(x) & R(x))
   220         (\<forall>x. (Q(x) \<longrightarrow> \<not> S(x)) \<longrightarrow> P(x) \<and> R(x))
   221     --> (\<forall>x. S(x))"
   221     \<longrightarrow> (\<forall>x. S(x))"
   222 by blast
   222 by blast
   223 
   223 
   224 text\<open>Problem 31\<close>
   224 text\<open>Problem 31\<close>
   225 lemma "~(\<exists>x. P(x) & (Q(x) | R(x))) &
   225 lemma "\<not>(\<exists>x. P(x) \<and> (Q(x) \<or> R(x))) \<and>
   226         (\<exists>x. L(x) & P(x)) &
   226         (\<exists>x. L(x) \<and> P(x)) \<and>
   227         (\<forall>x. ~ R(x) --> M(x))
   227         (\<forall>x. \<not> R(x) \<longrightarrow> M(x))
   228     --> (\<exists>x. L(x) & M(x))"
   228     \<longrightarrow> (\<exists>x. L(x) \<and> M(x))"
   229 by blast
   229 by blast
   230 
   230 
   231 text\<open>Problem 32\<close>
   231 text\<open>Problem 32\<close>
   232 lemma "(\<forall>x. P(x) & (Q(x)|R(x))-->S(x)) &
   232 lemma "(\<forall>x. P(x) \<and> (Q(x)\<or>R(x))\<longrightarrow>S(x)) \<and>
   233         (\<forall>x. S(x) & R(x) --> L(x)) &
   233         (\<forall>x. S(x) \<and> R(x) \<longrightarrow> L(x)) \<and>
   234         (\<forall>x. M(x) --> R(x))
   234         (\<forall>x. M(x) \<longrightarrow> R(x))
   235     --> (\<forall>x. P(x) & M(x) --> L(x))"
   235     \<longrightarrow> (\<forall>x. P(x) \<and> M(x) \<longrightarrow> L(x))"
   236 by blast
   236 by blast
   237 
   237 
   238 text\<open>Problem 33\<close>
   238 text\<open>Problem 33\<close>
   239 lemma "(\<forall>x. P(a) & (P(x)-->P(b))-->P(c))  =
   239 lemma "(\<forall>x. P(a) \<and> (P(x)\<longrightarrow>P(b))\<longrightarrow>P(c))  =
   240      (\<forall>x. (~P(a) | P(x) | P(c)) & (~P(a) | ~P(b) | P(c)))"
   240      (\<forall>x. (\<not>P(a) \<or> P(x) \<or> P(c)) \<and> (\<not>P(a) \<or> \<not>P(b) \<or> P(c)))"
   241 by blast
   241 by blast
   242 
   242 
   243 text\<open>Problem 34  AMENDED (TWICE!!)\<close>
   243 text\<open>Problem 34  AMENDED (TWICE!!)\<close>
   244 text\<open>Andrews's challenge\<close>
   244 text\<open>Andrews's challenge\<close>
   245 lemma "((\<exists>x. \<forall>y. p(x) = p(y))  =
   245 lemma "((\<exists>x. \<forall>y. p(x) = p(y))  =
   247               ((\<exists>x. \<forall>y. q(x) = q(y))  =
   247               ((\<exists>x. \<forall>y. q(x) = q(y))  =
   248                ((\<exists>x. p(x)) = (\<forall>y. q(y))))"
   248                ((\<exists>x. p(x)) = (\<forall>y. q(y))))"
   249 by blast
   249 by blast
   250 
   250 
   251 text\<open>Problem 35\<close>
   251 text\<open>Problem 35\<close>
   252 lemma "\<exists>x y. P x y -->  (\<forall>u v. P u v)"
   252 lemma "\<exists>x y. P x y \<longrightarrow>  (\<forall>u v. P u v)"
   253 by blast
   253 by blast
   254 
   254 
   255 text\<open>Problem 36\<close>
   255 text\<open>Problem 36\<close>
   256 lemma "(\<forall>x. \<exists>y. J x y) &
   256 lemma "(\<forall>x. \<exists>y. J x y) \<and>
   257         (\<forall>x. \<exists>y. G x y) &
   257         (\<forall>x. \<exists>y. G x y) \<and>
   258         (\<forall>x y. J x y | G x y -->
   258         (\<forall>x y. J x y \<or> G x y \<longrightarrow>
   259         (\<forall>z. J y z | G y z --> H x z))
   259         (\<forall>z. J y z \<or> G y z \<longrightarrow> H x z))
   260     --> (\<forall>x. \<exists>y. H x y)"
   260     \<longrightarrow> (\<forall>x. \<exists>y. H x y)"
   261 by blast
   261 by blast
   262 
   262 
   263 text\<open>Problem 37\<close>
   263 text\<open>Problem 37\<close>
   264 lemma "(\<forall>z. \<exists>w. \<forall>x. \<exists>y.
   264 lemma "(\<forall>z. \<exists>w. \<forall>x. \<exists>y.
   265            (P x z -->P y w) & P y z & (P y w --> (\<exists>u. Q u w))) &
   265            (P x z \<longrightarrow>P y w) \<and> P y z \<and> (P y w \<longrightarrow> (\<exists>u. Q u w))) \<and>
   266         (\<forall>x z. ~(P x z) --> (\<exists>y. Q y z)) &
   266         (\<forall>x z. \<not>(P x z) \<longrightarrow> (\<exists>y. Q y z)) \<and>
   267         ((\<exists>x y. Q x y) --> (\<forall>x. R x x))
   267         ((\<exists>x y. Q x y) \<longrightarrow> (\<forall>x. R x x))
   268     --> (\<forall>x. \<exists>y. R x y)"
   268     \<longrightarrow> (\<forall>x. \<exists>y. R x y)"
   269 by blast
   269 by blast
   270 
   270 
   271 text\<open>Problem 38\<close>
   271 text\<open>Problem 38\<close>
   272 lemma "(\<forall>x. p(a) & (p(x) --> (\<exists>y. p(y) & r x y)) -->
   272 lemma "(\<forall>x. p(a) \<and> (p(x) \<longrightarrow> (\<exists>y. p(y) \<and> r x y)) \<longrightarrow>
   273            (\<exists>z. \<exists>w. p(z) & r x w & r w z))  =
   273            (\<exists>z. \<exists>w. p(z) \<and> r x w \<and> r w z))  =
   274      (\<forall>x. (~p(a) | p(x) | (\<exists>z. \<exists>w. p(z) & r x w & r w z)) &
   274      (\<forall>x. (\<not>p(a) \<or> p(x) \<or> (\<exists>z. \<exists>w. p(z) \<and> r x w \<and> r w z)) \<and>
   275            (~p(a) | ~(\<exists>y. p(y) & r x y) |
   275            (\<not>p(a) \<or> \<not>(\<exists>y. p(y) \<and> r x y) \<or>
   276             (\<exists>z. \<exists>w. p(z) & r x w & r w z)))"
   276             (\<exists>z. \<exists>w. p(z) \<and> r x w \<and> r w z)))"
   277 by blast (*beats fast!*)
   277 by blast (*beats fast!*)
   278 
   278 
   279 text\<open>Problem 39\<close>
   279 text\<open>Problem 39\<close>
   280 lemma "~ (\<exists>x. \<forall>y. F y x = (~ F y y))"
   280 lemma "\<not> (\<exists>x. \<forall>y. F y x = (\<not> F y y))"
   281 by blast
   281 by blast
   282 
   282 
   283 text\<open>Problem 40.  AMENDED\<close>
   283 text\<open>Problem 40.  AMENDED\<close>
   284 lemma "(\<exists>y. \<forall>x. F x y = F x x)
   284 lemma "(\<exists>y. \<forall>x. F x y = F x x)
   285         -->  ~ (\<forall>x. \<exists>y. \<forall>z. F z y = (~ F z x))"
   285         \<longrightarrow>  \<not> (\<forall>x. \<exists>y. \<forall>z. F z y = (\<not> F z x))"
   286 by blast
   286 by blast
   287 
   287 
   288 text\<open>Problem 41\<close>
   288 text\<open>Problem 41\<close>
   289 lemma "(\<forall>z. \<exists>y. \<forall>x. f x y = (f x z & ~ f x x))
   289 lemma "(\<forall>z. \<exists>y. \<forall>x. f x y = (f x z \<and> \<not> f x x))
   290                --> ~ (\<exists>z. \<forall>x. f x z)"
   290                \<longrightarrow> \<not> (\<exists>z. \<forall>x. f x z)"
   291 by blast
   291 by blast
   292 
   292 
   293 text\<open>Problem 42\<close>
   293 text\<open>Problem 42\<close>
   294 lemma "~ (\<exists>y. \<forall>x. p x y = (~ (\<exists>z. p x z & p z x)))"
   294 lemma "\<not> (\<exists>y. \<forall>x. p x y = (\<not> (\<exists>z. p x z \<and> p z x)))"
   295 by blast
   295 by blast
   296 
   296 
   297 text\<open>Problem 43!!\<close>
   297 text\<open>Problem 43!!\<close>
   298 lemma "(\<forall>x::'a. \<forall>y::'a. q x y = (\<forall>z. p z x = (p z y::bool)))
   298 lemma "(\<forall>x::'a. \<forall>y::'a. q x y = (\<forall>z. p z x \<longleftrightarrow> (p z y)))
   299   --> (\<forall>x. (\<forall>y. q x y = (q y x::bool)))"
   299   \<longrightarrow> (\<forall>x. (\<forall>y. q x y \<longleftrightarrow> (q y x)))"
   300 by blast
   300 by blast
   301 
   301 
   302 text\<open>Problem 44\<close>
   302 text\<open>Problem 44\<close>
   303 lemma "(\<forall>x. f(x) -->
   303 lemma "(\<forall>x. f(x) \<longrightarrow>
   304               (\<exists>y. g(y) & h x y & (\<exists>y. g(y) & ~ h x y)))  &
   304               (\<exists>y. g(y) \<and> h x y \<and> (\<exists>y. g(y) \<and> \<not> h x y)))  \<and>
   305               (\<exists>x. j(x) & (\<forall>y. g(y) --> h x y))
   305               (\<exists>x. j(x) \<and> (\<forall>y. g(y) \<longrightarrow> h x y))
   306               --> (\<exists>x. j(x) & ~f(x))"
   306               \<longrightarrow> (\<exists>x. j(x) \<and> \<not>f(x))"
   307 by blast
   307 by blast
   308 
   308 
   309 text\<open>Problem 45\<close>
   309 text\<open>Problem 45\<close>
   310 lemma "(\<forall>x. f(x) & (\<forall>y. g(y) & h x y --> j x y)
   310 lemma "(\<forall>x. f(x) \<and> (\<forall>y. g(y) \<and> h x y \<longrightarrow> j x y)
   311                       --> (\<forall>y. g(y) & h x y --> k(y))) &
   311                       \<longrightarrow> (\<forall>y. g(y) \<and> h x y \<longrightarrow> k(y))) \<and>
   312      ~ (\<exists>y. l(y) & k(y)) &
   312      \<not> (\<exists>y. l(y) \<and> k(y)) \<and>
   313      (\<exists>x. f(x) & (\<forall>y. h x y --> l(y))
   313      (\<exists>x. f(x) \<and> (\<forall>y. h x y \<longrightarrow> l(y))
   314                 & (\<forall>y. g(y) & h x y --> j x y))
   314                 \<and> (\<forall>y. g(y) \<and> h x y \<longrightarrow> j x y))
   315       --> (\<exists>x. f(x) & ~ (\<exists>y. g(y) & h x y))"
   315       \<longrightarrow> (\<exists>x. f(x) \<and> \<not> (\<exists>y. g(y) \<and> h x y))"
   316 by blast
   316 by blast
   317 
   317 
   318 
   318 
   319 subsubsection\<open>Problems (mainly) involving equality or functions\<close>
   319 subsubsection\<open>Problems (mainly) involving equality or functions\<close>
   320 
   320 
   321 text\<open>Problem 48\<close>
   321 text\<open>Problem 48\<close>
   322 lemma "(a=b | c=d) & (a=c | b=d) --> a=d | b=c"
   322 lemma "(a=b \<or> c=d) \<and> (a=c \<or> b=d) \<longrightarrow> a=d \<or> b=c"
   323 by blast
   323 by blast
   324 
   324 
   325 text\<open>Problem 49  NOT PROVED AUTOMATICALLY.
   325 text\<open>Problem 49  NOT PROVED AUTOMATICALLY.
   326      Hard because it involves substitution for Vars
   326      Hard because it involves substitution for Vars
   327   the type constraint ensures that x,y,z have the same type as a,b,u.\<close>
   327   the type constraint ensures that x,y,z have the same type as a,b,u.\<close>
   328 lemma "(\<exists>x y::'a. \<forall>z. z=x | z=y) & P(a) & P(b) & (~a=b)
   328 lemma "(\<exists>x y::'a. \<forall>z. z=x \<or> z=y) \<and> P(a) \<and> P(b) \<and> (\<not>a=b)
   329                 --> (\<forall>u::'a. P(u))"
   329                 \<longrightarrow> (\<forall>u::'a. P(u))"
   330 by metis
   330 by metis
   331 
   331 
   332 text\<open>Problem 50.  (What has this to do with equality?)\<close>
   332 text\<open>Problem 50.  (What has this to do with equality?)\<close>
   333 lemma "(\<forall>x. P a x | (\<forall>y. P x y)) --> (\<exists>x. \<forall>y. P x y)"
   333 lemma "(\<forall>x. P a x \<or> (\<forall>y. P x y)) \<longrightarrow> (\<exists>x. \<forall>y. P x y)"
   334 by blast
   334 by blast
   335 
   335 
   336 text\<open>Problem 51\<close>
   336 text\<open>Problem 51\<close>
   337 lemma "(\<exists>z w. \<forall>x y. P x y = (x=z & y=w)) -->
   337 lemma "(\<exists>z w. \<forall>x y. P x y = (x=z \<and> y=w)) \<longrightarrow>
   338      (\<exists>z. \<forall>x. \<exists>w. (\<forall>y. P x y = (y=w)) = (x=z))"
   338      (\<exists>z. \<forall>x. \<exists>w. (\<forall>y. P x y = (y=w)) = (x=z))"
   339 by blast
   339 by blast
   340 
   340 
   341 text\<open>Problem 52. Almost the same as 51.\<close>
   341 text\<open>Problem 52. Almost the same as 51.\<close>
   342 lemma "(\<exists>z w. \<forall>x y. P x y = (x=z & y=w)) -->
   342 lemma "(\<exists>z w. \<forall>x y. P x y = (x=z \<and> y=w)) \<longrightarrow>
   343      (\<exists>w. \<forall>y. \<exists>z. (\<forall>x. P x y = (x=z)) = (y=w))"
   343      (\<exists>w. \<forall>y. \<exists>z. (\<forall>x. P x y = (x=z)) = (y=w))"
   344 by blast
   344 by blast
   345 
   345 
   346 text\<open>Problem 55\<close>
   346 text\<open>Problem 55\<close>
   347 
   347 
   348 text\<open>Non-equational version, from Manthey and Bry, CADE-9 (Springer, 1988).
   348 text\<open>Non-equational version, from Manthey and Bry, CADE-9 (Springer, 1988).
   349   fast DISCOVERS who killed Agatha.\<close>
   349   fast DISCOVERS who killed Agatha.\<close>
   350 schematic_goal "lives(agatha) & lives(butler) & lives(charles) &
   350 schematic_goal "lives(agatha) \<and> lives(butler) \<and> lives(charles) \<and>
   351    (killed agatha agatha | killed butler agatha | killed charles agatha) &
   351    (killed agatha agatha \<or> killed butler agatha \<or> killed charles agatha) \<and>
   352    (\<forall>x y. killed x y --> hates x y & ~richer x y) &
   352    (\<forall>x y. killed x y \<longrightarrow> hates x y \<and> \<not>richer x y) \<and>
   353    (\<forall>x. hates agatha x --> ~hates charles x) &
   353    (\<forall>x. hates agatha x \<longrightarrow> \<not>hates charles x) \<and>
   354    (hates agatha agatha & hates agatha charles) &
   354    (hates agatha agatha \<and> hates agatha charles) \<and>
   355    (\<forall>x. lives(x) & ~richer x agatha --> hates butler x) &
   355    (\<forall>x. lives(x) \<and> \<not>richer x agatha \<longrightarrow> hates butler x) \<and>
   356    (\<forall>x. hates agatha x --> hates butler x) &
   356    (\<forall>x. hates agatha x \<longrightarrow> hates butler x) \<and>
   357    (\<forall>x. ~hates x agatha | ~hates x butler | ~hates x charles) -->
   357    (\<forall>x. \<not>hates x agatha \<or> \<not>hates x butler \<or> \<not>hates x charles) \<longrightarrow>
   358     killed ?who agatha"
   358     killed ?who agatha"
   359 by fast
   359 by fast
   360 
   360 
   361 text\<open>Problem 56\<close>
   361 text\<open>Problem 56\<close>
   362 lemma "(\<forall>x. (\<exists>y. P(y) & x=f(y)) --> P(x)) = (\<forall>x. P(x) --> P(f(x)))"
   362 lemma "(\<forall>x. (\<exists>y. P(y) \<and> x=f(y)) \<longrightarrow> P(x)) = (\<forall>x. P(x) \<longrightarrow> P(f(x)))"
   363 by blast
   363 by blast
   364 
   364 
   365 text\<open>Problem 57\<close>
   365 text\<open>Problem 57\<close>
   366 lemma "P (f a b) (f b c) & P (f b c) (f a c) &
   366 lemma "P (f a b) (f b c) \<and> P (f b c) (f a c) \<and>
   367      (\<forall>x y z. P x y & P y z --> P x z)    -->   P (f a b) (f a c)"
   367      (\<forall>x y z. P x y \<and> P y z \<longrightarrow> P x z)    \<longrightarrow>   P (f a b) (f a c)"
   368 by blast
   368 by blast
   369 
   369 
   370 text\<open>Problem 58  NOT PROVED AUTOMATICALLY\<close>
   370 text\<open>Problem 58  NOT PROVED AUTOMATICALLY\<close>
   371 lemma "(\<forall>x y. f(x)=g(y)) --> (\<forall>x y. f(f(x))=f(g(y)))"
   371 lemma "(\<forall>x y. f(x)=g(y)) \<longrightarrow> (\<forall>x y. f(f(x))=f(g(y)))"
   372 by (fast intro: arg_cong [of concl: f])
   372 by (fast intro: arg_cong [of concl: f])
   373 
   373 
   374 text\<open>Problem 59\<close>
   374 text\<open>Problem 59\<close>
   375 lemma "(\<forall>x. P(x) = (~P(f(x)))) --> (\<exists>x. P(x) & ~P(f(x)))"
   375 lemma "(\<forall>x. P(x) = (\<not>P(f(x)))) \<longrightarrow> (\<exists>x. P(x) \<and> \<not>P(f(x)))"
   376 by blast
   376 by blast
   377 
   377 
   378 text\<open>Problem 60\<close>
   378 text\<open>Problem 60\<close>
   379 lemma "\<forall>x. P x (f x) = (\<exists>y. (\<forall>z. P z y --> P z (f x)) & P x y)"
   379 lemma "\<forall>x. P x (f x) = (\<exists>y. (\<forall>z. P z y \<longrightarrow> P z (f x)) \<and> P x y)"
   380 by blast
   380 by blast
   381 
   381 
   382 text\<open>Problem 62 as corrected in JAR 18 (1997), page 135\<close>
   382 text\<open>Problem 62 as corrected in JAR 18 (1997), page 135\<close>
   383 lemma "(\<forall>x. p a & (p x --> p(f x)) --> p(f(f x)))  =
   383 lemma "(\<forall>x. p a \<and> (p x \<longrightarrow> p(f x)) \<longrightarrow> p(f(f x)))  =
   384       (\<forall>x. (~ p a | p x | p(f(f x))) &
   384       (\<forall>x. (\<not> p a \<or> p x \<or> p(f(f x))) \<and>
   385               (~ p a | ~ p(f x) | p(f(f x))))"
   385               (\<not> p a \<or> \<not> p(f x) \<or> p(f(f x))))"
   386 by blast
   386 by blast
   387 
   387 
   388 text\<open>From Davis, Obvious Logical Inferences, IJCAI-81, 530-531
   388 text\<open>From Davis, Obvious Logical Inferences, IJCAI-81, 530-531
   389   fast indeed copes!\<close>
   389   fast indeed copes!\<close>
   390 lemma "(\<forall>x. F(x) & ~G(x) --> (\<exists>y. H(x,y) & J(y))) &
   390 lemma "(\<forall>x. F(x) \<and> \<not>G(x) \<longrightarrow> (\<exists>y. H(x,y) \<and> J(y))) \<and>
   391        (\<exists>x. K(x) & F(x) & (\<forall>y. H(x,y) --> K(y))) &
   391        (\<exists>x. K(x) \<and> F(x) \<and> (\<forall>y. H(x,y) \<longrightarrow> K(y))) \<and>
   392        (\<forall>x. K(x) --> ~G(x))  -->  (\<exists>x. K(x) & J(x))"
   392        (\<forall>x. K(x) \<longrightarrow> \<not>G(x))  \<longrightarrow>  (\<exists>x. K(x) \<and> J(x))"
   393 by fast
   393 by fast
   394 
   394 
   395 text\<open>From Rudnicki, Obvious Inferences, JAR 3 (1987), 383-393.
   395 text\<open>From Rudnicki, Obvious Inferences, JAR 3 (1987), 383-393.
   396   It does seem obvious!\<close>
   396   It does seem obvious!\<close>
   397 lemma "(\<forall>x. F(x) & ~G(x) --> (\<exists>y. H(x,y) & J(y))) &
   397 lemma "(\<forall>x. F(x) \<and> \<not>G(x) \<longrightarrow> (\<exists>y. H(x,y) \<and> J(y))) \<and>
   398        (\<exists>x. K(x) & F(x) & (\<forall>y. H(x,y) --> K(y)))  &
   398        (\<exists>x. K(x) \<and> F(x) \<and> (\<forall>y. H(x,y) \<longrightarrow> K(y)))  \<and>
   399        (\<forall>x. K(x) --> ~G(x))   -->   (\<exists>x. K(x) --> ~G(x))"
   399        (\<forall>x. K(x) \<longrightarrow> \<not>G(x))   \<longrightarrow>   (\<exists>x. K(x) \<longrightarrow> \<not>G(x))"
   400 by fast
   400 by fast
   401 
   401 
   402 text\<open>Attributed to Lewis Carroll by S. G. Pulman.  The first or last
   402 text\<open>Attributed to Lewis Carroll by S. G. Pulman.  The first or last
   403 assumption can be deleted.\<close>
   403 assumption can be deleted.\<close>
   404 lemma "(\<forall>x. honest(x) & industrious(x) --> healthy(x)) &
   404 lemma "(\<forall>x. honest(x) \<and> industrious(x) \<longrightarrow> healthy(x)) \<and>
   405       ~ (\<exists>x. grocer(x) & healthy(x)) &
   405       \<not> (\<exists>x. grocer(x) \<and> healthy(x)) \<and>
   406       (\<forall>x. industrious(x) & grocer(x) --> honest(x)) &
   406       (\<forall>x. industrious(x) \<and> grocer(x) \<longrightarrow> honest(x)) \<and>
   407       (\<forall>x. cyclist(x) --> industrious(x)) &
   407       (\<forall>x. cyclist(x) \<longrightarrow> industrious(x)) \<and>
   408       (\<forall>x. ~healthy(x) & cyclist(x) --> ~honest(x))
   408       (\<forall>x. \<not>healthy(x) \<and> cyclist(x) \<longrightarrow> \<not>honest(x))
   409       --> (\<forall>x. grocer(x) --> ~cyclist(x))"
   409       \<longrightarrow> (\<forall>x. grocer(x) \<longrightarrow> \<not>cyclist(x))"
   410 by blast
   410 by blast
   411 
   411 
   412 lemma "(\<forall>x y. R(x,y) | R(y,x)) &
   412 lemma "(\<forall>x y. R(x,y) \<or> R(y,x)) \<and>
   413        (\<forall>x y. S(x,y) & S(y,x) --> x=y) &
   413        (\<forall>x y. S(x,y) \<and> S(y,x) \<longrightarrow> x=y) \<and>
   414        (\<forall>x y. R(x,y) --> S(x,y))    -->   (\<forall>x y. S(x,y) --> R(x,y))"
   414        (\<forall>x y. R(x,y) \<longrightarrow> S(x,y))    \<longrightarrow>   (\<forall>x y. S(x,y) \<longrightarrow> R(x,y))"
   415 by blast
   415 by blast
   416 
   416 
   417 
   417 
   418 subsection\<open>Model Elimination Prover\<close>
   418 subsection\<open>Model Elimination Prover\<close>
   419 
   419 
   420 
   420 
   421 text\<open>Trying out meson with arguments\<close>
   421 text\<open>Trying out meson with arguments\<close>
   422 lemma "x < y & y < z --> ~ (z < (x::nat))"
   422 lemma "x < y \<and> y < z \<longrightarrow> \<not> (z < (x::nat))"
   423 by (meson order_less_irrefl order_less_trans)
   423 by (meson order_less_irrefl order_less_trans)
   424 
   424 
   425 text\<open>The "small example" from Bezem, Hendriks and de Nivelle,
   425 text\<open>The "small example" from Bezem, Hendriks and de Nivelle,
   426 Automatic Proof Construction in Type Theory Using Resolution,
   426 Automatic Proof Construction in Type Theory Using Resolution,
   427 JAR 29: 3-4 (2002), pages 253-275\<close>
   427 JAR 29: 3-4 (2002), pages 253-275\<close>
   428 lemma "(\<forall>x y z. R(x,y) & R(y,z) --> R(x,z)) &
   428 lemma "(\<forall>x y z. R(x,y) \<and> R(y,z) \<longrightarrow> R(x,z)) \<and>
   429        (\<forall>x. \<exists>y. R(x,y)) -->
   429        (\<forall>x. \<exists>y. R(x,y)) \<longrightarrow>
   430        ~ (\<forall>x. P x = (\<forall>y. R(x,y) --> ~ P y))"
   430        \<not> (\<forall>x. P x = (\<forall>y. R(x,y) \<longrightarrow> \<not> P y))"
   431 by (tactic\<open>Meson.safe_best_meson_tac @{context} 1\<close>)
   431 by (tactic\<open>Meson.safe_best_meson_tac @{context} 1\<close>)
   432     \<comment> \<open>In contrast, \<open>meson\<close> is SLOW: 7.6s on griffon\<close>
   432     \<comment> \<open>In contrast, \<open>meson\<close> is SLOW: 7.6s on griffon\<close>
   433 
   433 
   434 
   434 
   435 subsubsection\<open>Pelletier's examples\<close>
   435 subsubsection\<open>Pelletier's examples\<close>
   436 text\<open>1\<close>
   436 text\<open>1\<close>
   437 lemma "(P --> Q)  =  (~Q --> ~P)"
   437 lemma "(P \<longrightarrow> Q)  =  (\<not>Q \<longrightarrow> \<not>P)"
   438 by blast
   438 by blast
   439 
   439 
   440 text\<open>2\<close>
   440 text\<open>2\<close>
   441 lemma "(~ ~ P) =  P"
   441 lemma "(\<not> \<not> P) =  P"
   442 by blast
   442 by blast
   443 
   443 
   444 text\<open>3\<close>
   444 text\<open>3\<close>
   445 lemma "~(P-->Q) --> (Q-->P)"
   445 lemma "\<not>(P\<longrightarrow>Q) \<longrightarrow> (Q\<longrightarrow>P)"
   446 by blast
   446 by blast
   447 
   447 
   448 text\<open>4\<close>
   448 text\<open>4\<close>
   449 lemma "(~P-->Q)  =  (~Q --> P)"
   449 lemma "(\<not>P\<longrightarrow>Q)  =  (\<not>Q \<longrightarrow> P)"
   450 by blast
   450 by blast
   451 
   451 
   452 text\<open>5\<close>
   452 text\<open>5\<close>
   453 lemma "((P|Q)-->(P|R)) --> (P|(Q-->R))"
   453 lemma "((P\<or>Q)\<longrightarrow>(P\<or>R)) \<longrightarrow> (P\<or>(Q\<longrightarrow>R))"
   454 by blast
   454 by blast
   455 
   455 
   456 text\<open>6\<close>
   456 text\<open>6\<close>
   457 lemma "P | ~ P"
   457 lemma "P \<or> \<not> P"
   458 by blast
   458 by blast
   459 
   459 
   460 text\<open>7\<close>
   460 text\<open>7\<close>
   461 lemma "P | ~ ~ ~ P"
   461 lemma "P \<or> \<not> \<not> \<not> P"
   462 by blast
   462 by blast
   463 
   463 
   464 text\<open>8.  Peirce's law\<close>
   464 text\<open>8.  Peirce's law\<close>
   465 lemma "((P-->Q) --> P)  -->  P"
   465 lemma "((P\<longrightarrow>Q) \<longrightarrow> P)  \<longrightarrow>  P"
   466 by blast
   466 by blast
   467 
   467 
   468 text\<open>9\<close>
   468 text\<open>9\<close>
   469 lemma "((P|Q) & (~P|Q) & (P| ~Q)) --> ~ (~P | ~Q)"
   469 lemma "((P\<or>Q) \<and> (\<not>P\<or>Q) \<and> (P\<or> \<not>Q)) \<longrightarrow> \<not> (\<not>P \<or> \<not>Q)"
   470 by blast
   470 by blast
   471 
   471 
   472 text\<open>10\<close>
   472 text\<open>10\<close>
   473 lemma "(Q-->R) & (R-->P&Q) & (P-->Q|R) --> (P=Q)"
   473 lemma "(Q\<longrightarrow>R) \<and> (R\<longrightarrow>P\<and>Q) \<and> (P\<longrightarrow>Q\<or>R) \<longrightarrow> (P=Q)"
   474 by blast
   474 by blast
   475 
   475 
   476 text\<open>11.  Proved in each direction (incorrectly, says Pelletier!!)\<close>
   476 text\<open>11.  Proved in each direction (incorrectly, says Pelletier!!)\<close>
   477 lemma "P=(P::bool)"
   477 lemma "P=(P::bool)"
   478 by blast
   478 by blast
   480 text\<open>12.  "Dijkstra's law"\<close>
   480 text\<open>12.  "Dijkstra's law"\<close>
   481 lemma "((P = Q) = R) = (P = (Q = R))"
   481 lemma "((P = Q) = R) = (P = (Q = R))"
   482 by blast
   482 by blast
   483 
   483 
   484 text\<open>13.  Distributive law\<close>
   484 text\<open>13.  Distributive law\<close>
   485 lemma "(P | (Q & R)) = ((P | Q) & (P | R))"
   485 lemma "(P \<or> (Q \<and> R)) = ((P \<or> Q) \<and> (P \<or> R))"
   486 by blast
   486 by blast
   487 
   487 
   488 text\<open>14\<close>
   488 text\<open>14\<close>
   489 lemma "(P = Q) = ((Q | ~P) & (~Q|P))"
   489 lemma "(P = Q) = ((Q \<or> \<not>P) \<and> (\<not>Q\<or>P))"
   490 by blast
   490 by blast
   491 
   491 
   492 text\<open>15\<close>
   492 text\<open>15\<close>
   493 lemma "(P --> Q) = (~P | Q)"
   493 lemma "(P \<longrightarrow> Q) = (\<not>P \<or> Q)"
   494 by blast
   494 by blast
   495 
   495 
   496 text\<open>16\<close>
   496 text\<open>16\<close>
   497 lemma "(P-->Q) | (Q-->P)"
   497 lemma "(P\<longrightarrow>Q) \<or> (Q\<longrightarrow>P)"
   498 by blast
   498 by blast
   499 
   499 
   500 text\<open>17\<close>
   500 text\<open>17\<close>
   501 lemma "((P & (Q-->R))-->S)  =  ((~P | Q | S) & (~P | ~R | S))"
   501 lemma "((P \<and> (Q\<longrightarrow>R))\<longrightarrow>S)  =  ((\<not>P \<or> Q \<or> S) \<and> (\<not>P \<or> \<not>R \<or> S))"
   502 by blast
   502 by blast
   503 
   503 
   504 subsubsection\<open>Classical Logic: examples with quantifiers\<close>
   504 subsubsection\<open>Classical Logic: examples with quantifiers\<close>
   505 
   505 
   506 lemma "(\<forall>x. P x & Q x) = ((\<forall>x. P x) & (\<forall>x. Q x))"
   506 lemma "(\<forall>x. P x \<and> Q x) = ((\<forall>x. P x) \<and> (\<forall>x. Q x))"
   507 by blast
   507 by blast
   508 
   508 
   509 lemma "(\<exists>x. P --> Q x)  =  (P --> (\<exists>x. Q x))"
   509 lemma "(\<exists>x. P \<longrightarrow> Q x)  =  (P \<longrightarrow> (\<exists>x. Q x))"
   510 by blast
   510 by blast
   511 
   511 
   512 lemma "(\<exists>x. P x --> Q) = ((\<forall>x. P x) --> Q)"
   512 lemma "(\<exists>x. P x \<longrightarrow> Q) = ((\<forall>x. P x) \<longrightarrow> Q)"
   513 by blast
   513 by blast
   514 
   514 
   515 lemma "((\<forall>x. P x) | Q)  =  (\<forall>x. P x | Q)"
   515 lemma "((\<forall>x. P x) \<or> Q)  =  (\<forall>x. P x \<or> Q)"
   516 by blast
   516 by blast
   517 
   517 
   518 lemma "(\<forall>x. P x --> P(f x))  &  P d --> P(f(f(f d)))"
   518 lemma "(\<forall>x. P x \<longrightarrow> P(f x))  \<and>  P d \<longrightarrow> P(f(f(f d)))"
   519 by blast
   519 by blast
   520 
   520 
   521 text\<open>Needs double instantiation of EXISTS\<close>
   521 text\<open>Needs double instantiation of EXISTS\<close>
   522 lemma "\<exists>x. P x --> P a & P b"
   522 lemma "\<exists>x. P x \<longrightarrow> P a \<and> P b"
   523 by blast
   523 by blast
   524 
   524 
   525 lemma "\<exists>z. P z --> (\<forall>x. P x)"
   525 lemma "\<exists>z. P z \<longrightarrow> (\<forall>x. P x)"
   526 by blast
   526 by blast
   527 
   527 
   528 text\<open>From a paper by Claire Quigley\<close>
   528 text\<open>From a paper by Claire Quigley\<close>
   529 lemma "\<exists>y. ((P c & Q y) | (\<exists>z. ~ Q z)) | (\<exists>x. ~ P x & Q d)"
   529 lemma "\<exists>y. ((P c \<and> Q y) \<or> (\<exists>z. \<not> Q z)) \<or> (\<exists>x. \<not> P x \<and> Q d)"
   530 by fast
   530 by fast
   531 
   531 
   532 subsubsection\<open>Hard examples with quantifiers\<close>
   532 subsubsection\<open>Hard examples with quantifiers\<close>
   533 
   533 
   534 text\<open>Problem 18\<close>
   534 text\<open>Problem 18\<close>
   535 lemma "\<exists>y. \<forall>x. P y --> P x"
   535 lemma "\<exists>y. \<forall>x. P y \<longrightarrow> P x"
   536 by blast
   536 by blast
   537 
   537 
   538 text\<open>Problem 19\<close>
   538 text\<open>Problem 19\<close>
   539 lemma "\<exists>x. \<forall>y z. (P y --> Q z) --> (P x --> Q x)"
   539 lemma "\<exists>x. \<forall>y z. (P y \<longrightarrow> Q z) \<longrightarrow> (P x \<longrightarrow> Q x)"
   540 by blast
   540 by blast
   541 
   541 
   542 text\<open>Problem 20\<close>
   542 text\<open>Problem 20\<close>
   543 lemma "(\<forall>x y. \<exists>z. \<forall>w. (P x & Q y --> R z & S w))
   543 lemma "(\<forall>x y. \<exists>z. \<forall>w. (P x \<and> Q y \<longrightarrow> R z \<and> S w))
   544     --> (\<exists>x y. P x & Q y) --> (\<exists>z. R z)"
   544     \<longrightarrow> (\<exists>x y. P x \<and> Q y) \<longrightarrow> (\<exists>z. R z)"
   545 by blast
   545 by blast
   546 
   546 
   547 text\<open>Problem 21\<close>
   547 text\<open>Problem 21\<close>
   548 lemma "(\<exists>x. P --> Q x) & (\<exists>x. Q x --> P) --> (\<exists>x. P=Q x)"
   548 lemma "(\<exists>x. P \<longrightarrow> Q x) \<and> (\<exists>x. Q x \<longrightarrow> P) \<longrightarrow> (\<exists>x. P=Q x)"
   549 by blast
   549 by blast
   550 
   550 
   551 text\<open>Problem 22\<close>
   551 text\<open>Problem 22\<close>
   552 lemma "(\<forall>x. P = Q x)  -->  (P = (\<forall>x. Q x))"
   552 lemma "(\<forall>x. P = Q x)  \<longrightarrow>  (P = (\<forall>x. Q x))"
   553 by blast
   553 by blast
   554 
   554 
   555 text\<open>Problem 23\<close>
   555 text\<open>Problem 23\<close>
   556 lemma "(\<forall>x. P | Q x)  =  (P | (\<forall>x. Q x))"
   556 lemma "(\<forall>x. P \<or> Q x)  =  (P \<or> (\<forall>x. Q x))"
   557 by blast
   557 by blast
   558 
   558 
   559 text\<open>Problem 24\<close>  (*The first goal clause is useless*)
   559 text\<open>Problem 24\<close>  (*The first goal clause is useless*)
   560 lemma "~(\<exists>x. S x & Q x) & (\<forall>x. P x --> Q x | R x) &
   560 lemma "\<not>(\<exists>x. S x \<and> Q x) \<and> (\<forall>x. P x \<longrightarrow> Q x \<or> R x) \<and>
   561       (~(\<exists>x. P x) --> (\<exists>x. Q x)) & (\<forall>x. Q x | R x --> S x)
   561       (\<not>(\<exists>x. P x) \<longrightarrow> (\<exists>x. Q x)) \<and> (\<forall>x. Q x \<or> R x \<longrightarrow> S x)
   562     --> (\<exists>x. P x & R x)"
   562     \<longrightarrow> (\<exists>x. P x \<and> R x)"
   563 by blast
   563 by blast
   564 
   564 
   565 text\<open>Problem 25\<close>
   565 text\<open>Problem 25\<close>
   566 lemma "(\<exists>x. P x) &
   566 lemma "(\<exists>x. P x) \<and>
   567       (\<forall>x. L x --> ~ (M x & R x)) &
   567       (\<forall>x. L x \<longrightarrow> \<not> (M x \<and> R x)) \<and>
   568       (\<forall>x. P x --> (M x & L x)) &
   568       (\<forall>x. P x \<longrightarrow> (M x \<and> L x)) \<and>
   569       ((\<forall>x. P x --> Q x) | (\<exists>x. P x & R x))
   569       ((\<forall>x. P x \<longrightarrow> Q x) \<or> (\<exists>x. P x \<and> R x))
   570     --> (\<exists>x. Q x & P x)"
   570     \<longrightarrow> (\<exists>x. Q x \<and> P x)"
   571 by blast
   571 by blast
   572 
   572 
   573 text\<open>Problem 26; has 24 Horn clauses\<close>
   573 text\<open>Problem 26; has 24 Horn clauses\<close>
   574 lemma "((\<exists>x. p x) = (\<exists>x. q x)) &
   574 lemma "((\<exists>x. p x) = (\<exists>x. q x)) \<and>
   575       (\<forall>x. \<forall>y. p x & q y --> (r x = s y))
   575       (\<forall>x. \<forall>y. p x \<and> q y \<longrightarrow> (r x = s y))
   576   --> ((\<forall>x. p x --> r x) = (\<forall>x. q x --> s x))"
   576   \<longrightarrow> ((\<forall>x. p x \<longrightarrow> r x) = (\<forall>x. q x \<longrightarrow> s x))"
   577 by blast
   577 by blast
   578 
   578 
   579 text\<open>Problem 27; has 13 Horn clauses\<close>
   579 text\<open>Problem 27; has 13 Horn clauses\<close>
   580 lemma "(\<exists>x. P x & ~Q x) &
   580 lemma "(\<exists>x. P x \<and> \<not>Q x) \<and>
   581       (\<forall>x. P x --> R x) &
   581       (\<forall>x. P x \<longrightarrow> R x) \<and>
   582       (\<forall>x. M x & L x --> P x) &
   582       (\<forall>x. M x \<and> L x \<longrightarrow> P x) \<and>
   583       ((\<exists>x. R x & ~ Q x) --> (\<forall>x. L x --> ~ R x))
   583       ((\<exists>x. R x \<and> \<not> Q x) \<longrightarrow> (\<forall>x. L x \<longrightarrow> \<not> R x))
   584       --> (\<forall>x. M x --> ~L x)"
   584       \<longrightarrow> (\<forall>x. M x \<longrightarrow> \<not>L x)"
   585 by blast
   585 by blast
   586 
   586 
   587 text\<open>Problem 28.  AMENDED; has 14 Horn clauses\<close>
   587 text\<open>Problem 28.  AMENDED; has 14 Horn clauses\<close>
   588 lemma "(\<forall>x. P x --> (\<forall>x. Q x)) &
   588 lemma "(\<forall>x. P x \<longrightarrow> (\<forall>x. Q x)) \<and>
   589       ((\<forall>x. Q x | R x) --> (\<exists>x. Q x & S x)) &
   589       ((\<forall>x. Q x \<or> R x) \<longrightarrow> (\<exists>x. Q x \<and> S x)) \<and>
   590       ((\<exists>x. S x) --> (\<forall>x. L x --> M x))
   590       ((\<exists>x. S x) \<longrightarrow> (\<forall>x. L x \<longrightarrow> M x))
   591     --> (\<forall>x. P x & L x --> M x)"
   591     \<longrightarrow> (\<forall>x. P x \<and> L x \<longrightarrow> M x)"
   592 by blast
   592 by blast
   593 
   593 
   594 text\<open>Problem 29.  Essentially the same as Principia Mathematica *11.71.
   594 text\<open>Problem 29.  Essentially the same as Principia Mathematica *11.71.
   595       62 Horn clauses\<close>
   595       62 Horn clauses\<close>
   596 lemma "(\<exists>x. F x) & (\<exists>y. G y)
   596 lemma "(\<exists>x. F x) \<and> (\<exists>y. G y)
   597     --> ( ((\<forall>x. F x --> H x) & (\<forall>y. G y --> J y))  =
   597     \<longrightarrow> ( ((\<forall>x. F x \<longrightarrow> H x) \<and> (\<forall>y. G y \<longrightarrow> J y))  =
   598           (\<forall>x y. F x & G y --> H x & J y))"
   598           (\<forall>x y. F x \<and> G y \<longrightarrow> H x \<and> J y))"
   599 by blast
   599 by blast
   600 
   600 
   601 
   601 
   602 text\<open>Problem 30\<close>
   602 text\<open>Problem 30\<close>
   603 lemma "(\<forall>x. P x | Q x --> ~ R x) & (\<forall>x. (Q x --> ~ S x) --> P x & R x)
   603 lemma "(\<forall>x. P x \<or> Q x \<longrightarrow> \<not> R x) \<and> (\<forall>x. (Q x \<longrightarrow> \<not> S x) \<longrightarrow> P x \<and> R x)
   604        --> (\<forall>x. S x)"
   604        \<longrightarrow> (\<forall>x. S x)"
   605 by blast
   605 by blast
   606 
   606 
   607 text\<open>Problem 31; has 10 Horn clauses; first negative clauses is useless\<close>
   607 text\<open>Problem 31; has 10 Horn clauses; first negative clauses is useless\<close>
   608 lemma "~(\<exists>x. P x & (Q x | R x)) &
   608 lemma "\<not>(\<exists>x. P x \<and> (Q x \<or> R x)) \<and>
   609       (\<exists>x. L x & P x) &
   609       (\<exists>x. L x \<and> P x) \<and>
   610       (\<forall>x. ~ R x --> M x)
   610       (\<forall>x. \<not> R x \<longrightarrow> M x)
   611     --> (\<exists>x. L x & M x)"
   611     \<longrightarrow> (\<exists>x. L x \<and> M x)"
   612 by blast
   612 by blast
   613 
   613 
   614 text\<open>Problem 32\<close>
   614 text\<open>Problem 32\<close>
   615 lemma "(\<forall>x. P x & (Q x | R x)-->S x) &
   615 lemma "(\<forall>x. P x \<and> (Q x \<or> R x)\<longrightarrow>S x) \<and>
   616       (\<forall>x. S x & R x --> L x) &
   616       (\<forall>x. S x \<and> R x \<longrightarrow> L x) \<and>
   617       (\<forall>x. M x --> R x)
   617       (\<forall>x. M x \<longrightarrow> R x)
   618     --> (\<forall>x. P x & M x --> L x)"
   618     \<longrightarrow> (\<forall>x. P x \<and> M x \<longrightarrow> L x)"
   619 by blast
   619 by blast
   620 
   620 
   621 text\<open>Problem 33; has 55 Horn clauses\<close>
   621 text\<open>Problem 33; has 55 Horn clauses\<close>
   622 lemma "(\<forall>x. P a & (P x --> P b)-->P c)  =
   622 lemma "(\<forall>x. P a \<and> (P x \<longrightarrow> P b)\<longrightarrow>P c)  =
   623       (\<forall>x. (~P a | P x | P c) & (~P a | ~P b | P c))"
   623       (\<forall>x. (\<not>P a \<or> P x \<or> P c) \<and> (\<not>P a \<or> \<not>P b \<or> P c))"
   624 by blast
   624 by blast
   625 
   625 
   626 text\<open>Problem 34: Andrews's challenge has 924 Horn clauses\<close>
   626 text\<open>Problem 34: Andrews's challenge has 924 Horn clauses\<close>
   627 lemma "((\<exists>x. \<forall>y. p x = p y)  = ((\<exists>x. q x) = (\<forall>y. p y)))     =
   627 lemma "((\<exists>x. \<forall>y. p x = p y)  = ((\<exists>x. q x) = (\<forall>y. p y)))     =
   628       ((\<exists>x. \<forall>y. q x = q y)  = ((\<exists>x. p x) = (\<forall>y. q y)))"
   628       ((\<exists>x. \<forall>y. q x = q y)  = ((\<exists>x. p x) = (\<forall>y. q y)))"
   629 by blast
   629 by blast
   630 
   630 
   631 text\<open>Problem 35\<close>
   631 text\<open>Problem 35\<close>
   632 lemma "\<exists>x y. P x y -->  (\<forall>u v. P u v)"
   632 lemma "\<exists>x y. P x y \<longrightarrow>  (\<forall>u v. P u v)"
   633 by blast
   633 by blast
   634 
   634 
   635 text\<open>Problem 36; has 15 Horn clauses\<close>
   635 text\<open>Problem 36; has 15 Horn clauses\<close>
   636 lemma "(\<forall>x. \<exists>y. J x y) & (\<forall>x. \<exists>y. G x y) &
   636 lemma "(\<forall>x. \<exists>y. J x y) \<and> (\<forall>x. \<exists>y. G x y) \<and>
   637        (\<forall>x y. J x y | G x y --> (\<forall>z. J y z | G y z --> H x z))
   637        (\<forall>x y. J x y \<or> G x y \<longrightarrow> (\<forall>z. J y z \<or> G y z \<longrightarrow> H x z))
   638        --> (\<forall>x. \<exists>y. H x y)"
   638        \<longrightarrow> (\<forall>x. \<exists>y. H x y)"
   639 by blast
   639 by blast
   640 
   640 
   641 text\<open>Problem 37; has 10 Horn clauses\<close>
   641 text\<open>Problem 37; has 10 Horn clauses\<close>
   642 lemma "(\<forall>z. \<exists>w. \<forall>x. \<exists>y.
   642 lemma "(\<forall>z. \<exists>w. \<forall>x. \<exists>y.
   643            (P x z --> P y w) & P y z & (P y w --> (\<exists>u. Q u w))) &
   643            (P x z \<longrightarrow> P y w) \<and> P y z \<and> (P y w \<longrightarrow> (\<exists>u. Q u w))) \<and>
   644       (\<forall>x z. ~P x z --> (\<exists>y. Q y z)) &
   644       (\<forall>x z. \<not>P x z \<longrightarrow> (\<exists>y. Q y z)) \<and>
   645       ((\<exists>x y. Q x y) --> (\<forall>x. R x x))
   645       ((\<exists>x y. Q x y) \<longrightarrow> (\<forall>x. R x x))
   646     --> (\<forall>x. \<exists>y. R x y)"
   646     \<longrightarrow> (\<forall>x. \<exists>y. R x y)"
   647 by blast \<comment> \<open>causes unification tracing messages\<close>
   647 by blast \<comment> \<open>causes unification tracing messages\<close>
   648 
   648 
   649 
   649 
   650 text\<open>Problem 38\<close>  text\<open>Quite hard: 422 Horn clauses!!\<close>
   650 text\<open>Problem 38\<close>  text\<open>Quite hard: 422 Horn clauses!!\<close>
   651 lemma "(\<forall>x. p a & (p x --> (\<exists>y. p y & r x y)) -->
   651 lemma "(\<forall>x. p a \<and> (p x \<longrightarrow> (\<exists>y. p y \<and> r x y)) \<longrightarrow>
   652            (\<exists>z. \<exists>w. p z & r x w & r w z))  =
   652            (\<exists>z. \<exists>w. p z \<and> r x w \<and> r w z))  =
   653       (\<forall>x. (~p a | p x | (\<exists>z. \<exists>w. p z & r x w & r w z)) &
   653       (\<forall>x. (\<not>p a \<or> p x \<or> (\<exists>z. \<exists>w. p z \<and> r x w \<and> r w z)) \<and>
   654             (~p a | ~(\<exists>y. p y & r x y) |
   654             (\<not>p a \<or> \<not>(\<exists>y. p y \<and> r x y) \<or>
   655              (\<exists>z. \<exists>w. p z & r x w & r w z)))"
   655              (\<exists>z. \<exists>w. p z \<and> r x w \<and> r w z)))"
   656 by blast
   656 by blast
   657 
   657 
   658 text\<open>Problem 39\<close>
   658 text\<open>Problem 39\<close>
   659 lemma "~ (\<exists>x. \<forall>y. F y x = (~F y y))"
   659 lemma "\<not> (\<exists>x. \<forall>y. F y x = (\<not>F y y))"
   660 by blast
   660 by blast
   661 
   661 
   662 text\<open>Problem 40.  AMENDED\<close>
   662 text\<open>Problem 40.  AMENDED\<close>
   663 lemma "(\<exists>y. \<forall>x. F x y = F x x)
   663 lemma "(\<exists>y. \<forall>x. F x y = F x x)
   664       -->  ~ (\<forall>x. \<exists>y. \<forall>z. F z y = (~F z x))"
   664       \<longrightarrow>  \<not> (\<forall>x. \<exists>y. \<forall>z. F z y = (\<not>F z x))"
   665 by blast
   665 by blast
   666 
   666 
   667 text\<open>Problem 41\<close>
   667 text\<open>Problem 41\<close>
   668 lemma "(\<forall>z. (\<exists>y. (\<forall>x. f x y = (f x z & ~ f x x))))
   668 lemma "(\<forall>z. (\<exists>y. (\<forall>x. f x y = (f x z \<and> \<not> f x x))))
   669       --> ~ (\<exists>z. \<forall>x. f x z)"
   669       \<longrightarrow> \<not> (\<exists>z. \<forall>x. f x z)"
   670 by blast
   670 by blast
   671 
   671 
   672 text\<open>Problem 42\<close>
   672 text\<open>Problem 42\<close>
   673 lemma "~ (\<exists>y. \<forall>x. p x y = (~ (\<exists>z. p x z & p z x)))"
   673 lemma "\<not> (\<exists>y. \<forall>x. p x y = (\<not> (\<exists>z. p x z \<and> p z x)))"
   674 by blast
   674 by blast
   675 
   675 
   676 text\<open>Problem 43  NOW PROVED AUTOMATICALLY!!\<close>
   676 text\<open>Problem 43  NOW PROVED AUTOMATICALLY!!\<close>
   677 lemma "(\<forall>x. \<forall>y. q x y = (\<forall>z. p z x = (p z y::bool)))
   677 lemma "(\<forall>x. \<forall>y. q x y = (\<forall>z. p z x = (p z y::bool)))
   678       --> (\<forall>x. (\<forall>y. q x y = (q y x::bool)))"
   678       \<longrightarrow> (\<forall>x. (\<forall>y. q x y = (q y x::bool)))"
   679 by blast
   679 by blast
   680 
   680 
   681 text\<open>Problem 44: 13 Horn clauses; 7-step proof\<close>
   681 text\<open>Problem 44: 13 Horn clauses; 7-step proof\<close>
   682 lemma "(\<forall>x. f x --> (\<exists>y. g y & h x y & (\<exists>y. g y & ~ h x y)))  &
   682 lemma "(\<forall>x. f x \<longrightarrow> (\<exists>y. g y \<and> h x y \<and> (\<exists>y. g y \<and> \<not> h x y)))  \<and>
   683        (\<exists>x. j x & (\<forall>y. g y --> h x y))
   683        (\<exists>x. j x \<and> (\<forall>y. g y \<longrightarrow> h x y))
   684        --> (\<exists>x. j x & ~f x)"
   684        \<longrightarrow> (\<exists>x. j x \<and> \<not>f x)"
   685 by blast
   685 by blast
   686 
   686 
   687 text\<open>Problem 45; has 27 Horn clauses; 54-step proof\<close>
   687 text\<open>Problem 45; has 27 Horn clauses; 54-step proof\<close>
   688 lemma "(\<forall>x. f x & (\<forall>y. g y & h x y --> j x y)
   688 lemma "(\<forall>x. f x \<and> (\<forall>y. g y \<and> h x y \<longrightarrow> j x y)
   689             --> (\<forall>y. g y & h x y --> k y)) &
   689             \<longrightarrow> (\<forall>y. g y \<and> h x y \<longrightarrow> k y)) \<and>
   690       ~ (\<exists>y. l y & k y) &
   690       \<not> (\<exists>y. l y \<and> k y) \<and>
   691       (\<exists>x. f x & (\<forall>y. h x y --> l y)
   691       (\<exists>x. f x \<and> (\<forall>y. h x y \<longrightarrow> l y)
   692                 & (\<forall>y. g y & h x y --> j x y))
   692                 \<and> (\<forall>y. g y \<and> h x y \<longrightarrow> j x y))
   693       --> (\<exists>x. f x & ~ (\<exists>y. g y & h x y))"
   693       \<longrightarrow> (\<exists>x. f x \<and> \<not> (\<exists>y. g y \<and> h x y))"
   694 by blast
   694 by blast
   695 
   695 
   696 text\<open>Problem 46; has 26 Horn clauses; 21-step proof\<close>
   696 text\<open>Problem 46; has 26 Horn clauses; 21-step proof\<close>
   697 lemma "(\<forall>x. f x & (\<forall>y. f y & h y x --> g y) --> g x) &
   697 lemma "(\<forall>x. f x \<and> (\<forall>y. f y \<and> h y x \<longrightarrow> g y) \<longrightarrow> g x) \<and>
   698        ((\<exists>x. f x & ~g x) -->
   698        ((\<exists>x. f x \<and> \<not>g x) \<longrightarrow>
   699        (\<exists>x. f x & ~g x & (\<forall>y. f y & ~g y --> j x y))) &
   699        (\<exists>x. f x \<and> \<not>g x \<and> (\<forall>y. f y \<and> \<not>g y \<longrightarrow> j x y))) \<and>
   700        (\<forall>x y. f x & f y & h x y --> ~j y x)
   700        (\<forall>x y. f x \<and> f y \<and> h x y \<longrightarrow> \<not>j y x)
   701        --> (\<forall>x. f x --> g x)"
   701        \<longrightarrow> (\<forall>x. f x \<longrightarrow> g x)"
   702 by blast
   702 by blast
   703 
   703 
   704 text\<open>Problem 47.  Schubert's Steamroller.
   704 text\<open>Problem 47.  Schubert's Steamroller.
   705       26 clauses; 63 Horn clauses.
   705       26 clauses; 63 Horn clauses.
   706       87094 inferences so far.  Searching to depth 36\<close>
   706       87094 inferences so far.  Searching to depth 36\<close>
   707 lemma "(\<forall>x. wolf x \<longrightarrow> animal x) & (\<exists>x. wolf x) &
   707 lemma "(\<forall>x. wolf x \<longrightarrow> animal x) \<and> (\<exists>x. wolf x) \<and>
   708        (\<forall>x. fox x \<longrightarrow> animal x) & (\<exists>x. fox x) &
   708        (\<forall>x. fox x \<longrightarrow> animal x) \<and> (\<exists>x. fox x) \<and>
   709        (\<forall>x. bird x \<longrightarrow> animal x) & (\<exists>x. bird x) &
   709        (\<forall>x. bird x \<longrightarrow> animal x) \<and> (\<exists>x. bird x) \<and>
   710        (\<forall>x. caterpillar x \<longrightarrow> animal x) & (\<exists>x. caterpillar x) &
   710        (\<forall>x. caterpillar x \<longrightarrow> animal x) \<and> (\<exists>x. caterpillar x) \<and>
   711        (\<forall>x. snail x \<longrightarrow> animal x) & (\<exists>x. snail x) &
   711        (\<forall>x. snail x \<longrightarrow> animal x) \<and> (\<exists>x. snail x) \<and>
   712        (\<forall>x. grain x \<longrightarrow> plant x) & (\<exists>x. grain x) &
   712        (\<forall>x. grain x \<longrightarrow> plant x) \<and> (\<exists>x. grain x) \<and>
   713        (\<forall>x. animal x \<longrightarrow>
   713        (\<forall>x. animal x \<longrightarrow>
   714              ((\<forall>y. plant y \<longrightarrow> eats x y)  \<or> 
   714              ((\<forall>y. plant y \<longrightarrow> eats x y)  \<or> 
   715               (\<forall>y. animal y & smaller_than y x &
   715               (\<forall>y. animal y \<and> smaller_than y x \<and>
   716                     (\<exists>z. plant z & eats y z) \<longrightarrow> eats x y))) &
   716                     (\<exists>z. plant z \<and> eats y z) \<longrightarrow> eats x y))) \<and>
   717        (\<forall>x y. bird y & (snail x \<or> caterpillar x) \<longrightarrow> smaller_than x y) &
   717        (\<forall>x y. bird y \<and> (snail x \<or> caterpillar x) \<longrightarrow> smaller_than x y) \<and>
   718        (\<forall>x y. bird x & fox y \<longrightarrow> smaller_than x y) &
   718        (\<forall>x y. bird x \<and> fox y \<longrightarrow> smaller_than x y) \<and>
   719        (\<forall>x y. fox x & wolf y \<longrightarrow> smaller_than x y) &
   719        (\<forall>x y. fox x \<and> wolf y \<longrightarrow> smaller_than x y) \<and>
   720        (\<forall>x y. wolf x & (fox y \<or> grain y) \<longrightarrow> ~eats x y) &
   720        (\<forall>x y. wolf x \<and> (fox y \<or> grain y) \<longrightarrow> \<not>eats x y) \<and>
   721        (\<forall>x y. bird x & caterpillar y \<longrightarrow> eats x y) &
   721        (\<forall>x y. bird x \<and> caterpillar y \<longrightarrow> eats x y) \<and>
   722        (\<forall>x y. bird x & snail y \<longrightarrow> ~eats x y) &
   722        (\<forall>x y. bird x \<and> snail y \<longrightarrow> \<not>eats x y) \<and>
   723        (\<forall>x. (caterpillar x \<or> snail x) \<longrightarrow> (\<exists>y. plant y & eats x y))
   723        (\<forall>x. (caterpillar x \<or> snail x) \<longrightarrow> (\<exists>y. plant y \<and> eats x y))
   724        \<longrightarrow> (\<exists>x y. animal x & animal y & (\<exists>z. grain z & eats y z & eats x y))"
   724        \<longrightarrow> (\<exists>x y. animal x \<and> animal y \<and> (\<exists>z. grain z \<and> eats y z \<and> eats x y))"
   725 by (tactic\<open>Meson.safe_best_meson_tac @{context} 1\<close>)
   725 by (tactic\<open>Meson.safe_best_meson_tac @{context} 1\<close>)
   726     \<comment> \<open>Nearly twice as fast as \<open>meson\<close>,
   726     \<comment> \<open>Nearly twice as fast as \<open>meson\<close>,
   727         which performs iterative deepening rather than best-first search\<close>
   727         which performs iterative deepening rather than best-first search\<close>
   728 
   728 
   729 text\<open>The Los problem. Circulated by John Harrison\<close>
   729 text\<open>The Los problem. Circulated by John Harrison\<close>
   730 lemma "(\<forall>x y z. P x y & P y z --> P x z) &
   730 lemma "(\<forall>x y z. P x y \<and> P y z \<longrightarrow> P x z) \<and>
   731        (\<forall>x y z. Q x y & Q y z --> Q x z) &
   731        (\<forall>x y z. Q x y \<and> Q y z \<longrightarrow> Q x z) \<and>
   732        (\<forall>x y. P x y --> P y x) &
   732        (\<forall>x y. P x y \<longrightarrow> P y x) \<and>
   733        (\<forall>x y. P x y | Q x y)
   733        (\<forall>x y. P x y \<or> Q x y)
   734        --> (\<forall>x y. P x y) | (\<forall>x y. Q x y)"
   734        \<longrightarrow> (\<forall>x y. P x y) \<or> (\<forall>x y. Q x y)"
   735 by meson
   735 by meson
   736 
   736 
   737 text\<open>A similar example, suggested by Johannes Schumann and
   737 text\<open>A similar example, suggested by Johannes Schumann and
   738  credited to Pelletier\<close>
   738  credited to Pelletier\<close>
   739 lemma "(\<forall>x y z. P x y --> P y z --> P x z) -->
   739 lemma "(\<forall>x y z. P x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow>
   740        (\<forall>x y z. Q x y --> Q y z --> Q x z) -->
   740        (\<forall>x y z. Q x y \<longrightarrow> Q y z \<longrightarrow> Q x z) \<longrightarrow>
   741        (\<forall>x y. Q x y --> Q y x) -->  (\<forall>x y. P x y | Q x y) -->
   741        (\<forall>x y. Q x y \<longrightarrow> Q y x) \<longrightarrow>  (\<forall>x y. P x y \<or> Q x y) \<longrightarrow>
   742        (\<forall>x y. P x y) | (\<forall>x y. Q x y)"
   742        (\<forall>x y. P x y) \<or> (\<forall>x y. Q x y)"
   743 by meson
   743 by meson
   744 
   744 
   745 text\<open>Problem 50.  What has this to do with equality?\<close>
   745 text\<open>Problem 50.  What has this to do with equality?\<close>
   746 lemma "(\<forall>x. P a x | (\<forall>y. P x y)) --> (\<exists>x. \<forall>y. P x y)"
   746 lemma "(\<forall>x. P a x \<or> (\<forall>y. P x y)) \<longrightarrow> (\<exists>x. \<forall>y. P x y)"
   747 by blast
   747 by blast
   748 
   748 
   749 text\<open>Problem 54: NOT PROVED\<close>
   749 text\<open>Problem 54: NOT PROVED\<close>
   750 lemma "(\<forall>y::'a. \<exists>z. \<forall>x. F x z = (x=y)) -->
   750 lemma "(\<forall>y::'a. \<exists>z. \<forall>x. F x z = (x=y)) \<longrightarrow>
   751       ~ (\<exists>w. \<forall>x. F x w = (\<forall>u. F x u --> (\<exists>y. F y u & ~ (\<exists>z. F z u & F z y))))"
   751       \<not> (\<exists>w. \<forall>x. F x w = (\<forall>u. F x u \<longrightarrow> (\<exists>y. F y u \<and> \<not> (\<exists>z. F z u \<and> F z y))))"
   752 oops 
   752 oops 
   753 
   753 
   754 
   754 
   755 text\<open>Problem 55\<close>
   755 text\<open>Problem 55\<close>
   756 
   756 
   757 text\<open>Non-equational version, from Manthey and Bry, CADE-9 (Springer, 1988).
   757 text\<open>Non-equational version, from Manthey and Bry, CADE-9 (Springer, 1988).
   758   \<open>meson\<close> cannot report who killed Agatha.\<close>
   758   \<open>meson\<close> cannot report who killed Agatha.\<close>
   759 lemma "lives agatha & lives butler & lives charles &
   759 lemma "lives agatha \<and> lives butler \<and> lives charles \<and>
   760        (killed agatha agatha | killed butler agatha | killed charles agatha) &
   760        (killed agatha agatha \<or> killed butler agatha \<or> killed charles agatha) \<and>
   761        (\<forall>x y. killed x y --> hates x y & ~richer x y) &
   761        (\<forall>x y. killed x y \<longrightarrow> hates x y \<and> \<not>richer x y) \<and>
   762        (\<forall>x. hates agatha x --> ~hates charles x) &
   762        (\<forall>x. hates agatha x \<longrightarrow> \<not>hates charles x) \<and>
   763        (hates agatha agatha & hates agatha charles) &
   763        (hates agatha agatha \<and> hates agatha charles) \<and>
   764        (\<forall>x. lives x & ~richer x agatha --> hates butler x) &
   764        (\<forall>x. lives x \<and> \<not>richer x agatha \<longrightarrow> hates butler x) \<and>
   765        (\<forall>x. hates agatha x --> hates butler x) &
   765        (\<forall>x. hates agatha x \<longrightarrow> hates butler x) \<and>
   766        (\<forall>x. ~hates x agatha | ~hates x butler | ~hates x charles) -->
   766        (\<forall>x. \<not>hates x agatha \<or> \<not>hates x butler \<or> \<not>hates x charles) \<longrightarrow>
   767        (\<exists>x. killed x agatha)"
   767        (\<exists>x. killed x agatha)"
   768 by meson
   768 by meson
   769 
   769 
   770 text\<open>Problem 57\<close>
   770 text\<open>Problem 57\<close>
   771 lemma "P (f a b) (f b c) & P (f b c) (f a c) &
   771 lemma "P (f a b) (f b c) \<and> P (f b c) (f a c) \<and>
   772       (\<forall>x y z. P x y & P y z --> P x z)    -->   P (f a b) (f a c)"
   772       (\<forall>x y z. P x y \<and> P y z \<longrightarrow> P x z)    \<longrightarrow>   P (f a b) (f a c)"
   773 by blast
   773 by blast
   774 
   774 
   775 text\<open>Problem 58: Challenge found on info-hol\<close>
   775 text\<open>Problem 58: Challenge found on info-hol\<close>
   776 lemma "\<forall>P Q R x. \<exists>v w. \<forall>y z. P x & Q y --> (P v | R w) & (R z --> Q v)"
   776 lemma "\<forall>P Q R x. \<exists>v w. \<forall>y z. P x \<and> Q y \<longrightarrow> (P v \<or> R w) \<and> (R z \<longrightarrow> Q v)"
   777 by blast
   777 by blast
   778 
   778 
   779 text\<open>Problem 59\<close>
   779 text\<open>Problem 59\<close>
   780 lemma "(\<forall>x. P x = (~P(f x))) --> (\<exists>x. P x & ~P(f x))"
   780 lemma "(\<forall>x. P x = (\<not>P(f x))) \<longrightarrow> (\<exists>x. P x \<and> \<not>P(f x))"
   781 by blast
   781 by blast
   782 
   782 
   783 text\<open>Problem 60\<close>
   783 text\<open>Problem 60\<close>
   784 lemma "\<forall>x. P x (f x) = (\<exists>y. (\<forall>z. P z y --> P z (f x)) & P x y)"
   784 lemma "\<forall>x. P x (f x) = (\<exists>y. (\<forall>z. P z y \<longrightarrow> P z (f x)) \<and> P x y)"
   785 by blast
   785 by blast
   786 
   786 
   787 text\<open>Problem 62 as corrected in JAR 18 (1997), page 135\<close>
   787 text\<open>Problem 62 as corrected in JAR 18 (1997), page 135\<close>
   788 lemma "(\<forall>x. p a & (p x --> p(f x)) --> p(f(f x)))  =
   788 lemma "(\<forall>x. p a \<and> (p x \<longrightarrow> p(f x)) \<longrightarrow> p(f(f x)))  =
   789        (\<forall>x. (~ p a | p x | p(f(f x))) &
   789        (\<forall>x. (\<not> p a \<or> p x \<or> p(f(f x))) \<and>
   790             (~ p a | ~ p(f x) | p(f(f x))))"
   790             (\<not> p a \<or> \<not> p(f x) \<or> p(f(f x))))"
   791 by blast
   791 by blast
   792 
   792 
   793 text\<open>Charles Morgan's problems\<close>
   793 text\<open>Charles Morgan's problems\<close>
   794 context
   794 context
   795   fixes T i n
   795   fixes T i n
   796   assumes a: "\<forall>x y. T(i x(i y x))"
   796   assumes a: "\<forall>x y. T(i x(i y x))"
   797     and b: "\<forall>x y z. T(i (i x (i y z)) (i (i x y) (i x z)))"
   797     and b: "\<forall>x y z. T(i (i x (i y z)) (i (i x y) (i x z)))"
   798     and c: "\<forall>x y. T(i (i (n x) (n y)) (i y x))"
   798     and c: "\<forall>x y. T(i (i (n x) (n y)) (i y x))"
   799     and c': "\<forall>x y. T(i (i y x) (i (n x) (n y)))"
   799     and c': "\<forall>x y. T(i (i y x) (i (n x) (n y)))"
   800     and d: "\<forall>x y. T(i x y) & T x --> T y"
   800     and d: "\<forall>x y. T(i x y) \<and> T x \<longrightarrow> T y"
   801 begin
   801 begin
   802 
   802 
   803 lemma "\<forall>x. T(i x x)"
   803 lemma "\<forall>x. T(i x x)"
   804   using a b d by blast
   804   using a b d by blast
   805 
   805