1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals...

54
1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    385
  • download

    20

Transcript of 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals...

Page 1: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

1

Discrete and Combinatorial Mathematics

R. P. Grimaldi, 5th edition, 2004

Chapter 2Fundamentals of Logic

Page 2: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

2

Logic

Logic = the study of correct reasoning

Use of logicIn mathematics:

to prove theorems

In computer science: to prove that programs do what they are

supposed to do

Page 3: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

3

Propositions (命題 )

A proposition or statement (陳述 ) is a declarative sentence that may be assigned a ‘true’ or ‘false’ value, but not both.

This value is the truth value of the proposition.

Propositions: “1+2=3”, “Peter is a programmer”, “It is snowing”.

Not Propositions: “Is 1+2=3?”, “What a beautiful evening!”, “The number x is an integer”.

Also Propositions: “There exists no ghost”.

Page 4: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

4

True or False, That’s All

The proposition “There exists no ghost” is on equal footing with the “1+2=3” proposition.

The only thing that matters is the fact that a proposition is ‘True’ or ‘False’. Because of this, we will often label our propositions simply p,q, etc. Sometimes we use 0 for False and 1 for True.

Things become interesting if we combine propositions…

Page 5: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

5

Connectives (連接詞 )If p and q are propositions, new compound propositions

(複合命題 ) can be formed by using connectives.

Most common connectives: Conjunction AND Symbol ^ ( 且 )

Disjunction OR Symbol v ( 或 )

Exclusive disjunction OR Symbol v (互斥或 )

Negation NOT Symbol ( 非 )

Implication Symbol (則,蘊含 )

Biconditional Symbol (若且唯若 )

The truth values of compound propositions can be described by truth tables ( 真值表) .

Page 6: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

6

Truth table of conjunction:

p ^ q is true only when both p and q are true.

Example: p = "Tigers are animals", q = "Lions are plants"

p ^ q = "Tigers are animals and Lions are plants"

Truth table of conjunction

p q p ^ q

1 1 1

1 0 0

0 1 0

0 0 0

Page 7: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

7

Truth table of disjunctionThe truth table of disjunction:

p q is false only when both p and q are false

Example: p = "John is a programmer", q = "Mary is a lawyer"p v q = "John is a programmer or Mary is a lawyer"

p q p v q

1 1 1

1 0 1

0 1 1

0 0 0

Page 8: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

8

Exclusive disjunction“Either p or q” (but not both), in symbols p q

p q is true only when p is true and q is false, or p is false and q is true.

Example: p = "John is programmer, q = "Mary is a lawyer“p v q = "Either John is a programmer or Mary is a lawyer but not

both."

p q p v q

1 1 0

1 0 1

0 1 1

0 0 0

Page 9: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

9

NegationNegation of p: in symbols p

p is false when p is true, p is true when p is false.

Example: p = "John is a programmer“

p = "It is not true that John is a programmer"

p p

1 0

0 1

Page 10: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

10

More compound propositions

Let p, q, r be primitive propositions (簡單命題 ).

We can form other compound propositions, such as(pq)^r

p(q^r)

( p)( q)

(pq)^( r)

and many others…

Page 11: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

11

Example: truth table of (pq)^rp q r (p q) ^ r

1 1 1 1

1 1 0 0

1 0 1 1

1 0 0 0

0 1 1 1

0 1 0 0

0 0 1 0

0 0 0 0

Page 12: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

12

ImplicationA conditional proposition (條件命題 ) is of the form “p

implies q”, denoted by p q, where p is the hypothesis (前提 ) and q is the conclusion (結論 ).

Also “If p then q”.“p is sufficient for q”, “p is a sufficient

condition (充分條件 ) for q”, “q is necessary for p”, “q is a necessary condition (必要條件 ) for p”, “p only if q”.

Example: p = " John is a programmer "q = " Mary is a lawyer "p q = “If John is a programmer then Mary is a lawyer"

Page 13: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

13

Truth table of p q

p q is true when both p and q are true or when p is false

p q p q

1 1 1

1 0 0

0 1 1

0 0 1

Page 14: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

14

BiconditionalThe biconditional proposition (雙向命題 ) is of the form “p if and only if

q” or “ p iff q ” (若且唯若 ), denoted by p q.

p q is true when both p q and q p are true.

Example: p = " John is a programmer "q = " Mary is a lawyer "p q = “John is a programmer iff Mary is a lawyer"

p q p q

1 1 1

1 0 0

0 1 0

0 0 1

Page 15: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

15

Logical equivalence (邏輯等價 ) Two propositions are said to be logically

equivalent () if their truth tables are identical.

Example: p q p q

p q p q p q

1 1 1 1

1 0 0 0

0 1 1 1

0 0 1 1

Page 16: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

16

Biconditional vs. Equivalence

Don’t confuse the equivalence with the biconditional (only the biconditional has a truth table).

For example:p p is a proposition, a statement within logic, p p is mathematically correct, … about logic.p p is a False, p p is incorrect Hence pp (pp), and so on.

Page 17: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

17

ConverseThe converse of p q is q p

These two propositions

are not logically equivalent

p

q p q q p

1 1 1 1

1 0 0 1

0 1 1 0

0 0 1 1

Page 18: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

18

Contrapositive (對換句 )The contrapositive of the proposition p q is

q p.

They are logically equivalent.

p q p q q p

1 1 1 1

1 0 0 0

0 1 1 1

0 0 1 1

Page 19: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

19

Tautology (恆真命題 )A proposition is a tautology (T0) if its truth table

contains only true values for every case.

p q p p v q

1 1 1

1 0 1

0 1 1

0 0 1

Page 20: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

20

Contradiction (矛盾命題 )A proposition is a contradiction (F0) if its truth table

contains only false values for every case.

p p ^ ( p)

1 0

0 0

Page 21: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

21

Example

Pay attention to the phrase “logically”:

“2 = 3–1” is not a tautology, but “2=1 or 21” is;“1+1=3” is not a contradiction, but “1=1 and 11” is.

As with equivalence: look at the truth tables.

Page 22: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

22

Proving Things in LogicThe standard approach is to use truth tables.

If we deal with n simple propositions p1,…,pn, our truth table will have size at least 2n.

This becomes a substantial disadvantage if n is big.

Sometimes there is a much more efficient way to prove equivalences.

First, look at some very simple equivalences…

Page 23: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

23

The Laws of Logic

1) Double negation law: p p ( 雙否定定律 )

2) De Morgan’s laws: (pq) pq,(De Morgan 定律 ) (pq) pq

3) Commutative laws: pq qp and (交換律 ) pq qp

4) Associative laws: p(qr) (pq)r, (結合律 ) p(qr) (pq)r

5) Distributive laws: p(qr) (pq)(pr), (分配律 ) p (qr) (pq)(pr)

Page 24: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

24

The Laws of Logic (Cont.)6) Idempotent laws: pp p,

(冪等定律 ) pp p 7) Identity laws: pFalse p,

(恆等定律 ) pTrue p8) Inverse laws: pp True,

(逆定律 ) pp False9) Domination laws: pTrue True,

(支配律 ) pFalse False10) Absorption laws: p(pq) p,

(吸收律 ) p(pq) p

Page 25: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

25

Proving EquivalencesProve (p q ) (p q) p.

(p q ) (p q) (p q ) (p q) [DeMorgan’s Law] (p q ) (p q) [Double Negation] p (q q) [Distributive Law] p F0 [Inverse Law]

p [Identity Law] #

Page 26: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

26

Simplify StatementsSimplify “(p q r) (p t q) (p t r)”.

(p q r) (p t q) (p t r) p [(q r) (t q) (t r)] [Distributive Law] p [(q r) (t r) (t q )] [Commutative Law] p [((q t) r) (t q )] [Distributive Law] p [((q t) r) (t q )] [Double Negation] p [((q t) r) (t q )] [DeMorgan’s Law] p [(t q ) ((q t) r)] [Commutative Law] p [((t q ) (q t)) ((t q ) r)] [Distributive Law] p [F0 ((t q ) r)] [s s F0 s]

p [(t q ) r] [F0 is the identity for ]

Page 27: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

27

Simplify Statements (Cont.) p [(t q ) r] p [(t q ) r] [DeMorgan’s Law] p [(t q ) r] [Double Negation] p [r (t q )] [Commutative Law]

Hence (p q r) (p t q) (p t r) p [r (t q )]. #

Page 28: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

28

Valid arguments (有效論證 )

Deductive reasoning (演繹推導) : the process of reaching a conclusion q from a sequence of propositions p1, p2, …, pn.

The propositions p1, p2, …, pn are called premises or hypothesis.

The proposition q that is logically obtained through the process is called the conclusion.

Page 29: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

29

Rules of inference

1. Modus ponens (肯定前件式 ) p q p Therefore, q

Example: Insects have six legs. Beetles are insects. Therefore beetles have six legs.

Page 30: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

30

Rules of inference (Cont.)

2. Modus tollens (否定後件式 ) p q ~q Therefore, ~p

Example: Insects have six legs. Spiders have eight legs. Therefore spiders are not insects.

Page 31: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

31

Rules of inference (Cont.)

3. Rule of disjunctive amplification p Therefore, p q

4. Rule of conjunctive simplification p ^ q Therefore, p

5. Rule of conjunction p q Therefore, p ^ q

Page 32: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

32

Rules of inference (Cont.)6. Law of the syllogism (三段論法 )

p q q r Therefore, p r

Example: 72 is divisible by 6. 6 is divisible by 3. Therefore 72 is divisible by 3.

Page 33: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

33

Rules of inference (Cont.)7. Rule of disjunctive syllogism (析取三段論法 )

p q p Therefore, q

Example: John is studying or sleeping. John is not studying. Therefore John is sleeping.

Page 34: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

34

Rules of inference (Cont.)8. Rule of contradiction (矛盾證法 )

p F0

Therefore, p

If we want to establish the validity of the argument (p1 p2 … pn) q, we can

establish the validity of the logically equivalent argument

(p1 p2 … pn q ) F0.

Page 35: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

35

ExampleDemonstrate the validity of the argument

((p r) (p q) (q s)) (r s)

(1) p r

(2) r p

(3) p q (4) r q (Law of the Syllogism)

(5) q s (6) Therefore r s (Law of the Syllogism)

Page 36: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

36

ExampleDemonstrate the validity of the argument

(((p q) (r s)) (r t) (t)) p

(1) r t

(2) t

(3) r (Rule of disjunctive syllogism)

(4) r s (Rule of disjunctive amplification)

(5) (r s) (De Morgan’s law)

(6) (p q) (r s)

(7) (p q) (Rule of disjunctive syllogism)

(8) p q (De Morgan’s law)

(9) Therefore p (Rule of conjunctive simplification)

Page 37: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

37

Quantifiers (量詞 )

A propositional function (命題函數 ) or open statement P(x) is a statement involving a variable x.

For example: P(x): 2x is an even integer, where x is an element of

a set D.

Page 38: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

38

Domain of a Propositional Function

In the propositional function

P(x): “2x is an even integer”,

the domain or universe D of P(x) must be defined, for instance D = {integers}.D is the set where the x's come from.

Page 39: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

39

For every and for some

Most statements in mathematics and computer science use terms such as for every and for some.

For example: For every triangle T, the sum of the angles of T is

180 degrees.

For every integer n, n is less than p, for some prime number p.

Page 40: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

40

Universal quantifierOne can write P(x) for every x in a domain D

In symbols: x P(x)“” is called the universal quantifier (通用量詞) .

The statement x P(x) is True if P(x) is true for every x DFalse if P(x) is not true for some x D

Example: Let P(n) be the propositional function n2 + 2n is an odd integer n D = {all integers}

P(n) is True only when n is an odd integer, False if n is an even integer.

Page 41: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

41

Existential quantifier

For some x D, P(x) is true if there exists an element x in the domain D for which P(x) is true.

In symbols: x, P(x)

“” is called the existential quantifier (存在量詞) .

Page 42: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

42

Counterexample

The universal statement x P(x) is false if x D such that P(x) is false.

The value x that makes P(x) false is called a counterexample to the statement x P(x).

Example:

P(x) = "every x is a prime number", for every integer x.

But if x = 4 (an integer) this x is not a primer number.

Then 4 is a counterexample to P(x) being true.

Page 43: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

43

Generalized De Morgan’s Laws

If P(x) is a propositional function, then each pair of propositions in a) and b) below have the same truth values:

a) ~(x P(x)) and x: ~P(x)"It is not true that for every x, P(x) holds" is equivalent to

"There exists an x for which P(x) is not true“

b) ~(x P(x)) and x: ~P(x) "It is not true that there exists an x for which P(x) is true" is

equivalent to "For all x, P(x) is not true"

Page 44: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

44

Rules of inference for quantified statements

1. Universal instantiation xD, P(x) d D Therefore P(d)

2. Universal generalization P(d) for any d D Therefore xD, P(x)

3. Existential instantiation x D, P(x) Therefore P(d) for some

d D

4. Existential generalization P(d) for some d D Therefore xD, P(x)

Page 45: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

45

Equivalences and Implicationsfor quantified statements

For a prescribed universe and any open statements P(x) and q(x) in the variable x:

x [p(x) q(x)] [x p(x) x q(x)]

x [p(x) q(x)] [x p(x) x q(x)]

x [p(x) q(x)] [x p(x) x q(x)]

[x p(x) x q(x)] x [p(x) q(x)]

Page 46: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

46

Demonstrate Universally Quantified Statement

In order to prove the universally quantified statement x P(x) is true It is not enough to

show P(x) true for some x D

You must show P(x) is true for every x D

In order to prove the universally quantified statement x P(x) is false It is enough to exhibit

some x D for which P(x) is false

This x is called the counterexample to the statement x P(x) is true

Page 47: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

47

Axioms (公設 )

An axiom is a proposition accepted as true without proof within the mathematical system.

There are many examples of axioms in mathematics:

Example: In Euclidean geometry the following are axioms

Given two distinct points, there is exactly one line that contains them.

Given a line and a point not on the line, there is exactly one line through the point which is parallel to the line.

Page 48: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

48

Theorems (定理)A theorem is a proposition of the form p q

which must be shown to be true by a sequence of logical steps that assume that p is true, and use definitions, axioms and previously proven theorems.

Page 49: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

49

Lemmas and corollaries

A lemma (輔助定理) is a small theorem which is used to prove a bigger theorem.

A corollary (引理) is a theorem that can be proven to be a logical consequence of another theorem.

Example from Euclidean geometry: "If the three sides of a triangle have equal length, then its angles also have equal measure."

Page 50: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

50

Types of proof

A proof is a logical argument that consists of a series of steps using propositions in such a way that the truth of the theorem is established.

Direct proof Indirect proof

Page 51: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

51

Direct proof

Direct proof: p qA direct method of attack that assumes the truth of proposition p, axioms and proven theorems so that the truth of proposition q is obtained.

Example: For all real numbers d, d1, d2, and x, if d=min{d1,d2} and xd, then xd1 and xd2.

Proof. From the definition of min, it follows that dd1 and dd2. From xd and dd1, we may derive xd1 by the transitive property of . From xd and dd2, we may derive xd2 by the same property.

Therefore, xd1 and xd2. #

Page 52: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

52

Indirect proofThe method of proof by contradiction of a

theorem p q consists of the following steps:

1. Assume p is true and q is false2. Show that ~p is also true.3. Then we have that p ^ (~p) is true. 4. But this is impossible, since the statement p ^ (~p) is

always false. There is a contradiction! 5. So, q cannot be false and therefore it is true.

Or show that the contrapositive (~q)(~p) is true.

Since (~q) (~p) is logically equivalent to p q, then the theorem is proved.

Page 53: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

53

Example of Indirect proof

For all real numbers x and y, if x+y2, then either x1 or y1.

Proof. Assume that x + y 2, x < 1 and y < 1. Then it follows that x + y < 1 + 1 = 2. It contradicts to the assumption x + y 2.

Thus, we conclude that x1 or y1. #

Page 54: 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 2 Fundamentals of Logic.

54

Brainstorm

騎士在旅途中遇見四個人,來自兩個不同家族 F1 和 F2 。在這四人的談話中,如果是關於與自己同家族所說的話,則是真話;否則是謊話。四人A,B,C,D 的對話如下 :

A: B 屬於 F1 家族。 B: C 屬於 F1 家族。 C: D 屬於 F2 家族。 D: A 屬於 F2 家族。 問題: 誰屬於 F1 家族?誰屬於 F2 家族?