Comp106 Logic
Comp106 Logic
Comp106 Logic
Let p be a proposition.
Negation of p is ¬p (not p)
e.g.
Proposition p: Today is Tuesday.
Negation of p: Today is not Tuesday
Truth table:
p ¬p
T F
F T
p q ??
p q ??
p q ??
Truth table:
p q pq pq pq
T T T T F
T F F T T
F T F T T
F F F F F
Definition: Implication (IF)
The implication p → q is F when p is T and q is F
is T otherwise.
p q p→q
T T T
T F F
F T T
F F T
p→q
p: premise (hypothesis)
q: conclusion (consequence)
“If you are blonde, then you have blue eyes”
“If you are older than 18 years, then you can have a driving license”
Converse: “If you can have a driving license, then you are older than 18 years”
Contrapositive: “If you cannot have a driving license, then you are not older than 18 years”
Definition: Biconditional (IFF)
The biconditional p ↔ q is T when p and q have same truth value and is F otherwise.
Example:
“You cannot ride the roller coaster if you are less than 1.70m tall unless you
are older than 18 years.”
Let’s try….
Translation from English to logical expression
Example:
“You cannot ride the roller coaster if you are less than 1.70m tall unless you
are older than 18 years.”
(r ¬s ) → ¬q
e.g.*:
• “It’s below freezing or it’s snowing; but it’s not snowing if it’s below freezing.”
* exempli gratia
e.g.:
• “It’s below freezing or it’s snowing; but it’s not snowing if it’s below freezing.”
(p q) (p → ¬q)
and ≈ but
Logic and bit operations:
Notation: r s
1.3 Propositional Equivalences
Notation: r s
e.g.
Show that ¬(p q) ¬p ¬q (De Morgan’s law)
p q pq ¬(pq) ¬p ¬q ¬p ¬q
T T T F F F F
T F T F F T F
F T T F T F F
F F F T T T T
Logical Equivalences
pTp
pFp Identity laws
pTT
pFF Domination laws
ppp
ppp Idempotent laws
pqqp
pqqp Commutative laws
(p q) r p (q r)
(p q) r p (q r) Associate laws
p (q r) (p q) (p r)
p (q r) (p q) (p r) Distributive laws
¬(p q) ¬p ¬q
¬(p q) ¬p ¬q De Morgan’s laws
Some additional useful logical equivalences:
p ¬p T
p ¬p F
(p → q) (¬p q)
(p ↔ q) (p → q) (q → p)
(p → q) (¬q → ¬p)
You can show all these logical equivalences using truth tables.
Definition:
e.g. p ¬p p ¬p
tautology contradiction
e.g.
Show that (p q) → (p q) is a tautology.
e.g.
Show that (p q) → (p q) is a tautology.
(p q) → (p q) ¬(p q) (p q)
(¬p ¬q) (p q) De Morgan
(¬p p) (¬q q) Assoc & Comm
TT
T
e.g.
Show that ¬(p → q) p ¬q
e.g.
Show that ¬(p ↔ q) (p q) (¬p ¬q)
You can show these logical equivalences using truth tables or using known
equivalences.
Consistency of Propositions
“Whenever the system software is being upgraded, users cannot access the file system”
“If users can access the file system, then they can save new files.”
“If users cannot save new files, then the system software is not being upgraded.”
“Whenever the system software is being upgraded, users cannot access the file system”
“If users can access the file system, then they can save new files.”
“If users cannot save new files, then the system software is not being upgraded.”
“Whenever the system software is being upgraded, users cannot access the file system”
“If users can access the file system, then they can save new files.”
“If users cannot save new files, then the system software is not being upgraded.”
Subject Predicate
: Universal quantifier
e.g.
“Every student in this class has studied calculus.”
Definition 1: Universal Quantification of P(x)
is the proposition “P(x) is T for all values of x in the universe of discourse (domain).”
Notation: x P(x)
“for all x P(x)”
“for every x P(x)”
: Universal quantifier
e.g.
“Every student in this class has studied calculus.”
Then x P(x), where universe of discourse is all the students in the class.
DOMAIN (universe of discourse) MUST BE SPECIFIED!!
OR
x (S(x) → P(x))
where
S(x) denotes “x is in the class”
Universe of discourse is the set of all students.
e.g.
What is the truth value of x P(x), where
P(x): “x2 < 10 ”
Universe of discourse: x {1,2,3,4}
Notation:
x P(x)
“there exists an x s.t. P(x)”
“there is at least one x s.t. P(x)”
: Existential quantifier
e.g.
P(x): x > 3 x {…, –1, 0, 1,…}
x P(x) T
e.g.
P(x): x = x +1, x R
x P(x) F
e.g.
P(x): x2 > 10, x {1, 2, 3, 4}
e.g.
“Everyone has exactly one best friend.”
“For every person x, there is a person y such that y is the best friend of x and
if z is a person other than y, then z is not the best friend of x.”
x y ( B(x, y) ( z (z y) → ¬B(x, z) ) )
x y z B(x, y) ( (z y) → ¬B(x, z) )
Remark:
So we can write
x (Q(x) → y P(x,y) ) x y ( Q(x) → P(x,y) )
Remark:
So we can write
x (Q(x) → y P(x,y) ) x y ( Q(x) → P(x,y) )
So we can write
x (Q(x) → y P(x,y) ) x y ( Q(x) → P(x,y) )
e.g.
Consider P(x,y): “Student x solves question y”, Q(x): “Student x passes the exam”
The order of quantifiers is important !!! unless all quantifiers are universal or
existential.
e.g.
x y P(x,y) is not equivalent to y x P(x,y).
x y P(x,y) : “ For every real number x there is a real number y such that x+y=0.”
y x P(x,y) : “ There is a real number y such that for every real number x, x+y=0.”
Negation of Quantified Statements:
e.g.
“There exists a living person who is 150 years old.”
Write down as a logical expression using predicates and quantifiers and then negate:
Let P(x): “x is 150 years old,” and the universe of discourse is set of living people.
Negation of Quantified Statements:
e.g.
“There exists a living person who is 150 years old.”
Write down as a logical expression using predicates and quantifiers and then negate:
Let P(x): “x is 150 years old,” and the universe of discourse is set of living people.
x P(x)
“There exists a living person who is 150 years old.” x P(x)
Negation of x P(x)?
“There exists a living person who is 150 years old.” x P(x)
Negation of x P(x)?
“Every living person is not 150 years old,” or equivalently “no living person is 150
years old.”
In the previous example, what changes if the universe of discourse is modifed as “the
set of all people”. Then we would need another propositional function, e.g., R(x): “x is
a living person”.
e.g.
P(x): x2 > 10, x {1, 2, 3, 4}
Negation of x P(x) ?
xy xy ≠ 1
e.g. Negate “Some student in this class has solved every exercise in the book.”
“Some student in this class has not solved every exercise in the book.” Not correct!!!
Let S(x,y) be “student x has solved exercise y”, where the universe of discourse for x is
the set of students in this class, and for y, the set of exercises in the book.
e.g. Negate “Some student in this class has solved every exercise in the book.”
“Some student in this class has not solved every exercise in the book.” Not correct!!!
Let S(x,y) be “student x has solved exercise y”, where the universe of discourse for x is
the set of students in this class, and for y, the set of exercises in the book.
“For every student in this class there is an exercise that she or he has not solved.”
Equivalently “No student in this class has solved every exercise in the book.”
e.g. Negate “Everyone has exactly one best friend.”
Universe of discourse is the set of all students in the class (for both x and y).
Let B (x,y): “y is the best friend of x”.
x y z B (x, y) ((z y) → ¬B (x, z))
Negation: “Everyone does not have exactly one best friend.” ? Not very informative!
e.g. Negate “Everyone has exactly one best friend.”
Universe of discourse is the set of all students in the class (for both x and y).
Let B (x,y): “y is the best friend of x”.
x y z B (x, y) ((z y) → ¬B (x, z))
Negation: “Everyone does not have exactly one best friend.” ? Not very informative!
¬x yz B (x, y) ((z y) → ¬B (x, z) )
x ¬y z B (x, y) ((z y) → ¬B (x, z) )
xy ¬z B (x, y) ((z y) → ¬B (x, z) )
xy z ¬(B (x, y) ((z y) → ¬B (x, z) ))
xy z ¬B (x, y) ¬((z y) → ¬B (x, z) ))
xy z ¬B (x, y) ((z y) B (x, z) ))
Note that
x ( (y P(x,y))→ Q(x) ) is not logically equivalent to x y ( P(x,y) → Q(x) )
1.6/1.8/1.9 Mathematical Reasoning & Methods of Proof
We will learn:
1. Rules of reasoning; how to reason correctly
2. Methods of proof; how to show whether a given (mathematical) statement is
true or not
Rules of Inference: (Rules of reasoning)
Are used to draw conclusions from other assertions and tie the steps of a proof.
Basic rule of inference: Modus ponens
(p (p → q)) → q
e.g.
“If it is sunny today, then we’ll play soccer. It is sunny today, so we’ll play soccer”.
Rules of Inference: (Rules of reasoning)
Are used to draw conclusions from other assertions and tie the steps of a proof.
Basic rule of inference: Modus ponens
(p (p → q)) → q
e.g.
“If it is sunny today, then we’ll play soccer. It is sunny today, so we’ll play soccer”.
Another notation:
p
p→q
q
Rules of Inference: (Rules of reasoning)
e.g.
“If it is sunny today, then we’ll play soccer. It is sunny today, so we’ll play soccer”.
p q p→q (p (p → q)) → q
T T T T
T F F T
F T T T
F F T T
e.g.
If it is sunny today, then we’ll play soccer. We’ll play soccer, so it is sunny today.
e.g.
If it is sunny today, then we’ll play soccer. We’ll play soccer, so it is sunny today.
[(p → q) q] → p
e.g.
If it is sunny today, then we’ll play soccer. We’ll play soccer, so it is sunny today.
e.g.
It is windy and raining now. Therefore, it is windy now. Tautology.
pq Simplification Rule
p
Rule of
Inference Tautology Name
p p → (p q) Addition
pq
pq (p q ) → p Simplification
p
p ((p) (q)) → (p q) Conjunction
q
pq
p [p (p → q)] → q Modus Ponens
p→q
q
¬q [¬q (p → q)] → ¬p Modus Tollens
p→q
¬p
p→q [(p → q) (q → r)] → (p → r) Hypothetical
q→r Syllogism
p→r
pq [(p q ) ¬p] → q Disjunctive
¬p Syllogism
q
e.g. Show that hypotheses
“If you help me, then I will finish writing the program,” “If you do not help me, then I will go to
sleep early,” and “If I go to sleep early, then I will wake up feeling refreshed”
Let
p: “you help me”
q: “I’ll finish writing the program”
r: “I’ll go to sleep early”
s: “I’ll wake up feeling refreshed”
e.g. Show that hypotheses
“If you help me, then I will finish writing the program,” “If you do not help me, then I will go to
sleep early,” and “If I go to sleep early, then I will wake up feeling refreshed”
Let
p: “you help me”
q: “I’ll finish writing the program”
r: “I’ll go to sleep early”
s: “I’ll wake up feeling refreshed”
Step Reason
1. p → q hypothesis
2. ¬q → ¬p contrapositive of step 1
3. ¬p → r hypothesis
4. ¬q → r hypothetical syllogism using steps 2, 3
5. r → s hypothesis
6. ¬q → s hypothesis syllogism using steps 4, 5
Rules of Inference for Quantified Statements
Universal generalization:
P(c) for an arbitrary cU
x P(x)
Existential instantiation:
Existential generalization:
P(x): “x is a lion”
Q(x): “x is fierce”
R(x): “x drinks coffee”
Universe of discourse is the set of all creatures.
e.g.
i) “All lions are fierce”
ii) “Some lions do not drink coffee”
Does i) and ii) imply that “some fierce creatures do not drink coffee” ?
P(x): “x is a lion”
Q(x): “x is fierce”
R(x): “x drinks coffee”
Universe of discourse is the set of all creatures.
i) x (P(x) → Q(x))
ii) x (P(x) ¬R(x))
i) ii) ? x (Q(x) ¬R(x))
e.g.
i) “All lions are fierce”
ii) “Some lions do not drink coffee”
Does i) and ii) imply that “some fierce creatures do not drink coffee” ?
P(x): “x is a lion”
Q(x): “x is fierce”
R(x): “x drinks coffee”
Universe of discourse is the set of all creatures.
i) x (P(x) → Q(x))
ii) x (P(x) ¬R(x))
i) ii) ? x (Q(x) ¬R(x))
(ii) implies that there is some x1 such that P(x1) ¬R(x1) by Existential Instantiation.
Hence by (i), Q(x1) is true (using Simplification and Modus Ponens rules).
¬R(x1) is also true by using again Simplification rule.
Then Q(x1) ¬R(x1) which implies that x (Q(x) ¬R(x)) by Existential Generalization.
Fallacies: Types of incorrect reasoning:
e.g.
“If you have solved every problem in this book, then you know Discrete Math.
You know Discrete Math. Therefore, you have solved every problem in this book.”
“If you are older than 18 years, then you can have a driving license. You are not older
than 18 years, so you can’t have a driving license.”
Begging the question fallacy: When one or more steps of a proof are based on the truth
of the statement being proved (circular reasoning)
Methods of Proving Theorems
To prove a theorem, you usually start from premises (conditions), and using known
theorems, axioms and definitions, you construct a sequence of steps that leads to the
conclusion (forward reasoning).
Example - Fermat’s Last Theorem:
The equation
xn+yn = zn
has no solution in integers x, y, and z with xyz 0, whenever n is an integer with n > 2.
Put forward in the 17th century, but formally proved only in 1990s.
Some further terminology:
“Every even positive integer greater than 4 is the sum of two primes”.
Direct proof: (forward reasoning)
Many theorems are implications:
p→q
e.g. p q
Prove that, nZ, if n is odd, then n2 is odd.
e.g.
Prove that, nZ, if 3n + 2 is odd, then n is odd.
Method: Suppose we want to prove p is true. We start assuming p is false and then
proceed. If we end up with a contradiction, then we conclude that the assumption “p is
false” is false, i.e., p is true.
Proof by cases:
p→q s.t. p (p1 p2 … pn)
e.g.
e.g.
e.g.
(p1 → q) (p2 → q) is T p → q is T
e.g. (iff)
i) p → q:
ii) q → p:
e.g. (iff)
x P(x) ? : Prove or disprove the existence of an a s.t. P(a) is true, without explicitly
finding it.
Theorems and Quantifiers:
x P(x) ? : Prove or disprove the existence of an a s.t. P(a) is true, without explicitly
finding it.
Counter-example:
x P(x) ?