Based on slides by Patrice Belleville and Steve Wolfman
CPSC 121: Models of Computation Unit 12 Sets and Functions Based - - PowerPoint PPT Presentation
CPSC 121: Models of Computation Unit 12 Sets and Functions Based - - PowerPoint PPT Presentation
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
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.
3
Unit 12: Sets and Functions
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 = 5y} B = {2i - 1 | i is a prime} C = {n Z | 0 < n 100}
4
Unit 12: Sets and Functions
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.
5
Unit 12: Sets and Functions
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.
6
Unit 12: Sets and Functions
Set Union
The union of A and B — denoted A B — is {x U | x A x B}. A B is the blue region...
7
A B
U
Unit 12: Sets and Functions
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...
8
A B
U
Unit 12: Sets and Functions
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
9
A B
U
Unit 12: Sets and Functions
Set Complement
The complement of A — denoted A — is {x U | x A}. A is everything but the blue region.
U Can we express this as a set difference?
10
A
U
Unit 12: Sets and Functions
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 20th century Bertrand Russell
discovered inconsistencies with the "naïve" set theory.
Let R be the set of all sets that
do not contain themselves. That is R = { x | ~xϵx }.
Then:
R R ~R R. which is a contradiction.
Set theory has been restricted in a way that disallow
this kind of sets.
Unit 12: Sets and Functions 12
Same question, different form: “Imagine a barber that shaves every man in town who does not shave himself. Does the barber shave himself?”
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, b, c) (a, c, b)
15 Unit 12: Sets and Functions
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}:
1 2 3 a b ( a , 3 ) ( a , 2 ) ( a , 1 ) ( b , 3 ) ( b , 2 ) ( b , 1 ) The order of the tuples definitely matters!
17 Unit 12: Sets and Functions
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) = x3
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, y1,y2 B, [(f(x) = y1) (f(x) = y2)] (y1 = y2).
A B
f
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.
Warning: some mathematicians would say that makes f “total”.
A B f
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(x) | x A }
A B f
x 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.
Unit 12: Sets and Functions
George CPSC 121/203 Ryan CPSC 121/202 Neil CPSC 210/BCS Kimberly CPSC 310 Gail CPSC 319 CPSC 110/201 George CPSC 110 Ryan CPSC 121 Gail CPSC 210 Kimberly CPSC 310 Neil CPSC 319 Injective Not injective: f(George) = f(Ryan)
24
Trying out Terminology
f(x) = |x| (the absolute value of x) Is it injective?
- a. No, if f:R R0
- b. Yes, if f:R0 R
Note: R0 = { x R | x 0 }
x f(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.
Unit 12: Sets and Functions
George CPSC 121/203 Ryan CPSC 121/202 Neil CPSC 210/BCS Kimberly CPSC 310 CPSC 319 George Ryan CPSC 121 Gail CPSC 210 Kimberly CPSC 310 Neil CPSC 319 Not Surjective Surjective
26
Trying out Terminology
f:R R0 f(x) = x2 Surjective? Yes What if f:R R? No What if f:Z Z0? Yes x f(x)
R0, Z0 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.
Unit 12: Sets and Functions
George CPSC 121/202 Ryan CPSC 121/202 Neil CPSC 210/BCS Kimberly CPSC 310 CPSC 319 CPSC 110/201 George Ryan CPSC 121 Gail CPSC 210 Kimberly CPSC 310 Neil CPSC 319 Not Bijective Not Bijective either
28
Bijective Functions
This is bijective
Unit 12: Sets and Functions
Ryan CPSC 121 Gail CPSC 210 Kimberly CPSC 310 Neil CPSC 319 Bijective
29
Trying out Terminology
f(x) = x2 f:? ? Bijective for what domain/co-domain? x f(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) = x2 : { (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