12/24/2021
Overview
• Basic Notations and Operators
CSIT113 • Reasoning using Logic
Problem Solving • Apply basic to solve logic puzzle
UNIT 3
REASONING USING LOGIC
1 2
1
Some introductory logic Logical Operators
• Logic dates back to ancient Greece.
• Logical operators combine one or two propositions to produce a new
• There are several different ways of looking at logic but all have a proposition. Such a proposition is also called a compound
common set of concepts. proposition.
• Propositions: • after introducing the truth table, we shall study the basic logical
• Statements which are either True or False operators, ~, Ʌ, ∨, and ≡,
• Axioms:
• Propositions which are True by definition
• Theorems:
• Propositions which can be proved to be True
• Universal Set:
• The set of elements or objectors that propositions refer to
3 4
12/24/2021
Truth tables Not (~)
• The Not operator operates on a single proposition.
• A useful tool in understanding logic is the truth table.
• For a proposition P, Not P is written as P. It’s truth value is the reverse
• This sets out all possible results of propositions in tabular form of the truth value of P.
• The definitions of logical operators (~, Ʌ, ∨, , ≡) are often presented in
truth tables. P ~P
T F
F T
5 6
And (Ʌ) Or (∨)
• The And operator combines two propositions, P and Q. • The Or operator combines two propositions, P and Q.
P Q PɅQ
T T T P Q P∨Q
T F F T T T
F T F T F T
F F F F T T
F F F
• And is true only if both P and Q are true • Or is true as long as at least one of P or Q is true
7 8
12/24/2021
Properties of logical Or
Equivalence (≡) • Commutative: p ∨ q ≡ q ∨ p
• The Equivalence operator combines two propositions, P and Q. • Associative: p ∨ ( q ∨ r) ≡ (p ∨ q) ∨ r
• Idempotent: p ∨ p ≡ p
• Has neutral element false: p ∨ false ≡ p
P Q P≡Q
T T T • Distributes over boolean equality:
T F F p ∨ ( q ≡ r) ≡ ((p ∨ q) ≡ (p ∨ r))
F T F
All the equivalence relations can be proved by constructing a truth table, e.g. The
F F T
following truth table shows the first relation:
p q p∨q q∨p
T T T T Since for each case, the values
• Equivalence is true if P and Q have the same truth value of p∨q and q∨p are identical.
T F T T
F T T T Hence,
F F F F p∨q ≡q∨p
9 10
Properties of logical And Implies ()
• The Implies operator combines two propositions, P and Q.
• Commutative: p Ʌ q ≡ q Ʌ p
• Associative: p Ʌ ( q Ʌ r) ≡ (p Ʌ q) Ʌ r
P Q PQ
• Idempotent: p Ʌ p ≡ p T T T
• Has neutral element true: p Ʌ true ≡ p T F F
F T T
F F T
• Implies is true unless P is true and Q is false
11 12
12/24/2021
Order for Evaluating Logical Connectives Some useful formulæ
Order Logical Connective • Inverse Laws:
P ~ P T
1 P~ P F
• Implies (if-then )
2 , P Q ≡ ~P ∨ Q
3 , • De Morgan’s laws
~(p ∨ q) ≡ ~p Ʌ ~q
~(p Ʌ q) ≡ ~p ∨ ~q
Compound statements in brackets must be evaluated first: from
inner to outer. Then, evaluate . Next, evaluate and . Last, • We can show all of these with truth tables.
last, evaluate and .
13
14
Q
Simplifying Logic
Testing propositions using Truth table • We can express all possible logical operators in terms of just two operators:
• We can use truth tables to test propositions to determine whether they • Not and And
are theorems. • Not and Or
• E.g. P (Q P) • P ∨ Q ≡ ~(~P Ʌ ~Q)
P Q QP P (Q P) P Q PQ ~P ~Q ~P Ʌ ~Q ~(~P Ʌ ~Q)
T T T T T T T F F F T
T F T T T F T F T F T
F T F T F T T T F F T
F F T T F F F T T T F
• Because the last column is all true, P (Q P) is a theorem • As the columns for P ∨ Q and ~(~P Ʌ ~Q) have identical values, hence, P ∨
Q ≡ ~(~P Ʌ ~Q)
15 16
12/24/2021
Q Q
Even simpler Nor
• ~P ≡ P nor P
• The two operators Nor and Nand make life even easier… • P Ʌ Q ≡ ~P nor ~Q
≡ (P nor P) nor (Q nor Q)
P Q P nor Q P Q P nand Q
T T F T T F
• P ∨ Q ≡ ~(P nor Q)
T F F T F T ≡ (P nor Q) nor (P nor Q)
F T F F T T
F F T F F T
• Either of these can produce all operators on its own…
17 18
Knights and Knaves Brute Force
• Every inhabitant of a mythical island is either a knight or a knave. • It is tempting to try to solve these problems by looking at all possible
cases (using truth table).
• Knights always tell the truth.
• The problems here are:
• Knaves always lie.
• the number of cases rapidly becomes too large
• This forms the basis of several problems in logic puzzle. • the answer is often still not clear
• Perhaps there is a better technique.
• One approach is Calculational Logic
19 20
12/24/2021
Calculational Logic Boolean Equivalence
• The basis of calculational logic is to calculate with Boolean • The Boolean equivalence relation satisfies a number of
expressions. properties:
• These expression, called propositions, are either true or false. • Reflexive: p ≡ p
• This method is less tedious than using truth table. • Symmetric: (p ≡ q) ≡ (q ≡ p).
• Transitive: if p ≡ q and q ≡ r then p ≡ r.
• In using calculational logic, we may need:
• Associative: (p ≡ (q ≡ r)) ≡ ((p ≡ q) ≡ r)
the basic Boolean equivalence and formalism introduced in the next
few slides, and • Substitution of equals for equals:
if p ≡ q and f is a Boolean function then f(p) ≡ f(q).
the formulae introduced earlier (for example, the formula for
associate and implies, and De Morgan’s laws, etc.).
21 22
Knights and Knaves Knights and Knaves
• If A is a native of the island the statement “A is a knight” is either true or • So if A says “the restaurant is to the left” then A ≡ L.
false.
• In other words either A is a knight and the restaurant is to the left or A is
• So, the statement is a proposition. not a knight and the restaurant is not to the left.
• Let A represent the proposition “A is a knight”. • If A says “I am a knight” we conclude that A ≡ A which tells us nothing!
• Suppose A makes some statement S.
• The truth or falsity of this statement is the same as the truth or falsity of
A.
A≡S
23 24
12/24/2021
Knights and Knaves Knights and Knaves
• If we ask A a Yes/No question, Q, the response will be the truth value of • Let's say we have two natives, A and B.
A ≡ Q.
• A says “B is a knight”
• That is, if the response is “yes”, either A is a knight and the answer to Q • What can we deduce?
really is yes or A is a knave and the answer is really no.
• If A represents the proposition A is a knight and B represents the
• Otherwise the response will be “no”. proposition B is a knight:
A ≡ B.
• That is, A and B are of the same type.
• Note that we don’t know which type.
25 26
Knights and Knaves Logic Puzzle: Problem 1
Knights and Knaves Logic Puzzle: Problem 1
• It is rumoured there is gold on the island. • Since A says “The statement ‘there is gold on the island’ and the
statement ‘I am a knight’ are either both true or both false”, A is
• A native tells you “The statement ‘there is gold on the island’ and the asserting A ≡ G where A is the proposition A is a knight and G the
statement ‘I am a knight’ are either both true or both false”. proposition there is gold on the Island.
• Can you tell if the native is a knight? • Note that A is NOT asserting AG.
• Can you tell if there is gold on the island?
• Any assertion by a native has the same truth value as A so:
A ≡ (A ≡ G)
(A ≡ A) ≡ G
true ≡ G
• From this we can conclude that there is gold on the island, even though
we have no idea if the native is a knight or a knave.
27 28
12/24/2021
Knights and Knaves Logic Puzzle: Problem 1
Knights and Knaves Logic Puzzle: Problem 2
• If we use brute force to solve problem 1, we will construct the following
truth table: • You come across two natives.
A G A≡G A ≡ (A ≡ G) • You ask each if the other is a knight.
• Do you get the same answer from both of them?
T T T T
T F F F
F T F T
F F T F
Since A ≡ (A ≡ G), it can only be the first case or third case. Hence, G is
true and A can be true or false
29 30
Knights and Knaves Logic Puzzle: Problem 2 Knights and Knaves Logic Puzzle: Problem 3
• A will answer “yes” if he is a knight and so is B or if he is a knave and • There are three natives, A, B and C.
so is B.
• A says “B and C are of the same type”.
• In other words: • What can we conclude about the number of knights present?
• A’s answer ≡ (A ≡ B)
• B’s answer ≡ (B ≡ A)
• Using the symmetry property:
• (A ≡ B) ≡ (B ≡ A)
• So B’s answer will be the same as A’s.
31 32
12/24/2021
Another Way to Solve Problem 3: Using Truth Table
Knights and Knaves Logic Puzzle: Problem 3 A B C B≡C A ≡ (B ≡ C)
• A says B ≡ C so: T T T T T
• A ≡ (B ≡ C) T T F F F
T F T F F
• So
• A is a knight and so are B and C T F F T T
or F T T T F
• A is a knight and B and C are knaves F T F F T
or F F T F T
F F F F F
• A is a knave and one of B and C is a knight
• From the truth table, we conclude that the four possible cases are the 4 rows that have
• There is an odd number of knights. the value “T” for A ≡ (B ≡ C) (indicated by “”).
• And, each of above-mentioned row has odd number of knights. Hence, we can
conclude that there are odd number of knights.
33 34
Knights and Knaves Logic Puzzle: Problem 4 Knights and Knaves Logic Puzzle: Problem 4
• There are three natives, A, B and C. • Let Q be the unknown question we must ask C, with truth value Q.
• A says “B and C are of the same type”. • Let A, B and C denote the propositions A, B, C is a knight.
• What question can we ask C to find out if A is telling the truth? • The response we want is A so:
• (C ≡ Q) ≡ A
• Which we regroup to give:
• Q ≡ ( C ≡ A)
• But A ≡ (B ≡ C) so substituting for A we get:
• Q ≡ (C ≡ (B ≡ C) )
• Which simplifies (after rearrangement) to:
• Q≡B
• In other words, the question is “Is B a knight?”.
35 36
12/24/2021
Knights and Knaves Logic Puzzle: Problem 5
Knights and Knaves Logic Puzzle: Problem 5
• We want a question, Q, whose answer, when asked of A, is the type of B.
• There are two natives, A and B.
• (A ≡ Q) ≡ B
• What question should you ask A to determine if B is a knight?
• Reorganising:
• Q ≡ (A ≡ B)
• In other words “Is B of the same type as you?”.
37 38
Knights and Knaves Logic Puzzle: Problem 6
Knights and Knaves Logic Puzzle: Problem 6
• We want a question, Q, which, when asked of A, determines if A and B
• There are two natives, A and B. are of the same type:
• What question should you ask A to determine whether A and B are of the same • (A ≡ Q) ≡ (A ≡ B)
type? • Regrouping and simplifying:
• Q ≡ (A ≡ (A ≡ B))
• Q ≡ ((A ≡ A) ≡ B)
• Q ≡ (true ≡ B)
• Q≡B
• In other words, the question is “Is B a knight?”.
39 40
12/24/2021
Knights and Knaves Logic Puzzle: Problem 7 Knights and Knaves Logic Puzzle: Problem 7
• Following the same rules as before:
• You come to a fork in the road. • (A ≡ Q) ≡ L
• There is a restaurant down one of the two branches. • Which we can rearrange as:
• There is a native at the fork. • Q ≡ (A ≡ L)
• What question do you ask to find out if the restaurant lies down the left fork?
• So our question is “Is the truth value of the statement ‘you are a knight’ the
same as the truth value of ‘the restaurant lies down the left fork’?”
• Our question can be rephrased as “Is it the case that the statement that the
left fork leads to the restaurant is equivalent to your being a knight?”
41 42
*Verification of Correctness of the Deduction for Problem 7
• We can check the deduction is correct using brute force
• From the truth table, we can see that A’s answer to Q is the same as L.
A L A≡L A’s answer to Q
T T T T
T F F F
F T F T
F F T F
43