Presentation is loading. Please wait.

Presentation is loading. Please wait.

Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Sets Steve Wolfman, based on notes by Patrice Belleville and others.

Similar presentations


Presentation on theme: "Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Sets Steve Wolfman, based on notes by Patrice Belleville and others."— Presentation transcript:

1 snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Sets Steve Wolfman, based on notes by Patrice Belleville and others

2 Lecture Prerequisites Read Section 5.1. Solve problems like Exercise Set 5.1, #1-21. (Note: the notion of a “partition” is important in CS, but we won’t discuss it in CPSC 121. We’ll talk more about “power sets” very soon.) Complete the open-book, untimed quiz on WebCT that will be due Tuesday evening March 17 th.

3 Learning Goals: Pre-Class By the start of class, you should be able to: –Define the set operations union, intersection, complement, and set difference and the logical operations subset and set equality in terms of predicate logic and set membership (  ). –Translate between sets represented explicitly (possibly using ellipses “…”, e.g., {4, 6, 8, …}) and using “set builder” notation (e.g., {x  Z + | x 2 > 10  x is even}). –Execute the union, intersection, complement, set difference, subset, and set equality operations on sets expressed explicitly, using set builder notation, or a combination of these and set operators. –Interpret the empty set symbol , including the fact that the empty set has no members and that it is a subset of any set.

4 Learning Goals: In-Class By the end of this unit, you should be able to: –Define the power set and cartesian product operations in terms of predicate logic and set membership/subset relations. –Execute the power set, cartesian product, and cardinality operations on sets expressed through any of the notations discussed so far. –Apply your proof skills to proofs involving sets. –Relate DFAs to sets.

5 Quiz 10 Notes Generally excellent results. Only the subset questions caused many problems, because of the empty set. Set A is a subset of set B exactly when every element of A is an element of B. Is the empty set a subset of B?

6 Outline Out-of-class notes on set definitions What’s the Use of Sets –Historical note –Application to DFAs More set operations –Cardinality (size) –Power set (and an induction proof) –Cartesian products (and application to DFAs) Set proofs

7 Flashback: Sets A set is a collection of elements: –the set of students in this class –the set of lowercase letters in English –the set of natural numbers (N) –the set of all left-handed students in this class An element is either in the set ( x  S ) or not ( x  S ). Is there a set of everything? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

8 Flashback: Sets and Predicates Is there a predicate that defines each set? –the set of students in this class –the set of lowercase letters in English –the set of natural numbers (N) –the set of all left-handed people in this class CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

9 Flashback: Quantifier Example Someone in this class is left-handed (where C is the set of people in this class):  x  C, L(x) CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

10 What is a Set? A set is an unordered collection of objects. The objects in a set are called members. ( a  S indicates a is a member of S ; a  S indicates a is not a member of S ) A set contains its members. CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

11 Describing Sets (1/4) Some sets… A = {1, 3, 9} B = {1, 3, 9, 27, snow} C = {1, 1, 3, 3, 9, 9} D = {A, B} D' = { {1, 3, 9}, {1, 3, 9, 27, snow} } E = { } CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

12 Describing Sets (2/4) Some sets… A = {1, 5, 25, 125, …} B = {…, -2, -1, 0, 1, 2, …} C = {1, 2, 3, …, 98, 99, 100} “…” is an ellipsis CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

13 Describing Sets (3/4) Some sets, using set builder notation: A = {x  N |  y  N, x = 5 y } B = {2 i - 1 | i is a prime} C = {n  Z | 0 < n  100} To read, start with “the set of all”. Read “ | ” as “such that”. To read A : “the set of all natural numbers x such that x is a (natural) power of 5 ” CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

14 Describing Sets (4/4) Graphical depiction of sets: Venn diagrams. Draw the set of all five-letter things. All red things? All red, five-letter things? fire truck snows happiness Texas heart books 7  U CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

15 Describing Sets (4/4) Graphical depiction of sets: Venn diagrams. Draw the set of all five-letter things. All red things? All red, five-letter things? fire truck snows happiness Texas heart books 7  U CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

16 Containment A set A is a subset of a set B iff  x  U, x  A  x  B. We write A is a subset of B as A  B. If A  B, can B have elements that are not elements of A ? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

17 Containment A set A is a subset of a set B iff  x  U, x  A  x  B. We write A is a subset of B as A  B. If A  B, can B have elements that are not elements of A ? Yes, but A can’t have elements that are not elements of B. CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

18 Membership and Containment A = {1, {2}} Is 1  A ? Is {1}  A ? Is 1  A ? Is {1}  A ? Is 2  A ? Is {2}  A ? Is 2  A ? Is {2}  A ? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

19 Membership and Containment A = {1, {2}} Is 1  A ? Yes Is {1}  A ? Yes Is 1  A ? No (not meaningful since 1 is not a set) Is {1}  A ? No Is 2  A ? No Is {2}  A ? No Is 2  A ? No (not meaningful since 2 is not a set) Is {2}  A ? Yes CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

20 Thought Question What if A  B and B  A ? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

21 Set Equality Sets A and B are equal — denoted A = B — if and only if  x  U, x  A  x  B. Can we prove that that’s equivalent to our mutual subset relationship? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

22 Set Equality Sets A and B are equal — denoted A = B — if and only if  x  U, x  A  x  B. Can we prove that that’s equivalent to our mutual subset relationship? Yes, using a standard predicate logic proof in which we note that p  q is logically equivalent to p  q  p  q. CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

23 Set Union The union of A and B — denoted A  B — is {x  U | x  A  x  B}. A  B is the blue region... AB U CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

24 Set Intersection The intersection of A and B — denoted A  B — is {x  U | x  A  x  B}. A  B is the dark blue region... AB U CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

25 Set Difference The difference of A and B — denoted A - B — is {x  U | x  A  x  B}. Draw A – B is the pure blue region. AB U CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

26 Set Complement The complement of A — denoted A — is {x  U | x  A}. A is everything but the blue region. A U Can we express this as a set difference? CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

27 Set Operation Identities Many logical equivalences have analogous set operation identities. Here are a few… read more in the text! A  B = B  A Commutative Law (A  B)  C = (A  C)  (B  C) Distributive Law (A  B) = A  B DeMorgan’s Law A  U = A U as identity for ... CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)

28 What Are Sets Good For? Historically: Mathematicians attempted to formalize set theory to create a foundation for all of mathematics. Essentially all mathematical constructs can be defined in terms of sets. Good news: this means sets are a powerful way to communicate many types of ideas.

29 Bad News: Russell’s Paradox (and other problems)

30 What Are Sets Good For? Applications for us: Codifying and communicating ideas. For example, formalizing DFAs...

31 What is a DFA? The states are: ______ The start state is: ____ The accepting states are: _____________ The input language is: ________________ What’s left? a b b a,b a

32 The Transition Function The arrows in our DFA have the following properties: An arrow starts from every state, for every letter in the input alphabet. The arrows lead to other states. We’ll formalize this as the function  soon, which will complete our DFA! a b b a,b a

33 What is a DFA? (Deterministic Finite Automaton) Q is the (finite) set of states. q 0 is the start state, and q 0  Q. F is the set of accepting states, and F  Q.  Is the (finite) set of letters in the input language.  is the transition function, to be described. These are just standard names we use, but the constraints make sense regardless of names. a b b a,b a

34 Problem: Formalizing an Example DFA For this DFA: Q = { } q 0 = F = { }  = { }  : (, )  (, )  a b b a,b a

35 Worked: Formalizing an Example DFA For this DFA: Q = { t, m, b, g} q 0 = t F = { t, b }  = { a, b }  : (t, a)  m (t, b)  b (m, a)  g (m, b)  b (b, a)  b (b, b)  b (g, a)  g (g, b)  g a b b a,b a t m b g “g” is for “garbage”. A garbage state is a rejecting state you cannot escape.

36 Problem: Testing the DFA Formalism Q is the set of states q 0 is the start state, and q 0  Q. F is the set of accepting states, and F  Q.  Is the set of letters in the input language.  is the transition function, to be described. Must a DFA have a start state? Can a DFA have more than one start state? Must a DFA have an accepting state? Can all states in a DFA be accepting? Can the start state be accepting?

37 Testing the DFA Formalism Must a DFA have a start state? Can a DFA have more than one start state? Must a DFA have an accepting state? Can all states in a DFA be accepting? Can the start state be accepting? q 0 is the start state; so, yes. q 0 is the only start state; so, no. F  Q. Is   Q? F  Q. Is Q  Q? q 0  Q and F  Q. Can q 0  F?

38 Must a DFA Have an Accepting State? What does a DFA with no accepting states look like? What language does it accept?

39 Can All States in a DFA Be Accepting? What does a DFA with no rejecting states look like? What language does it accept?

40 Outline Out-of-class notes on set definitions What’s the Use of Sets –Historical note –Application to DFAs More set operations –Cardinality (size) –Power set (and an induction proof) –Cartesian products (and application to DFAs) Set proofs

41 How Big Is a Set? How big are these sets? A = {1, 3} B = {1, 3, 27, snow} C = { {1, 3}, {1, 3, 27, snow} } D =  E = N F = { …, -4, -2, 0, 2, 4, … }

42 Cardinality The cardinality of a set A — denoted |A| — is the set’s size. For finite sets, the cardinality of the set is the number of elements it contains… |A| = |{1, 3}| = 2 |B| = |{1, 3, 27, snow}| = 4 |C| = |{ {1, 3}, {1, 3, 27, snow} }| = ?? |D| = |  | = ??

43 Cardinality The cardinality of a set A — denoted |A| — is the set’s size. For finite sets, the cardinality of the set is the number of elements it contains… |A| = |{1, 3}| = 2 |B| = |{1, 3, 27, snow}| = 4 |C| = |{ {1, 3}, {1, 3, 27, snow} }| = 2 |D| = |  | = 0

44 Cardinality of Infinite Sets? For now, we won’t worry about the cardinality of infinite sets. Why? Well, we can’t count the members of such sets. Side note: Depending on our definition, however, the results can be surprising. For example, under the standard definition of cardinality, these have the same cardinality: E = N = {1, 2, 3, … } F = { …, -4, -2, 0, 2, 4, … } Why? Try “folding” the set F over creatively.

45 Problem: Cardinality Exercises Given the definitions: A = {1, 2, 3} B = {2, 4, 6, 8} What are: |A|= _________ |B|= _________ |A  B|= _________ |A  B|= _________ |A – B|= _________ |B – A|= _________ |{{}}|= _________ |{  }|= _________ |{{  }}|= _________

46 Worked Cardinality Exercises Given the definitions: A = {1, 2, 3} B = {2, 4, 6, 8} What are: |A|= 3________ |B|= 4________ |A  B|= 6________ |A  B|= 1________ |A – B|= 2________ |B – A|= 3________ |{{}}|= 1________ |{  }|= 1________ |{{  }}|= 1________

47 Outline Out-of-class notes on set definitions What’s the Use of Sets –Historical note –Application to DFAs More set operations –Cardinality (size) –Power set (and an induction proof) –Cartesian products (and application to DFAs) Set proofs

48 A Touch of Logic Consider the four propositional logic variables p, q, r, and s. What are all the different ways can we assign truth values to each of these? Now, imagine a set S that contains exactly the true variables among p, q, r, and s. What are the possible “ S s” (depending on p, q, r, and s ’s truth values)?

49 A Touch of Logic: Rephrased Consider the set {p, q, r, s}. What are all the subsets of this set? Equivalently, what is: {S  U | S  {p,q,r,s}} ?

50 Power Sets The power set of a set T — denoted P(T) — is the set of all subsets of T : { S  U | S  T }

51 Using Logic to Build Power Sets pqrs Set from P(…) FFFF {} FFFT {s} FFTF {r} FFTT {r,s} FTFF {q} FTFT {q,s} FTTF {q,r} FTTT {q,r,s} pqrs Set from P(…) TFFF {p} TFFT {p,s} TFTF {p,r} TFTT {p,r,s} TTFF {p,q} TTFT {p,q,s} TTTF {p,q,r} TTTT {p,q,r,s} So, how big is the power set of a set? P({p,q,r,s}) = …

52 Problem: Power Set Exercises Given the definitions: A = {1, 2} B = {2, 4, 6} What are: P(A)= _____________________________ P(B)= _____________________________ |P(A)|= _____________________________ |P(B)|= _____________________________ |P(P(A))|= _____________________________ P(P(A))= _____________________________ P(A  B)= _____________________________

53 Power Set Exercises (Partially Worked) Given the definitions: A = {1, 2} B = {2, 4, 6} What are: P(A)= {{},{1},{2},{1,2}}___________ P(B)= {{},{2},{4},{6},{2,4},{2,6},{4,6},{2,4,6}} |P(A)|= 4____________________________ |P(B)|= 8____________________________ |P(P(A))|= 16___________________________ P(A  B)= Big; similar to P({p,q,r,s}) P(P(A))= Big; similar to P({p,q,r,s})

54 Cardinality of a Finite Power Set Theorem: |P(S)| = 2 |S| Base case: When |S| = 0, what is S ? What is P(S) ? How do we know?

55 Cardinality of a Finite Power Set Induction Hypothesis: Assume for all sets S of cardinality n  0, |P(S)| = 2 |S|. Inductive step: To prove: Given the induction hypothesis, for all sets T, |P(T)| = 2 |T| when |T| = n+1. The key is to drop an element from a set of size n+1. Then, take the power set. Then, consider how to put the element back in.

56 Worked: Cardinality of a Finite Power Set Base case: The only set with |S| = 0 (i.e., with no elements) is the empty set {}. P(  ) = {S  P( U ) | S  {}} But, only {} is a subset of {}. So, |P(  )| = 1 = 2 0

57 Worked: Cardinality of a Finite Power Set Inductive step: |T| = n+1  1 ; so, T has at least one element. Let x be an arbitrary element of T. Consider T – {x}. |T – {x}| = n. So, |P(T – {x})| = 2 n by the induction hypothesis. Furthermore P(T – {x}) is the set of all subsets of T that do not include x.

58 Worked: Cardinality of a Finite Power Set Inductive step (continued): However, each subset of T that does include x can be matched up with exactly one of the subsets that does not include x that is the same, but for x. In other words, there are exactly as many subsets of T that include x as do not include x. So, |P(T)| = 2|P(T – {x})| = 2*2 n = 2 n+1 QED!

59 Outline Out-of-class notes on set definitions What’s the Use of Sets –Historical note –Application to DFAs More set operations –Cardinality (size) –Power set (and an induction proof) –Cartesian products (and application to DFAs) Set proofs

60 Tuples A tuple is an ordered collection of elements. (An n -tuple is a tuple with n elements.) Two tuples are equal when each pair of corresponding elements is the same: (a, 1,  )= (a, 5 – 4, A  A) (a, b, c)  (a, c, b) Actual fact: database people love the word “tuple”. And… why shouldn’t they? Say “two-tuple”. Isn’t that great?

61 Formalizing DFAs: Where the Arrows Come From The arrows in our DFA have the following properties: An arrow starts from every state, for every letter in the input alphabet. The arrows lead to other states. We’ll formalize this as a function soon. What is the set of “things” for which there is an arrow? a b b a,b a t m b g

62 Cartesian Products The Cartesian product of the sets A and B — denoted A  B — is the set of all tuples whose first element is drawn from A and whose second element is drawn from B. In other words, A  B = {(a,b) | a  A  b  B}

63 Cartesian Products and the Cartesian Plane Let’s visualize N  N: 1 2 3 4 5 12345 678

64 Calculating Cartesian Products What is {1,2,3}  {a,b} : 1 2 3 ab (, )

65 Calculating Cartesian Products What is {1,2,3}  {a,b} : 1 2 3 ab ( 3, a ) ( 2, a ) ( 1, a ) ( 3, b ) ( 2, b ) ( 1, b )

66 Formalizing DFAs: Where the Arrows Come From The arrows in our DFA have the following properties: An arrow starts from every state, for every letter in the input alphabet. The arrows lead to other states. We’ll formalize this as a function soon. Each tuple of a state and a letter has an arrow. There’s an arrow for every member of Q   a b b a,b a t m b g

67 Example DFA, Revisited For this DFA: Q = { t, m, b, g} q 0 = t F = { t, b }  = { a, b }  : (t, a)  m (t, b)  b (m, a)  g (m, b)  b (b, a)  b (b, b)  b (g, a)  g (g, b)  g a b b a,b a t m b g

68 Outline Out-of-class notes on set definitions What’s the Use of Sets –Historical note –Application to DFAs More set operations –Cardinality (size) –Power set (and an induction proof) –Cartesian products (and application to DFAs) Set proofs

69 Problem: Proofs with Sets (1/2) Prove by contradiction that for all sets A and B, if A  B then A  B = { }. (Note: B contains all elements in the universe that are not in B.)

70 Problem: Proofs with Sets (2/2) Prove for all sets A and B, if A  B then P(A)  P(B). (Note: if A  B and B  C, then A  C.)

71 Learning Goals: In-Class By the end of this unit, you should be able to: –Define the power set and cartesian product operations in terms of predicate logic and set membership/subset relations. –Execute the power set, cartesian product, and cardinality operations on sets expressed through any of the notations discussed so far. –Apply your proof skills to proofs involving sets. –Relate DFAs to sets.


Download ppt "Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Sets Steve Wolfman, based on notes by Patrice Belleville and others."

Similar presentations


Ads by Google