Sets Set Identities Sets and propositional logic have some similar properties In fact both are forms of boolean algebra Compare Set Identities table (p.

Slides:



Advertisements
Similar presentations
Functions Reading: Epp Chp 7.1, 7.2, 7.4
Advertisements

1.6 Functions. Chapter 1, section 6 Functions notation: f: A B x in A, y in B, f(x) = y. concepts: –domain of f, –codomain of f, –range of f, –f maps.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Section 1.6: Sets Sets are the most basic of discrete structures and also the most general. Several of the discrete structures we will study are built.
Functions, Pigeonhole Principle Lecture 14: Nov 4 A B f( ) =
1 Section 1.7 Set Operations. 2 Union The union of 2 sets A and B is the set containing elements found either in A, or in B, or in both The denotation.
Lecture 3 Set Operations & Set Functions. Recap Set: unordered collection of objects Equal sets have the same elements Subset: elements in A are also.
modified from UCI ICS/Math 6D, Fall Sets+Functions-1 Sets “Set”=Unordered collection of Objects “Set Elements”
1 Section 1.8 Functions. 2 Loose Definition Mapping of each element of one set onto some element of another set –each element of 1st set must map to something,
CS 2210 (22C:019) Discrete Structures Sets and Functions Spring 2015 Sukumar Ghosh.
Rosen 1.6. Approaches to Proofs Membership tables (similar to truth tables) Convert to a problem in propositional logic, prove, then convert back Use.
Section 1.8: Functions A function is a mapping from one set to another that satisfies certain properties. We will first introduce the notion of a mapping.
Functions A B f( ) =. This Lecture We will define a function formally, and then in the next lecture we will use this concept in counting. We will also.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Sets Set Operations Functions. 1. Sets 1.1 Introduction and Notation 1.2 Cardinality 1.3 Power Set 1.4 Cartesian Products.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences.
 Let A and B be any sets A binary relation R from A to B is a subset of AxB Given an ordered pair (x, y), x is related to y by R iff (x, y) is in R. This.
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
February 12, 2015Applied Discrete Mathematics Week 2: Functions and Sequences 1Exercises Question 1: Given a set A = {x, y, z} and a set B = {1, 2, 3,
Week 15 - Wednesday.  What did we talk about last time?  Review first third of course.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFunctions.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
1 Annoucement n Skills you need: (1) (In Thinking) You think and move by Logic Definitions Mathematical properties (Basic algebra etc.) (2) (In Exploration)
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
Basic Structures: Sets, Functions, Sequences, and Sums CSC-2259 Discrete Structures Konstantin Busch - LSU1.
CS201: Data Structures and Discrete Mathematics I
MATH 224 – Discrete Mathematics
CompSci 102 Discrete Math for Computer Science
Mathematical Preliminaries
Sets Definition: A set is an unordered collection of objects, called elements or members of the set. A set is said to contain its elements. We write a.
CSC102 - Discrete Structures Functions
Section 3.2: Sequences and Summations. Def: A sequence is a function from a subset of the set of integers (usually the set of natural numbers) to a set.
1 Functions CS 202 Epp section ??? Aaron Bloomfield.
FUNCTIONS COSC-1321 Discrete Structures 1. Function. Definition Let X and Y be sets. A function f from X to Y is a relation from X to Y with the property.
Relations and Functions ORDERED PAIRS AND CARTESIAN PRODUCT An ordered pair consists of two elements, say a and b, in which one of them, say a is designated.
Week 15 - Wednesday.  What did we talk about last time?  Review first third of course.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
FUNCTIONS.
Sequences Lecture 11. L62 Sequences Sequences are a way of ordering lists of objects. Java arrays are a type of sequence of finite size. Usually, mathematical.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
1-1 Copyright © 2013, 2005, 2001 Pearson Education, Inc. Section 2.4, Slide 1 Chapter 2 Sets and Functions.
Functions Section 2.3.
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
Set Operations CS 202, Spring 2008 Epp, chapter 5.
Relations, Functions, and Matrices
CS 2210:0001 Discrete Structures Sets and Functions
Applied Discrete Mathematics Week 2: Functions and Sequences
MATH 224 – Discrete Mathematics
Functions.
Chapter 2 Sets and Functions.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Cardinality of Sets Section 2.5.
Functions Section 2.3.
CS201: Data Structures and Discrete Mathematics I
Discrete Math (2) Haiming Chen Associate Professor, PhD
Lecture 7 Functions.
Set Operations Section 2.2.
CS100: Discrete structures
Functions CS 202 Epp section 7.1.
CS 220: Discrete Structures and their Applications
A Brief Summary for Exam 1
Functions.
Sungho Kang Yonsei University
Copyright © Cengage Learning. All rights reserved.
Functions Rosen 2.3, 2.5 f( ) = A B Lecture 5: Oct 1, 2.
Math/CSE 1019N: Discrete Mathematics for Computer Science Winter 2007
Logic Logic is a discipline that studies the principles and methods used to construct valid arguments. An argument is a related sequence of statements.
Functions Section 2.3.
Presentation transcript:

Sets Set Identities Sets and propositional logic have some similar properties In fact both are forms of boolean algebra Compare Set Identities table (p. 130 in text) with Logical Equivalences table (p. 27 in text) We will look at the Wikipedia pages http://en.wikipedia.org/wiki/Algebra_of_sets https://en.wikipedia.org/wiki/Logical_equivalence These will be useful to remember See text for some proofs Let’s demonstrate just a few

A  B = B  A [Commutative Law] Sets A  B = B  A [Commutative Law] Greatly simplified / informalized proof using logic, previous known identities and set builder notation We will show equality by showing that each set is a subset of the other x, x  (A  B)  x  A v x  B [ Def. of Union]  x  B v x  A [Comm. Law Logic]  x  (B  A) [ Def. of Union]  (A  B)  (B  A) [ Def. of Subset ] We can apply similar assertions to show that (B  A)  (A  B) and thus the sets are equal Ex: A = { 1, 2, 3, 4, 5 } B = { 6, 7, 8, 9, 10} A  B = B  A = {1,2,3,4,5,6,7,8,9,10}

There is often more than one way to prove an assertion Sets There is often more than one way to prove an assertion For sets lets consider a membership table Same idea as a truth table for logic Instead of T and F for true and false We have 1 and 0 for member or not member Rows indicate the different ways elements may or may not be included Columns indicate the sub-expressions If the membership tables of two set expressions are identical then the expressions are equivalent Consider the Commutative Law that we just proved

Membership table for A  B and B  A Sets Membership table for A  B and B  A Note that the columns for A  B and B  A are identical Let's try another one! We know DeMorgan's Laws for logic Let's look at them for sets A B A  B B  A 1

[DeMorgan's Law 2] [DeMorgan’s Law 1] Sets [DeMorgan’s Law 1] [DeMorgan's Law 2] Let's prove the second law using same technique we did previously (detailed proof of first law is in the text) Definition of complement Definition of negation Definition of union DeMorgan’s for logic Definition of negation Definition of complement Definition of intersection Definition of subset

Ex: A = { x | x is a Pitt Student } B = { x | x is a CMU Student } Sets We (again) can apply similar logic to show that to complete the proof (by showing each is a subset of the other) Ex: A = { x | x is a Pitt Student } B = { x | x is a CMU Student } { x | x is not (a Pitt student or a CMU student) } = {x | x is not a Pitt student and x is not a CMU student }

Sets Membership table for Again the columns are identical so the expressions are equivalent See your course notes and text for more proofs / approaches for sets A B A  B 1

Consider again the Cartesian product of two sets, A x B Functions Consider again the Cartesian product of two sets, A x B Recall that this produces a set of ordered pairs over all of the elements in A and B Two important subsets of the Cartesian product of two sets are: A relation, R from set A to set B Ordered pairs chosen for a relation can be an arbitrary subset of the Cartesian product Relations are very useful and you will cover them in detail later in the term

A function, F from set A to set B Functions A function, F from set A to set B F : A  B y = F(x) where x  A and y  B Adds two constraints to a relation The domain of the function is the entire set A, or x  A y  B such that (x, y)  F Each x  A is mapped to only one y  B, or x  A, y, y’  B, if (x, y)  F and (x, y’)  F then y = y’ Another way to think of these rules is that, considering the ordered pairs in the Cartesian product, for a function, each value in set A will occur in exactly one ordered pair

Let’s look at an example: Functions Let’s look at an example: Let set Actors = {McGregor, Bale, Keaton, Downey, Guinness} Heroes = {Batman, Obi-Wan, IronMan, Holmes} Consider Function Plays : Actors  Heroes = {(McGregor, Obi-Wan), (Bale, Batman), (Keaton, Batman), (Downey, IronMan), (Guinness, Obi-Wan)} We call Actors the Domain of function Plays We call Heroes the Codomain of function Plays Within Heroes we call the subset {Batman, Obi-Wan, Ironman} the Range of function Plays It is the set of values actually mapped to by the function

Functions If we add ordered pair (Downey, Holmes) to the set F is it still a function? No, since now we have (Downey, IronMan) and (Downey, Holmes) and constraint ii. does not hold Value in domain mapped to multiple values in range If we remove ordered pair (Guinness, Obi-Wan) from the set F is it still a function? No, since now we have a value x in A such that no (x, y) exists in F and constraint i. does not hold Domain is not the entire set A

Injections A function F: A  B is an injection, or one to one, if no two elements in A map to the same element in B or y  B,  at most one x  A such that (x, y) is in F Is the previous example (from Slide 11) an injection? No, Plays(McGregor) = Plays(Guinness) No, Plays(Bale) = Plays(Keaton) Ex: Given Domain and Codomain = Positive Integers F(n) = 2n is one to one F(n) = N mod 2 is not one to one (F(4) = F(2) = 0, for example)

Surjections A function, F: A  B is a surjection, or onto, if the range of F is equal to the codomain (= B) or y  B,  an x  A such that (x, y) is in F Is the previous example (from Slide 11) a surjection? No, there is no pair (x, Holmes) in F We could make it onto if we add Cumberbatch to A and add (Cumberbatch, Holmes) to F Ex: Given Domain and Codomain = real numbers F(x) = x is onto F(x) = abs(x) is not onto, since the abs(x) cannot be negative

Note the similarities: One to one and Onto Note the similarities: One to one: y  B,  at most one x  A such that (x, y) is in F Onto: y  B,  an x  A such that (x, y) is in F But note the differences: One to one: Entire codomain does not have to be in the range  at most one means 0 or 1 Onto: Values in range can be in more than one pair  an means 1 or more

If a function is both one to one and onto it is called a bijection Ex: Domain and codomain = real numbers, R F(x) = x is a bijection Note that the domain and codomain are significant in determining a bijection With domain and codomain = R F(x) = 2x is a bijection With domain and codomain = Z F(n) = 2n is NOT a bijection It is not onto [ex: there is no n such that F(n) = 3]

Arbitrary subset of the Cartesian product Functions Let’s visualize these different subsets of Cartesian products: Relation: Arbitrary subset of the Cartesian product Does not require all elements of domain to be mapped Same value in domain can map to multiple values in range Multiple values in domain can map to same value in range Does not require all elements of codomain to be in range

Functions Function All elements of domain must be mapped Each value in domain can map to only one value in range Multiple values in domain can map to same value in range Does not require all elements of codomain to be in range

Functions Injection (One to One Function) All elements of domain must be mapped Each value in domain can map to only one value in range Each value in range is mapped from a distinct value in domain Does not require all elements of codomain to be in range

Functions Surjection (Onto Function) All elements of domain must be mapped Each value in domain can map to only one value in range Multiple values in domain can map to same value in range All elements in codomain must be in range

(One to One and Onto Function) Functions Bijection (One to One and Onto Function) All elements of domain must be mapped Each value in domain can map to only one value in range Each value in range is mapped from a distinct value in domain All elements in codomain must be in range

Consider the Java hash code for a String: public int hashCode() { More Examples Consider the Java hash code for a String: public int hashCode() { int h = hash; if (h == 0 && count > 0) { int off = offset; char val[] = value; int len = count; for (int i = 0; i < len; i++) { h = 31*h + val[off++]; } hash = h; return h; Let’s talk about this a bit Note: This function is utilized by the Hashtable (and other classes) to insert and retrieve data from a Collection. Note that the hashCode function can be negative. You will see (either in CS 0445 or CS 1501) the the actual index for a hash function must be non-negative, so that it can map to a valid index in an array.

Is it actually a function? More Examples Domain Set of character strings of arbitrary length Codomain Set of integers representable by a Java int Is it actually a function? Yes All Java Strings can be hashed No String will hash to more than one int Is it one-to-one? We would need to show that for every String S there is a unique hash value h(S) To disprove this, we simply need to show that at least two different Strings, S1 and S2, hash to the same value Domain: Max length of a String is actually Integer.MAX_VALUE which is 2,147,483,647

Let’s try to disprove it in the following way: More Examples Let’s try to disprove it in the following way: How many possible unique values can a Java int have? 232 = 4294967296 ~ 4.295 x 109 How may possible String values are there? Consider just Strings of letters (upper and lower case) This gives 2 * 26 = 52 possibilities per character Consider now Strings of 10 characters or fewer 5210 ~ 1.446 x 1017 Thus there are MANY MORE possible Strings (in the domain) than there are integers (in the codomain) Based on this is is impossible for each String in the domain to map to a unique integer in the codomain Note: This “proof” relies on some things we will be discussing later on: counting techniques and the pigeonhole principle – stay tuned!!!

Is it onto? Is it a bijection? More Examples This is more difficult to verify We would have to show that for every possible int value, x, in Java, there is some String S such that S.hashCode() = x Could be done with some number theory Is it a bijection? Since it is not one to one, clearly no

More Examples Consider the function SSN(x) which returns the Social Security number for a US citizen (or resident) Domain? Set of people living in the US Codomain? Set of 9-digit integers Is it actually a function? This is not as simple as it would seem See: http://ssa.gov/pubs/10093.html#how The tricky part is whether both numbers would still be associated with the same person

Assuming SSN is a function More Examples Assuming SSN is a function Is it one to one? In theory it should be Two different people should not have the same SSN Is it onto? Not yet (thankfully) We probably do not ever want it to be onto, since that would mean there are no remaining SSNs for new people!!! Is it a bijection? No, since it is not onto

Inverse Functions A function which is a bijection also has a mapping from the codomain back to the domain This is also a function and is called the inverse of the original function, and is denoted F-1 for function F Note: Why must the function be a bijection? If it is not one to one then F(x) = F(y) for some x ≠ y This implies that the “inverse” F-1 would map the same value, F(x) [ = F(y) ], to two different values, x and y, which means it is not a function (Rule ii.) If it is not onto then the exists some y in the codomain such that x  D, F(x) ≠ y This implies that there is at least one value in the codomain that would not be mapped back to the domain, so F-1 is not a function (Rule i.)

Ex: Let A = { 1, 2, 3, 4 } Let B = { a, b, c, d } Inverse Functions Ex: Let A = { 1, 2, 3, 4 } Let B = { a, b, c, d } if F : A  B = { (1, a), (2, b), (3, c), (4, d) } then F-1 : B  A = { (a, 1), (b, 2), (c, 3), (d, 4) } Note that, for all x in A, F-1(F(x)) = x We say that this is an identity function

Given functions: F : A  B G : B  C Inverse Functions Given functions: F : A  B G : B  C We call G(F(x)) the composition of functions F and G It is also shown as G o F Note that the range of F is the domain of G Ex: A = { a, b, c, d } B = { 1, 2, 3 } C = { #, $, &, @ } F : A  B = {(a, 2), (b, 3), (c, 1), (d, 1)} G : B  C = {(1, $), (2, @), (3, &)} Note that F is not one to one Note that G is not onto Bijections are not required for composition

Examples: Given domain and codomain = R F(x) = 2x F(x) = 2x2 Inverse Functions Examples: Given domain and codomain = R F(x) = 2x What is the inverse of F? y = 2x y/2 = x F-1(y) = y/2 F(x) = 2x2 y = 2x2 y/2 = x2 sqrt(y/2) = x So F-1(y) = sqrt(y/2)?????? 2x^2 is not one to one, since +- sqrt(y/2) = x NO!!! Why not??

Two functions of interest (among many) Floor and Ceiling Two functions of interest (among many) Floor: Domain: R Range: Z Floor(x) = x = greatest integer <= x Ceiling: Ceiling(x) = x = smallest integer >= x Can be confusing Floor is greatest? Ceiling is smallest? Important thing is the relational operator

Note that both floor and ceiling are Examples: x = 3.8 x = 3 x = 4 x = -3.8 x = -4 x = -3 x = 3.00000001 x = 3 x = 4 x = 3 x = 3 x = 3 Note that both floor and ceiling are Onto (surjections) Not one to one (not injections)

Floor and Ceiling functions are quite useful in CS Ex: I have 235 distinct values to represent in binary. How many bits do I need? lg2(235) = 8 You will see issues like this soon in counting (Ch. 6) Note: In programming, none of these things is ceiling or floor: (int) x or trunc(x) Not equal to floor when x is negative; ok for x >= 0 round(x) Depending on value of x could match one or other See Demo1.java

A bijective function is both one to one and onto Functions: Summary A function, F, is a subset of the Cartesian product of two sets, A and B such that The domain of F is all of A For all x in A, there exists exactly one pair (x, y) in F An injective function (one to one) contains at most one x in A for each y in B A surjective function (onto) contains at least one x in A for each y in B A bijective function is both one to one and onto

Functions have inverses iff they are bijections Functions: Summary Functions have inverses iff they are bijections Given F: A  B and G: B  C, the composition of functions F and G, G(F(x)): A  C The composition of a function and its inverse is an identify: F-1(F(x)) = x The floor and ceiling functions are of interest in computer science Be careful to understand their meanings