SlideShare a Scribd company logo
1 of 15
M. Hauskrecht
CS 441 Discrete mathematics for CS
CS 441 Discrete Mathematics for CS
Lecture 8
Milos Hauskrecht
milos@cs.pitt.edu
5329 Sennott Square
Sets and set operations: cont.
Functions.
M. Hauskrecht
CS 441 Discrete mathematics for CS
Set
• Definition: A set is a (unordered) collection of objects. These
objects are sometimes called elements or members of the set.
(Cantor's naive definition)
• Examples:
– Vowels in the English alphabet
V = { a, e, i, o, u }
– First seven prime numbers.
X = { 2, 3, 5, 7, 11, 13, 17 }
1
M. Hauskrecht
CS 441 Discrete mathematics for CS
Sets - review
• A subset of B:
– A is a subset of B if all elements in A are also in B.
• Proper subset:
– A is a proper subset of B, if A is a subset of B and A  B
• A power set:
– The power set of A is a set of all subsets of A
M. Hauskrecht
CS 441 Discrete mathematics for CS
Sets - review
• Cardinality of a set A:
– The number of elements of in the set
• An n-tuple
– An ordered collection of n elements
• Cartesian product of A and B
– A set of all pairs such that the first element is in A and
the second in B
2
M. Hauskrecht
CS 441 Discrete mathematics for CS
B = { 2, 4, 6, 9}
• A = {1,2,3,6}
• A - B = { 1, 3}
• B – A = {4, 9}
Set operations
Set union:
• A = {1,2,3,6} B = { 2,4,6,9}
• A  B = { 1,2,3,4,6,9 }
Set intersection:
• A = {1,2,3,6} B = { 2, 4, 6, 9}
• A  B = { 2, 6 }
Set difference:
M. Hauskrecht
CS 441 Discrete mathematics for CS
Example: U={1,2,3,4,5,6,7,8} A ={1,3,5,7}
• A = {2,4,6,8}
Complement of a set
Definition: Let U be the universal set: the set of all objects under
the consideration.
Definition: The complement of the set A, denoted by A, is the
complement of A with respect to U.
• Alternate: A = { x | x  A }
U
A
3
M. Hauskrecht
CS 441 Discrete mathematics for CS
Set identities
Set Identities (analogous to logical equivalences)
• Identity
– A  = A
– AU = A
• Domination
– A U = U
– A  = 
• Idempotent
– A A = A
– A A = A
M. Hauskrecht
CS 441 Discrete mathematics for CS
Set identities
• Double complement
– A = A
• Commutative
– A B = B A
– AB = B A
• Associative
– A (B  C) = (A B) C
– A (B C) = (A  B) C
• Distributive
–A (BC) = (A B) (A  C)
– A (B C) = (A B) (A C)
4
M. Hauskrecht
CS 441 Discrete mathematics for CS
Set identities
A B
A  B
• DeMorgan
– (A B) =
– (A B) =
• Absorbtion Laws
– A (A  B) = A
– A  (A  B) = A
• Complement Laws
– A  A = U
– A  A = 
M. Hauskrecht
CS 441 Discrete mathematics for CS
Set identities
• Set identities can be proved using membership tables.
• List each combination of sets that an element can belong to.
Then show that for each such a combination the element either
belongs or does not belong to both sets in the identity.
• Prove: (A B) = A  B
A B
_
A
_
B A B
_ _
AB
1 1 0 0 0 0
1 0 0 1 0 0
0 1 1 0 0 0
0 0 1 1 1 1
5
M. Hauskrecht
CS 441 Discrete mathematics for CS
Generalized unions and itersections
Definition: The union of a collection of sets is the set that
contains those elements that are members of at least one set
in the collection.
n
 Ai  {A1  A2  ...  An}
i1
Example:
• Let Ai= {1,2,...,i} i =1,2,...,n
•
A i  {1, 2 ,..., n }
n

i  1
M. Hauskrecht
CS 441 Discrete mathematics for CS
Generalized unions and intersections
Definition: The intersection of a collection of sets is the set that
contains those elements that are members of all sets in the
collection.
n
 Ai  {A1  A2  ...  An }
i1
Example:
• Let Ai = {1,2,...,i} i =1,2,...,n
n

i  1
A i  { 1 }
6
M. Hauskrecht
CS 441 Discrete mathematics for CS
Computer representation of sets
• How to represent sets in the computer?
• One solution: Data structures like a list
• A better solution:
• Assign a bit in a bit string to each element in the universal set
and set the bit to 1 if the element is present otherwise use 0
Example:
All possible elements: U={1 2 3 4 5}
• Assume A={2,5}
– Computer representation: A = 01001
• Assume B={1,5}
– Computer representation: B = 10001
M. Hauskrecht
CS 441 Discrete mathematics for CS
Computer representation of sets
Example:
• A = 01001
• B = 10001
• The union is modeled with a bitwise or
• A  B = 11001
• The intersection is modeled with a bitwise and
• A  B = 00001
• The complement is modeled with a bitwise negation
• A =10110
7
M. Hauskrecht
CS 441 Discrete mathematics for CS
Functions
M. Hauskrecht
Functions
• Definition: Let A and B be two sets. A function from A to B,
denoted f : A  B , is an assignment of exactly one element of
B to each element of A. We write f(a) = b to denote the
assignment of b to an element a of A by the function f.
A B
f: A  B
8
M. Hauskrecht
Functions
• Definition: Let A and B be two sets. A function from A to B,
denoted f : A  B , is an assignment of exactly one element of
B to each element of A. We write f(a) = b to denote the
assignment of b to an element a of A by the function f.
A B
f: A  B
Not allowed !!!
Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example1:
• Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as:
• 1  c
• 2  a
• 3  c
• Is f a function ?
• Yes. since f(1)=c, f(2)=a, f(3)=c. each element of A is assigned
an element from B
M. Hauskrecht
9
Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 2:
• Let A = {1,2,3} and B = {a,b,c}
• Assume g is defined as
• 1  c
• 1  b
• 2  a
• 3  c
• Is g a function?
• No. g(1) = is assigned both c and b.
M. Hauskrecht
M. Hauskrecht
Representing functions
Representations of functions:
1. Explicitly state the assignments in between elements of the
two sets
2. Compactly by a formula. (using ‘standard’ functions)
Example 3:
• A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
• Define h: A  B as:
• h(x) = x mod 3.
• (the result is the remainder after the division by 3)
• Assignments:
• 0  0
• 1 1
• 2  2
3  0
4  1
…
10
Important sets
Definitions: Let f be a function from A to B.
• We say that A is the domain of f and B is the codomain of f.
• If f(a) = b, b is the image of a and a is a pre-image of b.
• The range of f is the set of all images of elements of A. Also, if
f is a function from A to B, we say f maps A to B.
Example: Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as: 1  c, 2  a, 3  c
• What is the image of 1?
• 1  c c is the image of 1
• What is the pre-image of a?
• 2  a 2 is a pre-image of a.
• Domain of f ? {1,2,3}
• Codomain of f ? {a,b,c}
• Range of f ? {a,c}
M. Hauskrecht
Image of a subset
Definition: Let f be a function from set A to set B and let S be a
subset of A. The image of S is a subset of B that consists of the
images of the elements of S. We denote the image of S by f(S),
so that f(S) = { f(s) | s  S }.
Example:
• Let A = {1,2,3} and B = {a,b,c} and f: 1  c, 2  a, 3  c
• Let S = {1,3} then image f(S) = ?
M. Hauskrecht
B
A f: A  B
S
f(S)
11
Image of a subset
Definition: Let f be a function from set A to set B and let S be a
subset of A. The image of S is a subset of B that consists of the
images of the elements of S. We denote the image of S by f(S),
so that f(S) = { f(s) | s  S }.
Example:
• Let A = {1,2,3} and B = {a,b,c} and f: 1  c, 2  a, 3  c
• Let S = {1,3} then image f(S) = {c}.
M. Hauskrecht
B
A f: A  B
S
f(S)
M. Hauskrecht
Injective function
Definition: A function f is said to be one-to-one, or injective, if
and only if f(x) = f(y) implies x = y for all x, y in the domain of
f. A function is said to be an injection if it is one-to-one.
Alternate: A function is one-to-one if and only if f(x)  f(y),
whenever x  y. This is the contrapositive of the definition.
B
A f: A  B B
A f: A  B
Not injective Injective function
12
Injective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
• Define f as
– 1  c
– 2  a
– 3  c
• Is f one to one? No, it is not one-to-one since f(1) = f(3) = c, and
1  3.
Example 2: Let g : Z  Z, where g(x) = 2x - 1.
• Is g is one-to-one (why?)
• Yes.
• Suppose g(a) = g(b), i.e., 2a - 1 = 2b - 1 => 2a = 2b
`` => a = b.
M. Hauskrecht
M. Hauskrecht
Surjective function
Definition: A function f from A to B is called onto, or surjective,
if and only if for every b  B there is an element a  A such that
f(a) = b.
Alternative: all co-domain elements are covered
A B
f: A B
13
Surjective functions
Example 1: Let A = {1,2,3} and B = {a,b,c}
– Define f as
• 1  c
• 2  a
• 3  c
• Is f an onto?
• No. f is not onto, since b  B has no pre-image.
Example 2: A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2}
– Define h: A  B as h(x) = x mod 3.
• Is h an onto function?
• Yes. h is onto since a pre-image of 0 is 6, a pre-image of 1 is 4, a
pre-image of 2 is 8.
M. Hauskrecht
M. Hauskrecht
Bijective functions
Definition: A function f is called a bijection if it is both one-to-
one and onto.
A B
f: A B
14
Bijective functions
Example 1:
• Let A = {1,2,3} and B = {a,b,c}
– Define f as
• 1  c
• 2  a
• 3  b
• Is f is a bijection? Yes. It is both one-to-one and onto.
• Note: Let f be a function from a set A to itself, where A is finite.
f is one-to-one if and only if f is onto.
• This is not true for A an infinite set. Define f : Z  Z, where
f(z) = 2 * z. f is one-to-one but not onto (3 has no pre-image).
M. Hauskrecht
Bijective functions
Example 2:
• Define g : W  W (whole numbers), where
g(n) = [n/2] (floor function).
• 0  [0/2] = [0] = 0
• 1  [1/2] = [1/2] = 0
• 2  [2/2] = [1] = 1
• 3  [3/2] = [3/2] = 1
• ...
• Is g a bijection?
– No. g is onto but not 1-1 (g(0) = g(1) = 0 however 0  1.
M. Hauskrecht
15

More Related Content

Similar to Concept of functions 1.pptx

Similar to Concept of functions 1.pptx (20)

9108528.ppt
9108528.ppt9108528.ppt
9108528.ppt
 
Sets
SetsSets
Sets
 
Answers Of Discrete Mathematics
Answers Of Discrete MathematicsAnswers Of Discrete Mathematics
Answers Of Discrete Mathematics
 
Blackbox task 2
Blackbox task 2Blackbox task 2
Blackbox task 2
 
Set theory
Set theorySet theory
Set theory
 
Functionsandpigeonholeprinciple
FunctionsandpigeonholeprincipleFunctionsandpigeonholeprinciple
Functionsandpigeonholeprinciple
 
applications of set theory in economical problem
applications of set theory in economical problem applications of set theory in economical problem
applications of set theory in economical problem
 
Set concepts
Set conceptsSet concepts
Set concepts
 
Set Theory 1
Set Theory 1Set Theory 1
Set Theory 1
 
Set theory
Set theorySet theory
Set theory
 
Task3
Task3Task3
Task3
 
POWERPOINT (SETS & FUNCTIONS).pdf
POWERPOINT (SETS & FUNCTIONS).pdfPOWERPOINT (SETS & FUNCTIONS).pdf
POWERPOINT (SETS & FUNCTIONS).pdf
 
Sets (1).ppt
Sets (1).pptSets (1).ppt
Sets (1).ppt
 
Ch01
Ch01Ch01
Ch01
 
Set and Set operations, UITM KPPIM DUNGUN
Set and Set operations, UITM KPPIM DUNGUNSet and Set operations, UITM KPPIM DUNGUN
Set and Set operations, UITM KPPIM DUNGUN
 
01. Functions-Theory & Solved Examples Module-4.pdf
01. Functions-Theory & Solved Examples Module-4.pdf01. Functions-Theory & Solved Examples Module-4.pdf
01. Functions-Theory & Solved Examples Module-4.pdf
 
file_5.pptx
file_5.pptxfile_5.pptx
file_5.pptx
 
SETS
SETSSETS
SETS
 
Finite Maths Problems
Finite Maths ProblemsFinite Maths Problems
Finite Maths Problems
 
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
JEE+Crash+course+_+Phase+I+_+Session+1+_+Sets+and++Relations+&+Functions+_+7t...
 

Recently uploaded

Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Recently uploaded (20)

Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Concept of functions 1.pptx

  • 1. M. Hauskrecht CS 441 Discrete mathematics for CS CS 441 Discrete Mathematics for CS Lecture 8 Milos Hauskrecht milos@cs.pitt.edu 5329 Sennott Square Sets and set operations: cont. Functions. M. Hauskrecht CS 441 Discrete mathematics for CS Set • Definition: A set is a (unordered) collection of objects. These objects are sometimes called elements or members of the set. (Cantor's naive definition) • Examples: – Vowels in the English alphabet V = { a, e, i, o, u } – First seven prime numbers. X = { 2, 3, 5, 7, 11, 13, 17 } 1
  • 2. M. Hauskrecht CS 441 Discrete mathematics for CS Sets - review • A subset of B: – A is a subset of B if all elements in A are also in B. • Proper subset: – A is a proper subset of B, if A is a subset of B and A  B • A power set: – The power set of A is a set of all subsets of A M. Hauskrecht CS 441 Discrete mathematics for CS Sets - review • Cardinality of a set A: – The number of elements of in the set • An n-tuple – An ordered collection of n elements • Cartesian product of A and B – A set of all pairs such that the first element is in A and the second in B 2
  • 3. M. Hauskrecht CS 441 Discrete mathematics for CS B = { 2, 4, 6, 9} • A = {1,2,3,6} • A - B = { 1, 3} • B – A = {4, 9} Set operations Set union: • A = {1,2,3,6} B = { 2,4,6,9} • A  B = { 1,2,3,4,6,9 } Set intersection: • A = {1,2,3,6} B = { 2, 4, 6, 9} • A  B = { 2, 6 } Set difference: M. Hauskrecht CS 441 Discrete mathematics for CS Example: U={1,2,3,4,5,6,7,8} A ={1,3,5,7} • A = {2,4,6,8} Complement of a set Definition: Let U be the universal set: the set of all objects under the consideration. Definition: The complement of the set A, denoted by A, is the complement of A with respect to U. • Alternate: A = { x | x  A } U A 3
  • 4. M. Hauskrecht CS 441 Discrete mathematics for CS Set identities Set Identities (analogous to logical equivalences) • Identity – A  = A – AU = A • Domination – A U = U – A  =  • Idempotent – A A = A – A A = A M. Hauskrecht CS 441 Discrete mathematics for CS Set identities • Double complement – A = A • Commutative – A B = B A – AB = B A • Associative – A (B  C) = (A B) C – A (B C) = (A  B) C • Distributive –A (BC) = (A B) (A  C) – A (B C) = (A B) (A C) 4
  • 5. M. Hauskrecht CS 441 Discrete mathematics for CS Set identities A B A  B • DeMorgan – (A B) = – (A B) = • Absorbtion Laws – A (A  B) = A – A  (A  B) = A • Complement Laws – A  A = U – A  A =  M. Hauskrecht CS 441 Discrete mathematics for CS Set identities • Set identities can be proved using membership tables. • List each combination of sets that an element can belong to. Then show that for each such a combination the element either belongs or does not belong to both sets in the identity. • Prove: (A B) = A  B A B _ A _ B A B _ _ AB 1 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 0 1 1 1 1 5
  • 6. M. Hauskrecht CS 441 Discrete mathematics for CS Generalized unions and itersections Definition: The union of a collection of sets is the set that contains those elements that are members of at least one set in the collection. n  Ai  {A1  A2  ...  An} i1 Example: • Let Ai= {1,2,...,i} i =1,2,...,n • A i  {1, 2 ,..., n } n  i  1 M. Hauskrecht CS 441 Discrete mathematics for CS Generalized unions and intersections Definition: The intersection of a collection of sets is the set that contains those elements that are members of all sets in the collection. n  Ai  {A1  A2  ...  An } i1 Example: • Let Ai = {1,2,...,i} i =1,2,...,n n  i  1 A i  { 1 } 6
  • 7. M. Hauskrecht CS 441 Discrete mathematics for CS Computer representation of sets • How to represent sets in the computer? • One solution: Data structures like a list • A better solution: • Assign a bit in a bit string to each element in the universal set and set the bit to 1 if the element is present otherwise use 0 Example: All possible elements: U={1 2 3 4 5} • Assume A={2,5} – Computer representation: A = 01001 • Assume B={1,5} – Computer representation: B = 10001 M. Hauskrecht CS 441 Discrete mathematics for CS Computer representation of sets Example: • A = 01001 • B = 10001 • The union is modeled with a bitwise or • A  B = 11001 • The intersection is modeled with a bitwise and • A  B = 00001 • The complement is modeled with a bitwise negation • A =10110 7
  • 8. M. Hauskrecht CS 441 Discrete mathematics for CS Functions M. Hauskrecht Functions • Definition: Let A and B be two sets. A function from A to B, denoted f : A  B , is an assignment of exactly one element of B to each element of A. We write f(a) = b to denote the assignment of b to an element a of A by the function f. A B f: A  B 8
  • 9. M. Hauskrecht Functions • Definition: Let A and B be two sets. A function from A to B, denoted f : A  B , is an assignment of exactly one element of B to each element of A. We write f(a) = b to denote the assignment of b to an element a of A by the function f. A B f: A  B Not allowed !!! Representing functions Representations of functions: 1. Explicitly state the assignments in between elements of the two sets 2. Compactly by a formula. (using ‘standard’ functions) Example1: • Let A = {1,2,3} and B = {a,b,c} • Assume f is defined as: • 1  c • 2  a • 3  c • Is f a function ? • Yes. since f(1)=c, f(2)=a, f(3)=c. each element of A is assigned an element from B M. Hauskrecht 9
  • 10. Representing functions Representations of functions: 1. Explicitly state the assignments in between elements of the two sets 2. Compactly by a formula. (using ‘standard’ functions) Example 2: • Let A = {1,2,3} and B = {a,b,c} • Assume g is defined as • 1  c • 1  b • 2  a • 3  c • Is g a function? • No. g(1) = is assigned both c and b. M. Hauskrecht M. Hauskrecht Representing functions Representations of functions: 1. Explicitly state the assignments in between elements of the two sets 2. Compactly by a formula. (using ‘standard’ functions) Example 3: • A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2} • Define h: A  B as: • h(x) = x mod 3. • (the result is the remainder after the division by 3) • Assignments: • 0  0 • 1 1 • 2  2 3  0 4  1 … 10
  • 11. Important sets Definitions: Let f be a function from A to B. • We say that A is the domain of f and B is the codomain of f. • If f(a) = b, b is the image of a and a is a pre-image of b. • The range of f is the set of all images of elements of A. Also, if f is a function from A to B, we say f maps A to B. Example: Let A = {1,2,3} and B = {a,b,c} • Assume f is defined as: 1  c, 2  a, 3  c • What is the image of 1? • 1  c c is the image of 1 • What is the pre-image of a? • 2  a 2 is a pre-image of a. • Domain of f ? {1,2,3} • Codomain of f ? {a,b,c} • Range of f ? {a,c} M. Hauskrecht Image of a subset Definition: Let f be a function from set A to set B and let S be a subset of A. The image of S is a subset of B that consists of the images of the elements of S. We denote the image of S by f(S), so that f(S) = { f(s) | s  S }. Example: • Let A = {1,2,3} and B = {a,b,c} and f: 1  c, 2  a, 3  c • Let S = {1,3} then image f(S) = ? M. Hauskrecht B A f: A  B S f(S) 11
  • 12. Image of a subset Definition: Let f be a function from set A to set B and let S be a subset of A. The image of S is a subset of B that consists of the images of the elements of S. We denote the image of S by f(S), so that f(S) = { f(s) | s  S }. Example: • Let A = {1,2,3} and B = {a,b,c} and f: 1  c, 2  a, 3  c • Let S = {1,3} then image f(S) = {c}. M. Hauskrecht B A f: A  B S f(S) M. Hauskrecht Injective function Definition: A function f is said to be one-to-one, or injective, if and only if f(x) = f(y) implies x = y for all x, y in the domain of f. A function is said to be an injection if it is one-to-one. Alternate: A function is one-to-one if and only if f(x)  f(y), whenever x  y. This is the contrapositive of the definition. B A f: A  B B A f: A  B Not injective Injective function 12
  • 13. Injective functions Example 1: Let A = {1,2,3} and B = {a,b,c} • Define f as – 1  c – 2  a – 3  c • Is f one to one? No, it is not one-to-one since f(1) = f(3) = c, and 1  3. Example 2: Let g : Z  Z, where g(x) = 2x - 1. • Is g is one-to-one (why?) • Yes. • Suppose g(a) = g(b), i.e., 2a - 1 = 2b - 1 => 2a = 2b `` => a = b. M. Hauskrecht M. Hauskrecht Surjective function Definition: A function f from A to B is called onto, or surjective, if and only if for every b  B there is an element a  A such that f(a) = b. Alternative: all co-domain elements are covered A B f: A B 13
  • 14. Surjective functions Example 1: Let A = {1,2,3} and B = {a,b,c} – Define f as • 1  c • 2  a • 3  c • Is f an onto? • No. f is not onto, since b  B has no pre-image. Example 2: A = {0,1,2,3,4,5,6,7,8,9}, B = {0,1,2} – Define h: A  B as h(x) = x mod 3. • Is h an onto function? • Yes. h is onto since a pre-image of 0 is 6, a pre-image of 1 is 4, a pre-image of 2 is 8. M. Hauskrecht M. Hauskrecht Bijective functions Definition: A function f is called a bijection if it is both one-to- one and onto. A B f: A B 14
  • 15. Bijective functions Example 1: • Let A = {1,2,3} and B = {a,b,c} – Define f as • 1  c • 2  a • 3  b • Is f is a bijection? Yes. It is both one-to-one and onto. • Note: Let f be a function from a set A to itself, where A is finite. f is one-to-one if and only if f is onto. • This is not true for A an infinite set. Define f : Z  Z, where f(z) = 2 * z. f is one-to-one but not onto (3 has no pre-image). M. Hauskrecht Bijective functions Example 2: • Define g : W  W (whole numbers), where g(n) = [n/2] (floor function). • 0  [0/2] = [0] = 0 • 1  [1/2] = [1/2] = 0 • 2  [2/2] = [1] = 1 • 3  [3/2] = [3/2] = 1 • ... • Is g a bijection? – No. g is onto but not 1-1 (g(0) = g(1) = 0 however 0  1. M. Hauskrecht 15