Discrete Mathematics Chapter 1 The Foundations : Logic and Proofs, Sets, and Functions 大葉大學 資訊工程系 黃鈴玲
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) = 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)
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. “ pq p q TTT TFF FTF FFF p ﹁ p TF FT
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 raining today. “ Table 4. The truth table for the Exclusive or (xor) of two propositions. pq p q TTT TFT FTT FFF pq p ⊕ q TTF TFT FTT FFF
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) pqp → q TTT TFF FTT FFT
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.” pqp → qq → pp ↔ q TTTTT TFFTF FTTFF FFTTT ( 若且唯若 )
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
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 OperatorPrecedence ﹁ 1 2 3 →4 5
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﹁pp ﹁ pp ﹁ p T F T F F T T F
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)) pq ﹁ ( p q ) ﹁p﹁p ﹁q﹁q ﹁ p ﹁ q TTFFFF TFFFTF FTFTFF FFTTTT commutative laws. 交換律 associative laws. 結合律 distributive laws 分配律
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)
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)
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 屬性數量詞
14 Table 1. Quantifiers Example 13 : Let P(x) : x 2 > 10, when x ∈, x ≤ 4 What is the truth value of ∃ x P(x) ? Sol : x ∈ {1, 2, 3, 4} ∴ 4 2 = 16 > 10 ∴ ∃ x P(x) is true. StatementWhen 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. +
15 Table 2. Negating Quantifiers. Example 16 : P(x) : x 2 > x, Q(x) : x 2 = 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 NegationEquivalent 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.
16 補充 : 習題 48 “ ∃ ! ” 表示 “ 存在且唯一 “ ∃ !x P(x) 表示 “ There exists a unique x s.t. P(x) is true. ” Example : What is the truth values of the statements (a) ∃ ! x ( x 2 = 1 ) (b) ∃ ! x ( x + 3 = 2x ) where the universe of discourse is the set of integers. ( 即 x ∈ ) Ans : (a) 1 2 = 1, (-1) 2 =1 (b) True.
Nested Quantifiers eg. ∀ x ∃ y (x + y = 0 ) Table 2. Quantifications of Two Variables. StatementWhen 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) is 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
Sets Def 1 : A set is an unordered collection of objects. Def 2 : The objects in a set are called the elements, or members 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 numbers ( 有理數 ) R = the set of real numbers ( 實數 ) ( 元素可表示成 等小數形式 )
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 }
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
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
22 Def 6 : A 1, A 2, …, A n : 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
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. ABAB α β γ α β γ Not a function
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) = x 2, 則 f 的 domain, codomain 及 range ? AB 1 2 α β γ AB α β γ 4 a function
25 Example 4 : Let f 1 : R → R and f 2 : R → R s.t. f 1 (x) = x 2, f 2 (x) = x - x 2, What are the function f 1 + f 2 and f 1 f 2 ? Sol : ( f 1 + f 2 )(x) = f 1 (x) + f 2 (x) = x 2 + ( x – x 2 ) = x ( f 1 f 2 )(x) = f 1 (x) . f 2 (x) = x 2 ( x – x 2 ) = x 3 – x 4 Def : A function f is said to be one-to-one, or injective, iff f (x) ≠ f (y) whenever x ≠ y. Example 6 : AB 1 2 a b c AB 1 2 a b c d d 是 1-1 不是 1-1, 因 g (a) = g (d) = 4 f g
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 b c d f not noto AB a b c f
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 not 1-1, onto a b c d 1-1 and onto a b c d
28 ※ Some important functions Def 12 : floor function : x : ≤ x 的最大整數,即 [ x ] ceiling function : x : ≥ x 的最小整數. Example 21 : ½ = -½ = 7 = Example 26 : factorial function : f : N → Z +, f ( n ) = n ! = 1 x 2 x … x n Exercise : 1,12,17,19