# Theory Hard_Quantifiers

```(*  Title:      Sequents/LK/Hard_Quantifiers.thy
Author:     Lawrence C Paulson, Cambridge University Computer Laboratory

Hard examples with quantifiers.  Can be read to test the LK system.
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.

Uses pc_tac rather than fast_tac when the former is significantly faster.
*)

theory Hard_Quantifiers
imports "../LK"
begin

lemma "⊢ (∀x. P(x) ∧ Q(x)) ⟷ (∀x. P(x)) ∧ (∀x. Q(x))"
by fast

lemma "⊢ (∃x. P ⟶ Q(x)) ⟷ (P ⟶ (∃x. Q(x)))"
by fast

lemma "⊢ (∃x. P(x) ⟶ Q) ⟷ (∀x. P(x)) ⟶ Q"
by fast

lemma "⊢ (∀x. P(x)) ∨ Q ⟷ (∀x. P(x) ∨ Q)"
by fast

text "Problems requiring quantifier duplication"

(*Not provable by fast: needs multiple instantiation of ∀*)
lemma "⊢ (∀x. P(x) ⟶ P(f(x))) ∧ P(d) ⟶ P(f(f(f(d))))"
by best_dup

(*Needs double instantiation of the quantifier*)
lemma "⊢ ∃x. P(x) ⟶ P(a) ∧ P(b)"
by fast_dup

lemma "⊢ ∃z. P(z) ⟶ (∀x. P(x))"
by best_dup

text "Hard examples with quantifiers"

text "Problem 18"
lemma "⊢ ∃y. ∀x. P(y)⟶P(x)"
by best_dup

text "Problem 19"
lemma "⊢ ∃x. ∀y z. (P(y)⟶Q(z)) ⟶ (P(x)⟶Q(x))"
by best_dup

text "Problem 20"
lemma "⊢ (∀x y. ∃z. ∀w. (P(x) ∧ Q(y)⟶R(z) ∧ S(w)))
⟶ (∃x y. P(x) ∧ Q(y)) ⟶ (∃z. R(z))"
by fast

text "Problem 21"
lemma "⊢ (∃x. P ⟶ Q(x)) ∧ (∃x. Q(x) ⟶ P) ⟶ (∃x. P ⟷ Q(x))"
by best_dup

text "Problem 22"
lemma "⊢ (∀x. P ⟷ Q(x)) ⟶ (P ⟷ (∀x. Q(x)))"
by fast

text "Problem 23"
lemma "⊢ (∀x. P ∨ Q(x)) ⟷ (P ∨ (∀x. Q(x)))"
by best

text "Problem 24"
lemma "⊢ ¬ (∃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 pc

text "Problem 25"
lemma "⊢ (∃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 best

text "Problem 26"
lemma "⊢ ((∃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 pc

text "Problem 27"
lemma "⊢ (∃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 pc

text "Problem 28.  AMENDED"
lemma "⊢ (∀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 pc

text "Problem 29.  Essentially the same as Principia Mathematica *11.71"
lemma "⊢ (∃x. P(x)) ∧ (∃y. Q(y))
⟶ ((∀x. P(x) ⟶ R(x)) ∧ (∀y. Q(y) ⟶ S(y)) ⟷
(∀x y. P(x) ∧ Q(y) ⟶ R(x) ∧ S(y)))"
by pc

text "Problem 30"
lemma "⊢ (∀x. P(x) ∨ Q(x) ⟶ ¬ R(x)) ∧
(∀x. (Q(x) ⟶ ¬ S(x)) ⟶ P(x) ∧ R(x))
⟶ (∀x. S(x))"
by fast

text "Problem 31"
lemma "⊢ ¬ (∃x. P(x) ∧ (Q(x) ∨ R(x))) ∧
(∃x. L(x) ∧ P(x)) ∧
(∀x. ¬ R(x) ⟶ M(x))
⟶ (∃x. L(x) ∧ M(x))"
by fast

text "Problem 32"
lemma "⊢ (∀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 best

text "Problem 33"
lemma "⊢ (∀x. P(a) ∧ (P(x) ⟶ P(b)) ⟶ P(c)) ⟷
(∀x. (¬ P(a) ∨ P(x) ∨ P(c)) ∧ (¬ P(a) ∨ ¬ P(b) ∨ P(c)))"
by fast

text "Problem 34  AMENDED (TWICE!!)"
(*Andrews's challenge*)
lemma "⊢ ((∃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 best_dup

text "Problem 35"
lemma "⊢ ∃x y. P(x,y) ⟶ (∀u v. P(u,v))"
by best_dup

text "Problem 36"
lemma "⊢ (∀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 fast

text "Problem 37"
lemma "⊢ (∀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 pc

text "Problem 38"
lemma "⊢ (∀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 pc

text "Problem 39"
lemma "⊢ ¬ (∃x. ∀y. F(y,x) ⟷ ¬ F(y,y))"
by fast

text "Problem 40.  AMENDED"
lemma "⊢ (∃y. ∀x. F(x,y) ⟷ F(x,x)) ⟶
¬ (∀x. ∃y. ∀z. F(z,y) ⟷ ¬ F(z,x))"
by fast

text "Problem 41"
lemma "⊢ (∀z. ∃y. ∀x. f(x,y) ⟷ f(x,z) ∧ ¬ f(x,x))
⟶ ¬ (∃z. ∀x. f(x,z))"
by fast

text "Problem 42"
lemma "⊢ ¬ (∃y. ∀x. p(x,y) ⟷ ¬ (∃z. p(x,z) ∧ p(z,x)))"
oops

text "Problem 43"
lemma "⊢ (∀x. ∀y. q(x,y) ⟷ (∀z. p(z,x) ⟷ p(z,y)))
⟶ (∀x. (∀y. q(x,y) ⟷ q(y,x)))"
oops

text "Problem 44"
lemma "⊢ (∀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 fast

text "Problem 45"
lemma "⊢ (∀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 best

text "Problems (mainly) involving equality or functions"

text "Problem 48"
lemma "⊢ (a = b ∨ c = d) ∧ (a = c ∨ b = d) ⟶ a = d ∨ b = c"

text "Problem 50"
lemma "⊢ (∀x. P(a,x) ∨ (∀y. P(x,y))) ⟶ (∃x. ∀y. P(x,y))"
by best_dup

text "Problem 51"
lemma "⊢ (∃z w. ∀x y. P(x,y) ⟷ (x = z ∧ y = w)) ⟶
(∃z. ∀x. ∃w. (∀y. P(x,y) ⟷ y = w) ⟷ x = z)"

text "Problem 52"  (*Almost the same as 51. *)
lemma "⊢ (∃z w. ∀x y. P(x,y) ⟷ (x = z ∧ y = w)) ⟶
(∃w. ∀y. ∃z. (∀x. P(x,y) ⟷ x = z) ⟷ y = w)"

text "Problem 56"
lemma "⊢ (∀x.(∃y. P(y) ∧ x = f(y)) ⟶ P(x)) ⟷ (∀x. P(x) ⟶ P(f(x)))"
(*requires tricker to orient the equality properly*)

text "Problem 57"
lemma "⊢ 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 fast

text "Problem 58!"
lemma "⊢ (∀x y. f(x) = g(y)) ⟶ (∀x y. f(f(x)) = f(g(y)))"

text "Problem 59"
(*Unification works poorly here -- the abstraction %sobj prevents efficient
operation of the occurs check*)
lemma "⊢ (∀x. P(x) ⟷ ¬ P(f(x))) ⟶ (∃x. P(x) ∧ ¬ P(f(x)))"
using [[unify_trace_bound = 50]]
by best_dup

text "Problem 60"
lemma "⊢ ∀x. P(x,f(x)) ⟷ (∃y. (∀z. P(z,y) ⟶ P(z,f(x))) ∧ P(x,y))"
by fast

text "Problem 62 as corrected in JAR 18 (1997), page 135"
lemma "⊢ (∀x. p(a) ∧ (p(x) ⟶ p(f(x))) ⟶ p(f(f(x)))) ⟷
(∀x. (¬ p(a) ∨ p(x) ∨ p(f(f(x)))) ∧
(¬ p(a) ∨ ¬ p(f(x)) ∨ p(f(f(x)))))"
by fast

(*18 June 92: loaded in 372 secs*)
(*19 June 92: loaded in 166 secs except #34, using repeat_goal_tac*)
(*29 June 92: loaded in 370 secs*)
(*18 September 2005: loaded in 1.809 secs*)

end
```