Download Chapter 1 - National Taiwan University

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Axiom of reducibility wikipedia , lookup

Inquiry wikipedia , lookup

History of logic wikipedia , lookup

Mathematical proof wikipedia , lookup

Meaning (philosophy of language) wikipedia , lookup

Modal logic wikipedia , lookup

Argument wikipedia , lookup

Quantum logic wikipedia , lookup

Intuitionistic logic wikipedia , lookup

Truth wikipedia , lookup

Tractatus Logico-Philosophicus wikipedia , lookup

History of the function concept wikipedia , lookup

Boolean satisfiability problem wikipedia , lookup

Catuṣkoṭi wikipedia , lookup

Syllogism wikipedia , lookup

Interpretation (logic) wikipedia , lookup

Laws of Form wikipedia , lookup

Bernard Bolzano wikipedia , lookup

Propositional formula wikipedia , lookup

Propositional calculus wikipedia , lookup

Analytic–synthetic distinction wikipedia , lookup

Natural deduction wikipedia , lookup

Law of thought wikipedia , lookup

Principia Mathematica wikipedia , lookup

Truth-bearer wikipedia , lookup

Transcript
Discrete Mathematics
Chapter 1
Instructor: Hsu-Chun Yen
Scripts prepared by Dr. Bow-Yaw Wang of IIS, Academia Sinica
Spring 2011
The Foundations: Logic and Proof
1. Propositional Logic
A proposition is a declarative sentence that is either true or false, but not both.
Example 1. The following declarative sentences are propositions:
• Tainan is a city in Taiwan.
• 1 + 0 = 1.
The following sentences are not propositions:
• How many people are enrolled in this class?
• x + 1 = y.
Just like we use letters to denote integer variables, letters are also used to denote propositions. We use
p, q, r, s, . . . to denote propositions. For true propositions, their truth value is true (denoted by T). On the other
hand, the truth value of false proposition is false (denoted by F).
The area of logic that deals with propositions is called the propositional calculus or propositional logic.
Definition 1. Let p be a proposition. The statement “It is not the case that p” is another proposition, called the
negation of p. The negation of p is denoted by ¬p, read “not p.”
A truth table displays the relationships between the truth values of propositions. Figure 1 shows the truth
table for the negation of a proposition.
¬p
F
T
p
T
F
Figure 1. Truth Table for Negation of p
The negation of a proposition can also be considered the result of the operation of the negation operator on
a proposition. There are other logical operators that can be use to form new propositions. These logical operators
are called connectives.
p
F
F
T
T
q
F
T
F
T
p∧q
F
F
F
T
p∨q
F
T
T
T
p⊕q
F
T
T
F
p→q
T
T
F
T
Figure 2. Truth Table for p ∧ q, p ∨ q, p ⊕ q and p → q
Definition 2. Let p and q be propositions. The proposition “p and q” (write p ∧ q) is the proposition that is true
only when both p and q are true and false otherwise. The proposition p ∧ q is also called the conjunction of p
and q.
Definition 3. Let p and q be propositions. The proposition “p or q” (write p ∨ q) is the proposition that is false
only when both p and q are false and true otherwise. The proposition p ∨ q is also called the disjunction of p
and q.
Definition 4. Let p and q be propositions. The exclusive or of p and q (write p ⊕ q) is the proposition that is
true only when one of p and q is true and false otherwise.
Definition 5. Let p and q be propositions. The implication p → q is the proposition that is false only when p
is true and q is false, and true otherwise.
1
2
p q
F F
F T
T F
T T
p↔q
T
F
F
T
Figure 3. Truth Table for p ↔ q
Figure 2 shows the truth table for conjunction, disjunction, exclusive or and implication.
Notice that p → q is false when p is true and q is false. For instance,
“If 1 + 1 = 1, then I am God.”
is true by definition.
Some related implications can be derived from p → q. The proposition q → p is called the converse of p → q.
¬q → ¬p is called the contrapositive of p → q. And ¬p → ¬q is called the inverse of p → q.
Definition 6. Let p and q be propositions. The biconditional p ↔ q is the proposition that is true when p and
q have the same truth values, and false otherwise.
Figure 3 shows the truth table for biconditional p ↔ q.
1.1. Applications. We can find propositional calculus in many applications. Here are a few of them.
1.1.1. System Specifications.
Example 2. Express the following specification using logical connectives:
• “The diagnostic message is stored in the buffer or it is retransmitted.”
• “The diagnostic message is not stored in the buffer.”
• “If the diagnostic message is stored in the buffer, then it is retransmitted.”
Solution.Let p denote “The diagnostic message is stored in the buffer” and q for “The diagnostic message is
retransmitted.” Then the above specification can be formulated as follows.
• p ∨ q.
• ¬p.
• p → q.
Specification should not contain conflicting requirements. That is, there should be a way to satisfy all requirements. In this case, the specification is consistent. In the above example, we can take p to be false and q to be
true. Hence the above specification is consistent.
Example 3. Suppose we add “The diagnostic message is not retransmitted.” Is the specification still consistent?
Solution.No. Since ¬p must be true by second requirement, p must be false. But then q must be true by the first
requirement. It is contradictory to ¬q, the added requirement.
1.1.2. Logic Puzzles.
Example 4. On an island, there are only two kinds of inhabitants: knights and knaves. Knights always tell the
truth, but knaves always lie. You’re visiting the island and encounter two people A and B. A says “B is a knight”
and B says “The two of us are of opposite kinds.” Do you know what are A and B?
Solution.Let p denote “A is a knight” and q for “B is a knight.” We would like to find the truth values for p and
q. Suppose p is true. Then A tells the truth. So q is true. But then B must also tell the truth. Since p and q are
both true, B cannot tell the truth. A contradiction.
On the other hand, Suppose p is false. Then A lies and q is false. Since q is false, B lies. Thus both p and q
must have the same truth value. This is exactly the case. We know conclude A and B are knaves.
Example 5. After playing in their backyard, John and Mary get mud on their foreheads without knowing it. (But
each can see the other’s forehead is dirty, though.) When they go home, their mother says “At least one of you
has a muddy forehead,” and asks the children to answer the question: “Do you know whether you have a muddy
forehead?” The mother asks the question twice. What will the children answer each time the question is asked?
3
Solution.Let j and m denote John and Mary has a muddy forehead respectively. When the mother asks the
question the first time, both know j ∨ m is true. Although they can see the mud in the other’s forehead, noone
can tell whether his or her forehead is dirty. Hence both can only answer “No” to the question.
After the question is asked, John knows his forehead is dirty by the following reasoning. If his forehead was
clean, Mary would know immediately that her forehead is dirty. Since Mary answers “No” to the question, John
realizes his forehead must be dirty. Symmetrically, Mary knows her forehead is dirty after the question is asked.
Hence when the mother asks the question the second time, both will answer “Yes” to the question.
1.1.3. Logic and Bit Operations.
Definition 7. A bit has two possible values, 0 and 1. A variable is called a Boolean variable if its value is
either true or false. Hence, a Boolean variable can be represented by a bit.
A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string.
Example 6. Let x = 01 1011 0110 and y = 11 0001 1101. Compute their bitwise OR, AND and XOR.
Solution.
01
11
11
01
10
1011
0001
1011
0001
1010
0110
1101
1111
0100
1011
bitwise OR
bitwise AND
bitwise XOR
1.2. A Famous Problem in Computer Science. In Example 2, we show how to use propositional logic to
write system specifications. Additionally, we mentioned that system specifications should be consistent. That is,
we should be able to assign truth values to propositions such that all requirements are satisfied. In Example 2,
we are lucky to have simple requirements where there are only 2 propositions p and q. In real world, there may be
hundreds, even thousands of propositions in the requirements. How to find proper truth values for them cannot
be done by hand. This problem is called satisfiability problem.
Since there are so many propositions, one would write a program to find a solution for us. However, if there
are 300 propositions in the specification, a brute-force method may try 2300 possible combinations. It is worth
noting that 2300 ≈ 1090 but the number of particles in our universe is roughly 1087 . It doesn’t sound “efficient”.
?
Whether there is an “efficient” way to solve the problem is the famous P = N P problem.
2. Propositional Equivalences
Definition 8. A compound proposition that is always true is called a tautology. A compound proposition that
is always false is called a contradiction. A proposition that is neither a tautology nor a contradiction is called
a contingency.
Example 7. Let p be a proposition. Then p ∨ ¬p is a tautology. p ∧ ¬p is a contradiction. p and ¬p are
contingencies.
Definition 9. The propositions p and q are called logically equivalent if p ↔ p is a tautology. We write p ≡ q
when p and q are logically equivalent.
Remark.The symbol ≡ is not a logical connective since p ≡ q is not a compound proposition. We also use ⇔
for logical equivalence sometimes.
Example 8. Show ¬(p ∨ q) and ¬p ∧ ¬q are logically equivalent.
Solution.We build the following truth table:
p
F
F
T
T
q
F
T
F
T
p∨q
F
T
T
T
¬(p ∨ q)
T
F
F
F
¬p ∧ ¬q
T
F
F
F
Remark.A truth table of a compound proposition with n different propositions requires 2n rows in truth table.
4
Equivalence
p∧T ≡p
p∨F ≡p
p∨T ≡T
p∧F ≡F
p∨p≡p
p∧p≡p
¬(¬p) ≡ p
p∨q ≡q∨p
p∧q ≡q∧p
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r)
(p ∧ q) ∧ r ≡ p ∧ (q ∧ r)
p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r)
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r)
¬(p ∧ q) ≡ ¬p ∨ ¬q
¬(p ∨ q) ≡ ¬p ∧ ¬q
p ∨ (p ∧ q) ≡ p
p ∧ (p ∨ q) ≡ p
p ∨ ¬p ≡ T
p ∧ ¬p ≡ F
p → q ≡ ¬p ∨ q
p → q ≡ ¬q → ¬p
(p → q) ∧ (p → r) ≡ p → (q ∧ r)
(p → r) ∧ (q → r) ≡ (p ∨ q) → r
(p → q) ∨ (p → r) ≡ p → (q ∨ r)
(p → r) ∨ (q → r) ≡ (p ∧ q) → r
p ↔ q ≡ (p → q) ∧ (q → p)
p ↔ q ≡ (p ∧ q) ∨ (¬p ∧ ¬q)
¬(p ↔ q) ≡ p ↔ ¬q
Name
Identity laws
Domination laws
Idempotent laws
Double negation law
commutative laws
Associative laws
Distributive laws
De Morgan’s laws
Absorption laws
Negation laws
Figure 4. Logical Equivalences
Figure 4 shows some important logical equivalences.
Logical equivalences can be used to show two compound propositions are logically equivalent.
Example 9. Show that ¬(p ∨ (¬p ∧ q)) and ¬p ∧ ¬q are logically equivalent.
Proof.
¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q)
≡ ¬p ∧ (p ∨ ¬q)
≡ (¬p ∧ p) ∨ (¬p ∧ ¬q)
≡ ¬p ∧ ¬q
3. Predicates and Quantifiers
Let P (x) be a proposition with x as its parameter. Then P is called a predicate or propositional function.
Example 10. Let P (x) denote “x > 3.” What are the truth values for P (3) and P (4)?
Solution.P (3) stands for “3 > 3,” which is false. Therefore P (3) is false. P (4) stands for “4 > 3.” Hence P (4) is
true.
We can generalize to multiple parameters. A statement of the form P (x1 , x2 , . . . , xn ) is the value of the
propositional function P at the n-tuple (x1 , x2 , . . . , xn ). P is also called a predicate.
In addition to assign values to parameters, we can also make predicates become propositions by quantification.
The area of logic that deals with predicates and quantifiers is called the predicate calculus.
5
Definition 10. The universal quantification of P (x) is the proposition “P (x) is true for all values of x in
the universe of discourse.” We write ∀xP (x) for the universal quantification of P (x).
Example 11. What is the truth value of ∀x(x2 ≥ x) when x ranges over integers and real numbers respectively?
Solution.If x ranges over integers, x2 ≥ x. Hence ∀x(x2 ≥ x) is true. On the other hand, x2 ≤ x when |x| ≤ 1.
Therefore ∀x(x2 ≥ x) is false when x ranges over real numbers.
Definition 11. The existential quantification of P (x) is the proposition “There exists an element x in the
universe of discourse such that P (x) is true.”
Example 12. Let Q(x) be “x ̸= x.” What is the truth value of ∃xQ(x)?
Solution.False, apparently.
When a quantifier is used on the variable x or when we assign a value of it, we say that this occurrence of x is
bound. An occurrence of a variable that is not bound is said to be free. The part of a logical expression where
a quantifier is applied is called the scope of the quantifier.
Consider ¬∀xP (x). Since ∀xP (x) means “for all values of x, P (x) is true,” its negation should be “it is not the
case that for all values of x, P (x) is true.” In other words, there is a value for x such that P (x) is false. Hence
∃x¬P (x). In fact, we have the following logical equivalences:
¬∀xP (x)
≡ ∃x¬P (x)
¬∃xP (x)
≡ ∀x¬P (x)
Example 13. What are the negations of ∀x(x2 > x) and ∃x(x2 = 2)?
Solution.¬∀x(x2 > x) ≡ ∃x¬(x2 > x) ≡ ∃x(x2 ̸> x) ≡ ∃x(x2 ≤ x). Similarly, ¬∃x(x2 = 2) ≡ ∀x¬(x2 = 2) ≡
∀x(x2 ̸= 2).
Example 14. Consider the following two statements:
• “All lions are fierce.”
• “Some lions do not drink coffee.”
Can you deduce “Some fierce creatures do no drink coffee?”
Solution.Let P (x), Q(x) and R(x) be the statement “x is a lion,” “x is fierce” and “x drinks coffee” respectively.
Then we have ∀x(P (x) → Q(x)) and ∃x(P (x) ∧ ¬R(x)). We prove ∃x(Q(x) ∧ ¬R(x)) as follows. By ∃x(P (x) ∧
¬R(x)), we have an x0 such that P (x0 ) ∧ ¬R(x0 ). Since ∀x(P (x) → Q(x)), P (x0 ) → Q(x0 ) in particular.
Therefore Q(x0 ) ∧ ¬R(x0 ). By taking x to x0 , we have ∃x(Q(x) ∧ ¬R(x)).
Example 15. Logic programming languages are designed to reason using the rules of predicate logic. Consider
the following Prolog program which defines predicates instructor (p, c) and enrolled (s, c) in a university.
instructor(chou, computer-programming)
instructor(wang, discrete-mathematics)
instructor(chen, calculus)
enrolled(harry, computer-programming)
enrolled(peter, computer-programming)
enrolled(peter, discrete-mathematics)
enrolled(alice, discrete-mathematics)
enrolled(alice, calculus)
A new predicate teaches(p, s) can be defined in Prolog as follows.
teaches(P, S) :- instructor(P, C), enrolled(S, C)
What are the outputs of the following Prolog queries?
?enrolled(harry, computer-programming)
?enrolled(X, discrete-mathematics)
?teaches(X, alice)
Solution.
(1) yes
6
peter
alice
wang
(3)
chen
(2)
4. Nested Quantifiers
We can have nested quantification. In fact, you have seen it in calculus!
Example 16. The definition of limit uses nested quantifiers. Recall the definition of
lim f (x) = b :
x→a
∀ϵ∃δ(|x − a| < δ → |f (x) − b| < ϵ).
The order of nested quantification is important.
Example 17. Consider ∀x∃y(x = y) and ∃y∀x(x = y). What are their truth values? What about ∀x∃y(y ≤ |x|)
and ∃y∀x(y ≤ |x|)?
Solution.∀x∃y(x = y) is true, simply take y to be x. But ∃y∀x(x = y) is false. Since no matter what y is,
y + 1 ̸= y.
Both ∀x∃y(y ≤ |x|) and ∃y∀x(y ≤ |x|) are true, simply take y to be 0.
In fact, we have ∃y∀xP (x, y) → ∀x∃yP (x, y). Can you prove it?
5. Rules of Inference
Definition 12. An argument in proposional logic is a sequence of propositions. The final proposition in an
argument is called the conclusion; the others are called premises.
Figure 5 shows some rules of inferences which are useful when you write proofs.
6. Introduction to Proofs
We demonstrate some proofs by two simple theorems in elementary number theory. Dr. Hardy (a renowned
mathematician) thinks both theorems are of the highest class (in A Mathematician’s Apology). They are actually
proved by the Greek two thousands years ago!
Theorem 1. (Euclid) There are infinitely many primes.
Proof. Suppose there are finitely many primes. And 2, 3, 5, . . . , p is the list of all primes. Consider q = (2 × 3 ×
5 × · · · × p) + 1. Clearly, q is not divisible by any of the primes 2, 3, 5, . . . , p. A contradiction.
Definition 13. The real number r is rational if there are integers p and q with q ̸= 0 such that r = pq . A real
number that is not rational is called irrational.
√
Theorem 2. (Pythagoras) 2 is not rational.
√
Proof. Suppose 2 = ab where gcd(a, b) = 1. Then 2 = ( ab )2 . a2 = 2b2 . Since a2 is even, a must be even.
Let a = 2k. Then a2 = (2k)2 = 4k 2 = 2b2 . 2k 2 = b2 . And b must be even. This is a contradiction since
gcd(a, b) = 1.
As another example, let us examine fallacious arguments.
Example 18. What is wrong with the following “proof ” of 1 = 2?
Let a and b be two equal positive numbers. Hence a = b. We multiply both sides by a and have a2 = ab.
Subtract b2 from both sides, we have a2 − b2 = ab − b2 . Thus (a + b)(a − b) = b(a − b). Therefore a + b = b. Since
a = b, we have 2b = b and 2 = 1.
For the other example, we need the following definition:
Definition 14. A binary relation ∼ is called an equivalence relation if
• (Reflexivity) ∀x x ∼ x.
• (Symmetry) ∀x∀y (x ∼ y → y ∼ x).
• (Transitivity) ∀x∀y∀z ((x ∼ y ∧ y ∼ z) → x ∼ z).
7
Rule of Inference
p
∴ p∨q
p∧q
∴
p
p
q
∴ p∧q
p
p→q
∴
q
¬q
p→q
∴
¬p
p→q
q→r
∴
p→r
p∨q
¬p
∴
q
p∨q
¬p ∨ r
∴
q∨r
∀xP (x)
∴
P (c)
P (c) for an arbitrary c
∴
∀xP (x)
∃xP (x)
∴ P (c) for some elementc
P (c) for some element c
∴
∃xP (x)
Name
Addition
Simplification
Conjunction
Modus ponens
Modus tollens
Hypothetical syllogism
Disjunctive syllogism
Resolution
Universal instantiation
Universal generalization
Existential instantiation
Existential generalization
Figure 5. Rules of Inferences
The following example is borrowed from Topology: A First Course by James R. Munkre.
Example 19. The following argument “proves” that symmetry and transitivity entails reflexivity. Can you
identify the flaw?
By symmetry, we have x ∼ y and thus y ∼ x. By transitivity, x ∼ y and y ∼ x implies x ∼ x. Therefore
reflexivity x ∼ x is derived from symmetry and transitivity.
7. Proof Methods and Strategy
Please read Section §1.7 of your textbook. It takes effort to know how to write correct proofs. When you read
the text, please try to understand how the statements are proved, instead of what the statements are proving.
Sometimes, we may make a statement without knowing whether it is true or not. Such statements are called
conjectures. When a conjecture is made, we can either prove it and make it a theorem. Or, we can find a
counterexample to illustrate the conjecture is false.
Conjecture 1. Let pn be (1 + the product of the first n primes). Then pn is a prime for all n.
For instance, p1 = 1 + 2 = 3, p2 = 1 + 2 · 3 = 7, and p3 = 1 + 2 · 3 · 5 = 31 are primes. Is it true for all n?
Example 20. Find a counterexample to falsify Conjecture 1.
Solution.p6 = 1 + 2 · 3 · 5 · 7 · 11 · 13 = 30031. But 30031 = 59 · 509 is not a prime.
Theorem 3. (Fermat’s Last Theorem) The equation
xn + y n = z n
has no solutions x, y, z ∈ Z with xyz ̸= 0 whenever n > 2.
Remark.Notice that when n = 2, it is Pythagoras’s Theorem.
8
Conjecture 2. Define the function T : Z+ → Z+ as follows.
{
k
if x = 2k
T (x) =
3x + 1 if x = 2k + 1
The 3x + 1 conjecture states that for all positive integer x, we will eventually reach 1 if we apply T repeatedly.