src/HOL/ex/cla.ML
author kleing
Sat, 01 Mar 2003 16:45:51 +0100
changeset 13840 399c8103a98f
parent 11025 a70b796d9af8
permissions -rw-r--r--
keep a copy of generated files in repository

(*  Title:      HOL/ex/cla
    ID:         $Id$
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
    Copyright   1994  University of Cambridge

Higher-Order Logic: predicate calculus problems

Taken from FOL/cla.ML; beware of precedence of = vs <->
*)

writeln"File HOL/ex/cla.";

context HOL.thy; 

Goal "(P --> Q | R) --> (P-->Q) | (P-->R)";
by (Blast_tac 1);
result();

(*If and only if*)

Goal "(P=Q) = (Q = (P::bool))";
by (Blast_tac 1);
result();

Goal "~ (P = (~P))";
by (Blast_tac 1);
result();


(*Sample problems from 
  F. J. Pelletier, 
  Seventy-Five Problems for Testing Automatic Theorem Provers,
  J. Automated Reasoning 2 (1986), 191-216.
  Errata, JAR 4 (1988), 236-236.

The hardest problems -- judging by experience with several theorem provers,
including matrix ones -- are 34 and 43.
*)

writeln"Pelletier's examples";
(*1*)
Goal "(P-->Q)  =  (~Q --> ~P)";
by (Blast_tac 1);
result();

(*2*)
Goal "(~ ~ P) =  P";
by (Blast_tac 1);
result();

(*3*)
Goal "~(P-->Q) --> (Q-->P)";
by (Blast_tac 1);
result();

(*4*)
Goal "(~P-->Q)  =  (~Q --> P)";
by (Blast_tac 1);
result();

(*5*)
Goal "((P|Q)-->(P|R)) --> (P|(Q-->R))";
by (Blast_tac 1);
result();

(*6*)
Goal "P | ~ P";
by (Blast_tac 1);
result();

(*7*)
Goal "P | ~ ~ ~ P";
by (Blast_tac 1);
result();

(*8.  Peirce's law*)
Goal "((P-->Q) --> P)  -->  P";
by (Blast_tac 1);
result();

(*9*)
Goal "((P|Q) & (~P|Q) & (P| ~Q)) --> ~ (~P | ~Q)";
by (Blast_tac 1);
result();

(*10*)
Goal "(Q-->R) & (R-->P&Q) & (P-->Q|R) --> (P=Q)";
by (Blast_tac 1);
result();

(*11.  Proved in each direction (incorrectly, says Pelletier!!)  *)
Goal "P=(P::bool)";
by (Blast_tac 1);
result();

(*12.  "Dijkstra's law"*)
Goal "((P = Q) = R) = (P = (Q = R))";
by (Blast_tac 1);
result();

(*13.  Distributive law*)
Goal "(P | (Q & R)) = ((P | Q) & (P | R))";
by (Blast_tac 1);
result();

(*14*)
Goal "(P = Q) = ((Q | ~P) & (~Q|P))";
by (Blast_tac 1);
result();

(*15*)
Goal "(P --> Q) = (~P | Q)";
by (Blast_tac 1);
result();

(*16*)
Goal "(P-->Q) | (Q-->P)";
by (Blast_tac 1);
result();

(*17*)
Goal "((P & (Q-->R))-->S)  =  ((~P | Q | S) & (~P | ~R | S))";
by (Blast_tac 1);
result();

writeln"Classical Logic: examples with quantifiers";

Goal "(! x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
by (Blast_tac 1);
result(); 

Goal "(? x. P-->Q(x))  =  (P --> (? x. Q(x)))";
by (Blast_tac 1);
result(); 

Goal "(? x. P(x)-->Q) = ((! x. P(x)) --> Q)";
by (Blast_tac 1);
result(); 

Goal "((! x. P(x)) | Q)  =  (! x. P(x) | Q)";
by (Blast_tac 1);
result(); 

(*From Wishnu Prasetya*)
Goal "(!s. q(s) --> r(s)) & ~r(s) & (!s. ~r(s) & ~q(s) --> p(t) | q(t)) \
\   --> p(t) | r(t)";
by (Blast_tac 1);
result(); 


writeln"Problems requiring quantifier duplication";

(*Theorem B of Peter Andrews, Theorem Proving via General Matings, 
  JACM 28 (1981).*)
Goal "(EX x. ALL y. P(x) = P(y)) --> ((EX x. P(x)) = (ALL y. P(y)))";
by (Blast_tac 1);
result();

(*Needs multiple instantiation of the quantifier.*)
Goal "(! x. P(x)-->P(f(x)))  &  P(d)-->P(f(f(f(d))))";
by (Blast_tac 1);
result();

(*Needs double instantiation of the quantifier*)
Goal "? x. P(x) --> P(a) & P(b)";
by (Blast_tac 1);
result();

Goal "? z. P(z) --> (! x. P(x))";
by (Blast_tac 1);
result();

Goal "? x. (? y. P(y)) --> P(x)";
by (Blast_tac 1);
result();

writeln"Hard examples with quantifiers";

writeln"Problem 18";
Goal "? y. ! x. P(y)-->P(x)";
by (Blast_tac 1);
result(); 

writeln"Problem 19";
Goal "? x. ! y z. (P(y)-->Q(z)) --> (P(x)-->Q(x))";
by (Blast_tac 1);
result();

writeln"Problem 20";
Goal "(! x y. ? z. ! w. (P(x)&Q(y)-->R(z)&S(w)))     \
\   --> (? x y. P(x) & Q(y)) --> (? z. R(z))";
by (Blast_tac 1); 
result();

writeln"Problem 21";
Goal "(? x. P-->Q(x)) & (? x. Q(x)-->P) --> (? x. P=Q(x))";
by (Blast_tac 1); 
result();

writeln"Problem 22";
Goal "(! x. P = Q(x))  -->  (P = (! x. Q(x)))";
by (Blast_tac 1); 
result();

writeln"Problem 23";
Goal "(! x. P | Q(x))  =  (P | (! x. Q(x)))";
by (Blast_tac 1);  
result();

writeln"Problem 24";
Goal "~(? x. S(x)&Q(x)) & (! x. P(x) --> Q(x)|R(x)) &  \
\    (~(? x. P(x)) --> (? x. Q(x))) & (! x. Q(x)|R(x) --> S(x))  \
\   --> (? x. P(x)&R(x))";
by (Blast_tac 1); 
result();

writeln"Problem 25";
Goal "(? x. P(x)) &  \
\       (! x. L(x) --> ~ (M(x) & R(x))) &  \
\       (! x. P(x) --> (M(x) & L(x))) &   \
\       ((! x. P(x)-->Q(x)) | (? x. P(x)&R(x)))  \
\   --> (? x. Q(x)&P(x))";
by (Blast_tac 1); 
result();

writeln"Problem 26";
Goal "((? x. p(x)) = (? x. q(x))) &     \
\     (! x. ! y. p(x) & q(y) --> (r(x) = s(y))) \
\ --> ((! x. p(x)-->r(x)) = (! x. q(x)-->s(x)))";
by (Blast_tac 1);
result();

writeln"Problem 27";
Goal "(? x. P(x) & ~Q(x)) &   \
\             (! x. P(x) --> R(x)) &   \
\             (! x. M(x) & L(x) --> P(x)) &   \
\             ((? x. R(x) & ~ Q(x)) --> (! x. L(x) --> ~ R(x)))  \
\         --> (! x. M(x) --> ~L(x))";
by (Blast_tac 1); 
result();

writeln"Problem 28.  AMENDED";
Goal "(! x. P(x) --> (! x. Q(x))) &   \
\       ((! x. Q(x)|R(x)) --> (? x. Q(x)&S(x))) &  \
\       ((? x. S(x)) --> (! x. L(x) --> M(x)))  \
\   --> (! x. P(x) & L(x) --> M(x))";
by (Blast_tac 1);  
result();

writeln"Problem 29.  Essentially the same as Principia Mathematica *11.71";
Goal "(? x. F(x)) & (? y. G(y))  \
\   --> ( ((! x. F(x)-->H(x)) & (! y. G(y)-->J(y)))  =   \
\         (! x y. F(x) & G(y) --> H(x) & J(y)))";
by (Blast_tac 1); 
result();

writeln"Problem 30";
Goal "(! x. P(x) | Q(x) --> ~ R(x)) & \
\       (! x. (Q(x) --> ~ S(x)) --> P(x) & R(x))  \
\   --> (! x. S(x))";
by (Blast_tac 1);  
result();

writeln"Problem 31";
Goal "~(? x. P(x) & (Q(x) | R(x))) & \
\       (? x. L(x) & P(x)) & \
\       (! x. ~ R(x) --> M(x))  \
\   --> (? x. L(x) & M(x))";
by (Blast_tac 1);
result();

writeln"Problem 32";
Goal "(! x. P(x) & (Q(x)|R(x))-->S(x)) & \
\       (! x. S(x) & R(x) --> L(x)) & \
\       (! x. M(x) --> R(x))  \
\   --> (! x. P(x) & M(x) --> L(x))";
by (Blast_tac 1);
result();

writeln"Problem 33";
Goal "(! x. P(a) & (P(x)-->P(b))-->P(c))  =    \
\    (! x. (~P(a) | P(x) | P(c)) & (~P(a) | ~P(b) | P(c)))";
by (Blast_tac 1);
result();

writeln"Problem 34  AMENDED (TWICE!!)";
(*Andrews's challenge*)
Goal "((? x. ! y. p(x) = p(y))  =               \
\              ((? x. q(x)) = (! y. p(y))))   =    \
\             ((? x. ! y. q(x) = q(y))  =          \
\              ((? x. p(x)) = (! y. q(y))))";
by (Blast_tac 1);
result();

writeln"Problem 35";
Goal "? x y. P x y -->  (! u v. P u v)";
by (Blast_tac 1);
result();

writeln"Problem 36";
Goal "(! x. ? y. J x y) & \
\       (! x. ? y. G x y) & \
\       (! x y. J x y | G x y -->       \
\       (! z. J y z | G y z --> H x z))   \
\   --> (! x. ? y. H x y)";
by (Blast_tac 1);
result();

writeln"Problem 37";
Goal "(! z. ? w. ! x. ? y. \
\          (P x z -->P y w) & P y z & (P y w --> (? u. Q u w))) & \
\       (! x z. ~(P x z) --> (? y. Q y z)) & \
\       ((? x y. Q x y) --> (! x. R x x))  \
\   --> (! x. ? y. R x y)";
by (Blast_tac 1);
result();

writeln"Problem 38";
Goal "(! x. p(a) & (p(x) --> (? y. p(y) & r x y)) -->            \
\          (? z. ? w. p(z) & r x w & r w z))  =                 \
\    (! x. (~p(a) | p(x) | (? z. ? w. p(z) & r x w & r w z)) &  \
\          (~p(a) | ~(? y. p(y) & r x y) |                      \
\           (? z. ? w. p(z) & r x w & r w z)))";
by (Blast_tac 1);  (*beats fast_tac!*)
result();

writeln"Problem 39";
Goal "~ (? x. ! y. F y x = (~ F y y))";
by (Blast_tac 1);
result();

writeln"Problem 40.  AMENDED";
Goal "(? y. ! x. F x y = F x x)  \
\       -->  ~ (! x. ? y. ! z. F z y = (~ F z x))";
by (Blast_tac 1);
result();

writeln"Problem 41";
Goal "(! z. ? y. ! x. f x y = (f x z & ~ f x x))        \
\              --> ~ (? z. ! x. f x z)";
by (Blast_tac 1);
result();

writeln"Problem 42";
Goal "~ (? y. ! x. p x y = (~ (? z. p x z & p z x)))";
by (Blast_tac 1);
result();

writeln"Problem 43!!";
Goal "(! x::'a. ! y::'a. q x y = (! z. p z x = (p z y::bool)))   \
\ --> (! x. (! y. q x y = (q y x::bool)))";
by (Blast_tac 1);
result();

writeln"Problem 44";
Goal "(! x. f(x) -->                                    \
\             (? y. g(y) & h x y & (? y. g(y) & ~ h x y)))  &   \
\             (? x. j(x) & (! y. g(y) --> h x y))               \
\             --> (? x. j(x) & ~f(x))";
by (Blast_tac 1);
result();

writeln"Problem 45";
Goal "(! x. f(x) & (! y. g(y) & h x y --> j x y) \
\                     --> (! y. g(y) & h x y --> k(y))) &       \
\    ~ (? y. l(y) & k(y)) &                                     \
\    (? x. f(x) & (! y. h x y --> l(y))                         \
\               & (! y. g(y) & h x y --> j x y))                \
\     --> (? x. f(x) & ~ (? y. g(y) & h x y))";
by (Blast_tac 1); 
result();


writeln"Problems (mainly) involving equality or functions";

writeln"Problem 48";
Goal "(a=b | c=d) & (a=c | b=d) --> a=d | b=c";
by (Blast_tac 1);
result();

writeln"Problem 49  NOT PROVED AUTOMATICALLY";
(*Hard because it involves substitution for Vars;
  the type constraint ensures that x,y,z have the same type as a,b,u. *)
Goal "(? x y::'a. ! z. z=x | z=y) & P(a) & P(b) & (~a=b) \
\               --> (! u::'a. P(u))";
by (Classical.Safe_tac);
by (res_inst_tac [("x","a")] allE 1);
by (assume_tac 1);
by (res_inst_tac [("x","b")] allE 1);
by (assume_tac 1);
by (Fast_tac 1);    (*Blast_tac's treatment of equality can't do it*)
result();

writeln"Problem 50";  
(*What has this to do with equality?*)
Goal "(! x. P a x | (! y. P x y)) --> (? x. ! y. P x y)";
by (Blast_tac 1);
result();

writeln"Problem 51";
Goal "(? z w. ! x y. P x y = (x=z & y=w)) -->  \
\    (? z. ! x. ? w. (! y. P x y = (y=w)) = (x=z))";
by (Blast_tac 1);
result();

writeln"Problem 52";
(*Almost the same as 51. *)
Goal "(? z w. ! x y. P x y = (x=z & y=w)) -->  \
\    (? w. ! y. ? z. (! x. P x y = (x=z)) = (y=w))";
by (Blast_tac 1);
result();

writeln"Problem 55";

(*Non-equational version, from Manthey and Bry, CADE-9 (Springer, 1988).
  fast_tac DISCOVERS who killed Agatha. *)
Goal "lives(agatha) & lives(butler) & lives(charles) & \
\  (killed agatha agatha | killed butler agatha | killed charles agatha) & \
\  (!x y. killed x y --> hates x y & ~richer x y) & \
\  (!x. hates agatha x --> ~hates charles x) & \
\  (hates agatha agatha & hates agatha charles) & \
\  (!x. lives(x) & ~richer x agatha --> hates butler x) & \
\  (!x. hates agatha x --> hates butler x) & \
\  (!x. ~hates x agatha | ~hates x butler | ~hates x charles) --> \
\   killed ?who agatha";
by (Fast_tac 1);
result();

writeln"Problem 56";
Goal "(! x. (? y. P(y) & x=f(y)) --> P(x)) = (! x. P(x) --> P(f(x)))";
by (Blast_tac 1);
result();

writeln"Problem 57";
Goal "P (f a b) (f b c) & P (f b c) (f a c) & \
\    (! x y z. P x y & P y z --> P x z)    -->   P (f a b) (f a c)";
by (Blast_tac 1);
result();

writeln"Problem 58  NOT PROVED AUTOMATICALLY";
Goal "(! x y. f(x)=g(y)) --> (! x y. f(f(x))=f(g(y)))";
val f_cong = read_instantiate [("f","f")] arg_cong;
by (fast_tac (claset() addIs [f_cong]) 1);
result();

writeln"Problem 59";
Goal "(! x. P(x) = (~P(f(x)))) --> (? x. P(x) & ~P(f(x)))";
by (Blast_tac 1);
result();

writeln"Problem 60";
Goal "! x. P x (f x) = (? y. (! z. P z y --> P z (f x)) & P x y)";
by (Blast_tac 1);
result();

writeln"Problem 62 as corrected in JAR 18 (1997), page 135";
Goal "(ALL x. p a & (p x --> p(f x)) --> p(f(f x)))  =   \
\     (ALL x. (~ p a | p x | p(f(f x))) &                        \
\             (~ p a | ~ p(f x) | p(f(f x))))";
by (Blast_tac 1);
result();

(*From Davis, Obvious Logical Inferences, IJCAI-81, 530-531
  Fast_tac indeed copes!*)
goal (theory "Product_Type") 
             "(ALL x. F(x) & ~G(x) --> (EX y. H(x,y) & J(y))) & \
\             (EX x. K(x) & F(x) & (ALL y. H(x,y) --> K(y))) &   \
\             (ALL x. K(x) --> ~G(x))  -->  (EX x. K(x) & J(x))";
by (Fast_tac 1);
result();

(*From Rudnicki, Obvious Inferences, JAR 3 (1987), 383-393.  
  It does seem obvious!*)
goal (theory "Product_Type")
    "(ALL x. F(x) & ~G(x) --> (EX y. H(x,y) & J(y))) &        \
\    (EX x. K(x) & F(x) & (ALL y. H(x,y) --> K(y)))  &        \
\    (ALL x. K(x) --> ~G(x))   -->   (EX x. K(x) --> ~G(x))";
by (Fast_tac 1);
result();

(*Attributed to Lewis Carroll by S. G. Pulman.  The first or last assumption
can be deleted.*)
Goal "(ALL x. honest(x) & industrious(x) --> healthy(x)) & \
\     ~ (EX x. grocer(x) & healthy(x)) & \
\     (ALL x. industrious(x) & grocer(x) --> honest(x)) & \
\     (ALL x. cyclist(x) --> industrious(x)) & \
\     (ALL x. ~healthy(x) & cyclist(x) --> ~honest(x))  \
\     --> (ALL x. grocer(x) --> ~cyclist(x))";
by (Blast_tac 1);
result();

goal (theory "Product_Type")
    "(ALL x y. R(x,y) | R(y,x)) &                \
\    (ALL x y. S(x,y) & S(y,x) --> x=y) &        \
\    (ALL x y. R(x,y) --> S(x,y))    -->   (ALL x y. S(x,y) --> R(x,y))";
by (Blast_tac 1);
result();



writeln"Reached end of file.";