470 likes | 488 Views
Lecture 04: SETS AND FUNCTIONS 1.6, 1.7, 1.8. CS1050: Understanding and Constructing Proofs. Spring 2006. Jarek Rossignac. Lecture Objectives. Sets, specification, notation, construction Power sets, ordered pairs, relations Operations on sets and pointsets Functions and composition.
E N D
Lecture 04: SETS AND FUNCTIONS1.6, 1.7, 1.8 CS1050: Understanding and Constructing Proofs Spring 2006 Jarek Rossignac
Lecture Objectives • Sets, specification, notation, construction • Power sets, ordered pairs, relations • Operations on sets and pointsets • Functions and composition
What is a set? • Unordered collection of elements (members) A set contains its members • We may define a set by listing its elements S = {a,b,c} S={1,2,3…} • or by a property (set builder notation) S = {a: aZ (kZ a=2k+1) } S = {x : x is a positive integer less than 200 and divisible by 3}
What are the important sets of numbers? R = {real numbers} Q = {p/q : pZ, qZ, q≠0} Z = {… –1, 0, 1, ….} integers N = {0,1,2….} natural numbers Z+ = {1,2,3 ….} positive integers
When are two sets equal? • When they have the same elements {a,b,c} = {a,c,b} = {a,b,c,b,b}
What is a Venn diagram? Graphic depiction of (topological) set relationship Z+ N 0 Z Q R
What operators/notation are used for sets? Sets in upper case. Elements in lower case. sS s is an element of S. sS s is not in S |S| number of elements (cardinality) of a finite set S S=T S equals T (equality) S elements not in S (complement) ST elements in S and T (intersection) ST elements in S or T (union) S–T = ST, elements of S that are not in T (difference) ST ST – ST (symmetric difference) S T S included in or equal to T (inclusion) S T S included in (but not equal to) T ( proper inclusion) empty (i.e. null) set, also denoted {}. Different from {}
What are the subsets of a set S? All sets whose elements are all in S This always includes: • The empty set, , since S • The whole set, S , since S S
What is the power set of set S? • The power set P(S) of set S is the set of all subsets of S. P({a,b}) = {, {a},{b},{a,b}}
What is the power set of ? P() = {} Remember that is a set, not an element
What is the power set of {}? P({}) = {, {} } Remember that {} has one element, which is a set Hence its power set will contain two elements: the empty set the set itself {}
What is an ordered n-tuple? The ordered n-tuple (a,b,c) is the ordered list of elements: a, b, c Two n-tuples are equal , (a,b,c) = (d,e,f) , when corresponding elements are equal, (a=d, b=e, c=f).
What is an ordered pair? An n-tuple of two elements For example, The (x,y) coordinates of a point in the plane The vertices (a,b) of an oriented edge or link in the graph
What is the Cartesian product of two sets? A B = {(a,b): aA, bB} set of ordered pairs (a,b) such that a is an element of A and b is an element of B {a,b} {c,d} = {(a,c), (a,d), (b,c), (b,d)} Note that in general, A B ≠B A
How to use quantifiers with sets? sS means for all s in S sS means there exists an element s in S !sS means there exists a single element s in S
S T ST ST What are unions and intersections of sets? Union: ST = {u : uS uT} Intersection: ST = {u : uS uT}
S T S – T S T S What are the differences of sets? Complement: S = {u : uS}, also denoted !S Implicitly defined in a universal set U as S = U–S Difference: S–T = ST = {u : uS uT} Symmetric difference: ST = (S–T) (T–S)
Individual exercise Prove that (ST) – (ST) = (S–T) (T–S)
When are two sets disjoint? When their intersection is empty: ST = We often have to prove that two or more sets are pairwise disjoint Often it is necessary to test whether two sets are disjoint Components of a car engine do not interfere Objects do not collide in an animation
What is |ST| ? The cardinality, |ST|, is the number of elements of the union, ST, of the two finite sets S and T. |ST| = |S| + |T| – |ST| we need to subtract elements of ST, since they were counted both in |S| and in |T|.
Identities of Boolean operators • Identity: AU=A, AU=A • Idempotence: AA=A, AA=A • Domination: AU=U, A= • Complement: AA =U, AA= • Commutativity: AB=BA, AB=BA, • Associativity: A(BC)=(AB)C, A(BC)=(AB)C • Distributivity: A(BC)=(AB)(BC), A(BC)=(AB)(BC) !S denotes S Sand has higher priority than , , and – • Complementation: !(!A)=A • de Morgan: !(AB) = !A!B , !(AB) = !A!B • Absorption: A(AB)=A, A(AB)=A
Relation between sets and Booleans? Define the propositions A(u)=(uA) and B(u)=(uB). Then AB = { u U : A(u)B(u) } AB = { u U : A(u)B(u) } !A = { u U : ¬ A(u)} Hence, there is a correspondence between and (AND, &&) and (OR, ||) ! and ¬ (AND NOT, &&!) and F (false) U and T (true) Translate the previous identities into logic
Prove !(AB) = !A!B using inclusion Hint: To prove that S = T, prove that (ST) (TS) To prove that !(AB) !A !B assume that for some arbitrary x, x !(AB) hence ¬(xA xB) hence xA xB hence x!A x!B it follows that x (!A !B) Since our choice of x!(AB) was arbitrary, x!(AB) x(!A !B) Hence!(AB) !A !B To prove that !A !B !(AB) … prove that it follows that x !(AB)
Prove !(AB) = !A!B using builder This time we use the set builder notation: !(AB) = {x: x AB} = {x: ¬ (x AB)} = {x: ¬ ((x A) (x B))} = {x: ¬ (x A) ¬(x B))} # de Morgan = {x: x !A x !B} = {x: x (!A!B)}
Prove A(BC)=(AB)(AC) using cells Test one element in each cell against both expressions A B C
Exercise • Provide a concise Boolean expression for the set marked by the green cells A B C
Prove !(AB) = !A!B using a truth table • Test all combinations
How to represent finite sets? Consider a finite domain U={a,b,c,d….} where |U|<220 We can represent any subset of U by listing its elements. But working on such a representation may be expensive. A more efficient representation may be derived if we assume an ordering of the elements. For example the n-tuple (a,b,c,d…) Represent a subset S of U by a classification vector (bit string) V(S) = 0110… which indicates that aS, bS, cS, dS …
How to perform Boolean operations on sets? • Consider 2D arrays A[i][j] and B[i][j] of bits representing digitized versions of 2D sets A and B • (Pixel(i,j)A) (A[i][j] ==1) # red if 1, green if 0 • (Pixel(i,j)B) (B[i][j] ==1) • How to represent and compute AB?
How to deal with continuous pointsets? Use a constructive model: S=A(BC) Provide point/primitive classification methods A.isIn(x,y) returns true if point(x,y) A For example, if A is rect(lx,ly,hx,hy), then A.isIn(x, y) {return((lx<x)&&(x<hx)&& (ly<y)&&(y<hy));} Provide Boolean classification methods U.isIn(L,R) combines truth values L and R For example, if U is a union operator, then U.isIn(L,R) {return ( L || R );}
What is Constructive Solid Geometry? • A CSG model is a binary tree representing a 3D shape • Leaves represent solid primitives (blocks, spheres, bunnies…) • Nodes represent Boolean operators (, , –)
A B What is a relation from set A to set B? It is a subset of A B Think of it as links from elements of A to elements of B A relation assigns to each set of A zero or more elements of B
What is a function from A to B A relation assigning exactly one element of B to each element of A. Note that it may assign the same element bB to two different elements of A. We write it f : A B (here is not an implication) aA bB b=f(a) A is the domain of f A B
What is the image of S by f? bB is the imageof all elements aA for which b=f(a) The image f(S) of a subset S of A is the set of the images of elements of S. S A B
What is the range of a function? The image of A. (The set of images of elements of A). A B
When is a function injective? • f is injective (“one-to-one”) when f(x)=f(y) x=y Not injective Injective A A B B
When is a function surjective? • f is surjective (“onto”) when bB aA f(a)=b Not surjective Surjective A A B B
When is a function bijective? • f is bijective when it is both injective and surjective • (“one-to-one” and “onto”) • one-to-onecorrespondence • bB !aA f(a)=b Not bijective Bijective A A B B
What is the inverse of a function? • The inverse is only defined for bijective functions • The inverse f–1 of f maps each bB to aA where b=f(a) • f–1(b)=a b=f(a) f f–1 A A B B
What is the composition of two functions? • Let f : A B and g : B C • The composition fg : A C of f and g is defined as • fg(a) = f(g(a))
Application to computer graphics • Translation • Rotation • Composition • Do rotations and translations commute? T(2,1) R(30) T(2,1)R(30)
What is the graph of a function? • Set of ordered pairs { (a,b) : aA, bB, b=f(a) } • Sometimes we can plot it • Here f maps points (x,y) on the plane into height f(x,y) = x2+2y4–1
What are floor and ceiling? • The floor x of x is the larges integer not exceeding to x • The ceiling x is the smallest integer ≥ x • Properties: x–1< x ≤ x ≤ x < x+1 –x=–x, –x= –x x+n=x+n, x+n= x+n • Compute–0.5 and –0.5 • How many bytes (8-bit strings) do you need to encode 100 bits? • Prove or disprove x+y= x+ y
Quick test Let A and B be two sets • What is the symmetric difference of A and B? • When are A and B disjoint? • How would you prove that A=B? • What is the cardinality of AB? • What is Constructive Solid Geometry Let f be a function from A to B • What property does f have? • What is the image of a subset S of A by f? • When is f injective? • When is the inverse of f defined? • What is the floor of –3.2?
Assigned Reading • Sections 1.6, 1.7, 1.8
Assigned Exercises (for quiz) • 1.6 p 85 • 18 • 1.7 p 95: • 11, 15, 16, 21, 27, 28, 29, 30, 31, 32 ,33 • 1.8 p 109-110 • 28, 32, 35.b), 38, 40
Assigned Project • P1 is due Tu Jan 24 (on your PPP) • Email TA only if • you did not submit P0. • you plan to have a late submission. • you changed your PPP url.