Lecture 5 Knights and Knaves.

advertisement
AE1APS Algorithmic Problem Solving
John Drake




The island of Knights and Knaves is a fictional
island to test peoples’ ability to reason
logically.
There are two types of people on the island.
Knights who always tell the truth
Knaves who always lie.

Logic puzzles are about deducing facts about
the island, from statements made by the
people on the island. But you do not know
whether the statement was made by a knight
or a knave.

What happens if you ask a person if they are
a knight or a knave?
I’m a
Knight

I’m a
Knight
There may be gold on the island. What
question could you ask to establish this?







At school we learnt to manipulate
expressions. The values of expressions are
numbers
n2 –m2 = (n + m)(n - m)
To do this we use laws.
e.g. n + 0 = n and n – n = 0 (for ANY values
of n)
Associatively of addition
(m + n) +p = m + (n + p)
I am sure you are all familiar with laws
regarding addition, multiplication.





Boolean expressions are either true or false.
Boolean valued expressions are called
propositions.
“it is sunny” is an atomic Boolean expression.
“it is sunny and warm” is non atomic as it can
be broken down into two expressions.
We are concerned with the rules for
manipulating Boolean expressions.








Equality is a binary relation.
It is a function with a range of Boolean values
true and false.
Equality is reflexive: [x ≡ x]
It is symmetric: [x ≡ y is the same as y ≡ x]
It is transitive: [x ≡ y and y ≡ z implies z ≡ x]
If x ≡ y, then f(x) ≡ f(y)
It is associative: [(x ≡ y) ≡ z is the same as
x ≡ (y ≡ z) ]
It is substitutive [x ≡ (y ≡ z) can be replaced by
(y ≡ z) ≡ (y ≡ z) ]







“A” is a native on the island.
Therefore A is either a knight or a knave.
The statement “A is a knight” is either true or
false.
The statement “there is gold on the island” is
either true or false.
Suppose “A is a knight”, and suppose A makes
statement S.
The crucial observation is that the values of these
two propositions are the same.
Then “A is a knight” ≡ S

Suppose A is the proposition “person A is a
knight" and suppose A makes a statement S.
We can infer that A is true is the same as S is
true. That is,
 A≡S



If A says “I am a knight” then all we can infer
from the statement is A ≡ A. Not much use!
Similarly, it cannot be that a native says “I am
a knave” because we would then conclude
A ≡ ¬A which is always false.
If A says “I am the same type as B". We infer
that A ≡ (A ≡ B) which simplifies to B.
¬ Boolean symbol for negation (i.e. NOT A)



A native says “there is gold on this island, is
the same as, I am a knight”.
Let G denote the proposition “There is gold
on the island". A's statement is A ≡ G. So
what we are given is:
A≡A≡G
This simplifies to G. So we deduce that there
is gold on the island but it is not possible to
tell whether A is a knight or a knave.



If A is a knight, he will always tell the truth so
we will know there is gold on the island.
If A is a knave he will always lie so when
asked if A ≡ G (i.e. Are the answers to “Are
you a knight?” and “Is there gold on the
island?” the same), he will answer true when
there is gold on the island and false if not.
If not clear will go through case analysis
using truth tables

Given a pair of natives, what question would
you ask to discover if the other one is a
knight?

A tourist comes to a fork in a road, one way
leads to a restaurant, the other does not.
What question (yes/no) would you ask a
native to find out which way it is to the
restaurant?

Let Q be the question to be posed.

The response to the question will be A ≡ Q


Let L denote, “the gold can be found by
following the left fork”
The requirement is that L is the same as the
response to Q. i.e. we require L ≡ (A ≡ Q)




{but as equality is associative}
(L ≡ A) ≡ Q
So the question Q posed is L ≡ A
i.e. “is the value of ‘the restaurant can be
found by following the right fork’ equal to the
value of ‘you are a knight’”

There are three natives A, B and C.

C says “A and B are both the same type”

Formulate a question, that when posed to A
determines if C is telling the truth.






Let A be the statement “A is a knight”.
Let Q be the unknown question.
The response we want is C
(i.e. if C is true then C is a knight).
By the previous example, Q ≡ (A ≡ C) i.e. we
replace L by C.
C’s statement is A ≡ B, so now we know
C ≡ (A ≡ B) by equality.
So Q ≡ (A ≡ (A ≡ B)) which simplifies to Q ≡ B,
Therefore the question to be posed is “is B a
knight?”

Never trust a knave

Equality is reflexive, symmetric, transitive, substitutive
and associative – know these!

More knights and knaves on Thursday

Coursework 1, 2 and 3 now online, deadline for
Coursework 3 is Thursday 15th November at 1pm



http://www.cs.nott.ac.uk/~jqd/AE1APS-1213/
John.drake@nottingham.edu.cn
http://en.wikipedia.org/wiki/Knights_and_Knaves
Download