A Method To Solve The Puzzles of Knights and Knaves
A Method To Solve The Puzzles of Knights and Knaves
Knaves ∗
†
L. Aszalós
Abstract
In his book ”What is the name of this book?” Raymond M. Smullyan
used a lot of puzzles to illustrate the background of the Gödel incompleteness
theorem. These puzzles became popular and nowadays are being published in
amusement magazines, too. In each section of the book different conditions
are met. In the best known type of puzzles we have only two types of people,
knights and knaves. Knights always tell the truth and knaves always lie.
We describe a method to formulate this kind of puzzles, then we prove
the soundness and the completeness of this logic. At the end we give Prolog
programs for solving the puzzles.
1
2 L. Aszalós
• > ∈ F and ⊥ ∈ F.
• S ⊂ F,
• If A ∈ F, then ¬A ∈ F.
• If x ∈ P then Tx ∈ F, Fx ∈ F and Nx ∈ F.
• If x ∈ P and B ∈ F, then Sx B ∈ F.
The valuation ϑ assigns a truth value to every formula. If the formula A is true
in a valuation ϑ, this is denoted by ϑ |= A. The properties of the islanders can be
coded into the valuation: Let ϑS ⊂ S (ϑS is the set of true atomic statements),
ϑT : P → {t, f, n} (ϑT is the classification of islanders). ϑ = hϑS , ϑT i is a valuation
over F if:
A formula A is valid if for every valuation ϑ ϑ|= A and it is satisfiable if there exists
a valuation ϑ such that ϑ|= A.
We shall use analytic tableaux [1, pp. 20-21] to check the provability of formulae.
We shall use the notation and definitions of this book, but 1) in the nodes (except
the root) we allow not only a formula but the set of formulae, 2) we need rules
about can say:
Sx B ¬Sx B
Tx ¬Tx ¬Tx Tx ¬Tx
¬Fx Fx ¬Fx and ¬Fx Fx
¬Nx ¬Nx Nx ¬Nx ¬Nx
B ¬B ¬B B
2 Soundness
First we prove that our proving tool, the tableaux method is correct, that is, if we
can prove a formula using it, then the formula is valid.
• If A is a ¬Sx B type formula, then by ϑ6|= Sx B we know that ϑ|= Fx and ϑ|= B
or ϑ |= Tx and ϑ |= ¬B. In the first case ϑ |= ¬Tx and ϑ |= ¬Nx , in the second
case ϑ|= ¬Fx and ϑ|= ¬Nx by definition of ϑT , so one of the new paths is open,
too.
4 L. Aszalós
Now a closed tableaux Υ cannot be true under any interpolation, so the origin of
any closed tableaux must be unsatisfiable. From this follows that every formula
provable by the tableaux method must be valid. 2
3 Completeness
In this section we want to show that any valid formula is provable, so the method
is complete. For this purpose we shall introduce a function that assigns a natural
number to every formula. This number represents a measure of complexity of the
formula. In the inductive proof below we use these numbers. The degree of a
formula is defined as follows
The Hintikka set is a usual tool to show the completeness of a logic. Our logic is
more complicated than the propositional logic, so the following definition contains
four new items. The set of formulae U is a Hintikka set if the following holds:
H1 If α ∈ U, then α1 ∈ U and α2 ∈ U.
H2 If β ∈ U, then β1 ∈ U or β2 ∈ U.
H4 If x ∈ P then not all of ¬Tx , ¬Fx and ¬Nx are the members of U
H6 If ¬Sx B ∈ U, then {¬Tx , Fx , ¬Nx , A} or {Tx , ¬Fx , ¬Nx , ¬A} is the subset of
the set of formulae U.
Proof. Let U is a Hintikka set. We make a suitable ϑ, in which all the members
of U are true. Let ϑS be the set of all predicate letters which are in U.
The theorem above claims that our logic is complete. If we have a valid formula
A, then we can construct a tableaux for ¬A. This formula is unsatisfiable, so its
tableaux is closed.
do not need Nx , we have only two types of inhabitants, hence we need a different
ϑT : P → {t, f } and one item of the definition of the valuation is changed: ϑ|= Sx B
iff (ϑ|= Tx and ϑ|= B) or (ϑ|= Fx and ϑ6|= B). The rules for can say are the following:
Sx B ¬Sx B
Tx ¬Tx Tx ¬Tx
and
¬Fx Fx ¬Fx Fx
B ¬B ¬B B
The lemmas and theorems are the same as before, but the definition of the Hintikka
set is changed due the changes in preconditions. We leave to the reader to rewrite
and check the definitions and proofs.
Figure 1.
The puzzle 44 of [2] states that on Island of Bahava Mr. A said that his wife is
not a normal. Mrs. A said that her husband is not a normal. We are proving that
both of them are normals on Fig. 2.
Figure 2.
8 L. Aszalós
The canBeTrue and the canBeFalse are two predicates to test whether there is
a valuation in which the formula in the argument is true/false. For the predicate
logic the following code is well-known [3, Program 3.31]:
canBeTrue(true) :- !.
canBeTrue(~ X) :- canBeFalse(X).
canBeTrue(X -> Y) :- canBeFalse(X); canBeTrue(Y).
canBeTrue(X \/ Y) :- canBeTrue(X); canBeTrue(Y).
canBeTrue(X /\ Y) :- canBeTrue(X), canBeTrue(Y).
canBeTrue(X === Y) :-(canBeTrue(X), canBeTrue(Y));
(canBeFalse(X), canBeFalse(Y)).
canBeFalse(false) :- !.
canBeFalse(~ X) :- canBeTrue(X).
canBeFalse(X -> Y) :- canBeTrue(X), canBeFalse(Y).
canBeFalse(X \/ Y) :- canBeFalse(X), canBeFalse(Y).
canBeFalse(X /\ Y) :- canBeFalse(X); canBeFalse(Y).
canBeFalse(X === Y) :-(canBeTrue(X), canBeFalse(Y));
(canBeFalse(X), canBeTrue(Y)).
canBeTrue(knight(knight)).
canBeTrue(knave( knave) ).
canBeTrue(normal(normal)).
canBeFalse( knight(knave) ).
canBeFalse( knave(knight) ).
canBeFalse( knight(normal) ).
canBeFalse( knave(normal) ).
canBeFalse( normal(knight)).
canBeFalse( normal(knave)).
canBeTrue(knight s X) :- canBeTrue(X).
canBeTrue(knave s X) :- canBeFalse(X).
canBeTrue(normal s _).
canBeFalse(knight s X) :- canBeFalse(X).
canBeFalse(knave s X) :- canBeTrue(X).
If we want to check the validity of the formula of the puzzle then we can ask the
following:
In the program above we cheated. For the sake of simplicity we have used the
first-order predicates of Prolog. We could substitute the Horn-fact KnightA for
the predicate knight(A), and consistently in the others cases to obtain the same
program as our tableaux method, but this has no effect on the results.
7 Conclusion
We have shown a method to formulate Smullyan’s puzzles. We have proved sound-
ness and completeness of several logics of puzzles, in meantime we introduced some
new types of puzzles that do not occur in [2]. We have shown a Prolog program
that automatizes the solution of puzzles. This program can be easily improved to
be suitable for other types of puzzles, too.
10 L. Aszalós
8 Acknowledgements
I would like to express my thanks to K. Pásztor-Varga for her many helpful criti-
cisms during the preparation of this paper. I would like to thank late A. Kron for
his help, and for trying valiantly to make this a more readable paper.
References
[1] Raymond M. Smullyan. First-order logic. Springer-Verlag New York, Inc., New
York, 1968. Ergebnisse der Mathematik und ihrer Grenzgebiete, Band 43.
[2] Raymond M. Smullyan. What is the Name of This Book? (The Riddle of
Dracula and Other Logical Puzzles). Prentice-Hall Inc., 1978.
[3] L. Sterling and E. Shapiro. The Art of Prolog. MIT Press., 1986.
[4] L. Wos, R. Overbeek, E. Lusk and J. Boyle. Automated Reasoning: Introduction
and Applications. McGraw-Hill., 1992.