X - 陳光琦

Download Report

Transcript X - 陳光琦

資訊科學數學6
:
Predicates, Quantifiers &
Mathematical Induction
陳光琦助理教授 (Kuang-Chi Chen)
[email protected]
Predicates & Quantifiers
Predicates
• The statement “ X is greater than 3” has 2 parts:
object (variable X) and predicate (“is greater
than 3”).
• Let P(X) denote statement “X is greater than 3”,
where P denote the predicate “is greater than 3”.
P(X) is also said to be the value of propositional
function P(·) at X .
• For example, let P(X) denote “X > 3”, what are
the truth values of P(4) and P(2)?
Predicates
• Let Q(x, y) denote the statement “x = y+3”,
What are the truth values of the propositions
Q(1, 2) and Q(3, 0)?
• Let R(x, y, z) denote the statement “x+y = z”,
What are the truth values of the propositions
R(1, 2, 3) and R(0, 0, 1)?
• A statement of the form P(x1, x2, …, xn) is the
value of the propositional function P at the ntuple (x1, x2, …, xn), and P is also called a
predicate.
Predicate Logic
• Predicate logic is an extension of propositional
logic that permits concisely reasoning about
whole classes of entities.
• Propositional logic (recall) treats simple
propositions (sentences) as atomic entities.
• In contrast, predicate logic distinguishes the
subject of a sentence from its predicate.
- Remember these English grammar terms?
Applications of Predicate Logic
• It is the formal notation for writing perfectly
clear, concise, and unambiguous mathematical
definitions, axioms, and theorems for any
branch of mathematics.
- Predicate logic with function symbols, the “=”
operator, and a few proof-building rules is
sufficient for defining any conceivable
mathematical system, and for proving anything
that can be proved within that system!
Other Applications
• Predicate logic is the foundation of the
field of mathematical logic, which
culminated in Gödel’s incompleteness
theorem, which revealed the ultimate
limits of mathematical thought :
Given any finitely describable, consistent
proof procedure, there will always remain
some true statements that will never be
proven by that procedure.
Kurt Gödel
1906-1978
i.e., we can’t discover all mathematical truths, unless we
sometimes resort to making guesses.
Practical Applications of Predicate Logic
• It is the basis for clearly expressed formal
specifications for any complex system.
• It is basis for automatic theorem provers and
many other Artificial Intelligence systems.
E.g. automatic program verification systems.
• Predicate-logic like statements are supported
by some of the more sophisticated database
query engines and container class libraries.
- these are types of programming tools.
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 is true of the subject.
• In predicate logic, a predicate is modeled as a
function P(·) from objects to propositions.
- P(x) = “x is sleeping” (where x is any object).
More About Predicates
• Convention: Lowercase variables x, y, z... denote
objects/entities; uppercase variables P, Q, R…
denote propositional functions (predicates).
• Keep in mind that the result of applying a
predicate P to an object x is the proposition P(x).
But the predicate P itself (e.g. P = “is sleeping”)
is not a proposition (not a complete sentence).
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.”
Universes of Discourse
(U.D.s)
• The power of distinguishing objects 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.
(domain)
Quantifiers
• Quantifiers provide a notation to quantify
(count) how many objects satisfy a given
predicate.
• There are two types of quantifiers: universal
quantification and existential quantification.
Two Types of Quantifiers
• “” is the FORLL or universal quantifier.
x P(x) means for all x in the u.d., P holds.
• “” is the XISTS or existential quantifier.
x P(x) means there exists an x in the u.d. (that
is, 1 or more) such that P(x) is true.
The Universal Quantifier 
E.g., let the u.d. of x be parking spaces at TCU.
Let P(x) be the predicate “x is full.”
Then the universal quantification of P(x) is
x P(x), is the proposition:
“All parking spaces at TCU are full.”, i.e.,
“Every parking space at TCU is full.”, i.e.,
“For each parking space at TCU, that space is
full.”
The Existential Quantifier 
E.g., let the u.d. of x be parking spaces at TCU.
Let P(x) be the predicate “x is full.”
Then the existential quantification of P(x),
x P(x), is the proposition:
“Some parking space at TCU is full.”, i.e.,
“There is a parking space at TCU that is full.”
“At least one parking space at TCU is full.”
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.
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? y is free …]
• “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 still only a predicate: e.g., Q(y) = x P(x, y).
Negations
• Let x P(x) be the statement of
“Every student in the class has taken a course in
calculus”, where P(x) is “x has taken a course
in calculus”
• What is its negation? x P(x)
 (x P(x)) ≡ x P(x)
 (x Q(x)) ≡ x Q(x)
Translating from English into
Logical Expressions
• Express “Every student in this class has studied
Calculus” using predicates and quantifiers.
Sol.1: Let C(·) be the predicate of “· has studied
Calculus”. Assume universe of disclosure of x
consists of the students in the class.
It’s x C(x).
Translating from English into
Logical Expressions (cont’d)
Sol.2: If the u.d. is all people. Let S(·) be the
predicate of “· is in this class”. The solution is
x S(x)  C(x). [Not x S(x)  C(x) ? ]
Sol.3: We concern about other subjects. Let Q(x, y)
be the predicate of “student x has studied subject
y”. The solution is x (S(x)  Q(x, Calculus)).
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 variables.
Induction
Introduction to Induction
• A powerful, rigorous technique for proving that
a predicate P(n) is true for every natural number
n, no matter how large.
• Essentially a “domino effect” principle.
The First Principle of
Mathematical Induction
• Based on a predicate-logic inference rule:
P(0)
n0 (P(n)  P(n+1))
n0 P(n)
The “Domino Effect”
• Premise #1: Domino #0 falls.
• Premise #2: For every kN,
if domino #k falls, then so
does domino #k+1.
• Conclusion: All of
the dominoes fall down!
Note: this works even if there are
infinitely many dominoes!
Validity of Induction
Proof that n0 P(n) is a valid consequent:
Given any k0, the 2nd antecedent
k0 (P(k)P(k+1)) trivially implies that
k0 (k<n)(P(k)P(k+1)), i.e., that
(P(0)P(1))  (P(1)P(2))  …  (P(n1)P(n)).
Repeatedly applying the hypothetical syllogism
rule to adjacent implications in this list n−1
times then gives us P(0)P(n); which together
with P(0) (antecedent #1) and modus pones
gives us P(n). Thus n0 P(n). ■
Outline of An Inductive Proof
•Let us say we want to prove n P(n)…
–Do the base case (or basis step): Prove P(0).
–Do the inductive step: Prove n P(n)P(n+1).
E.g. you could use a direct proof, as follows:
•Let nN, assume P(n). (inductive hypothesis)
•Now, under this assumption, prove P(n+1).
–The inductive inference rule then gives us
n P(n).
Generalizing Induction
• Rule can also be used to prove nc P(n) for a
given constant cZ, where maybe c0.
– In this circumstance, the base case is to prove P(c)
rather than P(0), and the inductive step is to prove
nc (P(n)P(n+1)).
• Induction can also be used to prove
nc P(an) for any arbitrary series {an}.
• Can reduce these to the form already shown.
The Second Principle of
Mathematical Induction
•Characterized by another inference rule:
P(0) P is true in all previous cases
n0: (0kn P(k))  P(n+1)
n0: P(n)
“Strong Induction”
•The only difference between this and the 1st
principle is that:
- the inductive step here makes use of the stronger
hypothesis that P(k) is true for all smaller numbers
k < n+1, not just for k = n.
Examples of Induction
1st Principle Example
•Prove that the sum of the first n odd positive
integers is n2. That is, prove:
n
n  1:  (2i  1)  n
2
i 1
P(n)
• Proof by induction:
– Base case: Let n=1. The sum of the first 1 odd
positive integer is 1 which equals 12.
(cont’d…)
1st Principle Example
(cont’d)
• Inductive step: Prove  n≥1: P(n)→P(n+1).
Let n≥1, assume P(n), and prove P(n+1)
 n

(2i  1)    (2i  1)   (2(n  1)  1)

i 1
 i 1

2
 n  2n  1
n 1
 (n  1) 2
By inductive hypothesis P(n). ■
Another Induction Example
Prove that n > 0, n < 2n.
Let P(n) = (n < 2n)
Base case: P(1) = (1<21) = (1<2) = T.
Inductive step: For n>0, prove P(n)→P(n+1).
Assuming n < 2n, prove n + 1 < 2n+1.
Note n + 1 < 2n + 1 (by inductive hypothesis)
< 2n + 2n (1 < 2 = 2·20 ≤ 2·2n-1 = 2n)
= 2n+1
So n + 1 < 2n+1, and we’re done. ■
More Induction Examples
1.
2.
3.
4.
n3 – n is divisible by 3
1 + 2 + 22 + … + 2n = 2n+1 – 1
Sums of Geometric Progressions
An Inequality for Harmonic Numbers
5. H n  1  n / 2 , where H j  1  1/ 2  1/ 3    1/ j
2
6. DeMorgan’s law
7. Number of Subsets of a finite set
8. 2n < n!
More Induction Examples
E.g. 9: Any chessboard with 2n×2n squares but with one
removed can be tiled using L-shaped pieces (which
cover 3 squares at a time).
E.g. 10: The greedy algorithm (selects talk with earliest
ending time) schedules the most talks in a single
lecture halls.
The Second Principle of
Mathematical Induction
•Characterized by another inference rule:
P(0) P is true in all previous cases
n0: (0kn P(k))  P(n+1)
n0: P(n)
“Strong Induction”
•The only difference between this and the 1st
principle is that:
- the inductive step here makes use of the stronger
hypothesis that P(k) is true for all smaller numbers
k < n+1, not just for k = n.
The 2nd Principle of Math Induction
P(n) 為一命題,其中n為自然數:
1. 若 P(1), P(2), P(3), …, P(q) 成立,
2. 假設對於所有介於 1ik 之自然數
(其中qk),P(i) 成立,
3. 在 1& 2 成立下,若 P(k+1) 亦成立,
則 n0: P(n) 成立。
2nd Principle Example
• Show that every n>1 can be written as a product
 pi = p1p2…ps of some series of s prime numbers.
Let P(n) = “n has that property”
• Base case: n = 2, let s = 1, p1 = 2.
• Inductive step: Let n2. Assume 2 ≤ k ≤ n: P(k).
Consider n+1. If it’s prime, let s = 1, p1 = n+1.
Else n+1 = ab, where 2 ≤ a ≤ n and 2 ≤ b ≤ n.
Then a = p1p2…pt and b = q1q2…qu.
Then we have that n+1 = p1p2…pt q1q2…qu, a product
of s = t+u primes. ■
Another 2nd Principle Example
• Prove that every amount of postage of 12 cents or
more can be formed using just 4-cent and 5-cent
stamps. P(n) = “n can be…”
• Base case: 12 = 3(4), 13 = 2(4)+1(5), 14 = 1(4)+2(5),
15 = 3(5), so 12n15, P(n).
• Inductive step: Let n≥15, assume 12kn P(k).
Note 12n3n, so P(n3), so add a 4-cent stamp to
get postage for n+1.
The Well-Ordering Property
• Another way to prove the validity of the
inductive inference rule is by the well-ordering
property, which says that:
- Every non-empty set of non-negative integers
has a minimum (smallest) element.
-  SN : mS : nS : mn
• This implies that {n|P(n)} (if non-empty) has a
minimal element m, but then the assumption that
P(m−1)P((m−1)+1) would be contradicted.
The Well-Ordering Property
• Any non-empty subset of Z+ contains a smallest
element. (Z+ is well ordered)
Example 1: If a is an integer and d is a positive
integer. There are unique integers q and r with
0≦r<d and a = d×q + r.
Example 2: If there is a cycle of length m (m≧3)
among the players in a round-robin tournament,
there must be a cycle of three.
The Method of Infinite Descent
• A way to prove that P(n) is false for all nN.
(Sort of a converse to the principle of induction)
• Prove first that P(n): k<n: P(k).
- Basically, “For every P there is a smaller P.”
• But by the well-ordering property of N, we know
that P(m)  P(n): P(k): n≤k.
- Basically, “If there is a P, there is a smallest P.”
• Note that these are contradictory unless ¬P(m),
- that is, mN: ¬P(m). There is no P.
Infinite Descent
• Infinite Descent:For a propositional function
P(n), P(k) is false for all positive integers.
Example: 2 is irrational.
Infinite Descent Example
• Theorem: 21/2 is irrational.
Proof: Suppose 21/2 is rational, then m, nZ+:
21/2=m/n. Let M, N be the m, n with the least n.
M
M2
2   2  2  2N 2  M 2.
N
N
2 N  M (2 N  M ) N 2 N 2  MN M 2  MN ( M  N ) M M





M N
(M  N ) N
(M  N ) N (M  N ) N (M  N ) N N
1  2  2 1 
M
 2 N  M  2N 0  M  N  N
N
So k<N, j: 21/2 = j/k (let j = 2N−M, k = M−N). ■
補充
Propositional Equivalence
Propositional Equivalence
• Compound propositions p and q that have same
truth values in all possible cases are called
logically equivalent, denoted as p≡ q.
• The symbol ≡ is not a logical connective, it
means that p≡ q is not a compound prop.
• Sometimes, the symbol  is used instead of ≡.
Tautologies and Contradictions
• A tautology is a compound proposition that is
true no matter what the truth values of its
atomic propositions are!
Ex. p  p [Truth table …]
• A contradiction is a compound proposition that
is false no matter what!
Ex. p  p [Truth table …]
• Other compound props. are contingencies.
Logical Equivalence
• Compound proposition p is logically equivalent
to compound proposition q, written p≡ q, IFF
the compound proposition pq is a tautology.
• 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 rows
of their truth tables.
Prove Equivalence via Truth Tables
Ex. Prove that pq ≡ (p  q).
p q
FF
FT
TF
TT
pq p q p  q (p  q)
F
T
T
T
T
F
T
F
F
T
T
T
F
F
T
F
F
F
T
T
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 all or part of a much more
complicated proposition and to find an
equivalence for it.
Example of 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
• Trivial tautology/contradiction:
p  p ≡ T
p  p ≡ F
Nested Quantifiers
Nested Quantifiers
Example: Let the u.d. of x & y be people.
Let L(x, y) = “x likes y” (a predicate with 2 free
variables)
Then y L(x, y) = “There is someone whom x
likes.” (A predicate with 1 free variable, x)
Then x (y L(x, y)) =
“Everyone has someone whom they like.”
(A proposition with 0 free variables.)
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.
There’s a poor overburdened soul
y(x R(x,y))= whom everyone relies upon (including
himself)!
There’s some needy person who relies
x(y R(x,y))= upon everybody (including himself).
Everyone has someone who relies upon
y(x R(x,y))= them.
Everyone relies upon everybody,
x(y R(x,y))= (including themselves)!
Natural Language Is Ambiguous
• “Everybody likes somebody.”
– For everybody, there is somebody they like,
• x y Likes(x, y)
[Probably more likely]
– or, there is somebody (a popular person) whom
everyone likes?
• y x Likes(x, y)
• “Somebody likes everybody.”
– Same problem: Depends on context, emphasis.
More Conventions
• 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))
More About Binding
• x x P(x) - x is not a free variable in
x P(x), therefore the x binding isn’t used.
• (x P(x))  Q(x) - The variable x is outside of
the scope of the x quantifier, and is therefore
free. Not a proposition!
• (x P(x))  (x Q(x)) – This is legal, because
there are 2 different x’s!
Quantifier Equivalence Laws
•Definitions of quantifiers: If u.d.=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)  x P(x)
x P(x)  x P(x)
•Which propositional equivalence laws can be
used to prove this?
(Chalkboard)
• (Chalkboard) Another way to see why the order of
quantifiers matters is to expand out the definitions of
FORALL and EXISTS in terms of AND and OR. E.g.,
suppose the universe of discourse just consists of two
objects a and b. Now, consider some predicate P(x, y). Then,
FORALL x EXISTS y P(x, y)
 (EXISTS y P(a, y)) /\ (EXISTS y P(b, y))
 (P(a, a) \/ P(a, b)) /\ P(b, a) \/ P(b, b)).
In contrast,
EXISTS y FORALL x P(x, y)
 (FORALL x P(x, a)) \/ (FORALL x P(x, b))
 (P(a, a) /\ P(b, a)) \/ (P(a, b) /\ P(b, b)).
(Chalkboard)
• To see that these two are inequivalent, suppose only P(a,
a) and P(b, b) are true. Then, the first proposition (with
the FORALL first) is true, but, the second proposition
(with the EXISTS first) is true. Students can come up
with this counterexample in-class as an exercise.
More Equivalence Laws
• x y P(x,y)  y x P(x,y)
x y P(x,y)  y x P(x,y)
• x (P(x)  Q(x))  (x P(x))  (x Q(x))
x (P(x)  Q(x))  (x P(x))  (x Q(x))
Exercise:
See if you can prove these yourself.
– What propositional equivalences did you use?
More Notational Conventions
• Quantifiers bind as loosely as needed:
parenthesize x( P(x)  Q(x))
• Consecutive quantifiers of the same type can
be combined: x y z P(x,y,z) 
x,y,z P(x,y,z) or even xyz P(x,y,z)
• All quantified expressions can be reduced
to the canonical alternating form
x1x2x3x4… P(x1, x2, x3, x4, …)
Defining New Quantifiers
• As per their name, quantifiers can be used to
express that a predicate is true of any given
quantity (number) of objects.
• Define !x P(x) to mean “P(x) is true of
exactly one x in the universe of discourse.”
• !x P(x)  x (P(x)  y (P(y)  y x))
“There is an x such that P(x), where there is no
y such that P(y) and y is other than x.”
Some Number Theory Examples
• Let u.d. = the natural numbers 0, 1, 2, …
• “A number x is even, E(x), if and only if it is
equal to 2 times some other number.”
x (E(x)  (y x=2y))
• “A number is prime, P(x), iff it’s greater than 1
and it isn’t the product of two non-unity
numbers.”
x (P(x)  (x>1  yz x=yz  y1  z1))
Goldbach’s Conjecture (unproven)
• Using E(x) and P(x) from previous slide,
E(x>2): P(p),P(q): p+q = x
or, with more explicit notation:
x [x>2  E(x)] →
p q P(p)  P(q)  p+q = x.
“Every even number greater than 2
is the sum of two primes.”
Calculus Example
• One way of precisely defining the calculus
concept of a limit, using quantifiers:
lim f ( x)  L  
x a
   0 :   0 : x :



 | x  a |    | f ( x)  L |   
Deduction Example
• Definitions:
s :≡ Socrates (ancient Greek philosopher);
H(x) :≡ “x is human”;
M(x) :≡ “x is mortal”.
• Premises:
H(s)
x H(x)M(x)
Socrates is human.
All humans are mortal.
Deduction Example Continued
Some valid conclusions you can draw:
H(s)M(s)
[Instantiate universal.] If Socrates is human
then he is mortal.
H(s)  M(s)
Socrates is inhuman or mortal.
H(s)  (H(s)  M(s))
Socrates is human, and also either inhuman or mortal.
(H(s)  H(s))  (H(s)  M(s)) [Apply distributive law.]
F  (H(s)  M(s))
[Trivial contradiction.]
H(s)  M(s)
[Use identity law.]
M(s)
Socrates is mortal.
Another Example
• Definitions: H(x) :≡ “x is human”;
M(x) :≡ “x is mortal”; G(x) :≡ “x is a god”
• Premises:
– x H(x)  M(x) (“Humans are mortal”) and
– x G(x)  M(x) (“Gods are immortal”).
• Show that x (H(x)  G(x))
(“No human is a god.”)
The Derivation
• x H(x)M(x) and x G(x)M(x).
• x M(x)H(x) [Contrapositive.]
• x [G(x)M(x)]  [M(x)H(x)]
• x G(x)H(x)
[Transitivity of .]
• x G(x)  H(x) [Definition of .]
• x (G(x)  H(x)) [DeMorgan’s law.]
• x G(x)  H(x)
[An equivalence law.]
Summary of Predicate Logic
From these sections you should have learned:
- Predicate logic notation & conventions
- Conversions: predicate logic  clear English
- Meaning of quantifiers, equivalences
- Simple reasoning with quantifiers