Showing posts with label multiple solutions. Show all posts
Showing posts with label multiple solutions. Show all posts

Friday, May 31, 2019

[Part 11] Raymond Smullyan's Certified Knights and Knaves puzzles
A new puzzle



Here is a completely new puzzle that (as far as I know) isn't in any of Smullyan's or anybody else's books:
Every day on the island, I kept meeting natives and over time started to invent my own labels for them. For example, when two natives had a different type, i.e., knight versus knave, and a different certification status, i.e., certified versus uncertified (in any order), I thought of them as "full opposites".
One day, I met three natives A, B, and C. I knew nothing about A and B, and all I already knew about C (based on an earlier encounter) was that she was uncertified. During our brief encounter, A and B each made one statement that allowed me to infer that they were complete opposite of each other, but that neither one of them was a complete opposite of C. I was also able to infer that exactly one of my three interlocutors was a knave.
Which two statements would work? 
Can you solve this puzzle?

If so, can you find a "better" solution than mine?

How do you rank solutions anyway?

I can't wait to read your comments!


SPOILER: My answer appears below.



























Here is my solution:

A: "I am certified, C is a knight, but B and I are not both knights."
B: "Either A and I are knaves or else I am certified and C is a knight."

that I obtained by translating the following two formulas:

A <-> ((-A | -B) & (Ac & C))
B <-> ((-A & -B) | (Bc & C))

Thursday, May 30, 2019

[Part 10] Raymond Smullyan's Certified Knights and Knaves puzzles
Puzzle #6 - A new variant



Now that we have a JavaScript program to solve the following puzzle (see the last four posts):
On another particularly interesting occasion I came across two natives A and B each of whom made a statement such that I could infer that at least one of them must be an uncertified knight, but there was no way to tell which one it was. From neither statement alone could one have deduced this.
What two statements would work? [This problem is not easy!]
we can modify this program to solve a new puzzle, namely:
On another particularly interesting occasion I came across two natives A and B, only one of whom made a statement such that I could infer that at least one of them must be an uncertified knight, but there was no way to tell which one it was. From neither statement alone could one have deduced this.
What statement would work? [This problem is easy if you can program an automatic solver for it.]
So, can you modify our program (listed below) to solve this puzzle?
var     A = parseInt("0000000011111111",2);
var    Ac = parseInt("0000111100001111",2);
var     B = parseInt("0011001100110011",2);
var    Bc = parseInt("0101010101010101",2);
var onlyA = parseInt("0000000011010000",2);    
var onlyB = parseInt("0010001000000010",2);
var  both = parseInt("0000000000100000",2);
var  none = parseInt("1101110100001101",2);

function AND(x,y) { return x & y; };
function OR(x,y)  { return x | y; };
function XOR(x,y) { return x ^ y; };
function NOT(x)   { return ~x & 65535; };
function IFF(x,y) { return NOT( XOR(x,y) ); };

var literals = [A, Ac, B, Bc, NOT(A), NOT(Ac), NOT(B), NOT(Bc)];
var ops = [AND, OR];
var solutions = [];  // no solutions found yet

for(let pA1 of literals)
  for(let pA2 of literals) 
    for(let pB1 of literals) 
      for(let pB2 of literals) 
        if ((pA1 < pA2) && (pB1 < pB2)) 
          for(let opA of ops) 
            for(let opB of ops)
              check(pA1, opA, pA2, pB1, opB, pB2);

function check(pA1, opA, pA2, pB1, opB, pB2) {
    var phi = AND( IFF(A,opA(pA1,pA2)), IFF(B,opB(pB1,pB2)) );

    if (!(phi & none) && (phi & onlyA) && (phi & onlyB)) {
        // phi meets the requirements of a solution
        printAndSaveIfNewSolution(phi, pA1, opA, pA2, pB1, opB, pB2); 
    }
};

function printAndSaveIfNewSolution(phi, pA1, opA, pA2, pB1, opB, pB2) {
  if (! solutions.includes(phi)) {           // this is a new solution
    solutions.push(phi);                     // store it
    /* printing of the solution is omitted (see full code in Part 8) */
  }
};
In my solution, I assumed that the statement was made by A (say) and had the following structure:

\(A \leftrightarrow (\ (l_1\ op_2\ l_2)\  op_1\ (l_3\ op_3\ l_4)\ )\)

in which \(l_1\), \(l_2\), \(l_3\), and \(l_4\) are literals chosen from the same list as above and \(op_1\), \(op_2\), and \(op_3\) are logical operators chosen from the list:

ops = [AND, OR, XOR];

Note that I added XOR as a usable logical connective in this puzzle.

I hope that you'll have fun solving this puzzle!

For reference, here are the only three solutions that my program found:

Solution #1 
 A <-> ( (A & Ac) ^ (Bc | -B) )  

Solution #2 
 A <-> ( (B & -Bc) | (-A | -Ac) ) 

Solution #3 
 A <-> ( (Bc | -B) & (-A | -Ac) )

I think that the second solution is easiest to state concisely in English, namely:

A: "B is an uncertified knight or I am not a certified knight."

This solution is easy to check informally:
  • If A is a knight:
    • A's statement must be true. Therefore, either B is an uncertified knight or A is (since A is a knight but not a certified one), or both.
  • If A is a knave:
    • A's statement must be false. Therefore, both disjuncts must be false, including the second one, which implies that A must be a certified knight, which contradicts this case's assumption (i.e., A is a knave).
Therefore, in this solution, A must be a knight, but we do not know whether or not A is certified. However, if A is certified, then B must be an uncertified knight. So both A and B could be uncertified knights.

We can also check this solution formally with a truth table:

\(A\)\(Ac\)\(B\)\(Bc\)\(B\ \&\ {-Bc}\)\({-A}\ |\ {-Ac}\)\((B\ \&\ {-Bc})\ |\ ({-A}\ |\ {-Ac})\)Sol. #2
\(F\) \(F\) \(F\) \(F\) \(F\) \(T\) \(T\)
\(F\) \(F\) \(F\) \(T\) \(F\) \(T\) \(T\)
\(F\) \(F\) \(T\) \(F\) \(T\)\(T\) \(T\)
 only B
\(F\) \(F\) \(T\) \(T\) \(F\) \(T\) \(T\)
\(F\) \(T\) \(F\) \(F\) \(F\) \(T\) \(T\)
\(F\) \(T\) \(F\) \(T\) \(F\) \(T\) \(T\)
\(F\) \(T\) \(T\) \(F\) \(T\) \(T\) \(T\)
 only B
\(F\) \(T\) \(T\) \(T\) \(F\) \(T\) \(T\)
\(T\) \(F\) \(F\) \(F\) \(F\) \(T\) \(T\)  only A
\(T\) \(F\) \(F\) \(T\) \(F\) \(T\) \(T\)  only A
\(T\) \(F\) \(T\) \(F\) \(T\) \(T\) \(T\)  both A and B
\(T\) \(F\) \(T\) \(T\) \(F\) \(T\) \(T\)  only A
\(T\) \(T\) \(F\) \(F\) \(F\) \(F\) \(F\)
\(T\) \(T\) \(F\) \(T\) \(F\) \(F\) \(F\)
\(T\) \(T\) \(T\) \(F\) \(T\) \(F\) \(T\)  only B
\(T\) \(T\) \(T\) \(T\) \(F\) \(F\) \(F\)

Can you check the other two solutions for correctness?

Can you translate them into English?

Wednesday, May 29, 2019

[Part 9] Raymond Smullyan's Certified Knights and Knaves puzzles
Puzzle #6 - (At least) nine distinct solutions



Recall our sixth puzzle:
On another particularly interesting occasion I came across two natives A and B each of whom made a statement such that I could infer that at least one of them must be an uncertified knight, but there was no way to tell which one it was. From neither statement alone could one have deduced this.
What two statements would work? [This problem is not easy!]
and the nine solutions that our JavaScript program found:

Solution #1            Solution #4           Solution #7 
 A <-> (A | Bc)         A <-> (B | -A)        A <-> (-Bc | -A)
 B <-> (-B | -Ac)       B <-> (-Bc | -Ac)     B <-> (A & Ac) 

Solution #2            Solution #5           Solution #8
 A <-> (Ac | Bc)        A <-> (B | -Ac)       A <-> (-Bc | -A)
 B <-> (-B | -Ac)       B <-> (-Bc | -A)      B <-> (Ac | B)

Solution #3            Solution #6           Solution #9
 A <-> (B & Bc)         A <-> (-B | -Ac)      A <-> (-Bc | -B)
 B <-> (-Ac | -A)       B <-> (A | -Bc)       B <-> (A & Ac)

Solution #3 is the one that Smullyan discusses for this puzzle on page 45 of his book, namely:

 A: "B is a certified knight."
 B: "A is not a certified knight."

Note that B's statement can be more directly translated into propositional logic as:

B <-> -(Ac & A)

which, by De Morgan's law, is equivalent to the formula output by our program, namely:

B <-> (-Ac | -A)

Note that Solution #9 is equivalent to Solution #3 if we switch the names of the two natives.

These two solutions are the only ones in which each native only talks about the other native.

In Solution #7, B only talks about A but A describes both natives:

 A: "Either I am a knave or B is uncertified."
 B: "A is a certified knight."

In all other solutions, each native refers to both of them.

When translating these solution formulas into English statements, we can vary the grammatical structure using the following logical equivalences:
  1. "-x | -y" is equivalent to "-(x & y)"
  2. "-x | y" is equivalent to "x -> y"
  3. "x | y" is equivalent to "--x | y" is equivalent to "-x -> y"
B's statement in Solution #3 discussed above is an example of the first equivalence.

We can use the second equivalence to translate A's statement in Solution #4:

 A: "If I am a knight, then so is B."
 B: "At least one of us is uncertified."

Note that we used the commutativity of disjunction when translating A's statement.

We can use the third equivalence to translate A's statement in Solution #1:

 A: "If I am a knave, then B is certified."
 B: "If I am a knight then A is uncertified."

To conclude this discussion, it is worth emphasizing that all of these solutions are logically distinct.

Recall that each solution (i.e., each formula \(\varphi\)), is encoded by an integer (see the JavaScript program that we discussed earlier) and that the program removes duplicates.

This means that, in addition to the many ways to express them in grammatically correct English, these solutions ALL describe different scenarios.

This can be demonstrated easily by building a truth table for all of these solutions:

\(A\)\(Ac\)\(B\)\(Bc\)\(S1\)\(S2\)\(S3\)\(S4\)\(S5\)\(S6\)\(S7\)\(S8\)\(S9\)
\(F\)\(F\)\(F\)\(F\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(F\)\(F\)\(F\)\(T\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(F\)\(F\)\(T\)\(F\)\(\)\(\)\(\)\(\)\(\)\(\) only B
\(F\)\(F\)\(T\)\(T\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(F\)\(T\)\(F\)\(F\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(F\)\(T\)\(F\)\(T\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(F\)\(T\)\(T\)\(F\)\(\)\(\)\(\)\(\)\(\)\(\)\(\) only B
\(F\)\(T\)\(T\)\(T\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(T\)\(F\)\(F\)\(F\)\(\)\(\)\(\)\(\)\(\)\(\) only A
\(T\)\(F\)\(F\)\(T\)\(\)\(\)\(\)\(\)\(\)\(\)\(\) only A
\(T\)\(F\)\(T\)\(F\)\(\)\(\)\(\)\(\) both A and B
\(T\)\(F\)\(T\)\(T\)\(\)\(\)\(\)\(\) only A
\(T\)\(T\)\(F\)\(F\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(T\)\(T\)\(F\)\(T\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)
\(T\)\(T\)\(T\)\(F\)\(\)\(\)\(\)\(\) only B
\(T\)\(T\)\(T\)\(T\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)\(\)

In the table above, in each solution column, I used a checkmark instead of a True value and omitted the False values in order to make the relevant cases easier to pick out.

It is now easy to check that no two solutions pick out the same scenario.

For example, solutions 1, 4, 5, 6, and 8 make it possible for both natives to be uncertified knights, but none of the other solutions do.

Even solutions that allow exactly one native to be an uncertified knight are all distinct:
  • In Solution 2, the "other one" is either an uncertified knave (A) or a certified knight (B).
  • Solution 3 differs from solution 2 in that it allows for an extra possibility, namely for the other one (A) to be a certified knave.
  • Solution 7 only allows for two possibilities that are different from the ones in Solution 2.
  • Solution 9 allow for three possibilities that do not overlap with those in Solution 3.
Finally, there is one aspect of the puzzle that we have not discussed yet, namely, the condition that:

"From neither statement alone could one have deduced this."

Homework:
  • Do all nine solutions above satisfy this extra requirement?
  • Can you modify our program to check this automatically?