Sunteți pe pagina 1din 41

Unit II: Set Theory

1
Set Theory - Definitions and notation

A set is an unordered collection of objects referred to as elements or


members of the set.

A set is said to contain its elements.


Different ways of describing a set.

1 Explicitly: listing the elements of a set (roster method)


{1, 2, 3} is the set containing 1 and 2 and 3. list the members
between braces.
{1, 1, 2, 3, 3} = {1, 2, 3} since repetition is irrelevant.
{1, 2, 3} = {3, 2, 1} since sets are unordered.
{1,2,3, , 99} is the set of positive integers less than 100; use ellipses(...)
when the general pattern of the elements is obvious.

= {} is the empty set, or null set, or the set containing no elements.


A set with one element is called a singleton set.
2
Note: {}
Set Theory - Definitions and notation

2 Implicitly:
 {1, 2, 3, } is a way we denote an infinite set (in this case, the natural numbers).
 by using a set builder notation, stating the property or properties of the elements of the set.
O = {x | x is an odd positive integer less than 10},

or, specifying the universe as the set of positive integers, as


O = {x Z+ | x is odd and x < 10}.

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
Q = {p/q | p Z, q Z, and q != 0}, the set of rational numbers
R, the set of real numbers
R+ , the set of positive real numbers
C, the set of complex numbers.

Note: Real number are the numbers that can be represented by an infinite decimal representation,
such as 3.4871773339. The real numbers include both rational, and irrational numbers such
as and the 2 can be represented as points along an infinitely long number line.
3
Set Theory - Ways to define sets
: and | are read
such that or
Explicitly: {John, Paul, George, Ringo} where
Implicitly: {1,2,3,}, or {2,3,5,7,11,13,17,}
Set builder: { x : x is prime }, { x | x is odd }.
In general { x : P(x) is true }, where P(x) is some description of the set.

Let D(x,y) denote x is divisible by y.


Give another name for
{ x : y ((y > 1) (y < x)) D(x,y) }. Primes

4
Notation for intervals of real numbers:
[a, b] = {x | a x b} - closed interval
[a, b) = {x | a x < b}
(a, b] = {x | a < x b}
(a, b) = {x | a < x < b}- open interval

Sets can have other sets as members.

Two sets are equal if and only if they have the same elements.
Therefore, if A and B are sets, then A and B are equal if and
only if x(x A x B). We write A = B if A and B are equal
sets.

Georg Cantor is considered the founder of set theory.


Reveals contradiction in naive set theory. Avoid self-reference.
Use hierarchy of sets (types).
Set Theory - Russells Paradox
the set of all sets that do not
contain themselves as members

Can we use any predicate P to define a set


S = { x : P(x) }?
No!

Define S = { x : x is a set where x x }

Now, what about S itself? Its a set.


Is it in S? So S must not be
in S, right?
Then, if S S, then by defn of S, S S.

But, if S S, then by defn of S, S S.

Compare: There is a town with a barber who shaves all the people
(and only the people) who dont shave themselves.
Who shaves the 6
barber?
Aside: this laymans version of Russells paradox; has some drawbacks.

The Barber Question


There is a town with a barber who shaves all the people (and only the
people) who dont shave themselves.
Who shaves the
Does the barber shave himself? barber?
If the barber does not shave himself, he must abide by the rule and shave himself.
If he does shave himself, according to the rule he will not shave himself.

( x ) (barber ( x ) ( y )(shaves( y,y )shaves( x,y ))


This sentence is unsatisfiable (a contradiction) because of the universal quantifier.
The universal quantifier y will include every single element in the domain,
including our infamous barber x. So when the value x is assigned to y,
the sentence can be rewritten to:

{shaves( x,x )shaves( x,x ) }


{(shaves( x,x ) shaves( x,x )) (shaves( x,x ) shaves( x,x )) }
{shaves( x,x ) (shaves( x,x ) }
Contradiction!
7
Logically inconsistent definition / description. Town cannot exist!
Set Theory - Definitions and notation

x S means x is an element of set S.


x S means x is not an element of set S.

A B means A is a subset of B.

or, B contains A.
or, every element of A is also in B.
or, x ((x A) (x B)).

Venn Diagram
A

B
8
Set Theory - Definitions and notation

A B means A is a subset of B.
A B means A is a superset of B.
A = B if and only if A and B have exactly the same elements.

iff, A B and B A
iff, A B and A B
iff, x ((x A) (x B)).

So to show equality of sets A and B, show:


AB
BA
9
Set Theory - Definitions and notation

A B means A is a proper subset of B.


A B, and A B.
x ((x A) (x B)) x ((x B) (x A))
x ((x A) (x B)) x ((x B) v (x A))
x ((x A) (x B)) x ((x B) (x A))
x ((x A) (x B)) x ((x B) (x A))

10
Set Theory - Definitions and notation

Quick examples:
{1,2,3} {1,2,3,4,5}
{1,2,3} {1,2,3,4,5}

Is {1,2,3}? Yes! x (x ) (x {1,2,3}) holds (for all


over empty domain)

Is {1,2,3}? No!

Is {,1,2,3}? Yes!

Is {,1,2,3}? Yes!

11
Set Theory - Definitions and notation

A few more:
Yes
Is {a} {a}?

Is {a} {a,{a}}? Yes

Is {a} {a,{a}}? Yes

Is {a} {a}? No

12
Set Theory - Cardinality

If S is finite, then the cardinality of S, |S|, is the number of distinct


elements in S.

If S = {1,2,3}, |S| = 3.
If S = {3,3,3,3,3}, |S| = 1.
If S = , |S| = 0.
If S = { , {}, {,{}} }, |S| = 3.

If S = {0,1,2,3,}, |S| is infinite.

13
Set Theory - Power sets

If S is a set, then the power set of S is


2S = { x : x S }. aka P(S)
If S = {a}, We say, P(S) is
2S = {, {a}}.
the set of all
If S = {a,b}, 2S = {, {a}, {b}, {a,b}}. subsets of S.
If S = , 2S = {}.
If S = {,{}}, 2S = {, {}, {{}}, {,{}}}.

Fact: if S is finite, |2S| = 2|S|. (if |S| = n, |2S| = 2n) Why?

14
Set Theory Ordered Tuples
Cartesian Product

When order matters, we use ordered n-tuples

The Cartesian Product of two sets A and B is:


A x B = { <a,b> : a A b B}
If A = {Charlie, Lucy, Linus}, and B =
{Brown, VanPelt}, then Well use these
special sets
A x B = {<Charlie, Brown>, <Lucy, Brown>, <Linus, soon!
Brown>, <Charlie, VanPelt>, <Lucy, VanPelt>,
<Linus, VanPelt>}
a) AxB
b) |A|+|B|
A1 x A2 x x An = {<a1, a2,, an>: a1 A1, a2 A2, , an An} c) |A+B|
d) |A||B|
A,B finite |AxB| = ? 15
A subset R of the Cartesian product A B is called a relation from
the set A to the set B. The elements of R are ordered pairs, where the
first element belongs to A and the second to B.

For example, R = {(a, 0), (a, 1), (a, 3), (b, 1), (b, 2), (c, 0), (c, 3)} is a
relation from the set {a, b, c} to the set {0, 1, 2, 3}. A relation from a
set A to itself is called a relation on A.
Set Theory - Operators

The union of two sets A and B is:


A B = { x : x A v x B}

If A = {Charlie, Lucy, Linus}, and B = {Lucy, Desi},


then

A B = {Charlie, Lucy, Linus, Desi}

B
A

17
Set Theory - Operators

The intersection of two sets A and B is:


A B = { x : x A x B}
If A = {Charlie, Lucy, Linus}, and B = {Lucy, Desi},
then

A B = {Lucy}

B
A

18
Set Theory - Operators

The intersection of two sets A and B is:


A B = { x : x A x B}
If A = {x : x is a US president}, and B = {x : x is deceased}, then

A B = {x : x is a deceased US president}

B
A

19
Set Theory - Operators

The intersection of two sets A and B is:


A B = { x : x A x B}
If A = {x : x is a US president}, and B = {x : x is in this room}, then

A B = {x : x is a US president in this room} =

Sets whose
B
A intersection is
empty are called
disjoint sets

20
Set Theory - Operators

The complement of a set A is:

A = { x : x A}
If A = {x : x is bored}, then

A = {x : x is not bored}

U
A = U
and
U=

I.e., A = U A, where U is the universal set.


A set fixed within the framework of a theory and consisting 21
of all objects considered in the theory.
Set Theory - Operators

The set difference, A - B, is:

U
A
B

A-B = { x:xAx B }

A-B=AB

22
Set Theory - Operators

The symmetric difference, A B, is:


A B = { x : (x A x B) v (x B x A)}
= (A - B) U (B - A)

like
exclusive
or
U
A
B

23
Set Theory Operators
Example proof

A B = { x : (x A x B) v (x B x A)}
= (A - B) U (B - A)

Proof: { x : (x A x B) v (x B x A)}
= { x : (x A - B) v (x B - A)}

= { x : x ((A - B) U (B - A))}

= (A - B) U (B - A)

Q.E.D.

24
Directly from defns.
Set Theory - Identities

Identity AU=A
AU=A

Domination
AUU=U
A=
Idempotent

AUA=A
AA=A

25
Set Theory Identities, cont.

Complement Laws
AUA=U

AA=

Double complement
A=A

26
Set Theory - Identities, cont.

Commutativity
AUB= BUA
AB= BA
Associativity
(A U B) U C = A U (B U C)
(A B) C = A (B C)
Distributivity

A U (B C) = (A U B) (A U C)
A (B U C) = (A B) U (A C)

27
Compare to
rules for logical
connectives. There
DeMorgans I (A U B) = A B is a deep connection
via Boolean algebra.
DeMorgans II
(A B) = A U B

Proof by
diagram
(useful!), but
A B we aim for a
more formal
proof.
28
Proving identities

Prove that (A U B) = A B (De Morgan)

1. () (x A U B)
(x (A U B))
(x A and x B)
(x A B)

2. () (x ( A B))
(x A and x B)
(x A U B)
(x A U B)

29
Alt. proof
A B

Prove that(A U B) = A B using a membership table.


0 : element x is not in the specified set
1 : otherwise

A B A B AB AUB AUB

1 1 0 0 0 1 0

1 0 0 1 0 1 0

0 1 1 0 0 1 0

0 0 1 1 1 0 1 Havent we seen
this before?
Proof using logically equivalent set definitions:

(A U B) = A B

(A U B) = {x : (x A v x B)}

= {x : (x A) (x B)}

= {x : (x A) (x B)}

=AB 31
Example

X (Y - Z) = (X Y) - (X Z). True or False?


Prove your response.

(X Y) - (X Z) = (X Y) (X Z)

= (X Y) (X U Z) Distributive law
= (X Y X) U (X Y Z)

= U (X Y Z)
= (X Y Z)
= X (Y - Z)

Note: (X Z) = (X Z) (just different notation) 32


Example

AB=
Pv that if (A - B) U (B - A) = (A U B) then ______

Suppose to the contrary, that A B , and that x A B.


a) A=B
Then x cannot be in A-B and x cannot be in B-A. b) AB=
c) A-B = B-A =
Then x is not in (A - B) U (B - A).

Do you see the contradiction yet?

But x is in A U B since (A B) (A U B).


Trying to prove p --> q
Thus, (A - B) U (B - A) (A U B). Assume p and not q, and find
a contradiction.
Contradiction. Our contradiction was that
Thus, A B = . sets werent equal.
Set Theory - Generalized Union/Intersection
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.

We use the notation

The intersection of a collection of sets is the set that contains those


elements that are members of all the sets in the collection.

35
Set Theory - Generalized Union/Intersection
Suppose that Ai = {1, 2, 3, . . . , i} for i = 1, 2, 3, . . . . Then,

36
Set Theory - Inclusion/Exclusion

Example: 157
There are 217 cs students. 145
157 are taking cs280.
145 are taking cs211.
98 are taking both.

How many are taking neither?

217 - (157 + 145 - 98) = 13

37
Generalized Inclusion/Exclusion

A B
Suppose we have:

What about 4 sets?


And I want to know |A U B U C|

|A U B U C| = |A| + |B| + |C|


- |A B| - |A C| - |B C|
+ |A B C|
Set Theory - Sets as bit strings

Let U = {x1, x2,, xn}, and let A U.


Then the characteristic vector of A is
the n-vector whose elements, xi, are 1 if
xi A, and 0 otherwise.

Ex. If U = {x1, x2, x3, x4, x5, x6},


and A = {x1, x3, x5, x6}, then
the characteristic vector of A is
(101011)
Sets as bit strings

Ex. If U = {x1, x2, x3, x4, x5, x6},


A = {x1, x3, x5, x6}, and
B = {x2, x3, x6},
Then we have a quick way of
finding the characteristic vectors of
A B and A B.
A 1 0 1 0 1 1

B 0 1 1 0 0 1

Bit-wise OR AB 1 1 1 0 1 1

Bit-wise AND AB 0 0 1 0 0 1 41

S-ar putea să vă placă și