Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 121: Models of Computation 2016W2

Similar presentations


Presentation on theme: "CPSC 121: Models of Computation 2016W2"— Presentation transcript:

1 CPSC 121: Models of Computation 2016W2
Sets Steve Wolfman, based on notes by Patrice Belleville and others TODO (future terms): update term

2 Outline Prereqs, Learning Goals, and Quiz Notes
Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

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+ | x2 > 2  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. Discuss point of learning goals.

5 Outline Prereqs, Learning Goals, and Quiz Notes
CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) Outline Prereqs, Learning Goals, and Quiz Notes Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

6 Outline Prereqs, Learning Goals, and Quiz Notes
Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

7 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.

8 Bad News: Russell’s Paradox (and other problems)
Does the “set of all sets that contain themselves” contain itself? Yes, definitely. Maybe, either way is fine. No, definitely not. None of these. Russell’s Paradox: (1) Consider the set RP of all sets that contain themselves. Does RP contain RP? (2) Now, consider the set RP’ of all sets that DO NOT contain themselves. Does RP’ contain RP’? Uh-oh. Set theory “solves” this problem essentially by disallowing sets like the set of all sets that do not contain themselves. Is that cheating?

9 Bad News: Russell’s Paradox (and other problems)
Does the “set of all sets that do not contain themselves” contain itself? Yes, definitely. Maybe, either way is fine. No, definitely not. None of these. Russell’s Paradox: (1) Consider the set RP of all sets that contain themselves. Does RP contain RP? (2) Now, consider the set RP’ of all sets that DO NOT contain themselves. Does RP’ contain RP’? Uh-oh. Set theory “solves” this problem essentially by disallowing sets like the set of all sets that do not contain themselves. Is that cheating? English makes the non-gender-specific version of the barber problem awkward, since it’s unclear yet important whether the “they” in each case refers to the barber or everyone. However, the gender-specific version has the advantage of being solveable! So, bring that up  Same question, different form: “Imagine a barber that shaves every man in town who does not shave himself. Does the barber shave himself?”

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

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

12 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 N soon, which will complete our DFA! a a,b a b b a,b

13 What is a DFA? (Deterministic Finite Automaton)
I the (finite, non-empty) set of letters in the input language. S the (finite) set of states. s0 the initial state; s0  S. F the set of accepting (“final”) states; F  S. N the next-state function, to be described. a a,b a b b a,b These are just standard names we use, but the constraints make sense regardless of names.

14 Problem: Formalizing an Example DFA
For this DFA: I = { } S = { } s0 = F = { } N: ( , )  ( , )  a a,b a b b a,b

15 Problem: Testing the DFA Formalism
I the (finite, non-empty) set of letters in the input language. S the (finite) set of states. s0 the initial state; s0  S. F the set of accepting (“final”) states; F  S. N the next-state function, to be described. Must a DFA have an initial state? Can a DFA have more than one initial state? Must a DFA have an accepting state? Can all states in a DFA be accepting? Can the initial state be accepting? a. Yes b. No c. Not enough information.

16 Testing the DFA Formalism
Must a DFA have an initial state? Can a DFA have more than one initial state? Must a DFA have an accepting state? Can all states in a DFA be accepting? Can the initial state be accepting? s0 is the initial state; so, yes. s0 is the only initial state; so, no. F  S. Is   S? F  S. Is S  S? s0  S and F  S. Can s0  F?

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

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

19 Outline Prereqs, Learning Goals, and Quiz Notes
Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

20 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

21 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, … } a b c d e. None of these

22 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, … } Can you resist stopping to prove that the even numbers have the same cardinality as the natural numbers? I couldn’t. Why? Try “folding” the set F over creatively.

23 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| = _________ |{{}}| = _________ |{}| = _________ |{{}}| = _________ a b c d e. None of these

24 Outline Prereqs, Learning Goals, and Quiz Notes
Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

25 A Touch of Logic Consider the four propositional logic variables p, q, r, and s. What are all the different ways we can 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)?

26 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}}?

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

28 Using Logic to Build Power Sets
P({p,q,r,s}) = … p q r s Set from P(…) F {} T {s} {r} {r,s} {q} {q,s} {q,r} {q,r,s} p q r s Set from P(…) T F {p} {p,s} {p,r} {p,r,s} {p,q} {p,q,s} {p,q,r} {p,q,r,s} So, how big is the power set of a set?

29 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) = _____________________________

30 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?

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

32 Outline Prereqs, Learning Goals, and Quiz Notes
Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

33 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?

34 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. t a a,b a m g b b a,b b What is the set of “things” for which there is an arrow?

35 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}

36 Cartesian Products and the Cartesian Plane
Let’s visualize N  N: 1 2 3 4 5 1 2 3 4 5 6 7 8

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

38 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. t a a,b a m g b b a,b b Each tuple of a state and a letter has an arrow. There’s an arrow for every member of S  I

39 Example DFA, Revisited t a a,b a m g b b a,b b
For this DFA: I = { a, b } S = { t, m, b, g} s0 = t F = { t, b } N: (t, a)  m (t, b)  b (m, a)  g (m, b)  b (b, a)  b (b, b)  b (g, a)  g (g, b)  g t a a,b a m g b b a,b b

40 Outline Prereqs, Learning Goals, and Quiz Notes
Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

41 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.) Assume A subseteq B and A intersect B’ != {}. A intersect B’ != {}, means there’s at least one element in this set, and that means there is an element that’s in both A and B’, that is, not in B. But, A subseteq B means every element in A is in B. That’s a contradiction. QED

42 Containment A set A is a subset of a set B iff x  U, x  A  x  B.
CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS) 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.

43 CORRESPONDS TO TEXTBOOK READING (NOT COVERED IN CLASS)
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... U A B

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

45 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.) Assume A is a subset of B. To prove P(A) subseteq P(B), we’ll look at the definitions of P(.) and subset. So, for P(A) subseteq P(B), for any x, if x is an element of P(A), then it is also an element of P(B). Using the definition of P(.), that means if x is a subset of A, then it is also a subset of B. So, assume x is a subset of A. That means every element in x is also in A. But every element in A is also in B. So, every element in x is in B. X is a subset of B. QED.

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

47 Outline Prereqs, Learning Goals, and Quiz Notes
Out-of-class notes on set definitions What’s the Use of Sets (history & DFAs) More set operations Cardinality (size) Power set (and an induction proof) Cartesian products (and application to DFAs) Set proofs Next Lecture Notes

48 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. Discuss point of learning goals.

49 Next Lecture Learning Goals: Pre-Class
By the start of class, you should be able to: Define the terms domain, co-domain, range, image, and pre-image Use appropriate function syntax to relate these terms (e.g., f : A  B indicates that f is a function mapping domain A to co-domain B). Determine whether f : A  B is a function given a definition for f as an equation or arrow diagram.

50 Next Lecture Prerequisites
See the “Functions” readings on the “Textbook and References” section of the website. Complete the quiz on Vista before class.

51 Extra Slides: Worked Proofs
(Thanks to Meghan Allen)

52 Proofs with Sets #1 version 1
Prove that for all sets A and B: A  B = A  B Proof #1: A  B = {x  U | x  (A  B)} = {x  U | ~(x  A  x  B)} = {x  U | x  A  x  B} = {x  U | x  A  x  B} = A  B Def’n of Def’n of  De Morgan’s Def’n of Def’n of 

53 Proofs with Sets #1 version 2
Remember that for any two sets C and D, C = D iff C is a subset of D and D is a subset of C. C = D  [C  D  D  C]

54 Proofs with Sets #1 version 2
Prove that: A  B  A  B Pick an arbitrary x  A  B, Then x  A  B. ~(x  A  x  B) x  A  x  B x  A  x  B x  (A  B) Def’n of Def’n of  De Morgan’s Def’n of Def’n of 

55 Proofs with Sets #1 version 2
Prove that: A  B  A  B Pick an arbitrary x  A  B Then, x  A  x  B x  A  x  B ~(x  A  x  B) x  A  B x  A  B

56 Proofs with Sets #1 version 2 conclusion
We have shown that A  B  A  B and A  B  A  B . Therefore, A  B = A  B.

57 Proof with Sets #2 Prove that, for all sets A, B and C:
(A  B) – C = (A – C)  (B – C) This time we’ll use the Set Identities LHS: (A  B) – C = (A  B)  C Set Difference Law = C  (A  B) Commutative Law = (C  A)  (C  B) Distributive Law = (A  C)  (B  C) Commutative Law = (A - C)  (B – C) Set Difference Law

58 Proofs with Sets #3 Prove or disprove, for all sets A and B,
A – B = B – A We can disprove this with a counterexample. Let A = {1,2} and B = {2,3} Then, A-B = {1} and B-A = {3} A – B ≠ B – A

59 Proofs with Sets #4 Prove that for all sets A and B, if A  B then A  B =  Proof by contradiction. Assume A  B and A  B  . Then, there exists an element x  A  B. By the definition of intersection, that means x  A and x  B. Since x  B, x  B by the definition of complement. But, A  B, so since x  A, x  B by definition of subset. Thus, x  B and x  B which is a contradiction. Hence the assumption is false and therefore for all sets A and B, if A  B then A  B =  Proof by contradiction. Suppose A is a subset of B and A intersection B complement is not the emtpy set. Then, there exists an element x that is in A intersection B complement. By the definition of intersection, that means x is in A and x is in B complement. But, since A is a subset of B, so since x is in A, x is in B by definition of subset. Thus, x is not in B and x is in B which is a contradiction. Hence the supposition A intersection B complement is not empty is false and therefore A intersection B complement is empty.

60 Proofs with Sets #5 Prove that for all sets A and B, if A  B then P A)  P(B) WLOG, let A and B be sets. Proof by antecedent assumption: Assume A  B. Now, consider X  P(A) X  A by the definition of power set. But, because A  B, X  B by the transitive property of subsets* and thus, by the definition of power set, X  P(B). This proves that for all X, if X  P(A) then X  P(B) and so P(A)  P(B). Epp, 5.3 #13 *Epp -Theorem 5.2.1

61 Proofs with Sets #6 version 1
Prove that for all sets S,   S. We proceed by contradiction. Assume that there is a set S such that the empty set is not a subset of S. Then, by definition of subset, there must be some element x of the empty set that is not an element of S. However, the empty set has no elements. This is a contradiction. QED

62 Proofs with Sets #6 version 2
Prove that for all sets S,   S. Note that   S  x  U, x    x  S  x  U, x    x  S. We proceed by proving this last statement. We know nothing is an element of the empty set: x  U, x  . By generalization, it follows that: x  U, x    x  S. QED


Download ppt "CPSC 121: Models of Computation 2016W2"

Similar presentations


Ads by Google