Lecture 5 Knights and Knaves

advertisement
Lecture 5 Knights and Knaves.
Show hand in form.
Show plagiarism form.
Any problems with coursework?
Google knight and knaves and look at picture.
Do you want problem sheets this afternoon or to work on coursework.
Deadline is now Monday 
The island of Knights and Knaves.
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.
1. Knights who always tell the truth
2. Knaves who always lie.
Logic puzzles are about deducing facts about the island, from statements made by the
people on the island. But of course, you do not know whether the statement was made by
a knight or a knave. I am a knight, I am a knave!!!!!
Some examples
What happens if you ask a person if they are a knight or a knave?
There may be gold on the island. What question could you ask to establish this?
A native says “there is gold on this island, is the same as, I am a knight”.
What question would you ask a pair of natives 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?
Algebra
At school we learnt to manipulate expressions. The values of expressions are numbers
n^2 –m^2 = (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 algebra
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.
Knights and knaves.
“A” is a native on the island.
And is therefore either a knight or a knave.
The statement “A is a knight” is either true or false.
The statement “the restaurant is to the left” 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. Draw the truth table. P65
Example
If A says “the restaurant is to the left” then
“A is a knight”=”the restaurant is to the left”
In words,
A is a knight and the restaurant is to the left, or,
A is not a knight and the restaurant is not to the left.
Yes No response
If a native A is asked a question Q, the response will be the truth value of A=Q.
The response will be “yes” if A is a knight and the answer is really yes. Or
A is a knave and the answer is really no.
Otherwise the response will be “no”.
Simple example p66
A is asked whether B is a knight. And
B is asked whether A is a knight.
A’s response is A=B
B’s response is B=A
Equality is symmetrical so the two responses will always be the same.
Note that this does not involve case analysis of the four cases (draw truth table)
5.2.3 Boolean Equality.
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
Finally x=y, then f(x) = f(y)
Equality is a binary relation.
It is a function with a range of Boolean values true and false.
Multiplication and addition are associative.
Multiplication and addition are symmetric.
Is equality associative?
The expression (p = q) = r does not make sense if p q r are numbers, characters,
sequences or objects. Only for Boolean values.
It makes sense to ask if equality of Boolean values is associative.
Associatively
((p = q) = r) = (p = (q = r))
Construct a truth table.
It is true if an odd number of atoms are true.
(p=p)=true and p= (p=true)
The 2nd is used for elimination.
Hidden treasures. Yes/No question
A native says “I am a knight equals there is gold on the island”
Let A represent “the native is a knight”
Let G represent “there is gold on the island”
The native’s statement is A=G so we deduce
A = (A = G)
{equality of Booleans is associative}
(A=A)=G
{(A=A) = true}
True = G
{Equality is symmetrical}
G=true
{G = (G=true)}
G
We conclude that there is gold on the island, but we cannot deduce if the native is a
knight or a knave.
What question to ask.
You are at a fork in the road, you want to know if the gold is to the left or the right.
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 requreimet is that L is the same are the response to Q.
i.e. we reqire L=(A=Q)
{but as equality is associative}
(L = A) = Q
So the question Q posed is L=A
Ie “is the value of ‘the gold can be found by following the left fork’ equal to the value of
‘you are a knight’”
Equals for Equals
There are three natives A B 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 section, 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, so the question to be posed is “is B a
knight”. Show the formal working from book p 69
Equivalence and continued Equalities
Do we understand x=y=z as
(x=y)=z or as x=(y=z)
The two reading are different, why? Do calculation on board p71
Explain subtle difference on board.
We pronounce this as equivales
Examples of the Associatively of Equivalence.
A beautiful example.
n + m is even equivales n is even equivales m is even
We refer to “is even” of a number as parity.
n + m is even equivales (n is even equivales m is even)
states n + m is even when the parities of m and n are the same.
(n + m is even equivales n is even) equivales m is even
States, the operation of adding a number n to a number m does not change the parity of m
exactly when n is even.
Another way to read the statement is see page 72.
This single statement avoids case analysis (four in this case).
Negation
Two natives A B
Native A says “B is a knight equals I am not a knight”
If A makes a statement S we know A=S, so we get A = (B=not A)
(B=not A) means B is a knight equals I am not a knight.
Negation
not p = p= false
Read as not p = (p = false)
Functions as a definition, i.e. what does not p mean, it means p is false.
Read as (not p = p) = false
Is useful for simplifying in expressions.
Go thru algebra on p75
Simplification
The law of negation, along with associative and symmetry gives us a way to simplify
expressions
Do e.g. on page 75.
Proof not false = true
Inequivalence. P80
A says “B is different from myself”.
Formulate as B not= A
Or as not (B=A)
This is the same as “B is a knight equals I am not a knight”
Show working p80
Inequivalence not(p=q)= p = not q
Show working p80
.
Download