You are on page 1of 101

CSC102:Discrete Structure

Tanveer Ahmed Siddiqui

Department of Computer Science


COMSATS University, Islamabad
Recap

Lecture No 1-7

Department of Computer Science 2


Propositional Logic

Department of Computer Science 3


Propositional Logic

 Propositional logic is
 the study of propositions (true or false statements)
and
 The ways of combining them (logical operators) to
get new propositions.

Department of Computer Science


Review: Propositional Logic

 Atomic propositions: p, q, r, …
 Boolean operators:      
 Compound propositions: (p  q)  r
 Equivalences: pq  (p  q)
 Proving equivalences using:
 Truth tables.
 Laws of Logic

Department of Computer Science


Compound Statement

 The truth value of a compound statement is


determined by using Truth Table.

Department of Computer Science 6


Negation of AND, OR and Implication

 The negation of compound statement involving AND


 ~(p  q)  ~p  ~q.
 The negation of compound statement involving OR

~(p  q)  ~p  ~q.
 The negation of the conditional statement:
 ~ (p  q)  p  ~ q

Department of Computer Science 7


Testing Logically Equivalence using Laws

Department of Computer Science 8


Testing Logically Equivalence using Laws

Department of Computer Science 9


Valid and Invalid Arguments

 An argument (form) is a sequence of


statements (statement forms).
 All statements (statement forms) but the last are
called premises, hypotheses, or assumptions.
 The last statement (form) is called the
conclusion.
 The conclusion is preceded by “” (said
“therefore”).
 An argument (form) is valid if whenever its
premises are true, then its conclusion is also
true.
Department of Computer Science
Testing an Argument Form for Validity

 Identify the premises and conclusion of the


argument form.
 Construct a truth table showing the truth values
of all the premises and the conclusion.
 A row of the truth table in which all the
premises are true is called a critical row.

Department of Computer Science


Testing an Argument Form for Validity

 If there is a critical row in which the conclusion


is false, then it is possible for an argument of the
given form to have true premises and a false
conclusion, and so the argument form is invalid. If
the conclusion in every critical row is true, then
the argument form is valid.

Department of Computer Science


Additional Valid Argument Forms: Rule of Inference

A rule of inference is a form of argument that


is valid.

Department of Computer Science


Today Covered

After completing this lecture, you will be able to


understand:
 The Logic of Quantified Statements
 Predicates and Quantified Statements
 Rules of Inference for Quantified
Statements
 Building Arguments for Quantified
Statements

Department of Computer Science


Why not Propositional Logic?

 Are given statements proposition?


 p: n is an odd integer.
 q: computer x is under attack by an intruder
 r: computer y is functioning properly.
 No, these statements are neither true nor false
when the values of the variables are not
specified.
 But in mathematics, computer programs, and in
system specifications, we often encounter
statements involving variables.

Department of Computer Science


Predicate Logic

 Therefore, the propositional logic, studied so


far, cannot adequately express the meaning of
all statements in mathematics and computer
science.
 Since most of the statements in mathematics
and computer science use variables, we must
extend the system of logic to include such
statements.
 In this lecture we will introduce a more
powerful type of logic called predicate logic

Department of Computer Science


Predicate

 To understand predicate logic, we first need to


introduce the concept of a predicate.
 A predicate(a.k.a propositional function) is
a sentence that contains a finite number of
variables
 Anatomy of Predicate:

P(x) = x + 5 > x

variable predicate

Department of Computer Science


Propositional Function

 Functions with multiple variables:


 P(x) = x < 5
 Unary Predicate
 P(x,y) = x + y = 0
 Binary Predicate
 P(x,y,z) = x + y = z
 Ternary Predicate
 P(x1,x2,x3 … xn) = …
 n-ary predicate

Department of Computer Science 18


Propositional Function

 Consider P(x) = x < 5


 P(x) has no truth values (x is not given a value)
 P(1) is true
 The proposition 1<5 is true
 P(10) is false
 The proposition 10<5 is false
 Thus, P(x) will become a proposition when
given a value

Department of Computer Science 19


Propositional Function

 Functions with multiple variables:


 P(x,y) = x + y = 0
 P(1,2) is false,
 P(1,-1) is true
 P(x,y,z) = x + y = z
 P(3,4,5) is false,
 P(1,2,3) is true

Department of Computer Science 20


Propositional Function

 Let P(x) = “x is a multiple of 5”


 For what values of x is P(x) true?
 Let P(x) = x+1 > x
 For what values of x is P(x) true?
 Let x = the character ‘a’
 Is ‘a’+1 > ‘a’?
 Let x = the city of Pakistan
 Is Islamabad+1 > Islamabad?
 You need to specify your universe!
 What values x can represent
 Called the “domain” or “universe of discourse” by the
textbook

Department of Computer Science 21


Universe of Discourse or Domain

 Let P(x) = “x is a multiple of 5”


 For what values of x is P(x) true?
 Let P(x) = x+1 > x
 For what values of x is P(x) true?
 The set of all values that may be substituted in
place of the variable is called domain of a
predicate variable.

Department of Computer Science 22


Your Turn

 Let Q(x, y, z): x2 + y2 = z2.


 What is the truth value of Q(3, 4, 5)?
 What is the truth value of Q(2, 2, 3)?
 How many values of (x, y, z) make the predicate
true?

Department of Computer Science 23


UPSHOT

Let P(x) be a statement involving the variable x and


let D be a set. We call P a predicate (with respect to D)
(or propositional function or open sentence) if for
each x ∈ D, P(x) is a proposition. We call D the
domain of discourse of P.
 You can think of a propositional function as a
function that
 Evaluates to true or false.
 Takes one or more arguments.
 Expresses a predicate involving the argument(s).
 Becomes a proposition when values are assigned to
the arguments.
Department of Computer Science
Quantifiers

 A predicate becomes a proposition when we


assign it fixed values.
 However, another way to make a predicate
into a proposition is to quantify it.
 Consider the following statements:
 All people are mortal
 Every computer is a 16 bit-machine
 No birds are black
 Some people have blue eyes
 There exist an even prime number.

Department of Computer Science


Quantifiers

 How to make a propositional function into a


proposition:
 There are two ways to make a propositional
function into a proposition:
 Supply it with a value
 Provide a quantification

Department of Computer Science


Quantifiers

 Consider the following statements:


 All people are mortal
 Every computer is a 16 bit-machine
 No birds are black
 Some people have blue eyes
 There exist an even prime number.
 Each contains a word indicating the quantity
such as all, every, none, some, and one.
 Such words, called quantifiers, gives us an idea
about how many objects have a certain
property.
Department of Computer Science
Quantifiers

 Quantifiers are words that refer to quantities


such as "some" or "all" and tell for how many
elements a given predicate is true.
 That is, the predicate is true (or false) for all
possible values in the universe of discourse or for
some value(s) in the universe of discourse.

Department of Computer Science


Quantifier

 A quantifier is “an operator that limits the


variables of a proposition”
 Two types:
 Universal
 Which tell us that a predicate is true for every element
under consideration.
 Existential
 Which tell us that there is one or more element under
consideration for which the predicate is true.

Department of Computer Science 29


Universal Quantifier

 Represented by an upside-down A: 
 It means “for all”, “for each”, “for every”
 If the universe of discourse is finite, say {n1, n2, . . ,
nk}, then the universal quantifier is simply the
conjunction of all elements:

 We can state the following:


 x P(x)
 English translation: “for all values of x, P(x) is true”
 Let P(x) = x+1 > x
 English translation: “for all values of x, x+1>x is
true”
Department of Computer Science 30
Turth Value of Universal Quantifier

Department of Computer Science 31


Existential Quantifier
 Represented by an backwards E: 
 It means “there exists a”, “some”, for at least one
 If the universe of discourse is finite, say {n 1, n2, . . ,
nk}, then the universal quantifier is simply the
disjunction of all elements:

 We can state the following:


 x P(x)
 English translation: “there exists (a value of) x such
that P(x) is true”
 Let P(x) = x+1 > x
 English translation: “for at least one value of x,
x+1>x is true”
Department of Computer Science 32
Truth value of Existential Quantifier

Department of Computer Science 33


UPSHOT

 Recall that P(x) is a propositional function


 Let P(x) be “x = 0”
 Recall that a proposition is a statement that is
either true or false
 P(x) is not a proposition
 There are two ways to make a propositional
function into a proposition:
 Supply it with a value
 For example, P(5) is false, P(0) is true
 Provide a quantification
 For example, x P(x) is false and x P(x) is true
 Let the universe of discourse be the real numbers

Department of Computer Science 34


UPSHOT

Truth Values of Quantifiers

Department of Computer Science


Binding Variable

 When a quantifier is used on a variable x, we say


that x is bound.
 If no quantifier is used on a variable in a predicate
statement, it is called free.
 Let P(x,y) be x > y
 Consider: x P(x,y)
 This is not a proposition!
 What is y?
 If it’s 5, then x P(x,y) is false
 If it’s x-1, then x P(x,y) is true
 Note that y is not “bound” by a quantifier

Department of Computer Science 36


Binding Variable

 (x P(x))  Q(x)


 The x in Q(x) is not bound; thus not a proposition
 (x P(x))  (x Q(x))
 Both x values are bound; thus it is a proposition
 (x P(x)  Q(x))  (y R(y))
 All variables are bound; thus it is a proposition
 (x P(x)  Q(y))  (y R(y))
 The y in Q(y) is not bound; this not a proposition

Department of Computer Science 37


Binding Variable: UPSHOT

Department of Computer Science 38


Binding Variable: UPSHOT

Department of Computer Science 39


Negating Quantified Expressions

 Consider the statement:


 All students in this class have red hair
 What is required to show the statement is false?
 There exists a student in this class that does NOT
have red hair
 To negate a universal quantification:
 You negate the propositional function
 AND you change to an existential quantification
 ¬x P(x)  x ¬P(x)

Department of Computer Science 40


Your Turn

 Write the negation of the statement


 “Every student in your class has taken a course in
calculus.”
 Let P(x) :“x has taken a course in calculus”
 and the domain consists of the students in your
class.
 Now the given statement is a universal
quantification, namely, ∀xP(x),
 The negation of this statement is:
 “There is a student in your class who has not
taken a course in calculus.” ∃x ¬ P(x).
Department of Computer Science
Negating Quantified Expressions

 Consider the statement:


 There is a student in this class with red hair
 What is required to show the statement is false?
 All students in this class do not have red hair
 Thus, to negate an existential quantification:
 You negate the propositional function
 AND you change to a universal quantification
 ¬x P(x) = x ¬P(x)

Department of Computer Science 42


Your Turn

 Negate the following statement:


 “There is a student in this class who has taken a
course in calculus.”
 Let Q(x) :“x has taken a course in calculus
 This is the existential quantification ∃xQ(x)
 The negation of this statement is the
proposition
 Every student in this class has not taken
calculus
∀x ¬ Q(x).

Department of Computer Science


Upshot

Department of Computer Science


Some other Statements involving quntifiers

Department of Computer Science


Logical equivalence involving quantifiers

Department of Computer Science


Translating English statement involving Nested Quantifiers

 It is not difficult to translate English statement


to its equivalent logical expression if we follow
the following steps:
 Step 1: Read and understand the English
statement given in the question.
 Step 2: Find the domain of discourse according to
the statement.
 Step 3: Find the associated quantifiers.
 Step 4: Rewrite the statement so that the domain
of discourse and quantifiers are properly visible.
 Step 5: Finally, introduce the variables in the
statement.

Department of Computer Science 47


Translating from English

 “Every student in this class has studied Discrete


Structure”
 Let S(x) be “x is a student”
 Let C(x) be “x has studied Discrete Structure”
 Rephrased: “For every student x in this class, x
has studied Discrete Structure”
 x C(x)
 True if the universe of discourse is all students in this
class

Department of Computer Science 48


Translating from English
 What about if the universe of discourse is all
students (or all people?)
 x (S(x)C(x))
 This is wrong! Why?
 x (S(x)→C(x))
 Another option:
 Let Q(x,y) be “x has studied y”
 x (S(x)→Q(x, Discrete Structure)

Department of Computer Science 49


Translating from English

 Consider:
 “Some students have visited Karachi”
 “Every student in this class has visited Lahore or
Karachi”
 Let:
 S(x) be “x is a student in this class”
 K(x) be “x has visited Karachi”
 L(x) be “x has visited Lahore”

Department of Computer Science 50


Translating from English

 Consider: “Some students have visited Karachi”


 Rephrasing: “There exists a student who has visited
Karachi”
 x K(x)
 True if the universe of discourse is all students
 What about if the universe of discourse is all
people?
 x (S(x) → K(x))
 This is wrong! Why?
 x (S(x)  K(x))

Department of Computer Science 51


Translating from English

 Consider: “Every student in this class has visited


Lahore or Karachi”
 x (K(x)L(x)
 When the universe of discourse is all students
 x (S(x)→(K(x)L(x))
 When the universe of discourse is all people
 Why isn’t x (S(x)(K(x)L(x))) correct?

Department of Computer Science 52


Translating from English

 Note that it would be easier to define


V(x, y) as “x has visited y”
 x (S(x)  V(x,Karachi))
 x (S(x)→(V(x,Karachi)  V(x,Lahore))

Department of Computer Science 53


Translating from English
 Translate the statements:
 “All hummingbirds are richly colored”
 “No large birds live on honey”
 “Birds that do not live on honey are dull in color”
 “Hummingbirds are small”
 Assign our propositional functions
 Let P(x) be “x is a hummingbird”
 Let Q(x) be “x is large”
 Let R(x) be “x lives on honey”
 Let S(x) be “x is richly colored”
 Let our universe of discourse be all birds

Department of Computer Science 54


Translating from English

 Our propositional functions


 Let P(x) be “x is a hummingbird”
 Let Q(x) be “x is large”
 Let R(x) be “x lives on honey”
 Let S(x) be “x is richly colored”
 Translate the statements:
 “All hummingbirds are richly colored”
 x (P(x)→S(x))
 “No large birds live on honey”
 ¬x (Q(x)  R(x))
 Alternatively: x (¬Q(x)  ¬R(x))
 “Birds that do not live on honey are dull in color”
 x (¬R(x) → ¬S(x))
 “Hummingbirds are small”
 x (P(x) → ¬Q(x))

Department of Computer Science 55


Multiple Quantifiers

 You can have multiple quantifiers on a statement


 Nested quantifiers
 Two quantifiers are nested if one is within the
scope of the other.
 Example

Department of Computer Science 56


1
Multiple Quantifiers

 You can have multiple quantifiers on a statement


 xy P(x, y)
 xy P(x,y)
 xy P(x, y)
 xy P(x,y)

Department of Computer Science 57


Multiple Quantifiers

 xy P(x, y)
 “For all x, there exists a y such that P(x,y)”
 Example: xy (x+y = 0)

 xy P(x,y)
 There exists an x such that for all y P(x,y)”
 xy (x*y = 0)

Department of Computer Science 58


Truth Values of 2-variate Quantifiers

Department of Computer Science 59


Order of quantifiers

 xy and xy are not equivalent!

 xy P(x,y)
 P(x,y) = (x+y = 0) is false

 xy P(x,y)
 P(x,y) = (x+y = 0) is true

Department of Computer Science 60


Example 1

 Translate the statement “The sum of two


positive integers is always positive” into an
equivalent logical expression.
 Solution:
 Step 1: Read and understand the English
statement given in the question.
 Step 2: Find the domain of discourse
according to the statement.
 Let us suppose that the domain consists of all
integers.

Department of Computer Science 61


Example 1

Department of Computer Science 62


Example 1

Department of Computer Science 63


Translating English statement involving Nested Quantifiers

Department of Computer Science


64
Translating English statement involving Nested Quantifiers

Department of Computer Science


65
Translating English statement involving Nested Quantifiers

Department of Computer Science


66
Translating English statement involving Nested Quantifiers

The order of quantifiers (example)

Department of Computer Science


67
Translating English statement involving Nested Quantifiers

The order of quantifiers

The order of nested universal quantifiers in a statement


without other quantifiers can be changed without
changing the meaning of the quantified statement.

Department of Computer Science


68
Translating English statement involving Nested Quantifiers

The order of quantifiers (example)

Department of Computer Science


69
Translating English statement involving Nested Quantifiers

The order of quantifiers


The order of nested existential quantifiers in a
statement without other quantifiers can be changed
without changing the meaning of the quantified
statement.

Department of Computer Science


70
Translating English statement involving Nested Quantifiers

The order of quantifiers (example)

Department of Computer Science


71
Translating English statement involving Nested Quantifiers

The order of quantifiers (example)

Department of Computer Science


72
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)


Translate the following statement into a logical expression.
“The sum of two positive integers is always positive.”

Solution:
 Rewrite it in English that quantifiers and a domain are
shown

“For every pair of integers, if both integers are positive, then


the sum of them is positive.”

Department of Computer Science


73
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)


Translate the following statement into a logical expression. “The sum of two
positive integers is always positive.”

Solution:
 Introduce variables
“For every pair of integers, if both integers are positive, then the sum of them
is positive.”

“For all integers x, y, if x and y are positive, then x+y is positive.”

Department of Computer Science


74
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


75
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)


Translate the following statement into a logical expression. “Every
real number except zero has a multiplicative inverse.”
A multiplicative inverse of a real number x is a real number y such that xy = 1.

Solution:
 Rewrite it in English that quantifiers and a domain
are shown

“For every real number except zero, there is a multiplicative


inverse.”

Department of Computer Science


76
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


77
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


78
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


79
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


80
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


81
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


82
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

Department of Computer Science


83
Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

25

Department of Computer Science


Translating English statement involving Nested Quantifiers

Nested quantifiers (example)

26

Department of Computer Science


Negating Multiple quantifiers

 Recall negation rules for single quantifiers:


 ¬x P(x) = x ¬P(x)
 ¬x P(x) = x ¬P(x)
 Essentially, you change the quantifier(s), and negate
what it’s quantifying

 Examples:
 ¬(xy P(x,y))
 = x ¬y P(x,y)
 = xy ¬P(x,y)
 ¬(xyz P(x,y,z))
 = x¬yz P(x,y,z)
 = x¬yz P(x,y,z)
 = xyz ¬P(x,y,z)

Department of Computer Science 86


Negating Multiple quantifiers

 Consider ¬(xy P(x,y)) = xy ¬P(x,y)


 The left side is saying “for all x, there exists a y such
that P is true”
 To disprove it (negate it), you need to show that
“there exists an x such that for all y, P is false”

 Consider ¬(xy P(x,y)) = xy ¬P(x,y)


 The left side is saying “there exists an x such that for
all y, P is true”
 To disprove it (negate it), you need to show that “for
all x, there exists a y such that P is false”

Department of Computer Science 87


Translating between English and quantifiers

 Rosen, section 1.4, question 20

 The product of two negative integers is positive


 xy ((x<0)  (y<0) → (xy > 0))
 Why conditional instead of and?
 The average of two positive integers is positive
 xy ((x>0)  (y>0) → ((x+y)/2 > 0))
 The difference of two negative integers is not necessarily
negative
 xy ((x<0)  (y<0)  (x-y≥0))
 Why and instead of conditional?
 The absolute value of the sum of two integers does not
exceed the sum of the absolute values of these integers
 xy (|x+y| ≤ |x| + |y|)
Department of Computer Science 88
Translating between English and quantifiers

 Rosen, section 1.4, question 24

 xy (x+y = y)
 There exists an additive identity for all real numbers
 xy (((x≥0)  (y<0)) → (x-y > 0))
 A non-negative number minus a negative number is
greater than zero
 xy (((x≤0)  (y≤0))  (x-y > 0))
 The difference between two non-positive numbers is
not necessarily non-positive (i.e. can be positive)
 xy (((x≠0)  (y≠0)) ↔ (xy ≠ 0))
 The product of two non-zero numbers is non-zero if
and only if both factors are non-zero

Department of Computer Science 89


Practice

 Rewrite these statements so that the negations


only appear within the predicates
a) yx P(x,y)
yx P(x,y)
yx P(x,y)
b) xy P(x,y)
xy P(x,y)
xy P(x,y)
c) y (Q(y)  x R(x,y))
y (Q(y)  x R(x,y))
y (Q(y)  (x R(x,y)))
y (Q(y)  x R(x,y))

Department of Computer Science 90


Your Turn

 Express the negations of each of these statements so


that all negation symbols immediately precede
predicates.
a) xyz T(x,y,z)
(xyz T(x,y,z))
xyz T(x,y,z)
xyz T(x,y,z)
xyz T(x,y,z)
xyz T(x,y,z)
b) xy P(x,y)  xy Q(x,y)
(xy P(x,y)  xy Q(x,y))
xy P(x,y)  xy Q(x,y)
xy P(x,y)  xy Q(x,y)
xy P(x,y)  xy Q(x,y)

Department of Computer Science 91


Rule of Inference for Universal quantifier

Department of Computer Science 92


Rule of Inference for Universal quantifier

 Assume that we know that x P(x) is true


 Then we can conclude that P(c) is true
 Here c stands for some specific constant
 This is called “universal instantiation”

 Assume that we know that P(c) is true for any


value of c
 Then we can conclude that x P(x) is true
 This is called “universal generalization”

Department of Computer Science 93


Rule of Inference for Existential quantifier

 Assume that we know that x P(x) is true


 Then we can conclude that P(c) is true for some
value of c
 This is called “existential instantiation”

 Assume that we know that P(c) is true for some


value of c
 Then we can conclude that x P(x) is true
 This is called “existential generalization”

Department of Computer Science 94


Example of Proof

Department of Computer Science 95


Example of Proof

Department of Computer Science 96


Example of Proof

 Given the hypotheses:


“Laiba, a student in this class, owns

a red convertible.”
 “Everybody who owns a red C(Laiba)
convertible has gotten at least one R(Laiba)
speeding ticket”
 Can you conclude: “Somebody in x (R(x)→T(x))
this class has gotten a speeding
ticket”? x (C(x)T(x))

Department of Computer Science 97


Example of Proof

1. x (R(x)→T(x)) 3rd hypothesis


2. R(Laiba) → T(Laiba) Universal instantiation using step
1
3. R(Laiba) 2nd hypothesis
4. T(Laiba) Modes ponens using steps 2 & 3
5. C(Laiba) 1st hypothesis
6. C(Laiba)  T(Laiba) Conjunction using steps 4 & 5
7. x (C(x)T(x)) Existential generalization using
step 6

Thus, we have shown that “Somebody in this class has


gotten a speeding ticket”
Department of Computer Science 98
Example of proof

 Given the hypotheses:


 “There is someone in this class who
has been to France”
 “Everyone who goes to France visits
the Louvre”
 Can you conclude: “Someone in x (C(x)F(x))
this class has visited the Louvre”?
x (F(x)→L(x))

x (C(x)L(x))

Department of Computer Science 99


Example of proof

1. x (C(x)F(x)) 1st hypothesis


2. C(y)  F(y) Existential instantiation using step 1
3. F(y) Simplification using step 2
4. C(y) Simplification using step 2
5. x (F(x)→L(x)) 2nd hypothesis
6. F(y) → L(y) Universal instantiation using step 5
7. L(y) Modus ponens using steps 3 & 6
8. C(y)  L(y) Conjunction using steps 4 & 7
9. x (C(x)L(x)) Existential generalization using
step 8
Thus, we have shown that “Someone in this class has
visited the Louvre”
Department of Computer Science 100
Example of proof

Department of Computer Science 101

You might also like