Discrete Structure
L#5
1
Lecture 5
Set
Types of set
Operations of Set
2
Set Theory
Actually, you will see that logic
and set theory are very closely
related.
3
Set Theory
• Set: Collection of objects (called elements)
• aA “a is an element of A”
“a is a member of A”
• aA “a is not an element of
A”
• A = {a1, a2, …, an} “A contains a1, …, an”
• Order of elements is insignificant
• It does not matter how often the same
element is listed (repetition doesn’t
count). 4
Cardinality of Sets
If a set S contains n distinct elements, nN,
we call S a finite set with cardinality n.
Examples:
A = {Mercedes, BMW, Porsche}, |A| = 3
B = {1, {2, 3}, {4, 5}, 6} |B| =
C= 4
|C| = 0
D = { xN | x 7000 } |D| = 7001
E = { xN | x 7000 } E is infinite!
5
Types of set
Empty set
Finite set
Infinite set
Equal sets
Subset
Proper subset
power set
6
Set Equality
Sets A and B are equal if and only if they contain
exactly the same elements and n(A)=n(B)
(Cardinality of Sets) is equal.
Examples:
• A = {9, 2, 7, -3}, B = {7, 9, -3, A=B
2}
• A := {dog, cat, horse},
B = {cat, horse, squirrel, dog} AB
•: A = {dog, cat, horse},
A=B
B = {cat, horse, dog, dog} :
7
Examples for Sets
“Standard” Sets:
• Natural numbers N = { 1, 2, 3, …}
• Integers Z = {…, -2, -1, 0, 1, 2, …}
• Positive Integers Z+ = {1, 2, 3, 4, …}
• Real Numbers R = {47.3, -12, , …}
• Rational Numbers Q = {1.5, 2.6, -3.8,
15, …}
(correct definitions will follow)
8
Examples for Sets
• A= “empty set/null set”
• A= {z} Note: zA, but z
{z}
• A= {{b, c}, {c, x, d}} set of sets
• A= {{x, y}} Note: {x, y} A, but {x, y}
{{x, y}}
• A = {x | P(x)} “set of all x such that P(x)”
P(x) is the membership function of set A
• A = {x | x N x > 7} = {8, 9, 10, …}
“set builder notation”
9
Examples for Sets
We are now able to define the set of rational
numbers Q:
Q = {a/b | aZ bZ+}, or
Q = {a/b | aZ bZ b0}
And how about the set of real numbers R?
R = {r | r is a real number}
That is the best we can do. It can neither be
defined by enumeration nor builder function.
10
Subsets
AB “A is a subset of B”
A B if and only if every element of A is also
an element of B.
Examples:
A = {3, 9}, B = {5, 9, 1, 3}, A true
B?
A = {3, 3, 3, 9}, B = {5, 9, 1, 3}, A true
B?
A = {1, 2, 3}, B = {2, 3, 4}, A false
B? 11
Subsets
Useful rules:
(A B) (B C) and A C (see Venn
Diagram)
B
A C
12
Subsets
Useful rules:
• A for any set A
(but A may not hold for any set A)
• A A for any set A
Proper subsets:
AB “A is a proper subset of B”
B={1,2,3,6,8}
A={1,2,8} AB
A={1,2,3,6,8} AB
13
The Power Set
P(A) “power set of A” (also written as 2A)
P(A) = {B | B A} (contains all subsets of
A)
Examples:
A = {x, y, z}
P(A) = {, {x}, {y}, {z}, {x, y}, {x, z}, {y,
z}, {x, y, z}}
A=
P(A) = {}
Note: |A| = 0, |P(A)| = 1 14
Set Operations
Union: AB = {x | xA xB}, AB = BA
Example: A = {a, b}, B = {b, c, d}
AB = {a, b, c, d}
Intersection: AB = {x | xA xB}, A B = B A
Example: A = {a, b}, B = {b, c, d}
AB = {b}
Cardinality: |AB| = |A| + |B| - |AB|
15
Set Operations
Two sets are called disjoint if their intersection is
empty, that is, they share no elements:
AB =
The difference between two sets A and B
contains exactly those elements of A that are not
in B:
A-B ≠B-A
A-B = {x | xA xB}
Example: A = {a, b}, B = {b, c, d}, A-B = {a}
Cardinality: |A-B| = |A| - |AB|
16
Set Operations
The complement of a set A contains exactly
those elements under consideration that are
not in A: denoted AcA(or as in the text)
Ac = U-A
Example: U = N, B = {250, 251, 252, …}
Bc = {0, 1, 2, …, 248, 249}
17
Logical Equivalence
Equivalence laws
– Identity laws, P T P,
– Domination laws, P F F,
– Idempotent laws, P P P,
– Double negation law, ( P) P
– Commutative laws, P Q Q P,
– Associative laws, P (Q R) (P Q) R,
– Distributive laws, P (Q R) (P Q) (P R),
– De Morgan’s laws, (PQ) ( P) ( Q)
– Law with implication PQPQ
18
Set Laws
Table 1 in Section 1.7 shows many useful
equations
– Identity laws, A = A, AU = A
– Domination laws, AU = U, A =
– Idempotent laws, AA = A, AA = A
– Complementation law, (Ac)c = A
– Commutative laws, AB = BA, AB = BA
– Associative laws, A(B C) = (AB)C,
– Distributive laws, A(BC) = (AB)(AC), …
– De Morgan’s laws, (AB)c = AcBc, (AB)c =
AcBc
– Absorption laws, A(AB) = A, A(AB) = A
– Complement laws, AAc = U, AAc = 19
How can we prove A(BC) =
(AB)(AC)?
20
Set Operations
Method I: Membership table
1 means “x is an element of this set”
0 means “x is not an element of this set”
A B C BC A(BC) AB AC (AB) (AC)
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 21
U is a universal set. A and B are two disjoint
sets but the subset of the universal set i.e.,
A ⊆ U, B ⊆ U and A ∩ B = ф
U = {a, e, i, o, u}
A = {a, i} , B = {e, u}
Draw a Venn Diagrams of above
22
U
A B
a,i e,u
23
Class activity
1. Let A and B be two finite sets such that
n(A) = 20, n(B) = 28 and n(A ∪ B) = 36,
find n(A ∩ B).
Using the formula n(A ∪ B) = n(A) + n(B) -
n(A ∩ B).
24
Solution:
then n(A ∩ B) = n(A) + n(B) - n(A ∪ B)
= 20 + 28 - 36
= 48 - 36
= 12
25
Class activity
2. In a group of 60 people, 27 like cold
drinks and 42 like hot drinks and each
person likes at least one of the two drinks.
How many like both coffee and tea?
Using the formula n(A ∪ B) = n(A) + n(B) -
n(A ∩ B).
26
Solution
Let A = Set of people who like cold drinks.
B = Set of people who like hot drinks.
Given : (A ∪ B) = 60 n(A) = 27 n(B) = 42 then;
n(A ∩ B) = n(A) + n(B) - n(A ∪ B)
= 27 + 42 - 60
= 69 - 60 = 9
Therefore, 9 people like both tea and coffee. 27