CS 173: Discrete Mathematical Structures

Download Report

Transcript CS 173: Discrete Mathematical Structures

Discrete Structures & Algorithms
Basics of Set Theory
EECE 320 — UBC
Set Theory: Definitions and notation
A set is an unordered collection of elements.
Some examples
•
•
•
•
{1, 2, 3} is the set containing “1” and “2” and “3.”
{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, …} is a way we denote an infinite set (in this case, the
natural numbers).
•  = {} is the empty set, or the set containing no elements.
Note:   {}
2
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)).
A
B
Venn
Diagram
3
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:
AB
BA
4
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))
A
B
5
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, because (x  ) is false.
Vacuously
Is   {1,2,3}?
No!
Is   {,1,2,3}? Yes!
6
Definitions and notation
Quiz Time
Is {x}  {x}?
Yes
Is {x}  {x,{x}}?
Yes
Is {x}  {x,{x}}?
Yes
Is {x}  {x}?
No
7
How to specify sets
• Explicitly: {John, Paul, George, Ringo}: and | are read
“such that” or
• Implicitly: {1,2,3,…}, or {2,3,5,7,11,13,17,…}
“where”
• 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.
Example: Let D(x,y) denote “x is divisible by y.”
Give another name for
{ x : y ((y > 1)  (y < x))  D(x,y) }.
Can we use any predicate P to define a
set S = { x : P(x) }?
Primes
8
Predicates for defining sets
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 }
Then, if S  S, then by the definition of S, S  S.
So S must not be
in S, right?
But, if S  S, then by the definition of S, S  S.
Doh!
There is a town with a barber who shaves all the people (and
only the people) who do not shave themselves.
Who shaves the 9
barber?
Cardinality of sets
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. (more on this later)
10
Power sets
If S is a set, then the power set of S is
2S = { x : x  S }.
or P(S)
If S = {a}, 2S = {, {a}}.
If S = {a,b}, 2S = {, {a}, {b}, {a,b}}.
If S = ,
We say, “P(S) is
the set of all
subsets of S.”
2S = {}.
If S = {,{}}, 2S = {, {}, {{}}, {,{}}}.
Fact: if S is finite, |2S| = 2|S|. (If |S| = n, |2S| = 2n.)
11
Cartesian product
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
We’ll use these
special sets soon!
A x B = {<Charlie, Brown>, <Lucy, Brown>,
<Linus, Brown>, <Charlie, VanPelt>, <Lucy,
VanPelt>, <Linus, VanPelt>}
A1 x A2 x … x An = {<a1, a2,…, an>: a1  A1, a2  A2,
…, an  An}
a) AxB
A,B finite  |AxB| = ?
b)
c)
d)
|A|+|B|
|A+B|
|A||B|
12
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
13
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
14
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
15
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} = 
B
A
Sets whose
intersection is
empty are called
disjoint sets
16
Operators
The complement of a set A is
Ac = { x : x  A}
QuickTime™ and a
TIFF (Uncompressed) decompressor
are needed to see this picture.
If A = {x : x is bored}, then
A = {x : x is not bored} = 
U
A
c = U
and
Uc = 
17
Operators
The set difference, A - B, is:
U
A
B
A-B={x:xAxB}
A - B = A  Bc
18
Operators
The symmetric difference, A  B, is:
A  B = { x : (x  A  x  B) v (x  B  x  A)}
like
“exclusive
or”
= (A - B) U (B - A)
U
A
B
19
Operators
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)
20
Famous identities
• Two pages of (almost) obvious equivalences.
• One page of HS algebra.
• Some new material?
Don’t
memorize
them,
understand
them!
They’re in
Rosen, Sec. 2.2
21
Identities
• Identity
AU=A
AU=A
• Domination
AUU=U
A=
• Idempotent
AUA=A
AA=A
22
Identities
• Excluded middle A U A = U
• Uniqueness
AA=
• Double complement
A=A
23
Identities
• Commutativity
AUB= BUA
AB= BA
• 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)
24
Identities
• DeMorgan’s Law I
(A U B)c = Ac  Bc
• DeMorgan’s Law II
(A  B)c = Ac U Bc
p
q
Hand waving is
good for
intuition, but we
aim for a more
formal proof.
25
Proving identities
• Show that A  B and that A  B.
• Use a membership table.
New & important
Like truth tables
• Use previously proven identities.
Like 
• Use logical equivalences to prove equivalent
set definitions.
Not hard, a little tedious
26
Proving identities (1)
Prove that (A U B)c = Ac  Bc
1.
() (x  (A U B)c)  (x  A U B)  (x  A and x  B)  (x  Ac  Bc)
2.
() (x  Ac  Bc)  (x  A and x  B)  (x  A U B)  (x  (A U B)c)
27
Proving identities (2)
Prove that (A U B)c = Ac  Bc using a membership table.
0 : x is not in the specified set
1 : otherwise
A
B
A
B
AB
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
Have we not seen
this before?
28
Proving identities (3)
Prove that (A U B)c = Ac  Bc using identities.
(A U B) = A U B
=AB
=AB
29
Proving identities (4)
Prove that (A U B)c = Ac  Bc using logically
equivalent set definitions.
(A U B)c = {x : (x  A v x  B)}
= {x : (x  A)  (x  B)}
= {x : (x  Ac)  (x  Bc)}
= A c  Bc
30
A proof to do
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’)
= (X  Y  X’) U (X  Y  Z’)
=
U (X  Y  Z’)
= (X  Y  Z’)
31
Another proof to do
AB=
Prove that if (A - B) U (B - A) = (A U B) then ______
Suppose to the contrary, that A  B  , and that x  A  B.
a)
b)
c)
d)
AUB=
A=B
AB=
A-B = B-A = 
Then x cannot be in A-B and x cannot be in B-A.
DeMorgan’s Law
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 = .
Assume p and not q, and find a
contradiction.
Our contradiction was that sets
were not equal.
32
Wrap up
• Sets are an essential
structure for all
mathematics.
• We covered the basic
definitions and identities
that will allow us to reason
about sets.
33