28
Discrete Mathematics Chapter 1 The Foundations : Logic and Proofs, Sets, and Functions 大大大大 大大大大大 大大大

Discrete Mathematics

Embed Size (px)

DESCRIPTION

Discrete Mathematics. Chapter 1 The Foundations : Logic and Proofs, Sets, and Functions. 大葉大學 資訊工程系 黃鈴玲. 1-1 Logic. Def : A proposition ( 命題 ) is a statement that is either true or false, but not both. Example 1 : The following statements are propositions. - PowerPoint PPT Presentation

Citation preview

Page 1: Discrete Mathematics

Discrete Mathematics

Chapter 1 The Foundations : Logic and Proofs, Sets, and Functions

大葉大學 資訊工程系 黃鈴玲

Page 2: Discrete Mathematics

2

1-1 Logic

Def : A proposition ( 命題 ) is a statement that is either true or false, but not both.

Example 1 : The following statements are propositions.

(1) Toronto is the capital of Canada. (F)

(2) 1 + 1 = 2 (T) Example 2 : Consider the following sentences.

(1) what time is it ? (not statement)

(2) Read this carefully. (not statement)

(3) x + 1 = 2 (neither true nor false)

Page 3: Discrete Mathematics

3

Logical operators ( 邏輯運算子 ) and truth table ( 真值表 )

Table 1. The truth table for the Negation (not) of a Proposition

eg. p : “ Today is Friday.”

﹁ p : “ Today is not Friday.”

Def : A truth table displays the relationships between the truth values of propositions.

Table 2. The truth table for the Conjunction (and) of two propositions.

eg. p : “ Today is Friday.”

q : “ It’s raining today. ”

p q : “ Today is Friday

and it’s raining

today. “

p q p q

T T T

T F F

F T F

F F F

p ﹁ p

T F

F T

Page 4: Discrete Mathematics

4

Table 3. The truth table for the Disjunction (or) of two propositions.

eg. p : “ Today is Friday. “

q : “ It’s raining today . “

p q : “ Today is Friday or

it’s raini

ng today. “ Table 4. The truth table for the Exclusive or (xor) of two prop

ositions.

p q p qT T T

T F T

F T T

F F F

p q p q ⊕T T F

T F T

F T T

F F F

Page 5: Discrete Mathematics

5

Table 5. The truth table for the Implication (p implies q) p → q .

( 觀念 : 若 p 對,則 q 一定要對 若 p 錯,則對 q 不做要求 )

eg. p : “ You make more than $25000 ”

q : “ You must file a tax return. “ p → q : “ If you make more … then you must … . “

Some of the more common ways of expressing this implication are : (1) if p then q ( 若 p 則 q , p 是 q 的充分條件 ) (2) p implies q (3) p only if q ( 只有 q 是 True 時, p 才可能是 True ,

若 q 是 False ,則 p 一定是 False)

p q p → q

T T T

T F F

F T T

F F T

Page 6: Discrete Mathematics

6

Def : In the implication p → q , p is called the hypothesis ( 假設 )and q is called the conclusion ( 結論 ).

Def : Compound propositions ( 合成命題 ) are formed from existing propositions using logical operators. ( 即 、 、 ⊕、 →等 )

Table 6. The truth table for the Biconditional p ↔ q ( p → q and q → p )

“ p if and only if q “

“ p iff q “ “ If p then q , and

conversely.”

p q p → q q → p p ↔ q

T T T T T

T F F T F

F T T F F

F F T T T

( 若且唯若 )

Page 7: Discrete Mathematics

7

Example 9 : How can the following English sentence be translated into a logical expression ?

“ You can access the Internet from campus only if

you are a computer science major or you are not

a freshman. ” Sol :

p : “ You can access the Internet from campus. “

q : “ You are a computer science major. “

r : “ You are a freshman. “

∴ p only if ( q or ( ﹁ r ))

=> p → ( q ( ﹁ r ))

Translating English Sentences into Logical Expression

Page 8: Discrete Mathematics

8

Example 10 : You cannot ride the roller coaster ( 雲霄飛車 ) if you are under 4 feet tall unless you are older than 16 years old.

Sol : q : “ You can ride the roller coaster. “

r : “ You are under 4 feet tall. “

s : “ You are older than 16 years old. “

∴ ﹁ q if r unless s

∴ ( r ﹁ s ) → ﹁ q Table 7. Precedence of Logical Operators

eg. (1) p q r means ( p q ) r (2) p q → r means ( p q ) → r

(3) p ﹁ q means p ( ﹁ q )

Exercise : 9 、 13 、 25 、 27 、30

Operator Precedence

﹁ 1

2

3

→ 4

5

Page 9: Discrete Mathematics

9

1-2 Propositional Equivalences Def : A compound proposition that is always true

is called a tautology. ( 真理 )

A compound proposition that is always false

is called a contradiction. ( 矛盾 ) Example 1 :

Def : The propositions p and q that have the same truth values in all possible cases are called logically equivalent. The notation p ≡ q ( or p q ) denotes that p and q are logically equivalent.

p ﹁p

p ﹁ p p ﹁ p

T F T F

F T T F

Page 10: Discrete Mathematics

10

Example 2 : Show that ﹁ ( p q ) ≡ ﹁ p ﹁ q

pf :

※ Some important logically equivalences (Table 5) (1) p q ≡ q p (2) p q ≡ q p (3) ( p q ) r ≡ p (q r ) (4) ( p q ) r ≡ p (q r ) (5) p ( q r ) ≡ ( p q ) ( p r ) (6) p ( q r ) ≡ ( p q ) ( p r ) ((5) 、 (6) 的觀念類似於 (a + b) x c = (a x c ) + (b x c))

p q ﹁ ( p q ) ﹁ p ﹁ q ﹁ p ﹁ q

T T F F F F

T F F F T F

F T F T F F

F F T T T T

commutative laws. 交換律

associative laws. 結合律

distributive laws 分配律

Page 11: Discrete Mathematics

11

(7) ﹁ ( p q ) ≡ ﹁ p ﹁ q (8) ﹁ ( p q ) ≡ ﹁ p ﹁ q (9) p ﹁ p ≡ T (10) p ﹁ p ≡ F (11) p → q ≡ ﹁ p q

Example 5 : Show that ﹁ ( p ( ﹁ p q )) ≡ ﹁ p ﹁ q pf : ( 也可用真值表証 ) ﹁ ( p ( ﹁ p q ) ) ≡ ﹁ p ﹁ ( ﹁ p q )

≡ ﹁ p ( p ﹁ q ) ≡ ( ﹁ p p ) ( ﹁ p ﹁ q ) ≡ F ( ﹁ p ﹁ q ) ≡ ﹁ p ﹁ q

De Morgan’s laws

by (8)

by (7)

by (6)

by (10)

Page 12: Discrete Mathematics

12

Example 6 : Show ( p q ) → (p q) is a tautology. pf : ( p q ) → (p q) ≡ ﹁ ( p q ) (p q )

≡ ( ﹁ p ﹁ q ) (p q )

≡ ( ﹁ p p ) ( ﹁ q q )

≡ T T

≡ T

Exercise : 7 、 9 、 17

By (3)

By (11)

By (7)

Page 13: Discrete Mathematics

13

1-3 Predicates and Quantifiers

目標 : 了解 “ ∀ “ 及 “ ∃ “ 符號 Def : The statement P(x) is said to be the value of the

propositional function P at x . ex :

P(x) : “ x is greater than 3 “

※ 命題中出現變數 x 時 the universe of discourse (or domain) of x

指的是 x 的範圍 ※Quantifiers : ( 數量詞,如 some , any , all 等 )

∀ : universal quantifier ( for all ) ∃ : existential quantifier ( there exist , there is , for some

)

variable predicate

屬性 數量詞

Page 14: Discrete Mathematics

14

Table 1. Quantifiers

Example 13 : Let P(x) : x2 > 10, when x , x ∈ ≤ 4What is the truth value of x P(x) ∃ ?

Sol : x ∈ {1, 2, 3, 4} ∴ 42 = 16 > 10

∴ ∃x P(x) is true.

Statement When True ? When False ?

∀x P(x) P(x) is true for every x.

There is an x for which P(x) is false.

∃x P(x) There is an x for which P(x) is true.

P(x) is false for every x.

+

Page 15: Discrete Mathematics

15

Table 2. Negating Quantifiers.

Example 16 : P(x) : x2 > x , Q(x) : x2 = 2 , what is the negations of x P(x) and x Q(x) ?∀ ∃

Sol : ﹁∀ x P(x) ≡ x ∃ ﹁ P(x) ≡ x (x∃ 2 ≤ x)

﹁∃ x Q(x) ≡ x ∀ ﹁ Q(x) ≡ x (x∀ 2 ≠ x)

Exercise : 11 、 13 、 15 、 49

Negation Equivalent Statement

When True ? When False ?

﹁∃ x P(x)

∀x ﹁ P(x) P(x) is false for every x.

∃x, s.t. P(x) is true.

﹁∀ x P(x)

∃x ﹁ P(x) ∃x, s.t. P(x) is false

P(x) is true for every x.

Page 16: Discrete Mathematics

16

補充 : 習題 48 “ ∃! ” 表示 “ 存在且唯一 “ ∃!x P(x) 表示 “ There exists a unique x s.t. P(x) i

s true. ” Example : What is the truth values of the state

ments (a) ! x ( x∃ 2 = 1 ) (b) ! x ( x + 3 = 2x )∃

where the universe of discourse is the set of integers. ( 即 x )∈

Ans : (a) 12 = 1 , (-1)2=1 (b) True.

Page 17: Discrete Mathematics

17

1-4 Nested Quantifiers

eg. x y (x + y = 0 ) ∀ ∃ Table 2. Quantifications of Two Variables.

Statement When true ? When False ?

∀x y P(x,y)∀∀y x P(x,y)∀

P(x,y) is true for every pair x,y. ①

∃a pair (x,y) s.t. P(x,y) is false. ③

∀x y P(x,y)∃ For every x , y s.t. P(x,y) i∃s true. ②

∃x , s.t. P(x,y) is false for every y. ④

∃x y P(x,y)∀ There is an x for which P(x,y) is true for every y. ③

For every x, y s.t. P(x,y) ∃is false. ②

∃x y P(x,y)∃∃y x P(x,y)∃

∃ a pair (x,y) s.t. P(x,y) is true. ③

∀ pair (x,y) , P(x,y) is false. ⑤

例 : p(x,y) : x + y ① ≥0 , x,y N p(x,y) : xy = 0 , x,y Z∈ ③ ∈ ② p(x,y) : x + y = 2 , x,y Z p(x,y) : xy = -1 , x,y Z∈ ④ ∈ ⑤ p(x,y) : x + y = ½ , x,y Z∈ Exercise: 27

Page 18: Discrete Mathematics

18

1-6 Sets

Def 1 : A set is an unordered collection of objects. Def 2 : The objects in a set are called the elements , or m

embers of the set. Example 4 : 常見的重要集合

N = { 0,1,2,3,…} , the set of natural number ( 自然數 ) Z = { …,-2,-1,0,1,2,…} , the set of integers ( 整數 ) Z+ = { 1,2,3,…} , the set of positive integers ( 正整數 ) Q = { p / q | p Z , q Z , q≠0 } , the set of ∈ ∈ rational num

bers ( 有理數 ) R = the set of real numbers ( 實數 )

( 元素可表示成 1.234 等小數形式 )

Page 19: Discrete Mathematics

19

Def 4 : A ⊆ B iff x , x ∀ A ∈ → x B ∈補充: A ⊂ B 表示 A ⊆ B 但 A ≠ B

Def 5 : S : a finite set

The cardinality of S , denoted by |S| , is the number of elements in S.

Def 7 : S : a set

The power set of S , denoted by P(S) , is the set of all subsets of S.

Example 11 : S = {0,1,2}

P(S) = {, {0} , {1} , {2} , {0,1} , {0,2} , {1,2} , {0,1,2} } Def : A , B : sets The Cartesian Product of A and B ,

denoted by A x B , is the set A x B = { (a,b) | a A and b B }∈ ∈

Page 20: Discrete Mathematics

20

Note. |A x B| = |A| . |B| Example 14 :

A = {1,2} , B = {a, b, c}

A x B = {(1,a) , (1,b) , (1,c) , (2,a) , (2,b) , (2,c)}

Exercise : 5 、 7 、 8 、 13 、 17 、 19

Page 21: Discrete Mathematics

21

1-7 Set Operations

Def 1,2,4 : A,B : sets A B = { x | x ∪ A or x B } (union) A∩B = { x | x A and x B } (intersection) A – B = { x | x A and x B } ( 也常寫成 A \

B) Def 3 : Two sets A,B are disjoint if A∩B = Def 5 : Let U be the universal set. The complement of the set A , denoted by A , is

the set U – A . Example 10 : Prove that A∩B = A B ∪ pf :

稱為 Venn Diagram

Page 22: Discrete Mathematics

22

Def 6 : A1 , A2 , … , An : sets

Let I = {1,3,5} ,

Def : (p.95 右邊 ) A,B : sets

The symmetric difference of A and B , denoted by A B⊕ , is the set

{ x | x A B or x B A } = ( A B ) ∪ ( A ∩B ) ※Inclusion – Exclusion Principle ( 排容原理 )

|A ∪ B| = |A| + |B| |A ∩ B| Exercise : 10,37

n

n

iAAAA 21

1

n

n

iAAAA 21

1

531 AAAAIi

Page 23: Discrete Mathematics

23

1-8 Functions

Def 1 : A,B : sets

A function f : A → B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b is the unique element of B assigned by f to a A. ∈

eg. A B A B

1

2

3

1

2

α

β

γ

α

β

γ

Not a function Not a function

Page 24: Discrete Mathematics

24

Def : ( 以 f : A→B 為例,右上圖 )

f (α) = 1 , f (β) = 4 , f (γ) = 2

1 稱為 α 的 image ( 必唯一 ) , α 稱為 1 的 pre-image( 可能不唯一 )

A : domain of f , B : codomain of f

range of f = {f (a) | a A} = ∈ f (A) = {1,2,4} ( 未必 =B)

Example 2 : f : Z → Z , f (x) = x2 , 則 f 的 domain , codomain

及 range ?

A B

1

2

α

β

γ

A B

1

2

3

α

β

γ4

a function a function

Page 25: Discrete Mathematics

25

Example 4 : Let f1 : R → R and f2 : R → R s.t.

f1(x) = x2 , f2(x) = x - x2 , What are the function f1 + f2 and f1 f2 ?

Sol :

( f1 + f2 )(x) = f1(x) + f2(x) = x2 + ( x – x2 ) = x

(f1 f2)(x) = f1(x) . f2(x) = x2( x – x2 ) = x3 – x4

Def : A function f is said to be one-to-one , or injective , iff f (x) ≠ f (y) whenever x ≠ y.

Example 6 : A B

12

a

b

c

A B12

a

b

c

d

45

3d

34

5

是 1-1 不是 1-1 , 因 g(a) = g(d) = 4

f g

Page 26: Discrete Mathematics

26

Example 8 : Determine whether the function f (x) = x + 1 is one-to-one ?

Sol : x ≠ y x + 1 ≠ y + 1

f (x) ≠ f (y)

∴ f is 1-1 Def 7 : A function f : A → B is called onto , or surjective , iff

for every element b B , ∈ a ∃ A with ∈ f (a) = b. ( 即 B 的所有元素都被 f 對應到 )

Example 9 :

Note : 當 |A| < |B| 時,必定不會 onto.

noto

a

bcd

2

3

1

f

not noto

A B

a

b

c

1234

f

Page 27: Discrete Mathematics

27

Def 8 : The function f is a one-to-one correspondence , or a bijection , if it is both 1-1 and onto.

Examples in Fig 5

※ 補充 : f : A →B (1) If f is 1-1 , then |A| ≤ |B| (2) If f is onto , then |A| ≥ |B| (3) if f is 1-1 and onto , then |A| = |B|.

1-1 , onto

a

b

c

2

3

1

4

not 1-1 , onto

ab

c

1

2

3d

1-1 and onto

a

bcd

23

1

4

Page 28: Discrete Mathematics

28

※Some important functions Def 12 :

floor function : x : ≤ x 的最大整數,即 [ x ] ceiling function : x : ≥ x 的最小整數 .

Example 21 : ½ = -½ = 7 = ½ = -½ = 7 =

Example 26 : factorial function :

f : N → Z+ , f (n) = n! = 1 x 2 x … x n Exercise : 1,12,17,19