APznzaZ5hEpower Set Lec 4
APznzaZ5hEpower Set Lec 4
Lecture 4:
Sets
Outline
• Definitions: set, element
• Set Representations
• Terminologies
• Set Operations and Disjoint sets (union, intersection,
complement, difference),
• Set equivalences
• Using laws
• Using membership tables
• Generalized Unions and Intersection
• Computer Representation of Sets
Introduction
– Definition: A set is an unordered collection of
(unique) objects
Introduction
• Definition: The objects in a set are called
elements or members of a set. A set is said to
contain its elements
• Notation, for a set A:
– x ∈ A: x is an element of A
– x ∉ A: x is not an element of A
Introduction
• Sets can be elements of other sets
• Examples
– S1 = {∅,{a},{b},{a,b},c}
– S2={{1},{2,4,8},{3},{6},4,5,6}
Set Representations
• Roaster method
• Set Builder Notation
• Venn Diagram
Sets 6
Roaster Method
• One way to describe a set is to list all the members
of a set, when this is possible.
• For example, the notation {a, b, c, d} represents the
set with the four elements a, b, c, and d.
• This way of describing a set is known as the roster
method.
• EXAMPLE 1 The set V of all vowels in the English
alphabet can be written as V = {a, e, i, o, u}.
• EXAMPLE 2 The set O of odd positive integers less
than 10 can be expressed by O = {1, 3, 5, 7, 9}.
Roaster Method (Examples)
• EXAMPLE 3 Although sets are usually used to group elements
with common properties, nothing prevents a set from having
seemingly unrelated elements. For instance, {a, 2, Fred, New
Jersey} is the set containing the four elements a, 2, Fred, and
New Jersey.
• Sometimes, members of the set are listed, and then ellipses (.
. .) are used when the general pattern of the elements is
obvious.
• EXAMPLE 4 The set of positive integers less than 100 can be
denoted by {1, 2, 3, . . . , 99}.
Sets 8
Set Builder Notation
• We characterize all those elements in the set by
stating the property or properties they must have to
be members.
• For instance, the set O of all odd positive integers
less than 10 can be written as
• O = {x | x is an odd positive integer less than 10},
• O = {x ∈ Z+ | x is odd and x < 10}.
Set Builder Notation (Examples)
• The set-builder notation
O={ x | (x∈Z) ∧ (x=2k) for some k∈Z}
reads: O is the set that contains all x such that x is an
integer and x is even.
Some important Sets
• These sets, each denoted using a boldface letter,
play an important role in discrete mathematics:
• N = {0, 1, 2, 3, . . .}, the set of natural numbers
• Z = {. . . ,−2,−1, 0, 1, 2, . . .}, the set of integers
• Z+ = {1, 2, 3, . . .}, the set of positive integers
• R, the set of real numbers
• R+, the set of positive real numbers
• Beware that mathematicians disagree, whether 0 is a
natural number. We consider it quite natural.
Venn Diagram: Example
• A set can be represented graphically using a
Venn Diagram
U x y B
A
z
a
C
Terminologies
• Set Equality
• Empty Set
• Singleton Set
• Subset: Proper and Improper
• The cardinality of a set
• Power Set
• Ordered Tuples
• Cartesian Product
Sets 13
Set Equality
• Definition: Two sets, A and B, are equal if they
contain the same elements. We write A=B.
• Example:
– {2,3,5,7}={3,2,7,5}, because a set is unordered
– Also, {2,3,5,7}={2,2,3,5,3,7} because a set contains
unique elements
– However, {2,3,5,7} ≠{2,3}
empty set and singleton set
• A set that has no elements is called the empty
set or null set and is denoted ∅
• A set that has one element is called a
singleton set.
– For example: {a}, with brackets, is a singleton set
– a, without brackets, is an element of the set {a}
• Note the subtlety in ∅ ≠ {∅}
– The left-hand side is the empty set
– The right hand-side is a singleton set, and a set
containing a set
Subset of a set
• Definition: A is said to be a subset of B, and
we write A ⊆ B, if and only if every element
of A is also an element of B
• That is, we have the equivalence:
A ⊆ B ⇔ ∀ x (x ∈ A ⇒ x ∈ B)
Subset (Example)
• The set of all odd positive integers less than 10
is a subset of the set of all positive integers
less than 10.
Subset (Theorem)
• Theorem: For any set S
– ∅ ⊆ S and
– S⊆S
Proper subset
• Definition: A set A that is a subset of a set B is called
a proper subset if A ≠ B.
• That is there is an element x∈B such that x∉A
Set Equality
• we can show that if A and B are sets with A ⊆ B and
B ⊆ A, then A = B.
• That is, A = B if and only if ∀x(x ∈ A → x ∈ B) and
∀x(x ∈ B → x ∈ A) or equivalently if and only if
∀x(x ∈ A ↔ x ∈ B), which is what it means for the
A and B to be equal.
Sets 20
Cardinality of a set
• Definition: If there are exactly n distinct
elements in a set S, with n a nonnegative
integer, we say that:
– S is a finite set, and
– The cardinality of S is n. Notation: |S| = n.
• Definition: A set that is not finite is said to be
infinite
Cardinality of a set(Examples)
• Let A be the set of odd positive integers less
than 10. Then |A| = 5.
• Let S be the set of letters in the English
alphabet. Then |S| = 26.
• Because the null set has no elements, it
follows that |∅| = 0.
Cardinality of a set (Examples)
• Examples
– Let B = {x | (x≤100) ∧ (x is prime)}, the cardinality
of B is |B|=25 because there are 25 primes less
than or equal to 100.
– The sets N, Z, Q, R are all infinite
Power Set
• Definition: The power set of a set S, denoted P(S), is
the set of all subsets of S.
• Examples
1. Let A={a,b,c},
P(A)={∅,{a},{b},{c},{a,b},{b,c},{a,c},{a,b,c}}
2. Let A={{a,b},c}, P(A)={∅,{{a,b}},{c},{{a,b},c}}
• Note: the empty set ∅ and the set itself are always
elements of the power set.
Power Set (Examples)
• EXAMPLE 1: What is the power set of the set {0, 1, 2}?
Solution: The power set P({0, 1, 2}) is the set of all
subsets of {0, 1, 2}. Hence,
–P({0, 1, 2}) = {∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1,
2}}.
Power Set (Examples)
EXAMPLE 2: What is the power set of the empty set?
What is the power set of the set {∅}?
Solution: The empty set has exactly one subset,
namely, itself. Consequently,
P(∅) = {∅}.
The set {∅} has exactly two subsets, namely, ∅ and
the set {∅} itself. Therefore,
P({∅}) = {∅, {∅}}.
Sets 26
Cardinality of Power Set
• Fact: Let S be a set such that |S|=n, then
|P(S)| = 2n
Tuples
• Definition: The ordered n-tuple (a1,a2,…,an) is the
ordered collection with the element ai being the i-th
element for i=1,2,…,n
• Two ordered n-tuples (a1,a2,…,an) and (b1,b2,…,bn)
are equal iff for every i=1,2,…,n we have ai=bi
(a1,a2,…,an)
• A 2-tuple (n=2) is called an ordered pair
Cartesian Product (cross product)
Definition: Let A and B be two sets. The Cartesian
product of A and B, denoted AxB, is the set of all
ordered pairs (a,b) where a∈A and b∈B
AxB = { (a,b) | (a∈A) ∧ (b ∈ B) }
Note: AxB ≠ BxA unless A=∅ or B=∅ or A=B. Find a
counter example to prove this.
Relations
• Definition: A subset of a Cartesian product,
R ⊆ AxB is called a relation.
Sets 30
Cartesian Product (Example)
EXAMPLE 1 : What is the Cartesian product of A = {1, 2} and B =
{a, b, c}?
Solution: The Cartesian product A × B is
– A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}.
•Note that the Cartesian products A×B and B×A are not equal,
unless A = ∅ or B= ∅ (so that A × B = ∅) or A = B.
Cartesian Product (Example)
EXAMPLE 2: Show that the Cartesian product B × A is
not equal to the Cartesian product A × B, where A and
B are as in Example 1.
Solution: The Cartesian product B × A is
B × A = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)}.
This is not equal to A × B,
Cartesian Product : Generalization
• Cartesian Products can be generalized for any
n-tuple
Definition: The Cartesian product of n sets, A1,A2, …, An,
denoted A1×A2×… ×An, is
A1×A2×… ×An ={ (a1,a2,…,an) | ai ∈ Ai for i=1,2,…,n}
Cartesian Product (Example)
EXAMPLE 3: What is the Cartesian product A × B × C,
where A = {0, 1}, B = {1, 2}, and C = {0, 1, 2} ?
Solution: The Cartesian productA × B × C consists of all
ordered triples (a, b, c), where a ∈ A, b ∈ B, and c ∈
C. Hence,
•A × B × C = {(0, 1, 0), (0, 1, 1), (0, 1, 2),
(0, 2, 0), (0, 2, 1), (0, 2, 2),
(1, 1, 0), (1, 1, 1), (1, 1, 2),
(1, 2, 0), (1, 2, 1), (1, 2, 2)}.
Cartesian Product (Example)
EXAMPLE 4: Suppose that A = {1, 2}. It follows that
A2 = {(1, 1), (1, 2), (2, 1), (2, 2)} and
A3 ={(1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), (2, 1, 1), (2, 1,
2), (2, 2, 1), (2, 2, 2)}.
Outline
• Definitions: set, element
• Representations
• Terminologies
• Quantifiers
• Set Operations (union, intersection, complement,
difference), Disjoint sets
• Set equivalences
• Inclusion in both directions
• Using membership tables
• Generalized Unions and Intersection
• Computer Representation of Sets
Notation with Quantifiers
• Whenever we wrote ∃xP(x) or ∀xP(x), we specified
the universe of discourse using explicit English
language
• Now we can simplify things using set notation!
• Example
– ∀ x ∈ R (x2≥0)
– ∃ x ∈ Z (x2=1)
Notation with Quantifiers
• What do the statements ∀x∈R (x2 ≥ 0) and ∃x∈Z
(x2 = 1) mean?
• Solution: The statement ∀x∈R(x2 ≥ 0) states that for
every real number x, x2 ≥ 0. This statement can be
expressed as “The square of every real number is
nonnegative.”
• This is a true statement.
• The statement ∃x ∈ Z(x2 = 1) states that there
exists an integer x such that x2 = 1. This statement
can be expressed as “There is an integer whose
square is 1.”
2
Set Operations
• Similarly, set operators exist and act on two
sets to give us new sets
– Union
– Intersection
– Set difference
– Set complement
– Generalized union
– Generalized intersection
Set Operators: Union
• Definition: The union of two sets A and B is
the set that contains all elements that are
either in A or B, or both. We write:
A∪B = { x | (x ∈ A) ∨ (x ∈ B) }
U
A B
Set Operators: Union
• EXAMPLE 1 The union of the sets {1, 3, 5} and
{1, 2, 3} is the set {1, 2, 3, 5}; that is,
• {1, 3, 5} ∪ {1, 2, 3} = {1, 2, 3, 5}.
Set Operators: Union
• EXAMPLE 2 The union of the set of all
computer science majors at your school and
the set of all mathematics majors at your
school is the set of students at your school
who are majoring either in mathematics or in
computer science (or in both).
Sets 42
Set Operators: Intersection
• Definition: The intersection of two sets A and
B is the set that contains all elements that are
element of both A and B. We write:
A ∩ B = { x | (x ∈ A) ∧ (x ∈ B) }
U
A B
Set Operators: Intersection
• EXAMPLE 1 The intersection of the sets {1, 3, 5} and
{1, 2, 3} is the set {1, 3}; that is,
• {1, 3, 5} ∩ {1, 2, 3} = {1, 3}.
• EXAMPLE 2 The intersection of the set of all
computer science majors at your school and the set
of all mathematics majors is the set of all students
who are joint majors in mathematics and computer
science.
Disjoint Sets
• Definition: Two sets are said to be disjoint if
their intersection is the empty set: A ∩ B = ∅
U
A B
Disjoint Sets
• Let A = {1, 3, 5, 7, 9} and B = {2, 4, 6, 8, 10}. Because
A ∩ B = ∅, A and B are disjoint.
U
A B
Set Difference
• An element x belongs to the difference of A and B if
and only if x ∈ A and x ∈ B.
• A − B = {x | x ∈ A ∧ x ∈ B}.
Set Difference
EXAMPLE 1: The difference of {1, 3, 5} and {1, 2, 3} is
the set {5}; that is, {1, 3, 5} − {1, 2, 3} = {5}.
This is different from the difference of {1, 2, 3} and {1,
3, 5}, which is the set {2}.
Sets 49
Set Difference
EXAMPLE 2: The difference of the set of computer
science majors at your school and the set of
mathematics majors at your school is the set of all
computer science majors at your school who are not
also mathematics majors.
Sets 50
Set Complement
• Definition: The complement of a set A, denoted A
consists of all elements not in A. That is the
difference of the universal set and U: U-A
A = AC = {x | x ∉ A }
U A
A
Set Complement
• EXAMPLE 1: Let A = {a, e, i, o, u} (where the universal
set is the set of letters of the English alphabet). Then
• A = {b, c, d, f, g, h, j, k, l,m, n, p, q, r, s, t, v,w, x, y, z}.
U U
A A B
A
Set Idendities
• There are analogs of all the usual laws for set
operations.
Proving Set Equivalences
• Using propositional laws
• Using Set identities
• Using Membership tables
Using propositional laws
Using propositional laws
Using Set identities
Proving Set Equivalences: Memebership
Table
• An alternative proof is to use membership
tables where an entry is
– 1 if a chosen (but fixed) element is in the set
– 0 otherwise
• Example: Show that
A∩B∩C=A∪B∪C
Proving Set Equivalences: Example B (2)
A B C A∩B∩C A∩B∩C A B C A∪B∪C
0 0 0 0 1 1 1 1 1
0 0 1 0 1 1 1 0 1
0 1 0 0 1 1 0 1 1
0 1 1 0 1 1 0 0 1
1 0 0 0 1 0 1 1 1
1 0 1 0 1 0 1 0 1
1 1 0 0 1 0 0 1 1
1 1 1 1 0 0 0 0 0
∪A =A
n
i 1
∪ A2 ∪ … ∪ An
i=1
Generalized Intersection
• Definition: The intersection of a collection of
sets is the set that contains those elements
that are members of every set in the collection
n
∩A =A
i=1
i 1
∩ A2 ∩…∩ An
Computer Representation of Sets
• There really aren’t ways to represent infinite sets by a
computer since a computer has a finite amount of memory
• If we assume that the universal set U is finite, then we can
easily and effectively represent sets by bit vectors
• Specifically, we force an ordering on the objects, say:
U={a1, a2,…,an}
• For a set A⊆U, a bit vector can be defined as, for i=1,2,…,n
– bi=0 if ai ∉ A
– bi=1 if ai ∈ A
Computer Representation of Sets
• Examples
– Let U={0,1,2,3,4,5,6,7} and A={0,1,6,7}
– The bit vector representing A is: 1100 0011
– How is the empty set represented?
– How is U represented?
• Set operations become trivial when sets are
represented by bit vectors
– Union is obtained by making the bit-wise OR
– Intersection is obtained by making the bit-wise AND
Computer Representation of Sets
• Let U={0,1,2,3,4,5,6,7}, A={0,1,6,7}, B={0,4,5}
• What is the bit-vector representation of B?
• Compute, bit-wise, the bit-vector
representation of A∩B
• Compute, bit-wise, the bit-vector
representation of A∪B
• What sets do these bit vectors represent?