What is discrete mathematics?
Discrete mathematics is the part of
mathematics devoted to the study of
discrete objects. (Here discrete means
consisting of distinct or unconnected
elements.)
More generally, discrete mathematics is used
whenever
objects
are
counted,
when
relationships between finite (or countable) sets
are studied, and when processes involving a
finite number of steps are analyzed.
Logic
• Mathematical Logic is a tool for working with
compound statements
• Logic is the study of correct reasoning
• Use of logic
– In mathematics:
to prove theorems
– In computer science:
to prove that programs do what they are
supposed to do
Propositional Logic
• Our discussion begins with an introduction to the
basic building blocks of logic-propositions.
Definition: A proposition (usually denoted by p, q,
r, …) is a declarative statement that is either True
(T) or False (F), but not both or somewhere “in
between!”.
Note: Commands and questions are not propositions.
Examples of Propositions
The following are all propositions:
• “CAIRO, is the capital of ARE ” . (True)
• “The square root of 16 equals 3 ”. (False)
• “All mathematicians are liars”. (False)
But, the following are NOT propositions:
• “What did you pay for this book?” (Question)
• “Fa fa ya ya.” (Meaningless)
• “Stop designing databases!” (Command)
• “1 + 2” (Expression with a non-true/false value)
• “2 + 5 = x” (Expression with unknown value of x)
Explanation
Elephants are bigger than mice.
• Is this a proposition?
(Yes)
• What is the truth value of the proposition? (True)
520 < 111
• Is this a proposition?
(Yes)
• What is the truth value of the proposition? (False)
5
Explanation
y>5
• Is this a proposition?
(No)
• Its truth value depends on the value of y,
but this value is not specified.
• We call this type of statement a
propositional function or open sentence.
6
Operators / Connectives
An operator or connective combines one or more
operand expressions into a larger expression. (e.g.,
“+” in numeric expression.)
• Unary operators take 1 operand (e.g. −3);
• Binary operators take 2 operands (e.g. 3 4).
• Propositional or Boolean operators operate on
propositions (or their truth values) instead of on
number.
Some Popular Boolean Operators
Formal Name
Nickname
Arity
Symbol
Negation operator
NOT
Unary
¬ or ~
Conjunction operator
AND
Binary
Disjunction operator
OR
Binary
Exclusive-OR operator
XOR
Binary
Implication operator
IMPLIES
Binary
→
Biconditional operator
IFF
Binary
The Negation Operator
Definition: Let p be a proposition then ¬p is the
negation of p (Not p, it is not the case that p).
e.g. If p = “London is a city”
then ¬p = “London is not a city” or “It is not the
case that London is a city”
p p
The truth table for NOT:
T :≡ True; F :≡ False
“:≡” means “is defined as”.
F T
T F
Operand
column
Result
column
The Conjunction Operator
Definition: Let p and q be propositions, the
proposition “p AND q” denoted by (p q) is called
the conjunction of p and q.
p q pq
e.g.
F F F
F T F
If p = “I will have salad for lunch”
T F F
and q = “I will have steak for dinner”,
T T T
then p q = “I will have salad for
Operand
Result
column
lunch and I will have steak for dinner” column
Remember: “” points up like an “A”, and it means “AND”
The Disjunction Operator
Definition: Let p and q be propositions, the
proposition “p OR q” denoted by (p q) is called
the disjunction of p and q.
p q pq
F F
F
e.g.
F T
T Note the
differences
p = “My car has a bad engine”
T F
T from AND
q = “My car has a bad carburetor” T T T
p q = “Either my car has a bad engine, or my car
has a bad carburetor”
It is called inclusive or, because it includes the possibility that
both p and q are true.
Compound Statements
• Let p, q, r, s be simple statements
• We can form other compound statements, such as
➢ (p q) r
➢ p (q r)
➢ ¬p ¬q
➢ (p q) (¬r s)
➢ and many others…
Example: Truth Table of (p q) r
p
q
r
pq
(p q) r
F
F
F
F
F
F
F
T
F
F
F
T
F
T
F
F
T
T
T
T
T
F
F
T
F
T
F
T
T
T
T
T
F
T
F
T
T
T
T
T
Three propositions p, q, r, then there are 23 = 8 rows in its truth table.
Note that p1 p2 … pn of n propositions will lead 2n rows in its truth table
Definition
Let p and q be propositions. The exclusive or
of p and q, denoted by p ⊕ q (or p XOR q), is
the proposition that is true when exactly one
of p and q is true and is false otherwise.
14
The Exclusive Or Operator
The binary exclusive-or operator “” (XOR)
combines two propositions to form their logical
p q pq
“exclusive or” (exjunction?).
F F F
e.g.
F T T
p = “I will earn an A in this course”
T F T
the
T T F Note
q = “I will drop this course”
difference
p q = “I will either earn an A in this course, or from OR
I will drop it (but not both!)”
This operation is called exclusive or, because it excludes possibility
that both p and q are true.
Natural Language is Ambiguous
Note that English “or” can be ambiguous regarding
the “both” case!
“Pat is a singer or
Pat is a writer”
“Pat is a man or
Pat is a woman”
Need context to disambiguate the meaning!
For this class, assume “OR” means inclusive.
Example
• Express the statement “I will use all my
savings to travel to Europe or to buy an electric
car” in propositional logic using the statement
p: “I will use all my savings to travel to
Europe” and the statement q: “I will use all my
savings to buy an electric car.”
• This statement can be expressed as p ⊕ q.
17
A Simple Exercise
Let p = “It rained last night”,
q = “The sprinklers came on last night” ,
r = “The grass was wet this morning”.
Translate each of the following into English:
¬p
=
“It didn’t rain last night”
r ¬p
=
“The grass was wet this morning, and
it didn’t rain last night”
¬rpq =
“Either the grass wasn’t wet this
morning, or it rained last night, or
the sprinklers came on last night”
Conditional Statements
• Let p and q be propositions. The conditional
statement p → q is the proposition “if p, then q.”
The conditional statement p → q is false when p is
true and q is false, and true otherwise.
• In the conditional statement p → q, p is called the
hypothesis (or antecedent or premise) and q is
called the conclusion (or consequence).
19
The Implication Operator
Hypothesis
Conclusion
The implication p → q states that p implies q.
If p is true, then q is true; but if p is not true, then q
could be either true or false.
e.g. Let p = “You get 100% on the final”
q = “You will get an A”
p → q = “If you get 100% on the final, then
you will get an A”
Implication Truth Table
• p → q is false only when
p is true but q is not true.
• p → q does not say
that p causes q!
• p → q does not require
that p or q are ever true!
p
F
F
T
T
q p→q
F
T
T T The only
F
F False case!
T T
e.g. “(1 = 0) → pigs can fly” is TRUE!
Understanding Implication
• In p → q there does not need to be any connection
between the antecedent or the consequent. The
“meaning” of p → q depends only on the truth values
of p and q.
• These implications are perfectly fine but would not be
used in ordinary English.
– “If the moon is made of green cheese, then I have more
money than Bill Gates.”
– “If the moon is made of green cheese, then I’m on
welfare.”
– “If 1 + 1 = 3, then your grandma wears combat boots.”
Examples of Implications
• “If this lecture ever ends, then the sun will rise
tomorrow.” True or False?
• “If Tuesday is a day of the week, then I am a
penguin.” True or False?
• “If 1 + 1 = 6, then Trump is the president of
USA.” True or False?
Different Ways of Expressing
p→q
“if p, then q”
“p implies q”
“if p, q”
“p only if q”
“p is sufficient for q”
“a sufficient condition for q is p”
“q if p”
“q whenever p”
“q when p”
“q is necessary for p”
“a necessary condition for p is q”
“q follows from p”
“q unless ¬p”
“q provided that p”
24
Example
• If Maria learns discrete mathematics, then she will find a
good job (if p, then q)
– Maria will find a good job if she learns discrete
mathematics (q if p)
– Maria will find a good job when she learns discrete
mathematics (q when p)
– For Maria to get a good job, it is sufficient for her to
learn discrete mathematics (sufficient condition for q
is p)
– Maria will find a good job unless she does not learn
discrete mathematics (q unless not p)
Example: Truth Table of
(p q)→ (p q)
Show that (p q)→ (p q) by truth table.
p
q
q
p q
pq
(p q) → (p q)
F
F
T
T
F
F
F
T
F
F
F
T
T
F
T
T
F
F
T
T
F
T
T
T
Important Logical Equivalence
p q is logically equivalent to p → q
p
p
q
p q
p→q
F
T
F
T
T
F
T
T
T
T
T
F
F
F
F
T
F
T
T
T
Converse, Inverse, Contrapositive
Some terminology, for an implication p → q :
• Its converse is:
q→p
• Its inverse is:
p → q
• Its contrapositive is: q → p
Example of Converse, Inverse,
Contrapositive
Write the converse, inverse and contrapositive of the
statement “if x ≠ 0, then John is a programmer”
• Its converse is:
“if John is a programmer, then x ≠ 0”
• Its inverse is:
“if x = 0, then John is not a programmer”
• Its contrapositive is:
“if John is not a programmer, then x = 0”
Note: The negation operation (¬) is different from the
inverse operation.
Example of Converse, Inverse, Contrapositive
Find the contrapositive, the converse, and the inverse
of the conditional statement:
“If it is raining, then the home team wins.”
• Its converse is:
“If the home team wins, then it is raining.”
• Its inverse is:
“If it is not raining, then the home team does not win.”
• Its contrapositive is:
“If the home team does not win, then it is not raining.”
Note: The negation operation (¬) is different from the
inverse operation.
Biconditional Truth Table
In English:
• “p if and only if q”
• "If p, then q, and conversely”
• “p is sufficient and necessary for q”
• Written p q
p
F
F
T
T
q pq
F
T
T
F
F
F
T
T
Nested Propositional Expressions
• Use parentheses to group sub-expressions:
“I just saw my old friend, and either he’s grown or
I’ve shrunk” = f (g s)
– (f g) s would mean something different
– f gs
would be ambiguous
• By convention, “¬” takes precedence over both
“” and “”. (¬ , , , → , )
– ¬s f means (¬s) f , not ¬ (s f )
Precedence of Logical Operators
Translation English Sentences into
Logical Expressions
• If you are a computer science major or you are not
a freshman, then you can access the internet from
campus :
is translated to:
(c f ) → a
Translation English Sentences into
Logical Expressions
How can this English sentence be translated into a
logical expression?
“You cannot ride the roller coaster if you are under
4 feet tall unless you are older than 16 years old.”
Let q represents “You can ride the roller coaster”
r represents “You are under 4 feet tall”
s represents “You are older than 16 years old”
Then the sentence can be translated to
(r ¬s) → ¬q
سنه فلن تستطيع ركوب السفينة الدوارة16 اقدام وسنك اقل من4 لو طولك اقل من
Example: Truth Table of
p q → r
p
q
r
r
pq
p q → r
F
F
F
F
F
T
T
F
F
F
T
T
F
F
T
T
T
T
F
F
F
T
F
T
T
F
T
F
T
T
T
T
T
F
T
F
T
T
T
T
F
T
T
F
T
T
T
F
Propositional Equivalence,
Tautologies and Contradictions
• A tautology is a compound proposition that is
always true.
e.g. p p T
• A contradiction is a compound proposition that
is always false.
e.g. p p F
Tautology
Example: Show that p → p q is a tautology.
pq p→pq
p
q
F
F
F
T
F
T
T
T
T
F
T
T
T
T
T
T
Equivalence Laws
• Identity:
pTp , pFp
• Domination:
pTT , pFF
• Idempotent:
ppp , ppp
• Double negation: p p
• Commutative:
pqqp , pqqp
• Associative:
(p q) r p (q r)
(p q) r p (q r)
More Equivalence Laws
• Distributive: p (q r) (p q) (p r)
p (q r) (p q) (p r)
• De Morgan’s:
(p q) p q
(p q) p q
• Trivial tautology/contradiction:
p p T , p p F
Augustus
De Morgan
(1806-1871)
Implications / Biconditional Rules
•
p → q p q
•
(p → q) (p q) p q
•
p → q q → p (contrapositive)
•
p q (p → q) (q → p)
•
(p q) p q
Proving Equivalence via Truth Tables
Example 1: Prove that p q and (p q) are
logically equivalent.
p
F
F
T
T
q
F
T
F
T
pq
F
T
T
T
p
T
T
F
F
q p q (p q)
T
T
F
F
F
T
T
F
T
F
F
T
Proving Equivalence using Logic
Laws
Example 2: Show that (p (p q)) and
(p q) are logically equivalent.
(p (p q))
p (p q)
p ((p) q)
p (p q )
(p p) (p q)
F (p q)
(p q)
De Morgan
De Morgan
Double negation
Distributive
Negation
Identity
Proving Equivalence using Logic
Laws
Example 3: Show that ((p → q) → q) is a
contradiction.
( (p → q) → q)
( (p q) → q)
( (p q) → q)
( (p q) q)
(p q q)
(p T)
(T)
F
Equivalence
De Morgan
Equivalence
De Morgan
Trivial Tautology
Domination
Contradiction
Proving Equivalence using Logic
Laws
Example :
Show that ¬(p → q) and p ¬q are logically
equivalent.
Proving Equivalence using Logic Laws
Example : Show that (p q) → (p q) is a
tautology.