The Hardest Logic Puzzle Ever

Carvings of the gods of Fu, Lu, and Shou; sourced from http://en.wikipedia.org/wiki/File:Mammoth_Ivory_Three_Star_Gods.JPGSome time ago I wrote a post about the well-known logic puzzle of The Traveller’s Paradox and attempted to derive and justify a solution using the formal methods of propositional calculus (zeroth order logic). I return today to another intriguing and somewhat challenging problem within the realm of mathematical logic, albeit with what I hope is a much clearer approach and argument.

Although “The Hardest Logic Puzzle Ever” is scarcely a logically verifiable statement, the puzzle does indeed have a reputation as a rather tricky logic puzzle (at least among those encountered by laymen) and in any case has a non-trivial solution. The problem has some notable names attached to it, having originally been published in The Harvard Review of Philosophy by the logician George Boolos, but originating with the popular mathematician Raymond Smullyan, and altered slightly by the late computer scientist and AI pioneer John McCarthy.

The puzzle is commonly stated as follows.

Three gods A, B, and C are called, in no particular order, True, False, and Random. True always speaks truly, False always speaks falsely, but whether Random speaks truly or falsely is a completely random matter. Your task is to determine the identities of A, B, and C by asking three yes-no questions; each question must be put to exactly one god. The gods understand English, but will answer all questions in their own language, in which the words for yes and no are da and ja, in some order. You do not know which word means which.

At first glance, the problem may appear insurmountable due to the behaviour of god C, yet when we notice that his behaviour is not truly random, but rather only his veracity is — he otherwise follows all rules of logic. Boolos clarified: “Whether Random speaks truly or not should be thought of as depending on the flip of a coin hidden in his brain: if the coin comes down heads, he speaks truly; if tails, falsely.”.

Encountering this puzzle for the first time just in the past week, I made an effort to solve it on my own using a formal approach, as much as possible. As it turns out, I had some success, and hence thought I might share my reasoning here in the form of an article.

Let us begin by setting up the puzzle in the standard language of propositional logic (that is, Boolean algebra). We first define our useful propositional variables and predicates, which are

  • R, whether the da response corresponds to yes (absolute truth). $R$ is thus true if da means yes and ja means no, and false if da means no and ja means yes;
  • T, whether a given god (we consider them independently) is telling the truth. Note, this has a well-defined value even for Random (god C), since the context is a specific question and corresponding response.
  • Q, the question (propositional predicate) that is asked to a given god.

Note that the latter two variables are semantically valid within only within individual questions. However, because we shall only utilise them within the context of question-response pairs, we need not concern ourselves with this.

There is a number of ways to convert the verbal problem statement into a set of formal logical expressions, but I shall adopt a fairly direct and unambiguous one here. We start by noting two simple facts regarding the truthfulness of a particular yes-no response A.

\begin{aligned}  T &\rightarrow (A \leftrightarrow Q) \\  \neg T &\rightarrow (A \leftrightarrow \neg Q) .  \end{aligned}

Note that the biconditional (\leftrightarrow) can be interpreted as material (syntactic) equality. This is precisely equivalent to the non-fundamental XNOR (\oplus) operator in propositional logic. With a bit of manipulation it can be shown that

A \leftrightarrow \neg (Q \oplus T) .

In other words, the yes-no of any response shall be the absolute (true) answer to the question XNOR whether one is asking a truth-teller.

We must then note the complication to the puzzle introduced by the fact we do not understand the language of the gods. ‘da’ could mean either yes or no and ‘ja’ conversely. To account for this, we can write two more statements specifically about the da-ja response (denoted B), which take virtually identical forms to before;

\begin{aligned}  R &\rightarrow (B \leftrightarrow A) \\  \neg R &\rightarrow (B \leftrightarrow \neg A) .  \end{aligned}

Unsurprisingly, this can be rewritten in the same way to use the XNOR operator;

B \leftrightarrow \neg (A \oplus R) .

Note that the value of B represents the actual response; that is, it is the single observable of the logical system we have constructured to represent the puzzle.

While we could restrict ourselves to the use of the primitive Boolean operators (AND, OR, and NOT), the use of the XOR operator here facilitates things considerably, due to its special properties (notably commutativity and associativity) and the simplicity it gives our theorems.

Now, combining the two expressions (theorems) for A and B (this can be seen easily by considering the biconditional as equality), we can factor out the negations and use associativity of the XOR operator to write

\begin{aligned}  B &\leftrightarrow \neg (\neg (Q \oplus T) \oplus R) \\  B &\leftrightarrow Q \oplus T \oplus R .  \end{aligned}

We now have an easily manageable form for the da-ja response of a given god. The question now becomes, how do we extract the absolute truth value of the response from this observable variable? Clearly, one has no control over the T and R variables, which are predetermined by god being asked the question (and possibly by the flip of a coin) as well as the language of the gods. However, we do have direct and full control over the question to ask, the predicate Q.

In order to extra meaningful (absolute) truth value we first note that any propositional variable XNOR itself is false, thus disappearing from its containing expression. Given that we wish to eliminate the variables T and R from the final expression, we can decompose the predicate Q; that is, give it an explicit form.

Let Q = Q' \oplus T \oplus R. Hence, we can say

\begin{aligned}  B &\leftrightarrow Q' \oplus T \oplus R \oplus T \oplus R  B &\leftrightarrow Q' \oplus (T \oplus T) \oplus (R \oplus R)  B &\leftrightarrow Q' .  \end{aligned}

At this point we almost have a solution to the puzzle. We have shown that one can obtain an accurate true-false response to any question we wish to ask any god. As long as we ask a question of the form Q, then a response (effectively to question Q') of ‘da’ always corresponds to truth and ‘ja’ always to falsehood.

There are a number of ways to use this to reveal the identities of the three gods. The simplest and most direct, I feel, is to ask gods A and B whether they are Random. This definitively indicates the Random god (since if both answer in the negative, then it must be god C by elimination). One can then simply ask either of the remaining gods (not Random) whether he is True, deducing the identities of the True and False gods in a single question. Hence, we have totally and provably solved the puzzle within the desired three questions.

The only task that now remains is to translate the formal solution, which we have stated as a set of predicates of form Q = Q' \oplus T \oplus R (in zeroth-order logic), into natural language. Since the first question to ask is invariably the most intricate, and the second or third must be conditional on previous answer(s) in some way, it makes sense only to consider the verbal representation of the first as an exercise.

George Boolos (the populariser of the puzzle) proposed asking the following initial question.

Does da mean yes iff you are True iff B is Random?

When we recall that iff (if and only if), i.e. the biconditional connective, is logically equivalent to the XNOR operator, it is quite straightforward to see that this is of the above proposed form for Q. (Note that a triple of formulas connected either by a pair of XOR or pair of XNOR operators form the equivalent expression.)

The Wikipedia entry for the logic puzzle gives only a slight variation on the above that is fully equivalent;

Are an odd number of the following statements true: you are False, da means yes, B is Random.

Start by considering how the operations X \oplus \top and X \oplus \bot change the truth value of X. The former clearly inverts the value, while the latter leaves it unchanged. In order words, each XOR with a formula that is true inverts the overall truth value. Hence, considering an arbitrary number of formulae XORed together, we must deduce that if an odd number of statements are true, then the entire expression must in fact be true (and conversely if an even number of statements are true then the entire expression is false).

We now come to a somewhat different form of verbal solution, first proposed by T. S. Roberts (Journal of Philosophical Logic, 2001);

If I asked you Q’, would you say ja?

(We do not assume for now that Q' is the same variable as used in the formal solution given above.)

A counterfactual may be thought of as a nested question; that is, an ‘if-then’ style of statement/predicate. Let us first consider the slightly simpler question: “If I asked you Q’, what would you answer?”. It should not be hard to see that this essential form of the counterfactual is equivalent to Q' \oplus T. The additional “would you say ja?” (as opposed to simply “what would you say?”) may be evaluated as a post-condition, equating Q' \oplus T to ja. Formally, we may infer

\begin{aligned}  Q' \oplus T = R ,\\  \neg ((Q' \oplus T) \oplus R) ,\\  Q' \oplus T \oplus \neg R .  \end{aligned}

Since \neg R represents “ja” under our labelling, this formula is clearly equivalent to the expression for Q reached at the end of the previous section. Hence by equating the separate expressions, the two Q' originally assumed to be independent are in fact rendered identical.

This concludes my article on The Hardest Logic Puzzle ever. I hope that I’ve given readers some appreciation for a formal (mathematical) solution to this intriguing puzzle, and indeed an insight into the equivalence of the various forms of solutions that one might posit from thinking about the problem holistically. No doubt, an exhaustive truth table would have proven the isomorphisms just as well, except that I felt they added little to overall understanding. If anyone has an additional alternative solution or general comments on the preceding, by all means please share via the comments section.

2 Responses to “The Hardest Logic Puzzle Ever”

  1. Noldorin says:

    For those who are so inclined, there has been some vaguely interesting discussion/comments on this post over at the Math sub-Reddit.

    http://www.reddit.com/r/math/comments/nwtcz/the_hardest_logic_puzzle_ever_an_excursion_into_a/

  2. [...] amusingly, my most popular post of the whole year was posted was only posted several of days from the end, while I was on [...]

RSS feed for comments on this post. And trackBack URL.

Leave a Reply