Discrete Structures1
Discrete Structures1
1.Recommended Books:
MAIN TOPICS:
1. Logic
2. Sets & Operations on sets
3. Relations & Their Properties
4. Functions
5. Sequences & Series
6. Recurrence Relations
7. Mathematical Induction
8. Loop Invariants
9. Loop Invariants
10. Combinatorics
11. Probability
12. Graphs and Trees
Continuous
Discrete
Set of Integers:
• • • • • •
3 -2 -1 0 1 2
• • • • • • •
-3 -2 -1 0 1 2 3
LOGIC:
Logic is the study of the principles and methods that distinguish between a
valid and an invalid argument.
SIMPLE STATEMENT:
A statement is a declarative sentence that is either true or false but not both.
A statement is also referred to as a proposition
EXAMPLES:
a. 2+2 = 4,
b. It is Sunday today
EXAMPLES:
Propositions Not Propositions
1) Grass is green. 1) Close the door.
2) 4 + 2 = 6 2) x is greater than 2.
3) 4 + 2 = 7 3) He is very rich
4) There are four fingers in a hand.
Rule:
If the sentence is preceded by other sentences that make the pronoun or variable reference
clear, then the sentence is a statement.
Example
Example:
x=1 Bill Gates is an American
x>2 He is very rich
“x > 2” is a statement with truth-value “He is very rich” is a statement with truth-
FALSE. value TRUE.
4
© Copyright Virtual University of Pakistan
1-Logic VU
UNDERSTANDING STATEMENTS
1) x + 2 is positive. Not a statement
2) May I come in? Not a statement
3) Logic is interesting. A statement
4) It is hot today. A statement
5) -1 > 0 A statement
6) x + y = 12 Not a statement
COMPOUND STATEMENT:
Simple statements could be used to build a compound statement.
LOGICAL CONNECTIVES
EXAMPLES:
SYMBOLIC REPRESENTATION
Statements are symbolically represented by letters such as p, q, r,...
EXAMPLES:
Disjunction or Vel
5
© Copyright Virtual University of Pakistan
1-Logic VU
EXAMPLES
EXAMPLE
Truth Table
A truth table specifies the truth value of a compound proposition for all
possible truth values of its constituent propositions.
6
© Copyright Virtual University of Pakistan
1-Logic VU
NEGATION (~):
If p is a statement variable, then negation of p, “not p”, is denoted as “~p”
It has opposite truth value from p i.e., if p is true, then ~ p is false; if p is false, then ~ p is
true.
p ~p
T F
F T
CONJUNCTION ( ):
If p and q are statements, then the conjunction of p and q is “p and q”, denoted as
“p q”.
Remarks
o p q is true only when both p and q are true.
o If either p or q is false, or both are false, then p q is false.
p q p q
T T T
T F F
F T F
F F F
DISJUNCTION ( ) or INCLUSIVE OR
Remarks:
o p q is true when at least one of p or q is true.
o p q is false only when both p and q are false.
7
© Copyright Virtual University of Pakistan
1-Logic VU
p q p q
T T T
T F T
F T T
F F F
Note it that in the table F is only in that row where both p and q have F and all other
values are T. Thus for finding out the truth values for the disjunction of two statements
we will only first search out where the both statements are false and write down the F in
the corresponding row in the column of p q and in all other rows we will write T in the
column of p q.
Remark:
Note that for Conjunction of two statements we find the T in both the
statements, But in disjunction we find F in both the statements. In other words, we will
fill T in the first row of conjunction and F in the last row of disjunction.
SUMMARY
1. What is a statement?
2. How a compound statement is formed.
3. Logical connectives (negation, conjunction, disjunction).
4. How to construct a truth table for a statement form.
8
© Copyright Virtual University of Pakistan
2-Truth Tables VU
1. ~p q
2. ~ p (q ~ r)
3. (p q) ~ (p q)
p q ~p ~p q
T T F F
T F F F
F T T T
F F T F
p q r ~r q ~r ~p ~p (q ~ r)
T T T F T F F
T T F T T F F
T F T F F F F
T F F T T F F
F T T F T T T
F T F T T T T
F F T F F T F
F F F T T T T
Truth table for (p q) ~ (p q)
p q p q p q ~ (p q) (p q) ~ (p q)
T T T T F F
T F T F T T
F T T F T T
F F F F T F
© Copyright Virtual University of Pakistan
2-Truth Tables VU
The word OR is sometimes used in an exclusive sense (p or q but not both). As in the
below statement
While defining a disjunction the word OR is used in its inclusive sense. Therefore, the
symbol means the “inclusive OR”
EXCLUSIVE OR:
When OR is used in its exclusive sense, The statement “p or q” means “p or q but not
both” or “p or q and not p and q” which translates into symbols as (p q) ~ (p q)
It is abbreviated as p q or p XOR q
T T F
T F T
F T T
F F F
p q p q p q ~ (p q) (p q) ~ (p q)
T T T T F F
T F T F T T
F T T F T T
F F F F T F
10
© Copyright Virtual University of Pakistan
2-Truth Tables VU
Note: Basically
p q ≡ (p ∧ ∼ q) ∨ (~ p ∧ q)
≡ [p ∧ ~ q) ∨ ~ p] ∧ [(p ∧ ~ q) ∨ q]
≡ (p ∨ q) ∧ ∼ (p ∧ q)
≡ (p ∨ q) ∧ (∼ p ∨ ~ q)
LOGICAL EQUIVALENCE
If two logical expressions have the same logical values in the truth table, then we say that
the two logical expressions are logically equivalent. In the following example, ~ (~ p ) is
logically equivalent p. So it is written as ~(~p) ≡ p
p ~p ~(~p)
T F T
F T F
Example
Rewrite in a simpler form:
“It is not true that I am not happy.”
Solution:
Let p = “I am happy”
then ~ p = “I am not happy”
and ~ ( ~ p) = “It is not true that I am not happy”
Since ~ ( ~ p) ≡ p
Hence the given statement is equivalent to “I am happy”
Example
Show that ~ (p∧q) and ~ p ∧ ~ q are not logically equivalent
Solution:
p q ~p ~q p∧q ~(p∧q) ~p ∧ ~q
T T F F T F F
T F F T F T F
F T T F F T F
F F T T F T T
11
© Copyright Virtual University of Pakistan
2-Truth Tables VU
DE MORGAN’S LAWS
Symbolically ~ (p ∧ q) ≡ ~ p ∨ ~ q
Symbolically ~ (p ∨ q) ≡ ~ p ∧ ~ q
Truth Table of ~ (p ∨ q) ≡ ~ p ∧ ~ q
p q ~p ~q p∨q ~(p ∨ q) ~p ∧ ~q
T T F F T F F
T F F T T F F
F T T F T F F
F F T T F T T
Solution:
a) The fan is not slow and it is not very hot.
b) Akram is not unfit or Saleem is not injured.
12
© Copyright Virtual University of Pakistan
2-Truth Tables VU
EXERCISE:
1. Show that (p ∧ q) ∧ r ≡ p ∧ (q ∧ r)
2. Are the statements ( p ∧ q ) ∨ r and p ∧ ( q ∨ r ) logically equivalent?
TAUTOLOGY:
A tautology is a statement form that is always true regardless of the truth values of the
statement variables. A tautology is represented by the symbol “t”.
p ~p p∨~p
T F T
F T T
p∨~p≡t
CONTRADICTION:
A contradiction is a statement form that is always false regardless of the truth values of
the statement variables. A contradiction is represented by the symbol “c”.
EXAMPLE:
The statement form p ∧ ~ p is a contradiction.
p ~p p∧~p
T F F
F T F
Since in the last column in the truth table we have F in all the entries, so it is a
contradiction i.e. p ∧ ~ p ≡c
REMARKS:
– Most statements are neither tautologies nor contradictions.
– The negation of a tautology is a contradiction and vice versa.
– In common usage we sometimes say that two statement are contradictory.
By this we mean that their conjunction is a contradiction: they cannot both
be true.
13
© Copyright Virtual University of Pakistan
2-Truth Tables VU
1. Show that p ∧ t ≡ p
p t p∧t
T T T
F T F
Since in the above table the entries in the first and last columns are identical so we have
the corresponding statement forms are Logically equivalent that is
p∧t≡p
Show that p ∧ c ≡ c
p c p∧c
T F F
F F F
EXERCISE:
Use truth table to show that ( p ∧ q ) ∨ (~ p ∨ ( p ∧ ~q )) is a tautology.
SOLUTION:
Since we have to show that the given statement form is Tautology, so the
column of the above proposition in the truth table will have all entries as T. As clear from
the table below
p q p∧q ~p ~q p∧~q ~ p∨ (p ∧ ~q) (p ∧ q) ∨
(~p ∨ (p ∧ ~q))
T T T F F F F T
T F F F T T T T
F T F T F F T T
F F F T T F T T
Hence ( p ∧ q ) ∨(~ p ∨( p ∧ ~ q )) ≡ t
EXERCISE:
Use truth table to show that (p ∧ ~q) ∧(~p∨q) is a contradiction.
14
© Copyright Virtual University of Pakistan
2-Truth Tables VU
SOLUTION:
Since we have to show that the given statement form is Contradiction, so its
column in the truth table will have all entries as F. As clear from the table below.
p q ~q p∧~q ~p ~p∨q ( p ∧ ~ q ) ∧( ~ p ∨ q )
T T F F F T F
T F T T F F F
F T F F T T F
F F T F T T F
LAWS OF LOGIC
1) Commutative Laws
p∧q ≡q∧ p
p∨q ≡q∨ p
2) Associative Laws
(p∧q ) ∧r ≡ p∧(q ∧r)
(p∨q ) ∨r ≡ p∨(q ∨r)
3) Distributive Laws
p∧(q∨r) ≡(p∧q ) ∨( p∧r)
p∨(q ∧r) ≡(p∨q ) ∧( p∨r)
4) Identity Laws
p∧t ≡p
p∨c≡p
5) Negation Laws
p ∨ ∼p ≡ t
p ∧ ∼p ≡ c
7) Idempotent Laws
p∧p≡p
p∨p≡p
8) DeMorgan’s Laws
~ ( p ∧ q ) ≡ ~p ∨ ∼q
~ ( p ∨ q ) ≡ ~p ∧ ∼q
15
© Copyright Virtual University of Pakistan
2-Truth Tables VU
16
© Copyright Virtual University of Pakistan
3-Laws of logic VU
SIMPLIFYING A STATEMENT:
“You will get an A if you are hardworking and the sun shines, or you are hardworking
and it rains.” Rephrase the condition more simply.
Solution:
Let p = “You are hardworking’
q = “The sun shines”
r = “It rains” .
The condition is (p ∧ q) ∨ (p ∧ r)
Using distributive law in reverse,
(p ∧ q) ∨ (p ∧ r) ≡ p ∧ (q ∨ r)
EXERCISE:
Use Logical Equivalence to rewrite each of the following sentences more simply.
CONDITIONAL STATEMENTS:
Introduction
Consider the statement:
"If you earn an A in Math, then I'll buy you a computer."
This statement is made up of two simpler statements:
p: "You earn an A in Math"
q: "I will buy you a computer."
TRUTH TABLE:
p q p→q
T T T
T F F
F T T
F F T
18
© Copyright Virtual University of Pakistan
3-Laws of Logic VU
EXERCISE:
Write the following statements in the form “if p, then q” in English.
a)Your guarantee is good only if you bought your CD less than 90 days ago.
If your guarantee is good, then you must have bought your CD player less
than 90 days ago.
b)To get tenure as a professor, it is sufficient to be world-famous.
If you are world-famous, then you will get tenure as a professor.
c)That you get the job implies that you have the best credentials.
If you get the job, then you have the best credentials.
d)It is necessary to walk 8 miles to get to the top of the Peak.
If you get to the top of the peak, then you must have walked 8 miles.
1.To get an A in this class it is necessary for you to get an A on the final.
SOLUTION p r
2.You do every exercise in this book; You get an A on the final, implies,
you get an A in the class.
SOLUTION p q r
3. Getting an A on the final and doing every exercise in this book is sufficient
For getting an A in this class.
SOLUTION p q r
2. ~q r
19
© Copyright Virtual University of Pakistan
3-Laws of Logic VU
If you don’t miss the final exam, you will pass the course.
3. ~p ~q r
If you neither have flu nor miss the final exam, then you will pass the course.
HIERARCHY OF OPERATIONS
FOR LOGICAL CONNECTIVES
•~ (negation)
•∧ (conjunction), ∨ (disjunction)
•→ (conditional)
p q ~ ~p p ∨ ~q p ~q ~p
q
T T F F T F
T F T F T F
F T F T F T
F F T T T T
20
© Copyright Virtual University of Pakistan
3-Laws of Logic VU
p q ~q ~p p→q ~q → ~p
T T F F T T
T F T F F F
F T F T T T
F F T T T T
IMPLICATION LAW
p q ~p q
p q p→q ~p ~p∨q
T T T F T
T F F F F
F T T T T
F F T T T
Thus the negation of “if p then q” is logically equivalent to “p and not q”.
Accordingly, the negation of an if-then statement does not start with the word if.
EXAMPLES
21
© Copyright Virtual University of Pakistan
3-Laws of Logic VU
SOLUTIONS:
1. Ali lives in Pakistan and he does not live in Lahore.
2. My car is in the repair shop and I can get to class.
3. x is prime but x is not odd and x is not 2.
4. n is divisible by 6 but n is not divisible by 2 or by 3.
p q p→q ~p ~q ~p →~q
T T T F F T
T F F F T T
F T T T F F
F F T T T T
A conditional and its converse are not equivalent. i.e., is not a commutative operator.
22
© Copyright Virtual University of Pakistan
3-Laws of Logic VU
p q p→q q→p
T T T T
T F F T
F T T F
F F T T
EXERCISE:
1. Show that p→q ≡ ~ q → ~ p ( Use the truth table. )
2. Show that q→ p ≡ ~ p → ~ q ( Use the truth table. )
23
© Copyright Virtual University of Pakistan
4-Biconditional VU
BICONDITIONAL
If p and q are statement variables, the biconditional of p and q is “p if and only if q”.
It is denoted p q. “if and only if” is abbreviated as iff.
The double headed arrow " " is the biconditional operator.
Remark:
o p ↔ q is true only when p and q both are true or both are false.
o p ↔ q is false when either p or q is false.
EXAMPLES:
Identify which of the following are True or false?
REPHRASING BICONDITIONAL:
T T T T T T
T F F F T F
F T F T F F
F F T T T T
EXERCISE:
Rephrase the following propositions in the form “p if and only if q” in English.
1. If it is hot outside, you buy an ice cream cone, and if you buy an ice cream
cone, it is hot outside.
Sol You buy an ice cream cone if and only if it is hot outside.
2. For you to win the contest it is necessary and sufficient that you have the
only winning ticket.
Sol You win the contest if and only if you hold the only winning ticket.
3. If you read the news paper every day, you will be informed and conversely.
Sol You will be informed if and only if you read the news paper every day.
5. The train runs late on exactly those days when I take it.
Sol The train runs late if and only if it is a day I take the train.
p q p→q ~q ~p ~ q→ ~ p (p→q) ↔ (~ q→ ~ p)
T T T F F T T
T F F T F F T
F T T F T T T
F F T T T T T
25
© Copyright Virtual University of Pakistan
4-Biconditional VU
26
© Copyright Virtual University of Pakistan
4-Biconditional VU
p q ~p ~q ~p↔q p ↔ ~q
T T F F F F
T F F T T T
F T T F T T
F F T T F F
EXERCISE:
Show that ~(p q) and p q are logically equivalent.
LAWS OF LOGIC:
1.Commutative Law: p↔q≡q↔p
2.Implication Laws: p→q≡~p∨q
≡ ~ ( p ∧ ~ q)
3.Exportation Law: (p ∧ q)→r ≡ p →(q →r)
4.Equivalence: p ↔ q ≡ (p →q)∧(q →p)
5.Reductio ad absurdum p →q ≡ (p ∧ ~q) →c
APPLICATION:
Example: Rewrite the statement forms without using the symbols → or ↔
1. p ∧ ~ q→ r
2. ( p→ r ) ↔ ( q → r )
27
© Copyright Virtual University of Pakistan
4-Biconditional VU
Solution:
1. p∧~q→r ≡ (p ∧ ~q)→ r Order of operations
≡ ~ (p ∧ ~ q) ∨ r Implication law
STATEMENT REASON
~p ∨ q → r ∨ ~q Given statement form
≡ (~p ∨ q) → (r ∨ ~q) Order of operations
≡ ~[(~p ∨ q) ∧ ~ (r ∨ ~q)] Implication law p→q ≡ ~(p∧~ q)
≡ ~[~(p ∧ ~q) ∧ (~r ∧ q)] De Morgan’s law
Solution:
STATEMENT REASON
~(p→q) → p Given statement form
≡ ~[~(p ∧ ~q)] → p Implication law p→q ≡ ~(p ∧ ~q)
≡ (p ∧ ~q) → p Double negation law
≡ ~(p ∧ ~q) ∨ p Implication law p→q ≡ ~p ∨ q
≡ (~p ∨ q) ∨ p De Morgan’s law
≡ (q ∨ ~p) ∨ p Commutative law of ∨
≡ q ∨ (~p ∨ p) Associative law of ∨
≡q∨t Negation law
≡t Universal bound law
EXERCISE:
Suppose that p and q are statements so that p→q is false. Find the truth values
of each of the following:
1.~ p → q
2.p ∨ q
3.q ↔ p
SOLUTION
Hint: ( p→q is false when p is true and q is false.)
1.TRUE
2.TRUE
3.FALSE
28
© Copyright Virtual University of Pakistan
5-Arguments VU
Before we discuss in detail about the argument, we first consider the following argument:
ARGUMENT:
An argument is a list of statements called premises (or assumptions or
hypotheses) followed by a statement called the conclusion.
P1 Premise
P2 Premise
P3 Premise
. . . . .. . . . .
Pn Premise
______________
∴ C Conclusion
NOTE: The symbol ∴ read “therefore” is normally placed just before the conclusion.
p q p→q p q
T T T T T critical row
T F F T F
F T T F T
F F T F F
Since the conclusion q is true when the premises p→q and p are True. Therefore, it is a
valid argument.
p q p→q q p
T T T T T
T F F F T critical row
F T T T F
F F T F F
In the second critical row, the conclusion is false when the premises p→q and q are true.
Therefore, the argument is invalid.
EXERCISE:
Use truth table to determine the argument form
p q
p ~q
p r
∴ r
is valid or invalid.
premises conclusion
F T T T T T T
F T F T T T F
F F T F T T T
F F F F T T F
30
© Copyright Virtual University of Pakistan
5-Argument VU
In the third critical row, the conclusion is false when all the premises are true. Therefore,
the argument is invalid.
t h ~t → h ~h → t ~t ∨~h
T T T T F
T F T T T
F T T T T
F F F F T
( Remember that the critical rows are those rows where the premises have truth value T)
and in the first critical row conclusion has truth value F.
(Also remember that we say an argument is valid if in all critical rows conclusion has
truth value T)
EXERCISE
If at least one of these two numbers is divisible by 6, then the product of these two
numbers is divisible by 6.
Neither of these two numbers is divisible by 6.
∴ The product of these two numbers is not divisible by 6.
SOLUTION
Let d= at least one of these two numbers is divisible by 6.
p= product of these two numbers is divisible by 6.
Then the argument become in these symbols
d→p
~d
∴ ~p
We will made the truth table for premises and conclusion as given below
31
© Copyright Virtual University of Pakistan
5-Argument VU
d p d→p ~d ~p
T T T F F
T F F F T
F T T T F
F F T T T
In the first critical row, the conclusion is false when the premises are true. Therefore, the
argument is invalid.
EXERCISE
If I got an Eid bonus, I’ll buy a stereo.
If I sell my motorcycle, I’ll buy a stereo.
∴ If I get an Eid bonus or I sell my motorcycle, then I’ll buy a stereo.
SOLUTION:
Let
e = I got an Eid bonus
s = I’ll buy a stereo
m = I sell my motorcycle
The argument is
e→s
m→s
∴e ∨ m → s
e s m e →s m →s e∨m e∨m →s
T T T T T T T
T T F T T T T
T F T F F T F
T F F F T T F
F T T T T T T
F T F T T F T
F F T T F T F
F F F T T F T
The argument is valid because in the five critical rows, the conclusion is true.
EXERCISE
An interesting teacher keeps me awake. I stay awake in Discrete Mathematics class.
Therefore, my Discrete Mathematics teacher is interesting.
Solution:
t = My teacher is interesting
a = I stay awake
m = I am in Discrete Mathematics class
32
© Copyright Virtual University of Pakistan
5-Argument VU
t → a,
a∧m
Therefore m∧t
In the second critical row, the conclusion is false when the premises are true. Therefore,
the argument is invalid.
33
© Copyright Virtual University of Pakistan