This chapter define the term computer program, describe the use of flowcharts and pseudocode in programming, identify two ways in which a program can work toward a solution, differentiate the two main approaches to computer programming, list and describe three elements of object-oriented programming.
Trang 1The Foundations: Logic
and Proofs
Chapter 1, Part II:
Predicate LogicWith Question/Answer Animations
Copyright © McGraw-Hill Education All rights reserved No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Trang 2Predicate Logic (FirstOrder Logic (FOL), Predicate Calculus)
Trang 3Predicates and Quantifiers Section 1.4
Trang 5Propositional Logic Not
Later we’ll see how to draw inferences.
Trang 6Introducing Predicate Logic
Trang 8Examples of Propositional Functions
Let “x + y = z” be denoted by R(x, y, z) and U (for all three variables) be the integers. Find these truth values:
Trang 9propositions.
Trang 10We need quantifiers to express the meaning of English words including all and some:
Trang 14Thinking about Quantifiers
When the domain of discourse is finite, we can think of quantification as looping through the elements of the
Even if the domains are infinite, we can still think of the quantifiers this fashion, but the loops will not terminate in some cases
Trang 17Translating from English to Logic
Example 1: Translate the following sentence into predicate logic: “Every student in this class has taken a course in
Java.”
Solution:
First decide on the domain U.
Solution 1: If U is all students in this class, define a propositional function J(x) denoting “x has taken a course in Java” and
Trang 18Translating from English to Logic
Example 2: Translate the following sentence into predicate logic: “Some student in this class has taken a course in
Trang 19Returning to the Socrates
Trang 20equivalent.
Example: x ¬¬S(x) ≡ x S(x)
Trang 21Thinking about Quantifiers
as Conjunctions and
Disjunctions
If the domain is finite, a universally quantified
proposition is equivalent to a conjunction of propositions without quantifiers and an existentially quantified
proposition is equivalent to a disjunction of propositions without quantifiers.
If U consists of the integers 1,2, and 3:
Even if the domains are infinite, you can still think of the quantifiers in this fashion, but the equivalent expressions without quantifiers will be infinitely long
Trang 22Symbolically ¬ x J(x) and x ¬J(x) are equivalent
Trang 23Symbolically ¬ x J(x) and x ¬J(x) are equivalent
Trang 24De Morgan’s Laws for Quantifiers
The rules for negating quantifiers are:
The reasoning in the table shows that:
These are important. You will use these.
Trang 25Translation from English to Logic
Trang 26Some Fun with Translating from English into Logical
Trang 33Lewis Carroll Example
(18321898)
Trang 34Some Predicate Calculus
Trang 37Logic Programming (cont)
In Prolog, names beginning with an uppercase letter are variables.
p c s(I(p,c) ∧ E(s,c)) T(p,s))→
Trang 38Logic Programming (cont)
Prolog programs are loaded into a Prolog interpreter. The interpreter receives queries and returns answers using the
Trang 39Logic Programming (cont)
Trang 40Logic Programming (cont)
Trang 41Nested Quantifiers Section 1.4
Trang 42Negating Nested Quantifiers
Trang 46Questions on Order of Quantifiers
Trang 47Questions on Order of Quantifiers
Trang 48Quantifications of Two
Variables
P(x,y) is true for every pair x,y. There is a pair x, y for which P(x,y) is false.
For every x there is a y for which P(x,y) is true. There is an x such that P(x,y) is false for every y.
Trang 49Solution: Every student in your school has a computer or has a friend who has a computer.
Example 2: Translate the statement
x y z ((F(x, y) F(x,z) (y ≠z)) ¬F(y,z))∧ ∧ →
Solution: There is a student none of whose friends are
also friends with each other
Trang 50Translating Mathematical
Statements into Predicate
Logic
Example : Translate “The sum of two positive integers is always positive” into a logical expression
Trang 51Translating English into
Trang 52Calculus in Logic (optional)
Example: Use quantifiers to express the definition of the
limit of a realvalued function f(x) of a real variable x at a point a in its domain.
Solution: Recall the definition of the statement
is “For every real number > 0, there exists a real number ε > 0 such that |f(x) – L| < whenever 0 < |x –a| < ”δ ε δ
Using quantifiers:
Where the domain for the variables and consists of all ε δ
positive real numbers and the domain for x consists of all
real numbers.
Trang 53Questions on Translation
from English
Choose the obvious predicates and express in predicate logic
Trang 54Negating Nested Quantifiers
Example 1: Recall the logical expression developed three slides back:
Trang 55Return to Calculus and
Logic (Opt)
Example : Recall the logical expression developed in the
calculus example three slides back
Use quantifiers and predicates to express that does not exist
Trang 56Calculus in Predicate Logic
Trang 57Some Questions about
Can you distribute quantifiers over logical connectives?
Is this a valid equivalence?
Solution: Yes! The left and the right side will always have the same truth value no matter what propositional functions are
denoted by P(x) and Q(x).
Is this a valid equivalence?
Solution: No! The left and the right side may have different truth values. Pick “x is a fish” for P(x) and “x has scales” for
Q(x) with the domain of discourse being all animals. Then the
left side is false, because there are some fish that do not have
scales. But the right side is true since not all animals are fish.