CPSC 121: Models of Computation Unit 12 Sets and Functions Based on slides by Patrice Belleville and Steve Wolfman
PART 1 SETS Unit 12: Sets and Functions 2
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. Unit 12: Sets and Functions 3
Describing Sets Some sets… A = {1, 3, 9} B = {1, 3, 9, 27, snow} C = {1, 1, 3, 3, 9, 9} 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} Unit 12: Sets and Functions 4
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. Unit 12: Sets and Functions 5
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 A B and B A ? Yes, using a standard predicate logic proof in which we note that p q is logically equivalent to p q p q. Unit 12: Sets and Functions 6
Set Union The union of A and B — denoted A B — is {x U | x A x B} . A B is the blue region... U A B Unit 12: Sets and Functions 7
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 Unit 12: Sets and Functions 8
Set Difference The difference of A and B — denoted A - B — is {x U | x A x B} . A – B is the pure blue region. U U A B Unit 12: Sets and Functions 9
Set Complement The complement of A — denoted A — is {x U | x A} . A is everything but the blue region. U U A Can we express this as a set difference? Unit 12: Sets and Functions 10
Historical Notes on Sets Mathematicians formalized set theory to create a foundation for all of mathematics. Essentially all mathematical constructs can be defined in terms of sets. Hence sets are a powerful means of formalizing new ideas. But we have to be careful how we use them! Unit 12: Sets and Functions 11
Russell's Paradox At the beginning of the 20 th century Bertrand Russell discovered inconsistencies with the "naïve" set theory. Let R be the set of all sets that Same question, do not contain themselves. different form: That is “Imagine a barber that R = { x | ~x ϵ x }. shaves every man in Then: town who does not shave himself. Does R R ~R R . the barber shave himself?” which is a contradiction. Set theory has been restricted in a way that disallow this kind of sets. Unit 12: Sets and Functions 12
Set Cardinality Cardinality: the number of elements of a set S, denoted by |S|. The cardinality of the set: { 1, 2, 3, { a, b, c }, snow, rain } is 6. Unit 12: Sets and Functions 13
Power Sets The power set of a set S, denoted P (S), is the set whose elements are all the subsets of S. That is P (S) = { T | T S} Given the definitions A = { a, b, f }, B = { b, c }, then: P (B) = { , {b}, {c}, {b, c} } P (A - B) = { , {a}, {f}, {a, f} } Theorem : If S is a finite set then |P(S)| = 2 |S| Unit 12: Sets and Functions 14
Tuples An ordered tuple (or just tuple) is an ordered collection of elements. (An n -tuple is a tuple with n elements.) Two tuples are equal when their corresponding elements are equal. Example: (a, 1, ) = (a, 5 – 4, A A) (a, c, b) (a, b, c) Unit 12: Sets and Functions 15
Cartesian Product The cartesian product of two sets S and T, denoted S x T, is the set of all tuples whose first element is drawn from S and whose second element is drawn from T In other words, S x T = { (s, t) | s ∈ S t ∈ T }. Each element of S x T is called a 2-tuple or a pair. Unit 12: Sets and Functions 16
Calculating Cartesian Products What is {a,b} {1,2,3} : ( a , 3 ) ( b , 3 ) 3 2 ( a , 2 ) ( b , 2 ) 1 ( a , 1 ) ( b , 1 ) a b The order of the tuples definitely matters! Unit 12: Sets and Functions 17
PART 2 FUNCTIONS Unit 12: Sets and Functions 18
What is a Function? Mostly, a function is what you learned it was all through K-12 mathematics, with strange vocabulary to make it more interesting… A function f:A B maps values from its domain A to its co-domain B . Domain Co-domain f(x) = x 3 R or Z or... R or Z or... f(x) = x mod 4 Z or Z + or... Z or Z + or... f(x) = x R or R + or... Z or Z + or... Unit 12: Sets and Functions 19
What is a Function? Not every function has to do with numbers… A function f:A B maps values from its domain A to its co-domain B . Domain Co-domain f(x) = ~x {T, F} {T, F} f(x,y) = x y {T,F} {T,F} {T, F} f(x) = x ’s phone # Set of people? 10-dig #s? Unit 12: Sets and Functions 20
What is a Function? A function f:A B maps values from its domain A to its co-domain B . f can’t map one element of its domain to more than one element of its co-domain: x A, y 1 ,y 2 B, [(f(x) = y 1 ) (f(x) = y 2 )] (y 1 = y 2 ). f B A Unit 12: Sets and Functions 21
Function Terminology A function f:A B maps values from its domain A to its co-domain B . For f to be a function, it must map every element in its domain: x A, y B, f(x) = y. f B A Warning: some mathematicians would say that makes f “total”. Unit 12: Sets and Functions 22
Function Terminology A function f:A B maps values from its domain A to its co-domain B . f(x) is called the image of x (under f ). x is called the pre-image of f(x) (under f ). The range of f is the set of all images of elements of f ’s domain. In other words: f { f(x) | x A } x B A y Unit 12: Sets and Functions 23
Injective Functions Some special types of functions: A function f : A → B is injective (one-to-one) if ∀ x ∈ A, ∀ y ∈ A, x ≠ y → f(x) ≠ f(y). In the arrow diagram: at most one arrow points to each element of B. Not injective: f(George) = f(Ryan) Injective CPSC 110/201 George CPSC 110 George CPSC 121/203 Ryan CPSC 121 Ryan CPSC 121/202 Gail CPSC 210 Neil CPSC 210/BCS Kimberly CPSC 310 Kimberly CPSC 310 Neil CPSC 319 Gail CPSC 319 Unit 12: Sets and Functions 24
Trying out Terminology f(x) = |x| (the absolute value of x ) Is it injective? a. No, if f: R R 0 b. Yes, if f: R 0 R Note: R 0 = { x R | x 0 } f(x) x Unit 12: Sets and Functions 25
Surjective Functions A function f : A → B is surjective (onto) if ∀ y ∈ B, ∃ x ∈ A, f(x) = y. Can we define it in terms of range and co-domain? In the arrow diagram: at least one arrow points to each element of B. Surjective Not Surjective George George CPSC 121/203 Ryan CPSC 121 Ryan CPSC 121/202 Gail CPSC 210 Neil CPSC 210/BCS Kimberly CPSC 310 Kimberly CPSC 310 Neil CPSC 319 CPSC 319 Unit 12: Sets and Functions 26
Trying out Terminology f: R R 0 f(x) = x 2 f(x) Surjective? Yes What if f: R R ? No What if f: Z Z 0 ? Yes x R 0 , Z 0 are the sets of non-negative real, integer numbers Unit 12: Sets and Functions 27
Bijective Functions A function f : A → B is bijective (also one-to-one correspondence) if it is both one-to-one and onto (both injective and surjective). In the arrow diagram: exactly one arrow points to each element of B. Not Bijective either Not Bijective CPSC 110/201 George George CPSC 121/202 Ryan CPSC 121 Ryan CPSC 121/202 Gail CPSC 210 Neil CPSC 210/BCS Kimberly CPSC 310 Kimberly CPSC 310 Neil CPSC 319 CPSC 319 Unit 12: Sets and Functions 28
Bijective Functions This is bijective Bijective Ryan CPSC 121 Gail CPSC 210 Kimberly CPSC 310 Neil CPSC 319 Unit 12: Sets and Functions 29
Trying out Terminology f(x) = x 2 f:? ? f(x) Bijective for what domain/co-domain? x Unit 12: Sets and Functions 30
Inverse of a Function The inverse of a function f: A → B, denoted f -1 , is f -1 :B A . f -1 (y) = x f(x) = y . In other words: If we think of a function as a list of pairs. E.g. f(x) = x 2 : { (1, 1), (2, 4), (3, 9), (4, 16), ... } Then f -1 is obtained by swapping the elements of each pair: f -1 = { (1, 1), (4, 2), (9, 3), (16, 4), ... } f -1 is a function only when f is bijective. Unit 12: Sets and Functions 31
Appendix 3: An Inverse Proof Theorem : If f : A B is bijective, then f -1 : B A is a function. Proof: We proceed by antecedent assumption. Assume f : A B is bijective. Consider an arbitrary element y of B . Because f is surjective, there is some x in A such that f(x) = y . Because f is injective, that is the only such x . f -1 (y) = x by definition; so, f -1 maps every element of B to exactly one element of A . QED Unit 12: Sets and Functions 34
Recommend
More recommend