Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Mathematics Transparency No. 1-0 Chapter 1. The Foundations Cheng-Chia Chen.

Similar presentations


Presentation on theme: "Discrete Mathematics Transparency No. 1-0 Chapter 1. The Foundations Cheng-Chia Chen."— Presentation transcript:

1 Discrete Mathematics Transparency No. 1-0 Chapter 1. The Foundations Cheng-Chia Chen

2 The Foundations Transparency No. 1-2 1. The foundations Logic: The basis of all mathematical reasoning has practical applications to the design of computing machine give the precise meaning of math. statements. Sets: The basis of all mathematical structures. definitions, operations Functions : definitions, classification, operations

3 The Foundations Transparency No. 1-3 1.1 Logic Proposition: A statement that is either true or false (,but not both). Example: 1. Taipei is the capital of ROC. 2. Tokyo is the capital of Korea. 3. 1+1 = 2. 4. 2+2 = 3. 5. There is no integer x,y,z and n > 2 s.t. x n + y n = z n ---- Fermat’s last theorem 6. “Every nonprime even number is the sum of two prime numbers.” ---- Goldbach’s conjecture (1742) ==> 1. Statement (1)~(5) are propositions, 2. (1),(3) are true; (2),(4) are false. 3. Nobody knew (5) is true or false until 1994, but it must be true or false, hence it is a proposition. (6) open problem.

4 The Foundations Transparency No. 1-4 More Examples Examples: 1. What time is it? (interrogative) 2. Read this carefully! (command) 3. x+1 = 2. 4. x+y = z. 5. 李登輝是中華民國總統 ==> 1. (1) and (2) are not statements 2. (3),(4) are not propositions: neither true nor false! 3. How about (5) ?

5 The Foundations Transparency No. 1-5 Propositional variables and propositional constants In algebra, we use variables to denote an item with unspecified value. e.g. 10 chickens and rabbits in a cage with 16 feet. ==> #rabbits = ? and #chickens=? ==> let x = #rabbits, y = #chickens ==> x + y = 10 /\ 2x + 4y = 16. Likewise, In logic, we can use propositional variable to denote an arbitrary proposition with unspecified truth value. e.g., If it is raining, the ground is wet. since the ground is wet, it is raining now. ==> Let p = def “It is raining”, q = def “the ground is wet” ==> ((p ->q) /\ q) -> p. Propositional constants: only two values: T(true), F(false).

6 The Foundations Transparency No. 1-6 Forming Compound propositions from simpler ones Primitive propositions: propositional variables propositional constants P, Q: two known propositions Then the followings are also propositions: 1. “P and Q” : ( P /\ Q) conjunction of P and Q 2. “It is not the case that p”: (~P) negation of P 3. “P or Q” : (P \/ Q) disjunction of P and Q 4. “P implies Q” : ( P  Q) implication  P : antecedent, premise, hypotheses;  Q: consequence, conclusion  equivalent phrase: –“P entails Q”, “Q if P”, “P only if Q” 5. “p iff q” (p q) equivalence of P and Q

7 The Foundations Transparency No. 1-7 Truth conditions for compound propositions 1. P /\ Q is true iff both P and Q are true 2. P \/ Q is true iff either P or Q is true 3. ~P is true iff P is not true (i.e., false) 4. P Q is true iff both are true or both are false. 5. P  Q is true iff whenever P is true, Q is true ( i.e., it is not the case that P is true but Q is false ) In the propositions, /\, \/, and  are called binary connectives(or operations) and ~ is called unary connective(or operations). Other binary connectives are possible. What about the truth condition for primitive propositions?

8 The Foundations Transparency No. 1-8 From natural language statements to formal logic expressions Natural language statement Today is Friday I have a test today It is not the case that today is Friday Today is not Friday Today is Friday and I have a test today If today is Friday, then I have a test today. Today is Friday or I have a test today. symbolized logic expr. p q ~p (P ∧ q) (p  q) (P ∨ q)

9 The Foundations Transparency No. 1-9 Truth conditions for propositions Problem: Problem: when will you say that the sentence: It_is_raining is true ? => The proposition:” It_is_raining” is true if the meaning (or fact) that the proposition is intended to represent occurs(happens, exists) in the situation which the proposition is intended to describe. => Example: Since it is not raining now(the current situation), the statement It_is_raining is false (in the current situation). But if it were raining now, then I would say that It_is_raining is true. Factors affecting the truth value of a proposition: the situation in which the proposition is used. the meaning of the proposition.

10 The Foundations Transparency No. 1-10 Truth table The meaning of logical connectives can be represented by a truth table.

11 The Foundations Transparency No. 1-11 Other usual connectives Besides /\,\/,  and, there are also some other connectives as you have known in digital system. xor , nand, nor. Rules: let I(x) denote the truth value of x. I(A  B)= I(~(A B))=1 iff not I(A)=I(B) I(A nand B) = I(~(A/\B)). I(A nor B) = I(~( A \/B)).

12 The Foundations Transparency No. 1-12 1.2 Propositional Equivalence Some definitions: Let A be any proposition, then 1. A is a tautology(contradiction) iff A is true (false) no matter what the truth values of the prop. variables inside A are given. 2. If A is neither a tautology nor a contradiction, then A is called a contingency. The geography of propositions Tautologies (valid) Contradictions (unsatisfiable) Contingencies

13 The Foundations Transparency No. 1-13 Logical Equivalence A and B are logically equivalent (,A  B) if A B is a tautology Theorem1: Logical equivalence relation is reflexive, symmetric and transitive. I.e., for all propositions A,B and C, 1. A  A 2. A  B implies B  A and 3. A  B and B  C imply A  C. Theorem2[substitution theorem]: If A  B and C[X] is a proposition containing X as a subproposition, then C[A] and C[B] are logically equivalent, where C[A] is the result of C with X in C replaced by A. ex: (p ∨ q)  (q ∨ p), C[X] = def ~(p ∧ X) => ~(p ∧ (p ∨ q) )  ~(p ∧ (q ∨ p))

14 The Foundations Transparency No. 1-14 Determine tautologies, contradictions and contingencies Problems: Given a proposition A, how can you determine whether it is a tautology, a contradiction or a contingency? => Exhausted evaluation! (by using truth table) e.g., A = (p->q) (~p \/q) a tautology ? 1. there are two primitive props: p, q. 2. So there are 4 possible assignments of truth values to p and q. p=0,q=0: p=0,q=1: p=1,q=0: p=1,q=1: 3. Under each assignment, we can evaluate the truth value of A (in bottom up way) by the truth condition rule of connecting connectives.

15 The Foundations Transparency No. 1-15 Determine tautologies p:0 q:0 p->q:1 ~p:1 ~p \/q:1 (p  q) ~p\/q :1 The evaluation tree for (p->q) (~p\/q) The truth table for p  q ~p\/q 1 1 1 1 0 0 0 1 1 1 0 1 A tautology since all are 1’s

16 The Foundations Transparency No. 1-16 Determine other properties 1. logical equivalence : A  B iff A B is a tautology. So we can apply the procedure for determining tautology to determine if A  B. 2. contradiction : A is a contradiction iff ~A is a tautology 3. Satisfiability : A is satisfiable iff ~A is not a tautology. 4. contingence : A is a contingence iff neither A nor ~A is a tautology. 5. logical consequence : B is a logical consequence of A [denoted A |= B] iff A  B is a tautology.

17 The Foundations Transparency No. 1-17 P /\ T  PP/\P  P P \/ F  PP\/P  P P \/ T  T P /\ F  F ~(~P)  P P \/ Q  Q\/P P /\ Q  P \/ (Q \/ R)  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 \/ ~Q ~(P\/Q)  ==> ~(P1 /\ P1/\.../\Pn)  Some important logical equivalences Identity law Domination law Double negation Commutative Associative Distribution law DeMorgan’s law Idempotent law

18 The Foundations Transparency No. 1-18 One Example: Show that ~(p \/ (~p /\ q)  ~p /\ ~q Proof: 1. By truth table (omitted) 2. ~(p \/ (~p /\ q)  deM ~p /\ ~(~p /\ q)  deM ~p /\ (~(~p) \/ ~q)  DbNeg ~p /\ (p \/ ~q)  Distr (~p \/ ~q) /\ (~p \/ p)  ExMd (~p \/ ~q) \/ T  identity (~p \/ ~q)

19 The Foundations Transparency No. 1-19 1.3 Predicates ( 述詞 ) and quantifiers( 量詞 ) Problems of Propositional logic: Cannot analyze the content of primitive propositions. cannot group similar propositions cannot analyze quantifiers. Ex : Consider the following situations : 1. Family = {f,m,c 1,c 2,c 3 } 2. We are interested in who is whose brother. 3. Suppose In Family, c i is c j ’s brother if i  j for i,j =1..3.

20 The Foundations Transparency No. 1-20 Inadequacy of propositional logic Primitive propositions needed: x_is_y’s_brother, x,y  Family So we need 25 propositions. New approach: Parameterized proposition(Predicate). Use a (predicate) symbol B to symbolize the statement: B(x,y)  x is y ‘s brother. e.g., B(f,c 1 ) : f is c 1 ’s brother, B(c 2,c 2 ) : c 2 is c 2 ’s brother,...

21 The Foundations Transparency No. 1-21 Benefits of Predicates Advantage of using predicates: ==> 1. need only 6 (1 predicate and 5 names) symbols. 2. can group related propositions together. (B(x,y) and others, for instance, q(x)  x_isOld. ) 3.The most important : allow representation of quantified statement like: c 1 _has_a_brother (or, there is an object x which is c1’s brother,  x B(x, c 1 )) to be inferred from c 2 _is_c 1 ’s brother ( B(c 2,c 1 ) )

22 The Foundations Transparency No. 1-22 Predicates In the expression: B(x,y) B : predicate symbol (or proposition function) x (y) : first (2nd) argument B(x,y) : [ atomic] proposition (or formula) #arguments in B(X,Y): the arity of the predicate symbol B. Notes: 1. Each predicate symbol has a fixed arity. 2. B(x,y,c 1 ) and B(x) are meaningless. because used #arguments different from B’s arity.

23 The Foundations Transparency No. 1-23 Predicates (cont’d) 3. The truth value of a proposition p(x1,...,xn) depends on both p and real values of x1,...,xn. Ex1: Let p(x)  “x >3 “. then P(4)  “4 > 3” has truth value T, P(2)  “2 > 3” has truth value F. Ex2: Let Q(x,y)  “x = y +3” then Q(1,2) = “1 = 2 + 3” is false. Q(3,0) = “3 = 0 + 3” is true. Mathematically, we can define (the meaning of) P as a function [P] [P]: U n (n is P’s arity) --> {T,F}with the intention that “P(x 1,...,x n )” holds (is true) iff [P]([x 1 ],...,[x n ]) = T.

24 The Foundations Transparency No. 1-24 Set representations of truth-functions Ex: [B]: Family 2 -->{T,F} s.t. [b](x,y) = T iff x =[ci], y=[cj], i  j. p(x)  “x >3 “, So [P]: N --> {T,F } s.t. [P](x) = T iff x > 3. Q(x,y)  “x = y +3”, so [Q] : N 2 --> {T,F} with [Q](x,y) = T iff x = y +3. Note: P partition N into two sets, one with members mapped to T and one mapped to F. N {4,5,...} {1,2,3} P(x) = T. P(x) = F So, instead of represent P as a truth function, we equivalently represent P as the set {x | P(x) = T } = {4,5,6,...} Similarly, we can represent Q as {(x,y) | x = y + 3 }

25 The Foundations Transparency No. 1-25 constant, function, variables and terms In the statement: “y > min(x, 3)” --- (s1) x,y are called variables, 3 is a constant, min is a function symbol with arity 2 “min(3,2)” behaves more like x, 3 than “x >y”. So if let P(x,y)  “x > y”, then s1 can be represented as P(y, min(x,3)) we call any expression that can be put on the argument position of an atomic proposition a term Obviously, constants and variables are terms; moreover, if f is a function of arity n, and t1,...tn are n terms, then so is f(t1,...,tn).

26 The Foundations Transparency No. 1-26 Universal and existential quantifications A: any statement (or called formula) e.g., A = p(x,y) /\ q(x,f(3)),... x: any variable, Then 1. (  x A) is a new formula called the universal quantification of A, 2. (  x A) means: “A(x) is true for all values of x in the universe of discourse.” 3. (  x A) is a new formula called the existential quantification of A, 4. (  x A) means: “A(x) is true for some value of x in the universe of discourse.”

27 The Foundations Transparency No. 1-27 Quantifiers and universe of discourse Consider the sentence: p(x) = “x > 0”. 1. as stated before, p(x) is true or false depending on the value of x. 2. p(1), p(2),... : true; p(0), p(-1),...: false Universe of Discourse (U, 論域 ): The set of objects (domain) from which all variables are allowed to have values. Ex: consider the sentence: s2: ”all numbers are greater than 0”. (for-all x “x > 0” ) or (  x p(x) ) U = N + ={1,2,3,...} => s2 is true. U = Z={...,-1,0,1,...}=> s2 is false.

28 The Foundations Transparency No. 1-28 Translation of NL statements into logical ones Translate the following sentences into logical expressions: 1. Every body likes Chang 2. Everybody loves somebody. 3. There is somebody loved by every one. 4. Nobody likes everybody. 5.There is somebody Chang don’t like. 6. there is somebody no one likes. 7.there is exactly one person everybody likes. 8 Chang likes exactly two persons 9. Everyone likes himself. 10. There is someone who likes no one who does not like himself.

29 The Foundations Transparency No. 1-29 Terminology about formulas Occurrences of variables in formulas: A = p(f(x), c) \/ q(x,y) A contains 2 variables, one of which occurs twice. Free and bound variables: A: a formula fv(A) = the set of all free variables in A is defined as follows: If A is atomic => fv(A) is the set of all variables in A fv(~A) = fv(A) fv(A/\B)=fv(A\/B)=fv(A->B)=fv(A B)= fv(A) U fv(B). fv( for-all x A) = fv(  xA) = fv(A)\ {x}.

30 The Foundations Transparency No. 1-30 bd(A): the set of bound variables in A is defined as follows; 1. If A is atomic => bd(A) = {} 2. bd(~A) = bd(A) 3. bd(A/\B) = d(A\/B) = bd(A  B) =bd(A B) = bd(A) U bd(B). 4. bd( ∀ x A) =  bd(A) if x ∉ fv(A). bd(A) U {x} if x ∈ fv(A). Example A = (  x p(x,y)) \/ q(x) => fv(A) = {x,y}; bd(A) = {x} x occurs twice in A, one occurs free and the other occurs bound. Def: A is a sentence iff fv(A) = {} Note: A is a proposition if A is a sentence

31 The Foundations Transparency No. 1-31 More logical notions [omitted!!] A  B [logical equivalence (in predicate logic)] iff A B is a tautology(or valid) for all possible values of free variables in A and in B. Common equivalences: 1. all propositional equivalences A->B  ~A \/ B, ~~A  A, ~(A/\B)  ~A\/~B,... 2. ~  x A <   x ~A. 3. ~  xA   x ~A. 4.  x (A /\ B)   x A /\  xB. 5.  x(A \/B)   xA \/  XB If x is not free in B, and Q is  or , then 6 Qx (A /\ B)  QxA /\ QxB 7. Qx(A\/B)  QxA \/ QxB

32 The Foundations Transparency No. 1-32 1.4 Sets Basic structure upon which all other (discrete and continuous ) structures are built. a set is a collection of objects. an object is anything of interest, maybe itself a set. Definition 1. A set is a collection of objects. The objects is a set are called the elements or members of the set. If x is a member of a set S, we say S contains x. notation: x  S vs x  S Ex: In 1,2,3,4,5, the collection of 1,3 5 is a set.

33 The Foundations Transparency No. 1-33 Set description How to describe a set:? 1. List all its member. the set of all positive odd integer >10 = ? The set all decimal digits = ? the set of all upper case English letters = ? The set of all nonnegative integers= ? 2. Set builder notation: P(x) : a property (or a statement or a proposition) about objects. e.g., P(x) = “ x > 0 and x is odd” then {x | P(x) } is the set of objects satisfying property P. P(3) is true => 3  {x | P(x)} P(2) is false => 2  {x | P(x)}

34 The Foundations Transparency No. 1-34 Conventions N = def {x | x is a natural numbers } = { 0,1,2,3,...} N + = def {1,2,3,...} Z = def {...,-3,-2,-1,0,1,2,3,...} R = def the set of real numbers. Problem: The same set may have many different descriptions. {x | 0 < x <10 /\ x is odd } {1,3,5,7,9}, {5,3,1,9,7} {9,7,1,3,5}.

35 The Foundations Transparency No. 1-35 Set predicates Definition 2. Two sets S1, S2 are equal iff they have the same elements S1 = S2 iff  x (x  S1 x  S2) Ex: {1,3,5} = {1,5,3} = {1,1,3,3, 5} Graphical representation of sets: Venn Diagrams: rectangle: Universal set: U circles: sets points: particular elements point x inside circle S => x  S point x outside S => x  S.

36 The Foundations Transparency No. 1-36 Set predicates (cont’d) Null set ={} =  = def the collection of no objects. Def 3’: [empty set] for-all x x . Def 3. [subset] A  B iff all elements of A are elements of B. A  B  for-all x (x  A ⇒ x  B)). Def 3’’: A  B = def A  B /\ A  B. Exercise : Show that: 1. For all set A (  2. (A  B /\ B  A)  (A = B) 3. A  Diagram representation of the set inclusion relationship.

37 The Foundations Transparency No. 1-37 Size or cardinality of a set Def. 4: | A | = the size(cardinality) of A = # of distinct elements of A. Ex: |{1,3,3,5}| = ? |{}| = ? | the set of binary digits } | = ? |N| = ? ; |Z| = ? ; | {2i | i ∈ N} = ? |R| = ? Def. 5. A set A is finite iff |A| is a natural number ; o/w it is infinite. Two sets are of the same size (cardinality) iff there is a 1-1 & onto mapping between them.

38 The Foundations Transparency No. 1-38 countability of sets Exercise: Show that 1. |N| = |Z | = | Q | = |{4,5,6,...}| 2. |R| = | (-1, 1) | = |(0,1)| 3. |(0,1)| is uncountable Def. A set A is said to be denumerable iff |A| = |N|. A set is countable iff either |A| = n for some n in N or |A| = |N|. By exercise 1,2,3, R is not countable. Q and Z is countable.

39 The Foundations Transparency No. 1-39 The power set Def 6. If A is a set, then the collection of all subsets of A is also a set, called the poser set of A and is denoted as P(A) or 2 A. Ex: P({0,1,2}) = ? P({}) = ? |P({1,2,..., n})| = ? Order of elements in a set are indistinguishable. But some sometimes we need to distinguish between (1,3,4) and (3,4,1) --> ordered n-tuples

40 The Foundations Transparency No. 1-40 Show that |A| ≠ |2 A | Pf: (1) The case that A is finite is trivial since |2 A | = 2 |A| > |A| and there is no bijection b/t two finite sets with different sizes. (2) assume |A| = |2 A |, i.e., there is a bijection f: A -> 2 A. Let D = {x ∈ A | x  f(x) }. ==> 1. D is a subset of A; Hence 2.  y ∈ A s.t. f(y) = D. Problem: Is y  D ? if yes (i.e., y  D) ==> y  f(y) = D, a contradiction if no (i.e., y  D) ==> y  f(y) =D, a contradiction too. So the assumption is false, i.e., there is no bijection b/t A and 2 A.

41 The Foundations Transparency No. 1-41 The Halting Problem L : any of your favorite programming languages (C, C ++, Java, BASIC, etc. ) Problem: write an L-program HALT(P,X), which takes another L-program P(-) and string X as input, and HALT(P,X) returns true if P(X) halts and returns false if P(X) does not halt. P(X) Halt ? yes true no false Pr(x:String) { ….. } P “It’s a test …” X HALT(P,X) Program you are asked to design

42 The Foundations Transparency No. 1-42 Halt(P,X) does not exist Motivations of the proof: Problem1 : What about the truth value of the sentence: L: L is false Problem 2 : Let S = {X | X  X}. Does S belong to S or not ? The analysis: S  S => S  S; S  S => S  S. Conclusion: 1. S is not a set!! 2. If a language is too powerful, it may produce expressions that is meaningless or can not be realized. Question: If HALT(P,X) can be programmed, will it incur any absurd result like the case of S? Ans: yes!!

43 The Foundations Transparency No. 1-43 H(P) : Another program using HALT(-,-) as a subroutine H(P) Pr(x:String) { ….. } P P(P) Halt ? yes true no false HALT(P,X) Loop END Note: H(P) Halts iff HALT(P,P) returns false iff P(P) does not halt. P P

44 The Foundations Transparency No. 1-44 P(X) Halt ? yes true no false HALT(P,X) H(P) Loop END P(X) Halt ? yes true no false HALT(P,X) H(H(P)) Loop END Problem: Will H(H(P)) Halt? H(P) The anomaly : H(H(P) halts iff H(H(P)) does not halt.

45 The Foundations Transparency No. 1-45 Cartesian Products Def. 7 [n-tuple] If a 1,a 2,...,a n (n > 0) are n objects, then “(a 1,a 2,...,a n )” is a new object, called an (ordered) n-tuple [ with a i as its ith element. ] Any ordered 2-tuple is called a pair. (a 1,a 2,...,a m ) = (b 1,b 2,...,b n ) iff  (1) m = n and (2) for i = 1,..,n a i = b i.

46 The Foundations Transparency No. 1-46 Cartesian product Def. 8: [Cartesian product] A x B = def {(a,b) | a ∈ A and b ∈ B } A1 x A2 x...x An =def {(a1,...,an) | ai ∈ Ai }. Ex: A = {1,2}, B = {a,b,c}, C = {0,1} 1. A x B = ? ; 2. B x A = ? 3. A x {} = ? ;4. A x B x C = ? problem: 1. when will A x B = B x A ? 2. |A x B | = ?

47 The Foundations Transparency No. 1-47 1.5 Set operations union, intersection,difference, complement, Definition. 1. A  B = {x | x ∈ A or x ∈ B } 2. A  B = {x | x ∈ A and x ∈ B } 3. If A  B = {} => call A and B disjoint. 4. A - B = {x | x ∈ A but x ∉ B } 5. ~ A = U - A Venn diagram representations Ex: U = {1,..,10}, A = { 1,2,3,5,8} B = {2,4,6,8,10} => A  B, A  B, A - B, ~ A = ?

48 The Foundations Transparency No. 1-48 Set identities Identity laws: A ? ? = A Domination law: U ? ? = A; {} ?? = {} Idempotent law: A ? A = A ; complementation: ~~A = A commutative : A ? B = B ? A Associative: A ? (B ? C) = (A ? B ) ? C Distributive: A ? (B ? C) = ? DeMoregan laws: ~(AUB) = ?; ~(A ⋂ B)=?

49 The Foundations Transparency No. 1-49 Prove set equality 1. Show that ~(A  B) = ~A  ~B by show that 1. ~(A  B)  ~A  ~B 2. ~A  ~B  ~(A  B) pf: (By definition) Let x be any element in ~(A  B)  2. show (1) by using set builder and logical equivalence. 3. Show distributive law by using membership table. 4. show ~(A  (B  C)) = (~C  ~B)  ~A by set identities. Note the similarity between logical equivalence and set identities.

50 The Foundations Transparency No. 1-50 Generalized set operations Def. 6 A1,A2,...An: n sets B = {A1,A2,...An }  n  {i=1,..n} Ai = def ?  n  {i=1,..n} Ai= def ? quiz: if B = {} =>  = ?;  Venn diagram representation of  and   Example:   = ? 

51 The Foundations Transparency No. 1-51 Set representation (in computer) Unordered list or array union, intersection, ~: time consuming. Bit string: U = {a1,...,an} is the universal set. A: any subset of U A can be represented by the string: s(A) = x1 x2 x3....xn where xi = 1 if a1 ∈ A and 0 o/w. fast set operations suitable only if U is not large. constant size representation.

52 The Foundations Transparency No. 1-52 1.6 Functions Def. 1 [functions] A, B: two sets 1. a function f from A to B is a set of pairs (x, y) ∈ AxB s.t., for each x ∈ A there is at most one y ∈ B s.t. (x,y) ∈ f. 2. if (x,y) ∈ f, we write f(x) = y. 3. f :A  B means f is a function from A to B. Def. 2. If f:A  B then 1. A: the domain of f; 2. B: the codomain of f if f(a)=b => 3. b is the image of a 4. a is the preimage of b 5. range(f) = ? 6. preimage(f) = ? 7. f is total iff ?

53 The Foundations Transparency No. 1-53 Types of functions Def 4. f: A x B; S: a subset of A, T: a subset of B 1. f(S) = def ? 2. f -1 (T) = def ? Def. [1-1, onto, injection, surjection, bijection] f: A -> B. f is 1-1 (a injection) iff ? f is onto (surjective, a surjection) iff ? f is 1-1 & onto f is bijective (a bijection, 1-1 correspondence) Exercise:Show that if there are onto mappings from A to B and from B to A, then |A|=|B|.

54 The Foundations Transparency No. 1-54 Real valued functions F:A  B is a real valued function iff A and B are subsets of R. f 1,f 2: real valued functions => 1. f 1 +f 2 (x) = ? 2. f 1 f 2 (x) = f 1 (x) x f 2 (x). 3. f is increasing iff ? 4. f is strictly increasing iff ?

55 The Foundations Transparency No. 1-55 operations on functions A, B, C: any sets ; f: A  B; g: B  C, then 1. [identity function] id A : A  A s.t. id A (x) = x for all x in A. 2. [composition of g and f] gf: A  C s.t. gf(x) = g(f(x)) for x in A. 3. [inverse] If f is a bijection, then f -1 : B  A s.t. f -1 (y) = x iff f(x) = y for y in B. Graphical representations

56 The Foundations Transparency No. 1-56 Properties of operations on functions f: A  B. g: B  C; h: C  D, then 1. id A f = f = f id B 2. f(gh) = (fg) h --- assoc. 3. (fg) -1 = g -1 f -1 If f: A  A is a bijection then 4. f f -1 = f -1 f= id A. Sequence: finite A-sequence: a: [n] (or [1,n])  A  A-sequence: a : N (or N + )  A. B indexed A-sequence : f:B  A.

57 The Foundations Transparency No. 1-57 The growth of functions Summation rules  a i = def a 1 + a 2 +...a n + (...) a + (a+d) + (a+2d)+... = ? a + ar +arr +... = ? The growth of functions: If f is a positive valued function, then what do the following terms mean? O(f) means ? o(f) means ?  (f) means ?  (f) means ?  (f) means ? useful in the analysis of the efficiency of computer algorithms.

58 The Foundations Transparency No. 1-58 Problem, algorithm and Complexity A problem is a general question: description of parameters [input] description of solution[output] An algorithm is a step by step procedure to solve a problem. a recipe a computer program We want the most efficient algorithm fastest (mostly) most economical with memory (sometimes) expressed as a function of problem size

59 The Foundations Transparency No. 1-59 Parameters: Set of cities Inter-city distances Example: Traveling Salesman Problem c b d a 3 5 6 9 9 10

60 The Foundations Transparency No. 1-60 Solution [output] Solution: The shortest tour passing all cities Example: a,b,d,c,a has length 27 c b d a 3 5 6 9 9 10

61 The Foundations Transparency No. 1-61 Problem Size What is appropriate measure of problem size? m nodes? m(m+1)/2 distances? Use an encoding of the problem alphabet of symbols: a,b,c,d,0-9, |. strings: abcd||10|5|9|6|9|3. Measures Problem Size: length of encoding. Time Complexity: how long an algorithm takes, as function of problem size.

62 The Foundations Transparency No. 1-62 Time Complexity What is tractable? A function f(n) is O(g(n)) whenever ∃ c > 0 ∃ n 0 > 0 s.t. |f(n)| ≤ c ∙ |g(n)| for all n > n 0. A polynomial time algorithm is one whose time complexity is O(p(n)) for some polynomial p(n). An exponential time algorithm is one whose time complexity cannot be bounded by a polynomial (e.g., n log n ).

63 The Foundations Transparency No. 1-63 Tractability Basic distinction: polynomial time = tractable exponential time = intractable 102030405060 n.00001s.00002s.00003s.00004s.00005s.00006s n2n2.0001s.0004s.0009s.0016s.0025s.0036s n3n3.001s.008s.027s.064s.125s.216s n5n5.1s3.2s24.3s1.7 m5.2 m13.0 m 2n2n.001s1.0s17.9s12.7d35.7 y366c 3n3n.059 s58 m6.5 y3855 c2∙10 8 c1.3∙10 13 c execution time in microseconds( μ s)

64 The Foundations Transparency No. 1-64 Effect of Speed-ups for different order of functions Wait for faster hardware! Consider maximum problem size you can solve in an hour. present100 times faster1000 times faster nN1N1 100 N 1 1000 N 1 n2n2 N2N2 10N 2 31.6 N 2 n3n3 N3N3 4.64 N310 N 3 n5n5 N4N4 2.5 N 4 3.98 N 4 2n2n N5N5 N 5 +6.64N 5 +9.97 3n3n N6N6 N 6 +4.19N 6 +2.29

65 The Foundations Transparency No. 1-65 Asymptotic notations  ((g(n)) = {f(n) |  c 2,c 1 and k > 0 s.t. c 2 g(n)  f(n)  c 1 g(n) for all n > k }  ((g(n)) = {f(n) |  c and k > 0 s.t. f(n)  cg(n) for all n > k }  ((g(n)) = {f(n) |  c and k > 0 s.t. c g(n)  f(n) for all n > k }  ((g(n)) = {f(n) |  arbitrary small c >0  k > 0 s.t. f(n) k }  ((g(n)) = {f(n) |  arbitrary large c >0  k > 0 s.t. c g(n) k }

66 The Foundations Transparency No. 1-66 Examples Ex1: Show that f(x) = x 2 + 2x+ 1 is O(x 2 ). pf: Let c = 4, k = 1, It is easy to check that if x > k, then f(x) = x 2 + 2x+ 1 ≤ x 2 + 2 x 2 + x 2 ≤ c x 2. Hence by definition, f(x) = O(x2). Ex2: Show that f(x) = x 2 + 2x+ 1 is  (x 2 ). pf: Let c = 1, k = 1. Obviously, x 2 +2x+1 ≥ x 2 = cx 2 for all x >1=k. Hence f(x) =  (x 2 ).

67 The Foundations Transparency No. 1-67 Ex2: Show that f(x) = x 2 + 2x+ 1 is  (x 2 ). pf: Let c 1 = 1,c 2 =4, k = 1. c 1 x 2 ≤ x 2 +2x+1 ≥ c 2 x 2 for all x >1=k. Hence f(x) =  (x 2 ). Proposition: f =  (g) iff f =  (g) and f =  (g). pf: (=>:) direct from definition. (<=:) if f = O(g) = Q(g) => ∃ c 1, k 1 s.t f(x) ≤ c 1 g(x) for all x > k 1. ∃ c 2, k 2 s.t f(x) ≥ c 2 g(x) for all x > k 2. let k = max(k 1,k 2 ) => c 2 g(x) ≤ f(x) ≤ c 1 g(x) for all x > k. Hence f(x) =  (g).

68 The Foundations Transparency No. 1-68 Example: Ex2: Show that f(x) = x 2 + 2x+ 1 is not in o(x 2 ). pf: f(x) = o(x 2 ) means ∀ c > 0, ∃ k with f(x) k. But this does not hold: for c = 1, for all k > 0, we have f(x) ≥ c g(x) for some x > max(1, k). Hence f(x) is not in o(x 2 ). Ex2: Show that f(x) = x 2 + 2x+ 1 is in o(x 3 ). pf: for any c > 0, x 2 + 2x + 1 < c x3 iff 1/x + 2/x 2 + 1/x 3 < c if 4/x 3 < c if x > (4/c)1/3 = k. Hence f(x) = o(x 3 ).

69 The Foundations Transparency No. 1-69 Using the asymptotic notations We use f(n) =  (g(n)) to mean f(n)  (g(n)), where  = ,or . analog: O (asymptotic upper bound):  f(n) = O(g(n)) means like f(n)  g(n) o (asymptotic upper bound but not tight): < f(n) = o(g(n)) means like f(n) < g(n)  (asymptotic lower bound):  f(n) =  (g(n)) means like f(n)  g(n)  (asymptotic lower bound but not tight): > f(n) =  (g(n)) means like f(n) > g(n) Q (asymptotic tight bound : = f(n) = O(g(n)) means like f(n) = g(n)

70 The Foundations Transparency No. 1-70 Exercises Let f and g be positive real function. Show that 1. f =  (g) iff g =  (f) 2. f =  (g) iff g =  (f) 3. f =o(g) iff f =O(g) but not f =  (g) 4 f =  (g) iff f =  (g) but not f =  (g) 5 f = o(g) iff limit n  f/g = 0 iff limit n  g/f =  iff g =  (f).


Download ppt "Discrete Mathematics Transparency No. 1-0 Chapter 1. The Foundations Cheng-Chia Chen."

Similar presentations


Ads by Google