You are on page 1of 58

Arab Open University

Faculty of Computer Studies

MT131 - Discrete Mathematics

11/10/22
Course goals

• Mathematical reasoning
– Logic, Inference, proof
• Combinatorial analysis
– Count, Probability
• Discrete structures
– Sets, Functions, Relations, Graphs

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Course Contents

 Logic
 Sets, Functions and Matrices
 Number Theory and Cryptography
 Counting
 Discrete Probability
 Relations
 Graphs

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


1. The Foundations: Logic

11/10/22
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

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Propositional Logic
• Propositional logic: It deals with propositions.
• Predicate logic: It deals with predicates.

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.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Examples of Propositions
The following are all propositions:
• “Washington, D.C., is the capital of USA”
• “California is adjacent to New York”
• “1 + 2 = 3”
But, the following are NOT propositions:
• “What time is it?” (Question)
• “La la la la la.” (Meaningless)
• “Read this carefully!” (Command)
• “1 + 2” (Expression with a non-true/false value)
• “1 + 2 = x” (Expression with unknown value of x)
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
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
numbers.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Some Popular Boolean Operators

Formal Name Nickname Arity Symbol


Negation operator NOT Unary ¬
Conjunction operator AND Binary 
Disjunction operator OR Binary 
Exclusive-OR operator XOR Binary 
Implication operator IMPLIES Binary 
Biconditional operator IFF Binary ↔

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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: F T
T :≡ True; F :≡ False
T F
Operand Result
“:≡” means “is defined as”. column column

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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 pq
e.g. F F F
If p = “I will have salad for lunch” F T F
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 column
lunch and I will have steak for dinner”

Remember: “” points up like an “A”, and it means “AND”

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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 pq
e.g. F F F
F T T Note the
p = “My car has a bad engine” differences
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

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


The Exclusive Or Operator
The binary exclusive-or operator “” (XOR)
combines two propositions to form their logical
“exclusive or” (exjunction?). p q pq
e.g. F F F
p = “I will earn an A in this course” F T T
T F T
q = “I will drop this course” T T F
Note the
difference
from OR
p  q = “I will either earn an A in this course, 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
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
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.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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”

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Implication Truth Table

• p  q is false only when


p is true but q is not true. p q pq
• p  q does not say F F T
that p causes q! F T T
The only
• p  q does not require T F F False case!
that p or q are ever true! T T T

e.g. “(1 = 0)  pigs can fly” is TRUE!

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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 q pq
F F T
F T F
T F F
T T T

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Example: Truth Table of (pq)r
p q r pq (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
3 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
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Example: Truth Table of
(p  q) (p  q)

p q q p  q p  q (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

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Example: Truth Table of
p  q  r
p q r r pq p  q  r

F F F T F T
F F T F F T
F T F T T T
F T T F T F
T F F T T T
T F T F T F
T T F T T T
T T T F T F
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
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.”
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
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?

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Important Logical Equivalence

p  q is logically equivalent to p  q

p q p  q pq
F F T T
F T T T
T F F F
T T T T

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Different Ways of Expressing
pq

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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)

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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…

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Precedence of Logical Operators

Operator Precedence

() 1
 2
 , ,  3
, 4
Left to Right 5

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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”
¬rpq = “Either the grass wasn’t wet this
morning, or it rained last night, or
the sprinklers came on last night”

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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  g  s would be ambiguous
• By convention, “¬” takes precedence over both
“” and “”. (¬ ,  ,  ,  , )
– ¬s  f means (¬s)  f , not ¬ (s  f )

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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.
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Logic and Bit Operations
• Find the bitwise AND, bitwise OR, and bitwise
XOR of the bit strings 0110110110 and
1100011101.
0110110110
Truth value Bit
1100011101 F 0
__________ T 1
Bitwise AND 0100010100
Bitwise OR 1110111111
Bitwise XOR 1010101011
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
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
• Other compound propositions are contingencies.
e.g. p  q , p  q
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Tautology

Example: Sow that p  p  q is a tautology.

p q pq ppq
F F F T
F T T T
T F T T
T T T T

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Equivalence Laws 

• Identity: pTp , pFp


• Domination: pTT , pFF
• Idempotent: ppp , ppp
• Double negation: p  p
• Commutative: p  q  q  p , p  q  q  p
• Associative: (p  q)  r  p  (q  r)
(p  q)  r  p  (q  r)

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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:
Augustus
p  p  T , p  p  F De Morgan
(1806-1871)

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


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

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Proving Equivalence via Truth Tables

Example 1: Prove that p  q and (p  q) are


logically equivalent.

p q pq p q p  q (p  q)


F F F T T T F
F T T T F F T
T F T F T F T
T T T F F F T

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Proving Equivalence using Logic
Laws
Example 2: Show that (p  (p  q)) and
(p  q) are logically equivalent.

(p  (p  q))


 p  (p  q) De Morgan
 p  ((p)  q) De Morgan
 p  (p  q ) Double negation
 (p  p)  (p  q) Distributive
 F  (p  q) Negation
 (p  q) Identity
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Proving Equivalence using Logic
Laws
Example 3: Show that ((p  q)  q) is a
contradiction.

 ( (p  q)  q)
  ( (p  q)  q) Equivalence
  ( (p  q)  q) De Morgan
  ( (p  q)  q) Equivalence
  (p  q  q) De Morgan
  (p  T) Trivial Tautology
  (T) Domination
F Contradiction
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Predicates and Quantifiers
Predicates: “x is greater than 3” has two parts
First part: x , is a variable.
Second part: “is greater than 3”, is a predicate.
“x is greater than 3” can be denoted by the
propositional function P(x).
P(x): x > 3, let x = 4, then P(4) is true,
let x = 1, then P(1) is false.
Example: If R(x, y, z) : x + y = z then
R(1, 2, 3), 1 + 2 = 3, is true.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Examples of Propositional Functions

• Let “x + y = z” be denoted by R(x, y, z) and all three


variables be the integers. Find these truth values:
R(2, -1, 5) Solution: F
R(3, 4, 7) Solution: T
R(x, 3, z) Solution: Not a Proposition
• Now let “x - y = z” be denoted by Q(x, y, z), and all three
variables be the integers. Find these truth values:
Q(2, -1, 3) Solution: T
Q(3, 4, 7) Solution: F
Q(x, 3, z) Solution: Not a Proposition

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Examples of Propositional Functions
• Connectives from propositional logic carry over to
predicate logic.
• If P(x) denotes “x > 0,” find these truth values:
P(3) ∨ P(-1) Solution: T
P(3) ∧ P(-1) Solution: F
P(3) → P(-1) Solution: F
P(3) → ¬P(-1) Solution: T
• Expressions with variables are not propositions and
therefore do not have truth values. For example,
P(3) ∧ P(y)
P(x) → P(y)
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Quantifiers

Quantification Universal Quantification


Existential Quantification

Universes of Discourse (U.D) or Domain (D):


Collection of all persons, ideas, symbols, …

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


For every and for some
• We need quantifiers to express the meaning of English words
including all and some:
– “All men are Mortal.”
– “Some cats do not have fur.”
• The two most important quantifiers are:
– Universal Quantifier, “For all,” symbol: 
– Existential Quantifier, “There exists,” symbol: 
• We write as in x P(x) and x P(x).
 x P(x) asserts P(x) is true for every x in the domain.
 x P(x) asserts P(x) is true for some x in the domain.
• The quantifiers are said to bind the variable x in these expressions.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


The Universal Quantifier 

 x P(x): “P(x) is true for all (every) values of x in


the universe of discourse”.

• Example: What is the truth value of


x (x 2 ≥ x) .
- If UD is all real numbers, the truth value is false
(take x = 0.5, this is called a counterexample).
- If UD is the set of integers, the truth value is true.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


The Existential Quantifier 
  x Q(x): There exists an element x in the universe
of discourse such that Q(x) is true.

• Example 1: Let Q(x): x = x + 1, Domain is the set


of all real numbers:
- The truth value of  x Q(x) is false (as the is no
real x such that x = x + 1).
• Example 2: Let Q(x): x2 = x, Domain is the set of
all real numbers:
- The truth value of  x Q(x) is true (take x = 1).
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Important Note

Let P(x): x 2 ≥ x, Domain is the set {0.5, 1, 2, 3}.


 x P(x)  P(0.5)  P(1)  P(2)  P(3)
FTTT
F
  x P(x)  P(0.5)  P(1)  P(2)  P(3)
FTTT
T

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Example

Suppose that the universe of discourse of P(x, y) is


{1, 2, 3}. Write out the following propositions using
disjunctions and conjunctions:

• x P(x, 2):
P(1, 2)  P(2, 2)  P(3, 2)
• y P(3, y):
P(3, 1)  P(3, 2)  P(3, 3)

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Negations
   x P(x) ≡  x  P(x)
   x Q(x) ≡  x  Q(x)

• Example: Let P(x) is the statement “x2 − 1 = 0”,


where the domain is the set of real numbers R.
- The truth value of  x P(x) is False
- The truth value of  x P(x) is True
-   x P(x) ≡  x (x 2 − 1 ≠ 0) , which is True
-   x P(x) ≡  x (x 2 − 1 ≠ 0) , which is False
Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics
Example

Suppose that P(x) is the statement “x + 3 = 4x”


where the domain is the set of integers. Determine
the truth values of x P(x). Justify your answer.

It is clear that P(1) is True, but P(x) is False for


every x ≠ 1 (take x = 2 as a counterexample). Thus,
the truth value of x P(x) is False.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Translation using Predicates and
Quantifiers
• “Every student in this class has studied math and
C++ course”, Universes of Discourse is the
student in this class.
Translated to: x (M(x)  CPP(x))

• “For every person x, if x is a student in this class


then x has studied math and C++”, UD is all
people.
Translated to: x (S(x)  M(x)  CPP(x))

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Translation using Predicates and
Quantifiers

• “Some student in this class has studied math and


C++ course”, UD is the students in this class.
Translated to: x (M(x)  CPP(x))

• But if the UD is all people.


Translated to: x (S(x)  M(x)  CPP(x))

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Example
Let G(x), F(x), Z(x), and M(x) be the statements "x is a giraffe“,
"x is 15 feet or higher“, "x is in this zoo" and "x belongs to me"
respectively.  Suppose that the universe of discourse is the set of
animals.  Express each of the following quantifiers in English:
• x (Z(x)  G(x))
All animals in this zoo are giraffes
• x (M(x)  F(x))
I have no animals less than 15 feet high
• x (Z(x)  M(x))
There are no animals in this zoo that belong to anyone but me
x ( G(x)   F(x))
No animals, except giraffes, are 15 feet or higher

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Summary
• In order to prove the • In order to prove the
quantified statement universal quantified
x P(x) is true statement x P(x) is
– It is not enough to false
show that P(x) is true – It is enough to exhibit
for some x  D some x  D for which
– You must show that P(x) is false
P(x) is true for every x – This x is called the
D counterexample to the
– You can show that  x statement x P(x) is
 P(x) is false true

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Summary
• In order to prove the • In order to prove the
existential quantified existential quantified
statement  x Q(x) is statement  x Q(x) is
true false
– It is enough to exhibit – It is not enough to
some x  D for which show that Q(x) is false
Q(x) is true for some x  D
– You must show that
Q(x) is false for every
xD

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics


Free and Bound Variables

• The variable is either bound or free.

Examples:
- P(x, y), x and y are free variables.
- x P(x, y), x is bound and y is free.
- “P(x), where x = 3” is another way to bind x.
-  x (x + y = 1), x is bound and y is free.

Arab Open University – Faculty of Computer Studies MT131 - Discrete Mathematics

You might also like