0% found this document useful (0 votes)
27 views59 pages

Chapter Logic - Part2 - 241009 - 102525

Uploaded by

bdllhstudy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views59 pages

Chapter Logic - Part2 - 241009 - 102525

Uploaded by

bdllhstudy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Mansoura University

Faculty of Computers and Information


Department of Computer Science
First Semester- 2021-2022

DISCRETE MATHEMATICS
First Grade
Prof. Dr : Magdi Zakaria Prof Dr : Samir Elmougy

Dr : Rasha Sakr
Lecture 2

Chapter 1. The Foundations


2. Propositional Equivalences
3. Predicates and Quantifiers
1.2 Propositional Equivalence
Introduction
Two logical expressions are said to be equivalent if
they have the same truth value in all cases. Sometimes
this fact helps in proving a mathematical result by
replacing one expression with another equivalent
expression, without changing the truth value of the
original compound proposition.
1.2 Propositional Equivalence
❑ Types of propositions based on Truth values
◼ A tautology is a compound proposition that is always
true no matter what the truth values of its atomic
propositions are!
◼ e.g. p  p (“Today the sun will shine or today the sun

will not shine.”) [What is its truth table?]


◼ A contradiction is a compound proposition that is
false no matter what!
◼ e.g. p  p (“Today is Wednesday and today is not

Wednesday.”) [Truth table?]


◼ A contingency is a compound proposition that is
neither a tautology nor a contradiction.
◼ e.g. (p  q) → r
Definition of Logical Equivalence

◼ Formally, Two propositions p and q are said to


be logically equivalent if compound
proposition p  q or p  q is a Tautology,
written p  q or p  q, iff the p  q is a
tautology.The notation p  q is used to denote
that p and q are logically equivalent.

◼ Compound propositions p and q are logically


equivalent to each other iff p and q contain the
same truth values as each other in all
corresponding rows of their truth tables.
Logical Equivalence
One way of proving that two propositions are logically
equivalent is to use a truth table. The truth table must
be identical for all combinations for the given
propositions to be equivalent.
But this method is not always feasible since the
propositions can be increasingly complex both in the
number of propositional variables used and size of the
expression.
In this case, there needs to be a better way to prove
that the two given propositions are logically equivalent.
That better way is to construct a mathematical proof
which uses already established logical equivalences to
construct additional more useful logical equivalences.
Proving Equivalence
via Truth Tables
◼ Prove that (p  q)  p  q. (De Morgan’s law)

p q p q  p  q  p   q (p  q)
TT T F F F F
TF F F T T T
FT F T F T T
FF F T T T T
◼ Show that Check out the solution in the textbook!
◼ (p  q)  p  q (De Morgan’s law)

◼ p → q  p  q

◼ p  (q  r)  (p  q)  (p  r) (distributive law)
Problems with Truth Table
The above example could easily be solved using a
truth table. But this can only be done for a proposition
having a small number of propositional variables.
When the number of variables grows the truth table
method becomes impractical.
For a proposition having 20 variables, 220 rows have to
be evaluated in the truth table. This may be easy to do
with a computer, but even a computer would fail in
computing the truth table of a proposition having
1000 variables.
Equivalence Laws

◼ These are similar to the arithmetic identities


you may have learned in algebra, but for
propositional equivalences instead.

◼ They provide a pattern or template that can


be used to match part of a much more
complicated proposition and to find an
equivalence for it and possibly simplify it.
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)
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
◼ Absorption
p  (p  q)  p p  (p  q)  p
◼ Trivial tautology/contradiction:
p  p  T p  p  F
Defining Operators via
Equivalences

Using equivalences, we can define operators


in terms of other operators.

◼ Exclusive or: p  q  (p  q)  (p  q)


p  q  (p  q)  (p  q)
◼ Implies: p → q  p  q
◼ Biconditional: p  q  (p → q)  (q → p)
p  q  (p  q)
This way we can “normalize” propositions
An Example Problem
◼ Show that (p → q) and p  q are logically
equivalent.

(p → q) [Expand definition of →]


 (p  q) [DeMorgan’s Law]
 (p)  q [Double Negation]
 p  q
Another Example Problem

◼ Check using a symbolic derivation whether


(p  q) → (p  r)  p  q  r

(p  q) → (p  r) [Expand definition of →]


 (p  q)  (p  r) [Expand definition of ]
 (p  q)  ( (p  r)  (p  r) )
[DeMorgan’s Law]
 (p  q)  ( (p  r)  (p  r) )
cont.
Example Continued...
(p  q) → (p  r)  p  q  r

(p  q)  ((p  r)  (p  r)) [ Commutative]


 (q  p)  ((p  r)  (p  r)) [ Associative]
 q  ( p  ((p  r)  (p  r)) ) [Distribute  over ]
 q  ( ( (p  (p  r))  (p  (p  r) ) ) [ Assoc.]
 q  ( ( (p  p)  r)  (p  (p  r) ) ) [Trivial taut.]
 q  ( (T  r)  (p  (p  r) ) ) [Domination]
 q  ( T  (p  (p  r)) ) [Identity]
 q  ( p  (p  r) )
cont.
End of Long Example
(p  q) → (p  r)  p  q  r

q  (p  (p  r) ) [DeMorgan’s Law]


 q  ( p  (p  r) ) [ Associative]

 q  ( (p  p)  r ) [Idempotent]

 q  (p  r) [Associative]


 (q  p)  r [ Commutative]
 p  q  r ■
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

◼ Symbolic derivations (series of logical

equivalences) p  q  r  
1.3 Predicate Logic
◼ A proposition is the basic building block of logic. It is defined as a
declarative sentence that is either True or False, but not both.
◼ "Every person who is 18 years or older, is eligible to vote.“
◼ The above statement cannot be adequately expressed using only
propositional logic. The problem in trying to do so is that
propositional logic is not expressive enough to deal with
quantified variables. It would have been easier if the statement
were referring to a specific person. But since it is not the case and
the statement applies to all people who are 18 years or older, we
are stuck.
Therefore we need a more powerful type of logic.
Propositional Functions
Propositional Functions
What is a predicate?
Definition :
A statement of the form P(x1, x2, . . . , xn) is the value of the propositional function P. Here,
(x1, x2, . . . , xn) is an n-tuple and P is a predicate.

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.
• Let Q(x, y, z) denote the statement “x 2 + y 2 = z 2”. 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?
• Since 3 2 + 4 2 = 25 = 5 2 , Q(3, 4, 5) is true.
• Since 2 2 + 2 2 = 8 ≠ 3 2 = 9, Q(2, 2, 3) is false.
• There are infinitely many values for (x, y, z) that make this propositional function true—
how many right triangles are there?
1.3 Predicate Logic

◼ Consider the sentence “For every x, x  0”


If this were a true statement about the positive
integers, it could not be adequately symbolized using
only statement letters, parentheses and logical
connectives.
Predicate Logic is an extension of Propositional logic. It adds
the concept of predicates and quantifiers to better capture
the meaning of statements that cannot be adequately
expressed by propositional logic.
The sentence contains two new features: a
predicate and a quantifier
Subjects and Predicates
Consider the statement, “x is greater than 3″. It has two parts.
The first part, the variable x, is the subject of the statement.
The second part, “is greater than 3”, is the predicate. It refers to
a property that the subject of the statement can have.
The statement “x is greater than 3″ can be denoted by P(x)
where P denotes the predicate “is greater than 3” and x is the
variable.
The predicate P can be considered as a function. It tells the truth
value of the statement P(x) at x. Once a value has been
assigned to the variable x, the statement P(x) becomes a
proposition and has a truth value (T/ F).
Subjects and Predicates
◼ In the sentence “The dog is sleeping”:
◼ The phrase “the dog” denotes the subject –

the object or entity that the sentence is about.


◼ The phrase “is sleeping” denotes the predicate

– a property that the subject of the statement


can have.
◼ In predicate logic, a predicate is modeled as a
proposional function P(·) from subjects to
propositions.
◼ P(x) = “x is sleeping” (where x is any subject).

◼ P(The cat) = “The cat is sleeping” (proposition!)


Examples

In general, a statement involving n variables x1, x2, x3,.. , xn can be


denoted by P(x1, x2, x3,.. , xn). Here P is also referred to as n-place
predicate or a n-ary predicate.

Example 1: Let P(x) denote the statement “x > 10″. What are the truth
values of P(11) and P(5)?
Solution: P(11) is equivalent to the statement 11 > 10, which is True.
P(5) is equivalent to the statement 5 > 10, which is False.

Example 2: Let R(x,y) denote the statement “x = y + 1“. What is the truth
value of the propositions R(1,3) and R(2,1)?
Solution: R(1,3) is the statement 1 = 3 + 1, which is False.
R(2,1) is the statement 2 = 1 + 1, which is True.
More About Predicates
◼ Convention: Lowercase variables x, y, z...
denote subjects; uppercase variables P, Q,
R… denote propositional functions (or
predicates).
◼ Keep in mind that the result of applying a
predicate P to a value of subject x is the
proposition. But the predicate P, or the
statement P(x) itself (e.g. P = “is sleeping” or
P(x) = “x is sleeping” ) is not a proposition.
◼ e.g. if P(x) = “x is a prime number”,

P(3) is the proposition “3 is a prime number.”


Propositional Functions
◼ Predicate logic generalizes the grammatical
notion of a predicate to also include
propositional functions of any number of
arguments, each of which may take any
grammatical role that a noun can take.
◼ e.g.:

let P(x,y,z) = “x gave y the grade z”


then if
x = “Mike”, y = “Mary”, z = “A”,
then
P(x,y,z) = “Mike gave Mary the grade A.”
Examples
◼ Let P(x): x > 3. Then
◼ P(4) is TRUE/FALSE 4>3
◼ P(2) is TRUE/FALSE 2>3
◼ Let Q(x, y): x is the capital of y. Then
◼ Q(Washington D.C., U.S.A.) is TRUE

◼ Q(Hilo, Hawaii) is FALSE

◼ Q(Massachusetts, Boston) is FALSE


◼ Q(Denver, Colorado) is TRUE
◼ Q(New York, New York) is FALSE
◼ Read EXAMPLE
If x > 0 then x:= x + 1 (in a computer program)
Example
Define Q(x,y):x+y=1.

Which of the following are propositions; which are not?

Q(x,y)
Q(x,3)
Q(1,1)
Q(5,−4)
For those that are, determine their truth values.

Answer
Both (a) and (b) are not propositions, because they contain at least one variable.
Both (c) and (d) are propositions; Q(1,1) is false, and Q(5,−4) is true.

Determine the truth values of these statements


Q(5,−7)
Q(−6,7)
Q(x+1,−x)
Universe of Discourse (U.D.)
◼ The power of distinguishing subjects from
predicates is that it lets you state things about
many objects at once.
◼ e.g., let P(x) = “x + 1  x”. We can then say,
“For any number x, P(x) is true” instead of
(0 + 1  0)  (1 + 1  1)  (2 + 1  2)  ...

◼ The collection of values that a variable x can


take is called x’s universe of discourse or
the domain of discourse (often just referred
to as the domain).
Quantifier Expressions
◼ Quantifiers provide a notation that allows us
to quantify (count) how many objects in the
universe of discourse satisfy the given
predicate.

◼ “” is the FOR ALL or universal quantifier.


x P(x) means for all x in the domain, P(x).
◼ “” is the XISTS or existential quantifier.
x P(x) means there exists an x in the domain
(that is, for some values) such that P(x).
Log

The Universal Quantifier 


◼ x P(x): For all x in the domain, P(x).
◼ x P(x) is
◼ true if P(x) is true for every x in D (D: domain of

discourse)
◼ false if P(x) is false for at least one x in D

◼ For every real number x, x


2  0 TRUE

◼ For every real number x, x 2 – 1  0 FALSE

◼ A counter example to the universal statement


x P(x) is a value x in the domain D that makes
P(x) false
◼ What is the truth value of x P(x) when the
domain is empty? TRUE
The Universal Quantifier 
◼ If all the elements in the domain can be listed as x1,
x2,…, xn then, x P(x) is the same as the
conjunction:
∀xP(x) ⇐⇒ P(x1)  P(x2)  ···  P(xn)

◼ Example: Let the domain of x be parking spaces at


UH. Let P(x) be the statement “x is full.” Then the
universal quantification of P(x), x P(x), is the
proposition:
◼ “All parking spaces at UH are full.”
◼ or “Every parking space at UH is full.”
◼ or “For each parking space at UH, that space is full.”
Universal Quantifier Example

- Let P(x) be the predicate “x must take a discrete mathematics


course” and let Q(x) be the predicate “x is a computer science
student”.
The universe of discourse for both P(x) and Q(x) is all UNL
students.

Express the statement “Every computer science student must


take a discrete mathematics course”.

∀x(Q(x) → P(x))
Universal Quantifier Example

1- The statement
“For any real number x , we always have x2≥0 ”
is true. Symbolically, we can write ∀x∈ ℝ(x2 ≥0),or ∀x(x∈ ℝ ⇒ x2 ≥0).

2- The statement
∀x∈ℝ (x>5)

is false because x is not always greater than 5. To disprove a claim, it


suffices to provide only one counterexample. We can use x=4 as a
counterexample.
The Existential Quantifier 
◼ x P(x): There exists an x in the domain (that is,
some values) such that P(x).
◼ x P(x) is
◼ true if P(x) is true for at least one x in the
domain
◼ false if P(x) is false for every x in the domain

◼ What is the truth value of x P(x) when the


domain is empty? FALSE
◼ If all the elements in the domain can be listed as x1,
x2,…, xn then, x P(x) is the same as the disjunction:
◼ ∃xP(x) ⇐⇒ P(x1)  P(x2)  ···  P(xn)
The Existential Quantifier 
Express the statement “there exists a real solution to
ax2 + bx − c = 0”
Let P(x) be the statement
−𝑏± 𝑏2 −4𝑎𝑐
𝑥= where the universe
2𝑎
of discourse for x is the set of reals. Note here that a, b, c are all
fixed constants.
The statement can thus be expressed as
∃xP(x)
Question: what is the truth value of ∃xP(x)?
Answer: it is false. For any real numbers such that b2 < 4ac,
there will only be complex solutions, for these cases no such
real number x can satisfy the predicate.
How can we make it so that it is true?
Answer: change the universe of discourse to the complex numbers, C.
The Existential Quantifier 
◼ Example:
Let the domain of x be parking spaces at UH.
Let P(x) be the statement “x is full.”
Then the existential quantification of P(x),
x P(x), is the proposition:
◼ “Some parking spaces at UH are full.”
◼ or “There is a parking space at UH that is full.”
◼ or “At least one parking space at UH is full.”
Example
The proposition

“There exists a real number x such that x>5 ”

can be expressed, symbolically, as


∃x∈ ℝ(x>5),or ∃x(x∈ ℝ ∧ x>5).

Notice that in an existential quantification, we use ∧


instead of ⇒ to specify that x is a real number.
Unique Existential Quantifiers –
Although the universal and existential quantifiers are the most
important in Mathematics and Computer Science, they are not the
only ones. In Fact, there is no limitation on the number of different
quantifiers that can be defined, such as “exactly two”, “there are no
more than three”, “there are at least 10”, and so on.
Of all the other possible quantifiers, the one that is seen most often is
the uniqueness quantifier, denoted by !.

For example:
There is exactly one natural number x such that
x - 2 = 4.
Symbolically, this can be written:

∃!x in N, x - 2 = 4
Example

Let Q(x, y, z) denote the statement “x2 + y2 = z2”.


. What are the truth values of
(i) ∀(x,y,z) Q(x,y,z)
(ii) ∃(x,y,z) Q(x,y,z) Where the domain consists of all real
numbers.

i)Answer: false (Since 2 2 + 2 2 = 8 ≠ 3 2 = 9)


ii)Answer: true ( Since 3 2 + 4 2 = 25 = 5 2 )

Exercise : Let P(x) be the predicate x2 − x > 0 with domain the set R.
Write P(2) and P(1/2)
Example
To prove that a statement of the form “ ∃xP(x) ” is true,
it suffices to find an example of x such that P(x) is
true. Using this guideline, can you determine whether
these two propositions

∃x∈ ℝ (x>5)
∃x∈ ℝ ( 𝑥=0)
are true?

Answer
True. For example: x=6 .
True. For example: x=0 .
Example
Let P(x) be the statement x2 ≥ x.
(i) What are truth values of the propositions P(1) , P(-1) , P(0) and P( ½)
ii) What is the truth value of the proposition ∀xP(x), where the domain consists of all
real numbers?
(iii) What is the truth value of the proposition ∀xP(x), where the domain consists of all
integers?
a) P(x):x2 ≥ x.
i) P(1): 1=1 true
P(-1): 1>-1 true
P(0): 0=0 true
P(1/2): 1/4<1/2 false

ii)Answer: false (example: P(1/2): 1/4 )

iii)Answer: true
Example
- if P(x): x2 > x defined on ℤ , what is the truth values for
∃!x P(x) ∃x P(x) ∀x P(x)
∃!x P(x) is “F” ( For example: P(x=-2)and P (x=3) is “T”)
∃x P(x) is “T” ( For example :P(x=-3) is “T”)
∀ x P(x) is “F” ( For example :P(x=0) is “F” and P(x=1) is “F” )

- if P(x): x2 ≥ x defined on ℝ , what is the truth values for


i. ∃!x P(x) ∃x P(x) ∀x P(x)
∃!x P(x) is “F” ( For example: P(x=3)and P (x=4) is “T”)
∃x P(x) is “T” ( For example :P(x=3) is “T”)
∀ x P(x) is “F” ( For example :P(x=1/2) is “F”)

- if P(x): x2 > x defined on ℕ , what is the truth values for


i. ∃!x P(x) ∃x P(x) ∀x P(x)
∃!x P(x) is “F” ( For example: P(x=2) is “T” , also P(3) is “T” )
∃x P(x) is “T” ( For example :P(x=3) is “T”)
∀ x P(x) is “F” ( For example :P(x=0) is “F”)
Example
Log

Free and Bound Variables


◼ An expression like P(x) is said to have a free
variable x (meaning, x is undefined).
◼ A quantifier (either  or ) operates on an
expression having one or more free variables,
and binds one or more of those variables, to
produce an expression having one or more
bound variables.
◼ in the expression sum(k) =f( k,n) , n is a free variable and k is a bound
variable
◼  x P(x,y,z) has only one bound variable :x,
and two free variables : y and z.
Free and Bound Variables

An occurrence of a variable x in a formula is free if there


is no ∀x or ∃x on the leaf-to-root path from that
occurrence in the formula’s parse tree. If an occurrence
is not free, it is bound
Example:
∀x(P(x) ∧ Q(y) ∧ R(z) → ¬∃y(S(y, w) ∨ T(x)))

Here, all occurrences of x are bound, and all


occurrences of w and z are free.
The first occurrence of y (i.e., in Q(y)) is free and
the second occurrence of y (i.e., in S(y, w)) is bound.
Example of Binding
◼ P(x,y) has 2 free variables, x and y.
◼ x P(x,y) has 1 free variable , and one
bound variable . [Which is which?]
◼ “P(x), where x = 3” is another way to bind x.
◼ An expression with zero free variables is a
bona-fide (actual) proposition.
◼ An expression with one or more free
variables is not a proposition:
e.g. x P(x,y) =Q(y)
Quantifiers with Restricted Domains
◼ Sometimes the universe of discourse is
restricted within the quantification, e.g.,

◼ x0 P(x) is shorthand for


“For all x that are greater than zero, P(x).”
= x (x  0 → P(x))
◼ x0 P(x) is shorthand for
“There is an x greater than zero such that
P(x).”
= x (x  0  P(x))
Translating from English
◼ Express the statement “Every student in this class
has studied calculus” using predicates and
quantifiers.
◼ Let C(x) be the statement: “x has studied

calculus.”
◼ If domain for x consists of the students in this

class, then
◼ it can be translated as x C(x)

or
◼ If domain for x consists of all people
◼ Let S(x) be the predicate: “x is in this class”
◼ Translation: x (S(x) → C(x))
Translating from English
◼ Express the statement “Some students in this
class has visited Mexico” using predicates and
quantifiers.
◼ Let M(x) be the statement: “x has visited

Mexico”
◼ If domain for x consists of the students in this

class, then
◼ it can be translated as x M(x)

or
◼ If domain for x consists of all people

◼ Let S(x) be the statement: “x is in this class”

◼ Then, the translation is x (S(x)  M(x))


Translating from English
◼ Express the statement “Every student in this
class has visited either Canada or Mexico”
using predicates and quantifiers.
◼ Let C(x) be the statement: “x has visited
Canada” and M(x) be the statement: “x has
visited Mexico”
◼ If domain for x consists of the students in
this class, then
◼ it can be translated as x (C(x)  M(x))
Negations of Quantifiers
◼ x P(x): “Every student in the class has taken
a course in calculus” (P(x): “x has taken a
course in calculus”)
◼ “Not every student in the class … calculus”

x P(x)  x P(x)


◼ Consider x P(x): “There is a student in the
class who has taken a course in calculus”
◼ “There is no student in the class who has

taken a course in calculus”


x P(x)  x P(x)
Negations of Quantifiers
◼ Definitions of quantifiers: If the domain = {a, b, c,…}
◼ x P(x)  P(a)  P(b)  P(c)  ∙∙∙

◼ x P(x)  P(a)  P(b)  P(c)  ∙∙∙

◼ From those, we can prove the laws:


◼ x P(x)  (P(a)  P(b)  P(c)  ∙∙∙ )

 P(a)  P(b)  P(c)  ∙∙∙


 x P(x)
◼ x P(x)  (P(a)  P(b)  P(c)  ∙∙∙ )

 P(a)  P(b)  P(c)  ∙∙∙


 x P(x)
◼ Which propositional equivalence law was used to
prove this?
Negations of Quantifiers

Theorem:
◼ Generalized De Morgan's laws for logic
1. x P(x)  x P(x)

2.   x P(x)   x P(x)
Negations: Examples
◼ What are the negations of the statements
x (x2  x) and x (x2 =2)?
◼ x (x2  x)  x (x  x)  x (x2  x)
2

◼ x (x2 = 2)  x (x2 = 2)  x (x2  2)

◼ Show that x(P(x) → Q(x)) and


x(P(x)  Q(x)) are logically equivalent.
◼ x(P(x) → Q(x))  x (P(x) → Q(x))
 x (P(x)  Q(x))
 x (P(x)  Q(x))
Review: Predicate Logic
Objects x, y, z, …
Predicates P, Q, R, … are functions
mapping objects x to propositions P(x).
Multi-argument predicates P(x, y).
Quantifiers: [x P(x)] :≡ “For all x’s,
P(x).”
[x P(x)] :≡ “There is an x such that
P(x).”
Universes of discourse, bound & free
vars.
Quantifier Exercise
If R(x,y)=“x relies upon y,” express the
following in unambiguous English:
x(y R(x,y))= Everyone has someone to rely on.
y(x R(x,y))= There’s a poor overburdened soul whom
everyone relies upon (including himself)!
x(y R(x,y))=There’s some needy person who relies
upon everybody (including himself).
y(x R(x,y))=
Everyone has someone who relies upon them.
x(y R(x,y))= Everyone relies upon
everybody, (including
themselves)!
Summary

You might also like