DM Set03 Sets

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

1/17/2019

Tassos Dimitriou

CpE-203
Discrete Structures

Set 3

Prof. Tassos Dimitriou

Computer Engineering Department


Kuwait University

CpE-203: Discrete Structures 1

Tassos Dimitriou

Outline
Definitions
Common operations on sets
Representing set
Proving identities about sets

Reading: Chapter 3, on sets

CpE-203: Discrete Structures 2

1
1/17/2019

Tassos Dimitriou

What is a set?
Fundamental discrete structure on which all other discrete
structures are built.
 Sets are used to group objects together. Often, but not always,
the objects in a set have similar properties

A set is a unordered collection of “objects”


 People in a class: {Alice, Bob, Chris }
 States in the US: {Alabama, Alaska, Virginia, … }
 Sets can contain non-related elements: {3, a, red, Virginia }

We will mostly use sets of numbers


 All positive numbers less than or equal to 5: {1, 2, 3, 4, 5}
 A few selected real numbers: { 2.1, π, 0, -6.32, e }

CpE-203: Discrete Structures 3

Tassos Dimitriou

What is a set?
Properties
 Order does not matter
 {1, 2, 3, 4, 5} is equivalent to {3, 5, 2, 4, 1}

 Sets do not have duplicate elements


 Consider the list of students in this class
 It does not make sense to list somebody twice

A set is an unordered collection of objects, called elements or


members of the set. We write a ∈ A to denote that a is an
element of the set A. The notation a  A denotes that a is not an
element of the set A.

CpE-203: Discrete Structures 4

2
1/17/2019

Tassos Dimitriou

Specifying a Set
Capital letters (A, B, S…) for sets. Italic lower-case letter for
elements (a, x, y…)

Easiest way: list all the elements


 A = {1, 2, 3, 4, 5}, Not always feasible!

May use ellipsis (…): B = {0, 1, 2, 3, …}


 May cause confusion. C = {3, 5, 7, …}. What’s next?
 If the set is all odd integers greater than 2, it is 9
 If the set is all prime numbers greater than 2, it is 11

Can use set-builder notation


 D = {x | x is prime and x > 2}
 E = {x | x is odd and x > 2}
 The vertical bar means “such that”
CpE-203: Discrete Structures 5

Tassos Dimitriou

Often used sets


N = {0, 1, 2, 3, …} is the set of natural numbers
Z = {…, -2, -1, 0, 1, 2, …} is the set of integers
Z+ = {1, 2, 3, …} is the set of positive integers (a.k.a whole
numbers)
 Note that people disagree on the exact definitions of whole
numbers and natural numbers

Q = {p/q | p  Z, q  Z, q ≠ 0} is the set of rational numbers


 Any number that can be expressed as a fraction of two integers
(where the bottom one is not zero)

R is the set of real numbers

CpE-203: Discrete Structures 6

3
1/17/2019

Tassos Dimitriou

Notation for intervals


When a and b are real numbers with a < b, we write

 Note that [a, b] is called the closed interval from a to b and (a, b)
is called the open interval from a to b.

CpE-203: Discrete Structures 7

Tassos Dimitriou

The universal set


U is the universal set – the set of all of elements (or the
“universe”) from which given any set is drawn

 For the set {-2, 0.4, 2}, U would be the real numbers
 For the set {0, 1, 2}, U could be the N, Z, Q, R depending
on the context
 For the set of the vowels of the alphabet, U would be all the
letters of the alphabet

CpE-203: Discrete Structures 8

4
1/17/2019

Tassos Dimitriou

The Empty Set


If a set has zero elements, it is called the empty (or null)
set
 Written using the symbol 
 Thus,  = { }  VERY IMPORTANT

It can be a element of other sets


 { , 1, 2, 3, x } is a valid set

Is  the same as {  }?
 The first is a set of zero elements
 The second is a set of 1 element

CpE-203: Discrete Structures 9

Tassos Dimitriou

Venn diagrams
Represent sets graphically
 The box represents the universal set
 Circles represent the set(s)

U
S
Consider set S, which is
the set of all vowels in the e i
a
alphabet
o u

CpE-203: Discrete Structures 10

5
1/17/2019

Tassos Dimitriou

Set Equality, Subsets


Two sets are equal if they have the same elements
 {1, 2, 3, 4, 5} = {5, 4, 3, 2, 1}
 {1, 2, 3, 2, 4, 3, 2, 1} = {4, 3, 2, 1}
 Two sets are not equal if they do not have the same elements
 {1, 2, 3, 4, 5} ≠ {1, 2, 3, 4}

If all the elements of a set S are also elements of a set T, then


S is a subset of T
 If S = {2, 4, 6}, T = {1, 2, 3, 4, 5, 6, 7}, S is a subset of T
 This is specified by S  T meaning that  x (x  S  x  T)

For any set S, S  S (S S  S)


For any set S,   S (S   S).
CpE-203: Discrete Structures 11

Tassos Dimitriou

Proper Subsets
If S is a subset of T, and S is not equal to T, then S is a
proper subset of T
 Can be written as: R  T and R  T
 Let T = {0, 1, 2, 3, 4, 5}
 If S = {1, 2, 3}, S is not equal to T, and S is a subset of T
 A proper subset is written as S  T
 Let Q = {4, 5, 6}. Q is neither a subset or T nor a proper subset
of T

The difference between “subset” and “proper subset” is like


the difference between “less than or equal to” and “less than”
for numbers

CpE-203: Discrete Structures 12

6
1/17/2019

Tassos Dimitriou

Set cardinality
The cardinality of a set is the number of elements in a set,
written as |A|

Examples
 Let R = {1, 2, 3, 4, 5}. Then |R| = 5
 || = 0
 Let S = {, {a}, {b}, {a, b}}. Then |S| = 4

If there are exactly n distinct elements in S where n is a


nonnegative integer, we say that S is a finite set. A set is
said to be infinite if it is not finite.

CpE-203: Discrete Structures 13

Tassos Dimitriou

Power Sets
Many problems involve testing all combinations of elements of
a set to see if they satisfy some property. To consider all such
combinations of elements of a set S, we build a new set that
has as its members all the subsets of S.
Denoted by P(S) or 2S

Given S = {0, 1}. What are the possible subsets of S?


  (as it is a subset of all sets), {0}, {1}, and {0, 1}
 Therefore P(S) = { , {0}, {1}, {0,1} }

CpE-203: Discrete Structures 14

7
1/17/2019

Tassos Dimitriou

Power Sets (cont.)


Let T = {0, 1, 2}. What is P(T)?

What is P()?

If a set has n elements, what is the size of its power set?

CpE-203: Discrete Structures 15

Tassos Dimitriou

Cardinality of Power Sets


| 2A | = 2|A|
• Imagine each element in A has an “on/off” switch
• Each possible switch configuration in A corresponds to one element in
2A

A 1 2 3 4 5 6 7 8
x x x x x x x x x
y y y y y y y y y
z z z z z z z z z

• For 3 elements in A, there are 2×2×2 = 8 elements in 2A

CpE-203: Discrete Structures 16

8
1/17/2019

Tassos Dimitriou

Cartesian Product
The ordered n-tuple (a1, a2, a3, …, an) is an ordered collection
of objects.
 Two ordered n-tuples (a1, a2, a3, …, an) and (b1, b2, b3, …, bn) are equal
if and only if they contain exactly the same elements in the same order,
i.e. ai = bi for 1  i  n.

The Cartesian product of two sets is defined as:


 AB = {(a, b) | aA  bB}
 Example:
A = {x, y}, B = {a, b, c}
AB = {(x, a), (x, b), (x, c), (y, a), (y, b), (y, c)}

CpE-203: Discrete Structures 17

Tassos Dimitriou

Cartesian Product (cont.)


Note that:
• A = 
• A = 
• For non-empty sets A and B: AB  AB  BA
• |AB| = |A||B|

The Cartesian product of two or more sets is defined as:


 A1A2…An = {(a1, a2, …, an) | aiAi for 1  i  n}

CpE-203: Discrete Structures 18

9
1/17/2019

Tassos Dimitriou

Set Operations

CpE-203: Discrete Structures 19

Tassos Dimitriou

Union
Formal definition for the union of two sets:
A  B = { x | x  A or x  B }
Further examples
 {1, 2, 3}  {3, 4, 5} = {1, 2, 3, 4, 5}
 {a, b}  {3, 4} = {a, b, 3, 4}
 {1, 2}   = {1, 2}

Properties of the union operation


 A=A Identity law
 AU=U Domination law
 AA=A Idempotent law
 AB=BA Commutative law
 A  (B  C) = (A  B)  C Associative law

CpE-203: Discrete Structures 20

10
1/17/2019

Tassos Dimitriou

Intersection
Formal definition for the intersection of two sets:
A ∩ B = { x | x  A and x  B }
Examples
 {1, 2, 3} ∩ {3, 4, 5} = {3}
 {a, b} ∩ {3, 4} = 
 {1, 2} ∩  = 

Properties of the intersection operation


 A∩U=A Identity law
 A∩= Domination law
 A∩A=A Idempotent law
 A∩B=B∩A Commutative law
 A ∩ (B ∩ C) = (A ∩ B) ∩ C Associative law

CpE-203: Discrete Structures 21

Tassos Dimitriou

Union, Intersection
Using Venn diagrams

CpE-203: Discrete Structures 22

11
1/17/2019

Tassos Dimitriou

Disjoint sets
Two sets are disjoint if their intersection is the empty set.

Further examples
 {1, 2, 3} and {3, 4, 5} are not disjoint
 {a, b} and {3, 4} are disjoint
 {1, 2} and  are disjoint
 Their intersection is the empty set
  and  are disjoint!
 Their intersection is the empty set

How can we express the cardinality of the union of two sets A and
B?

CpE-203: Discrete Structures 23

Tassos Dimitriou

Difference
Formal definition for the difference of two sets:
A – B = { x | x  A and x  B }
Examples
 {1, 2, 3} - {3, 4, 5} = {1, 2}
 {a, b} - {3, 4} = {a, b}
 {1, 2} -  = {1, 2}
 The difference of any set S with the empty set will be the set S

CpE-203: Discrete Structures 24

12
1/17/2019

Tassos Dimitriou

Complements of sets
Formal definition for the complement of a set:
 A = { x | x  A } = Ac
 Or U – A, where U is the universal set

Further examples (assuming U = Z)


 {1, 2, 3}c = { …, -2, -1, 0, 4, 5, 6, … }
 {a, b}c = Z

Properties of complement sets


 (Ac)c = A Complementation law
 A Ac = U Complement law
 A ∩ Ac =  Complement law

CpE-203: Discrete Structures 25

Tassos Dimitriou

Set identities
A = A AU = U
Identity Law Domination law
AU = A A = 
AA = A Idempotent Complement
(Ac)c = A
AA = A Law Law
AB = BA Commutative (AB)c = AcBc
De Morgan’s Law
AB = BA Law (AB)c = AcBc
A(BC) A(BC) =
= (AB)C Associative (AB)(AC)
Law Distributive Law
A(BC) A(BC) =
= (AB)C (AB)(AC)
A(AB) = A Absorption A  Ac = U Complement
A(AB) = A Law A  Ac =  Law

CpE-203: Discrete Structures 26

13
1/17/2019

Tassos Dimitriou

How to prove a set identity


For example: A∩B = B-(B-A)

Four methods:
 Use the basic set identities
 Use set builder notation and logical equivalences
 Use membership tables
 Prove each set is a subset of each other

CpE-203: Discrete Structures 27

Tassos Dimitriou

What we are going to prove…


A∩B = B-(B-A)

A B

B-(B-A)
A∩B B-A

CpE-203: Discrete Structures 28

14
1/17/2019

Tassos Dimitriou

Proof by Set Identities


A  B = A - (A - B)

Proof: A - (A - B) = A - (A  Bc) Def. of Diff.


= A  (A  Bc)c Def. of Diff.
= A  (Ac  B) Def. of Compl.
= (A  Ac)  (A  B) Distributive
=   (A  B)
=AB

CpE-203: Discrete Structures 29

Tassos Dimitriou

Using set builder notation


(A  B)c = Ac  Bc

x  (A  B)c
 x  (A  B)
  (x  A  B)
  (x  A  x  B)
  (x  A)   (x  B)
xAxB
 x  Ac  x  Bc
 x  Ac  Bc

CpE-203: Discrete Structures 30

15
1/17/2019

Tassos Dimitriou

Using membership tables


Let’s prove A(BC) = (AB)(AC)
 1 means “x is an element of this set”
 0 means “x is not an element of this set”

A B C BC A(BC) AB AC (AB) (AC)


0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0
0 1 1 1 1 1 1 1
1 0 0 0 1 1 1 1
1 0 1 0 1 1 1 1
1 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1

CpE-203: Discrete Structures 31

Tassos Dimitriou

Proving each set is a subset of the other


Show A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
 Suppose that x ∈ A ∩ (B ∪ C). Then x ∈ A and x ∈ B ∪ C.
 By definition of union, it follows that x ∈ A, and x ∈ B or x ∈ C
(or both). Hence the compound proposition (x ∈ A) ∧ ((x ∈ B) ∨
(x ∈ C)) is true.
 By the distributive law for conjunction over disjunction, it
follows that ((x ∈ A) ∧ (x ∈ B)) ∨ ((x ∈ A) ∧ (x ∈ C)).
 We conclude that x ∈ A and x ∈ B, OR x ∈ A and x ∈ C.
 By definition of intersection, we have x ∈ A ∩ B or x ∈ A ∩ C.
 Using the definition of union, we conclude that x ∈ (A ∩ B) ∪ (A
∩ C).
 We conclude that A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C).
(then we have to prove the other way around, too)
CpE-203: Discrete Structures 32

16
1/17/2019

Tassos Dimitriou

Set Operations

Take-home message:

Every logical expression can be transformed into an


equivalent expression in set theory and vice versa.

CpE-203: Discrete Structures 33

Tassos Dimitriou

Examples
Let A, B, and C be sets. Show that:
 (A ∪ B)  (A ∪ B ∪ C)
 (A ∩ B ∩ C)  (A ∩ B)
 (A-B)-C  A-C
 (A-C) ∩ (C-B) = 

CpE-203: Discrete Structures 34

17
1/17/2019

Tassos Dimitriou

CpE-203: Discrete Structures 35

18

You might also like