src/HOL/ex/cla.ML
author paulson
Thu Aug 06 15:48:13 1998 +0200 (1998-08-06)
changeset 5278 a903b66822e2
parent 5150 6e2e9b92c301
child 6799 95abcc002a21
permissions -rw-r--r--
even more tidying of Goal commands
     1 (*  Title:      HOL/ex/cla
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1994  University of Cambridge
     5 
     6 Higher-Order Logic: predicate calculus problems
     7 
     8 Taken from FOL/cla.ML; beware of precedence of = vs <->
     9 *)
    10 
    11 writeln"File HOL/ex/cla.";
    12 
    13 context HOL.thy; 
    14 
    15 Goal "(P --> Q | R) --> (P-->Q) | (P-->R)";
    16 by (Blast_tac 1);
    17 result();
    18 
    19 (*If and only if*)
    20 
    21 Goal "(P=Q) = (Q = (P::bool))";
    22 by (Blast_tac 1);
    23 result();
    24 
    25 Goal "~ (P = (~P))";
    26 by (Blast_tac 1);
    27 result();
    28 
    29 
    30 (*Sample problems from 
    31   F. J. Pelletier, 
    32   Seventy-Five Problems for Testing Automatic Theorem Provers,
    33   J. Automated Reasoning 2 (1986), 191-216.
    34   Errata, JAR 4 (1988), 236-236.
    35 
    36 The hardest problems -- judging by experience with several theorem provers,
    37 including matrix ones -- are 34 and 43.
    38 *)
    39 
    40 writeln"Pelletier's examples";
    41 (*1*)
    42 Goal "(P-->Q)  =  (~Q --> ~P)";
    43 by (Blast_tac 1);
    44 result();
    45 
    46 (*2*)
    47 Goal "(~ ~ P) =  P";
    48 by (Blast_tac 1);
    49 result();
    50 
    51 (*3*)
    52 Goal "~(P-->Q) --> (Q-->P)";
    53 by (Blast_tac 1);
    54 result();
    55 
    56 (*4*)
    57 Goal "(~P-->Q)  =  (~Q --> P)";
    58 by (Blast_tac 1);
    59 result();
    60 
    61 (*5*)
    62 Goal "((P|Q)-->(P|R)) --> (P|(Q-->R))";
    63 by (Blast_tac 1);
    64 result();
    65 
    66 (*6*)
    67 Goal "P | ~ P";
    68 by (Blast_tac 1);
    69 result();
    70 
    71 (*7*)
    72 Goal "P | ~ ~ ~ P";
    73 by (Blast_tac 1);
    74 result();
    75 
    76 (*8.  Peirce's law*)
    77 Goal "((P-->Q) --> P)  -->  P";
    78 by (Blast_tac 1);
    79 result();
    80 
    81 (*9*)
    82 Goal "((P|Q) & (~P|Q) & (P| ~Q)) --> ~ (~P | ~Q)";
    83 by (Blast_tac 1);
    84 result();
    85 
    86 (*10*)
    87 Goal "(Q-->R) & (R-->P&Q) & (P-->Q|R) --> (P=Q)";
    88 by (Blast_tac 1);
    89 result();
    90 
    91 (*11.  Proved in each direction (incorrectly, says Pelletier!!)  *)
    92 Goal "P=(P::bool)";
    93 by (Blast_tac 1);
    94 result();
    95 
    96 (*12.  "Dijkstra's law"*)
    97 Goal "((P = Q) = R) = (P = (Q = R))";
    98 by (Blast_tac 1);
    99 result();
   100 
   101 (*13.  Distributive law*)
   102 Goal "(P | (Q & R)) = ((P | Q) & (P | R))";
   103 by (Blast_tac 1);
   104 result();
   105 
   106 (*14*)
   107 Goal "(P = Q) = ((Q | ~P) & (~Q|P))";
   108 by (Blast_tac 1);
   109 result();
   110 
   111 (*15*)
   112 Goal "(P --> Q) = (~P | Q)";
   113 by (Blast_tac 1);
   114 result();
   115 
   116 (*16*)
   117 Goal "(P-->Q) | (Q-->P)";
   118 by (Blast_tac 1);
   119 result();
   120 
   121 (*17*)
   122 Goal "((P & (Q-->R))-->S)  =  ((~P | Q | S) & (~P | ~R | S))";
   123 by (Blast_tac 1);
   124 result();
   125 
   126 writeln"Classical Logic: examples with quantifiers";
   127 
   128 Goal "(! x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
   129 by (Blast_tac 1);
   130 result(); 
   131 
   132 Goal "(? x. P-->Q(x))  =  (P --> (? x. Q(x)))";
   133 by (Blast_tac 1);
   134 result(); 
   135 
   136 Goal "(? x. P(x)-->Q) = ((! x. P(x)) --> Q)";
   137 by (Blast_tac 1);
   138 result(); 
   139 
   140 Goal "((! x. P(x)) | Q)  =  (! x. P(x) | Q)";
   141 by (Blast_tac 1);
   142 result(); 
   143 
   144 (*From Wishnu Prasetya*)
   145 Goal "(!s. q(s) --> r(s)) & ~r(s) & (!s. ~r(s) & ~q(s) --> p(t) | q(t)) \
   146 \   --> p(t) | r(t)";
   147 by (Blast_tac 1);
   148 result(); 
   149 
   150 
   151 writeln"Problems requiring quantifier duplication";
   152 
   153 (*Theorem B of Peter Andrews, Theorem Proving via General Matings, 
   154   JACM 28 (1981).*)
   155 Goal "(EX x. ALL y. P(x) = P(y)) --> ((EX x. P(x)) = (ALL y. P(y)))";
   156 by (Blast_tac 1);
   157 result();
   158 
   159 (*Needs multiple instantiation of the quantifier.*)
   160 Goal "(! x. P(x)-->P(f(x)))  &  P(d)-->P(f(f(f(d))))";
   161 by (Blast_tac 1);
   162 result();
   163 
   164 (*Needs double instantiation of the quantifier*)
   165 Goal "? x. P(x) --> P(a) & P(b)";
   166 by (Blast_tac 1);
   167 result();
   168 
   169 Goal "? z. P(z) --> (! x. P(x))";
   170 by (Blast_tac 1);
   171 result();
   172 
   173 Goal "? x. (? y. P(y)) --> P(x)";
   174 by (Blast_tac 1);
   175 result();
   176 
   177 writeln"Hard examples with quantifiers";
   178 
   179 writeln"Problem 18";
   180 Goal "? y. ! x. P(y)-->P(x)";
   181 by (Blast_tac 1);
   182 result(); 
   183 
   184 writeln"Problem 19";
   185 Goal "? x. ! y z. (P(y)-->Q(z)) --> (P(x)-->Q(x))";
   186 by (Blast_tac 1);
   187 result();
   188 
   189 writeln"Problem 20";
   190 Goal "(! x y. ? z. ! w. (P(x)&Q(y)-->R(z)&S(w)))     \
   191 \   --> (? x y. P(x) & Q(y)) --> (? z. R(z))";
   192 by (Blast_tac 1); 
   193 result();
   194 
   195 writeln"Problem 21";
   196 Goal "(? x. P-->Q(x)) & (? x. Q(x)-->P) --> (? x. P=Q(x))";
   197 by (Blast_tac 1); 
   198 result();
   199 
   200 writeln"Problem 22";
   201 Goal "(! x. P = Q(x))  -->  (P = (! x. Q(x)))";
   202 by (Blast_tac 1); 
   203 result();
   204 
   205 writeln"Problem 23";
   206 Goal "(! x. P | Q(x))  =  (P | (! x. Q(x)))";
   207 by (Blast_tac 1);  
   208 result();
   209 
   210 writeln"Problem 24";
   211 Goal "~(? x. S(x)&Q(x)) & (! x. P(x) --> Q(x)|R(x)) &  \
   212 \    (~(? x. P(x)) --> (? x. Q(x))) & (! x. Q(x)|R(x) --> S(x))  \
   213 \   --> (? x. P(x)&R(x))";
   214 by (Blast_tac 1); 
   215 result();
   216 
   217 writeln"Problem 25";
   218 Goal "(? x. P(x)) &  \
   219 \       (! x. L(x) --> ~ (M(x) & R(x))) &  \
   220 \       (! x. P(x) --> (M(x) & L(x))) &   \
   221 \       ((! x. P(x)-->Q(x)) | (? x. P(x)&R(x)))  \
   222 \   --> (? x. Q(x)&P(x))";
   223 by (Blast_tac 1); 
   224 result();
   225 
   226 writeln"Problem 26";
   227 Goal "((? x. p(x)) = (? x. q(x))) &     \
   228 \     (! x. ! y. p(x) & q(y) --> (r(x) = s(y))) \
   229 \ --> ((! x. p(x)-->r(x)) = (! x. q(x)-->s(x)))";
   230 by (Blast_tac 1);
   231 result();
   232 
   233 writeln"Problem 27";
   234 Goal "(? x. P(x) & ~Q(x)) &   \
   235 \             (! x. P(x) --> R(x)) &   \
   236 \             (! x. M(x) & L(x) --> P(x)) &   \
   237 \             ((? x. R(x) & ~ Q(x)) --> (! x. L(x) --> ~ R(x)))  \
   238 \         --> (! x. M(x) --> ~L(x))";
   239 by (Blast_tac 1); 
   240 result();
   241 
   242 writeln"Problem 28.  AMENDED";
   243 Goal "(! x. P(x) --> (! x. Q(x))) &   \
   244 \       ((! x. Q(x)|R(x)) --> (? x. Q(x)&S(x))) &  \
   245 \       ((? x. S(x)) --> (! x. L(x) --> M(x)))  \
   246 \   --> (! x. P(x) & L(x) --> M(x))";
   247 by (Blast_tac 1);  
   248 result();
   249 
   250 writeln"Problem 29.  Essentially the same as Principia Mathematica *11.71";
   251 Goal "(? x. F(x)) & (? y. G(y))  \
   252 \   --> ( ((! x. F(x)-->H(x)) & (! y. G(y)-->J(y)))  =   \
   253 \         (! x y. F(x) & G(y) --> H(x) & J(y)))";
   254 by (Blast_tac 1); 
   255 result();
   256 
   257 writeln"Problem 30";
   258 Goal "(! x. P(x) | Q(x) --> ~ R(x)) & \
   259 \       (! x. (Q(x) --> ~ S(x)) --> P(x) & R(x))  \
   260 \   --> (! x. S(x))";
   261 by (Blast_tac 1);  
   262 result();
   263 
   264 writeln"Problem 31";
   265 Goal "~(? x. P(x) & (Q(x) | R(x))) & \
   266 \       (? x. L(x) & P(x)) & \
   267 \       (! x. ~ R(x) --> M(x))  \
   268 \   --> (? x. L(x) & M(x))";
   269 by (Blast_tac 1);
   270 result();
   271 
   272 writeln"Problem 32";
   273 Goal "(! x. P(x) & (Q(x)|R(x))-->S(x)) & \
   274 \       (! x. S(x) & R(x) --> L(x)) & \
   275 \       (! x. M(x) --> R(x))  \
   276 \   --> (! x. P(x) & M(x) --> L(x))";
   277 by (Blast_tac 1);
   278 result();
   279 
   280 writeln"Problem 33";
   281 Goal "(! x. P(a) & (P(x)-->P(b))-->P(c))  =    \
   282 \    (! x. (~P(a) | P(x) | P(c)) & (~P(a) | ~P(b) | P(c)))";
   283 by (Blast_tac 1);
   284 result();
   285 
   286 writeln"Problem 34  AMENDED (TWICE!!)";
   287 (*Andrews's challenge*)
   288 Goal "((? x. ! y. p(x) = p(y))  =               \
   289 \              ((? x. q(x)) = (! y. p(y))))   =    \
   290 \             ((? x. ! y. q(x) = q(y))  =          \
   291 \              ((? x. p(x)) = (! y. q(y))))";
   292 by (Blast_tac 1);
   293 result();
   294 
   295 writeln"Problem 35";
   296 Goal "? x y. P x y -->  (! u v. P u v)";
   297 by (Blast_tac 1);
   298 result();
   299 
   300 writeln"Problem 36";
   301 Goal "(! x. ? y. J x y) & \
   302 \       (! x. ? y. G x y) & \
   303 \       (! x y. J x y | G x y -->       \
   304 \       (! z. J y z | G y z --> H x z))   \
   305 \   --> (! x. ? y. H x y)";
   306 by (Blast_tac 1);
   307 result();
   308 
   309 writeln"Problem 37";
   310 Goal "(! z. ? w. ! x. ? y. \
   311 \          (P x z -->P y w) & P y z & (P y w --> (? u. Q u w))) & \
   312 \       (! x z. ~(P x z) --> (? y. Q y z)) & \
   313 \       ((? x y. Q x y) --> (! x. R x x))  \
   314 \   --> (! x. ? y. R x y)";
   315 by (Blast_tac 1);
   316 result();
   317 
   318 writeln"Problem 38";
   319 Goal "(! x. p(a) & (p(x) --> (? y. p(y) & r x y)) -->            \
   320 \          (? z. ? w. p(z) & r x w & r w z))  =                 \
   321 \    (! x. (~p(a) | p(x) | (? z. ? w. p(z) & r x w & r w z)) &  \
   322 \          (~p(a) | ~(? y. p(y) & r x y) |                      \
   323 \           (? z. ? w. p(z) & r x w & r w z)))";
   324 by (Blast_tac 1);  (*beats fast_tac!*)
   325 result();
   326 
   327 writeln"Problem 39";
   328 Goal "~ (? x. ! y. F y x = (~ F y y))";
   329 by (Blast_tac 1);
   330 result();
   331 
   332 writeln"Problem 40.  AMENDED";
   333 Goal "(? y. ! x. F x y = F x x)  \
   334 \       -->  ~ (! x. ? y. ! z. F z y = (~ F z x))";
   335 by (Blast_tac 1);
   336 result();
   337 
   338 writeln"Problem 41";
   339 Goal "(! z. ? y. ! x. f x y = (f x z & ~ f x x))        \
   340 \              --> ~ (? z. ! x. f x z)";
   341 by (Blast_tac 1);
   342 result();
   343 
   344 writeln"Problem 42";
   345 Goal "~ (? y. ! x. p x y = (~ (? z. p x z & p z x)))";
   346 by (Blast_tac 1);
   347 result();
   348 
   349 writeln"Problem 43!!";
   350 Goal "(! x::'a. ! y::'a. q x y = (! z. p z x = (p z y::bool)))   \
   351 \ --> (! x. (! y. q x y = (q y x::bool)))";
   352 by (Blast_tac 1);
   353 result();
   354 
   355 writeln"Problem 44";
   356 Goal "(! x. f(x) -->                                    \
   357 \             (? y. g(y) & h x y & (? y. g(y) & ~ h x y)))  &   \
   358 \             (? x. j(x) & (! y. g(y) --> h x y))               \
   359 \             --> (? x. j(x) & ~f(x))";
   360 by (Blast_tac 1);
   361 result();
   362 
   363 writeln"Problem 45";
   364 Goal "(! x. f(x) & (! y. g(y) & h x y --> j x y) \
   365 \                     --> (! y. g(y) & h x y --> k(y))) &       \
   366 \    ~ (? y. l(y) & k(y)) &                                     \
   367 \    (? x. f(x) & (! y. h x y --> l(y))                         \
   368 \               & (! y. g(y) & h x y --> j x y))                \
   369 \     --> (? x. f(x) & ~ (? y. g(y) & h x y))";
   370 by (Blast_tac 1); 
   371 result();
   372 
   373 
   374 writeln"Problems (mainly) involving equality or functions";
   375 
   376 writeln"Problem 48";
   377 Goal "(a=b | c=d) & (a=c | b=d) --> a=d | b=c";
   378 by (Blast_tac 1);
   379 result();
   380 
   381 writeln"Problem 49  NOT PROVED AUTOMATICALLY";
   382 (*Hard because it involves substitution for Vars;
   383   the type constraint ensures that x,y,z have the same type as a,b,u. *)
   384 Goal "(? x y::'a. ! z. z=x | z=y) & P(a) & P(b) & (~a=b) \
   385 \               --> (! u::'a. P(u))";
   386 by (Classical.Safe_tac);
   387 by (res_inst_tac [("x","a")] allE 1);
   388 by (assume_tac 1);
   389 by (res_inst_tac [("x","b")] allE 1);
   390 by (assume_tac 1);
   391 by (Fast_tac 1);    (*Blast_tac's treatment of equality can't do it*)
   392 result();
   393 
   394 writeln"Problem 50";  
   395 (*What has this to do with equality?*)
   396 Goal "(! x. P a x | (! y. P x y)) --> (? x. ! y. P x y)";
   397 by (Blast_tac 1);
   398 result();
   399 
   400 writeln"Problem 51";
   401 Goal "(? z w. ! x y. P x y = (x=z & y=w)) -->  \
   402 \    (? z. ! x. ? w. (! y. P x y = (y=w)) = (x=z))";
   403 by (Blast_tac 1);
   404 result();
   405 
   406 writeln"Problem 52";
   407 (*Almost the same as 51. *)
   408 Goal "(? z w. ! x y. P x y = (x=z & y=w)) -->  \
   409 \    (? w. ! y. ? z. (! x. P x y = (x=z)) = (y=w))";
   410 by (Blast_tac 1);
   411 result();
   412 
   413 writeln"Problem 55";
   414 
   415 (*Non-equational version, from Manthey and Bry, CADE-9 (Springer, 1988).
   416   fast_tac DISCOVERS who killed Agatha. *)
   417 Goal "lives(agatha) & lives(butler) & lives(charles) & \
   418 \  (killed agatha agatha | killed butler agatha | killed charles agatha) & \
   419 \  (!x y. killed x y --> hates x y & ~richer x y) & \
   420 \  (!x. hates agatha x --> ~hates charles x) & \
   421 \  (hates agatha agatha & hates agatha charles) & \
   422 \  (!x. lives(x) & ~richer x agatha --> hates butler x) & \
   423 \  (!x. hates agatha x --> hates butler x) & \
   424 \  (!x. ~hates x agatha | ~hates x butler | ~hates x charles) --> \
   425 \   killed ?who agatha";
   426 by (Fast_tac 1);
   427 result();
   428 
   429 writeln"Problem 56";
   430 Goal "(! x. (? y. P(y) & x=f(y)) --> P(x)) = (! x. P(x) --> P(f(x)))";
   431 by (Blast_tac 1);
   432 result();
   433 
   434 writeln"Problem 57";
   435 Goal "P (f a b) (f b c) & P (f b c) (f a c) & \
   436 \    (! x y z. P x y & P y z --> P x z)    -->   P (f a b) (f a c)";
   437 by (Blast_tac 1);
   438 result();
   439 
   440 writeln"Problem 58  NOT PROVED AUTOMATICALLY";
   441 Goal "(! x y. f(x)=g(y)) --> (! x y. f(f(x))=f(g(y)))";
   442 val f_cong = read_instantiate [("f","f")] arg_cong;
   443 by (fast_tac (claset() addIs [f_cong]) 1);
   444 result();
   445 
   446 writeln"Problem 59";
   447 Goal "(! x. P(x) = (~P(f(x)))) --> (? x. P(x) & ~P(f(x)))";
   448 by (Blast_tac 1);
   449 result();
   450 
   451 writeln"Problem 60";
   452 Goal "! x. P x (f x) = (? y. (! z. P z y --> P z (f x)) & P x y)";
   453 by (Blast_tac 1);
   454 result();
   455 
   456 writeln"Problem 62 as corrected in JAR 18 (1997), page 135";
   457 Goal "(ALL x. p a & (p x --> p(f x)) --> p(f(f x)))  =   \
   458 \     (ALL x. (~ p a | p x | p(f(f x))) &                        \
   459 \             (~ p a | ~ p(f x) | p(f(f x))))";
   460 by (Blast_tac 1);
   461 result();
   462 
   463 (*From Davis, Obvious Logical Inferences, IJCAI-81, 530-531
   464   Fast_tac indeed copes!*)
   465 goal Prod.thy "(ALL x. F(x) & ~G(x) --> (EX y. H(x,y) & J(y))) & \
   466 \             (EX x. K(x) & F(x) & (ALL y. H(x,y) --> K(y))) &   \
   467 \             (ALL x. K(x) --> ~G(x))  -->  (EX x. K(x) & J(x))";
   468 by (Fast_tac 1);
   469 result();
   470 
   471 (*From Rudnicki, Obvious Inferences, JAR 3 (1987), 383-393.  
   472   It does seem obvious!*)
   473 goal Prod.thy
   474     "(ALL x. F(x) & ~G(x) --> (EX y. H(x,y) & J(y))) &        \
   475 \    (EX x. K(x) & F(x) & (ALL y. H(x,y) --> K(y)))  &        \
   476 \    (ALL x. K(x) --> ~G(x))   -->   (EX x. K(x) --> ~G(x))";
   477 by (Fast_tac 1);
   478 result();
   479 
   480 goal Prod.thy
   481     "(ALL x y. R(x,y) | R(y,x)) &                \
   482 \    (ALL x y. S(x,y) & S(y,x) --> x=y) &        \
   483 \    (ALL x y. R(x,y) --> S(x,y))    -->   (ALL x y. S(x,y) --> R(x,y))";
   484 by (Blast_tac 1);
   485 result();
   486 
   487 
   488 
   489 writeln"Reached end of file.";