200 likes | 294 Views
Lecture 3. Set Operations & Set Functions. Recap. Set: unordered collection of objects Equal sets have the same elements Subset: elements in A are also in B Power-set: set of all subsets Cartesian Product: set of ordered pairs. A. A. B. 1.7 Set Operations.
E N D
Lecture 3 Set Operations & Set Functions
Recap • Set: unordered collection of objects • Equal sets have the same elements • Subset: elements in A are also in B • Power-set: set of all subsets • Cartesian Product: set of ordered pairs.
A A B 1.7 Set Operations Union:The union of 2 sets A and B is the set with elements in either A or B or both. U Example: A={1,2,3}, B={2,3,4} AUB = {1,2,3,4}
A A B 1.7 Set Operations Intersection: The intersection of 2 sets A and B is the set containing elements in both A and B. Example: U Example: A={1,2,3}, B={2,3,4} A B = {2,3}
1.7 Set Operations Sets are disjoint if their intersection is the empty set. I.e. They have no elements in common. Principle of inclusion-exclusion: this terms is needed because elements both in A and B are counted once in AUB. Example: A={1 2 3}, B = {p,q,r}. A and B are disjoint. |AUB|=|A|+|B|=6 Example: A={1 2 3}, B={1 2 3}. A=B. |AUB|=3+3-3=3.
A A B 1.7 Set Operations Difference: The difference between 2 sets A and B is the set with elements in A but not in B. U Example: A={1 2 3}, B={2 3 4} A-B={1}
1.7 Set Operations Complement: The complement of a set A in U is the set U-A. Example: U={x|x in English alphabet} A={x| x is consonant } A = {x|x is vowel} U A
1.7 Set Operations Set identities: U A A B Morgan’s law
1.7 Set Operations Membership tables (just like truth tables): Generalized Union: The union of a collection of sets is the set with elements in at least one of the sets in the collection. Generalized intersection:The intersection of a collection of sets is the set with elements in all sets in the collection.
1.7 Set Operations Example: Ai = {i,i+1,i+2....} Efficient representation in a computer: Assume arbitrary order and denote set membership with a bit string: U={1,2,...10} (in this order) A = {1 2 3 4 5}=1 1 1 1 1 0 0 0 0 0 B = {4,5,6} = 0 0 0 1 1 1 0 0 0 0 AUB = 1 1 1 1 1 1 0 0 0 0 = BIT-wise AND = {1 2 3 4 5 6}
domain f a b= f(a) image A B 1.8 Functions function: The assignment of exactly one element of the set B to each element of the set A. f:AB or f(a)=b. co-domain A is the domain of f. B is the co-domain. of f. b is the image of a. a is the pre-image of b. range of f: set of all images of elements of A. range pre- image Example: f:ZZ, f(x)=x^2 domain/co-domain: Z range: perfect squares {0,1,4,9,...}
1.8 Functions If f1 and f2 are two functions from A to R (real numbers), then g=f1+f2 and h=f1*f2 are also functions defined by: (f1+f2)(x) = f1(x) + f2(x) (f1*f2)(x) = f1(x)*f2(x) Example: f1(x) = x, f2(x) = x^2. (f1+f2)(x) = x+x^2 (f1*f2)(x) = x^3. f:AB, and S is a subset of A. Then we can define f:SImage(S)=f(S) f f(S) A S B
1.8 Functions One-to-one or injective function: A function f is one-to-one if and only if f(x)=f(y) implies x=y for all x,y in domain f. f it is not allowed that two arrows point to the same element in B equivalent since: Example: f:ZZ, f(x)=x^2 one-to-one? No; x=-1 & x=1 map both to f(1)=f(-1)=1. A B
1.8 Functions strictly increasing strictly decreasing x,y real decreasing increasing f(x) > f(y’) f(y) > f(a)=f(b) f(x’) y x < x’ < y’ Strictly increasing and strictly decreasing functions are one-to-one
1.8 Functions Onto or surjective functions: A function f from A to B is onto if for every element b in B there is an element a in A with f(a)=b. x y f Example: F:ZZ, f(x)=x^2 onto? No, y=-1 has no pre-image. A B There is no element without incoming arrows
1.8 Functions One-to-one correspondence or bijection: A function f is in one-to-one correspondence if it is both one-to-one and onto. Number of elements in A and B must be the same. Every element in A is uniquely associated with exactly one element in B. Example: f:RR, f(x)= -x bijection! f A B
f A B 1.8 Functions Inverse function: The inverse function of a bijection is the function that assigns to b in B the element a in A such that f(a)=b. inverse of f A B If a function is not a bijection it is not invertible: example: f:rR, f(x)=x^2.
g f C 1.8 Functions Composition: A composition of 2 functions g:AB and f:BC is defined by: Range of g must be subset of domain of f! A C B A B
1.8 Functions Graph of a function: The graph of a function f is the set of ordered pairs {(a,b)|a in A, f(a)=b}. This is a subset of the Cartesian product AXB (i.e. it is a “relation”). f(a) a in A (for some ordering)
1.8 Functions Some examples: (more details later)