Upload
mary-bishop
View
226
Download
2
Embed Size (px)
Citation preview
1
Set Theory
Foundation of Relational Database Systems
E.F. Codd
2
Basic Concepts
A set is a collection of elements
From a known background “Universe”
A definition we are satisfied with
Everything is in the “Universe”
An element could be any thing
3
Examples
• All UWP students in CS363 this semester
A = {UWP students in CS363 this semester}
• B = {All UWP students who play Bridge}
• C = {1, 2, 3, 4}
• I = {i: i is an integer}
• Number of elements of each set
4
No repeating elements
{1, 2, 3, 4, 2}
Not a set in classic set theory
Elements are not ordered
{1, 2, 3, 4}
{2, 4, 1, 3}
The same set
5
Empty Set
A = {UWP students in CS363 this semester}
D = {s | s in A and has attended Turing
Award ceremony}
D = {}
=
This is not empty set: {}
6
Sets and Elements
S is a set
X is an element in the “Universe”
Two possibilities:
x is in S
(x S)
or
x is not in S
(x S)
7
Subsets
For two sets A and B and any element x,if x A then x B
Then A is a subset of BA B or B A
(similar to A < B or B > A)
A could be the same as B A B or B A (similar to A <= B or B >= A)
8
Subsets
For two sets A and B and any element x,if x A then x B
Then A is a subset of B
A is not a subset of BThere is an element x such that
x A and x B
9
Subsets (II)
For any set X,
X
No element e such that
e and e X
10
Proper Subsets
For any set X, X X X
A is a proper subset of B, if all the three conditions are true:
A B (A B) A B A
11
Cardinality
C = {1, 2, 3, 4} |C| = 4 A = {UWP students in CS363 this semester} |A| = 55
I = {i: i is an integer} |I| =
(Number of elements of finite sets)
12
Power Set
For any set X, P(X) = {S | S is a subset of X} = {S | S X}
C = {1, 2, 3, 4}
P(C) = {{1}, {2}, {3}, {4},
{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4},
{1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4},
{1, 2, 3, 4},
{}}
13
Power Set
C = {1, 2, 3, 4}
P(C) = {{1}, {2}, {3}, {4},
{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4},
{1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4},
{1, 2, 3, 4},
{}}
P(C) = {{1}, {2}, {3}, {4},
{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4},
{1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4},
{1, 2, 3, 4},
}
14
The cardinality of the power set
X is a set and its cardinality is |X|
The power set of X is P(X) and its cardinality is |P(X)| = 2|X|
15
Example I
C = {1, 2, 3, 4}|C| = 4
P(C) = {{1}, {2}, {3}, {4},
{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4},
{1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4},
{1, 2, 3, 4},
}
|P(C)| = 24 = 16
16
Example II
X = {x0, x1, x2, x3, x4, x5, x6, x7} |X| = 8 |P(X)| = 28
x0 x1 x2 x3 x4 x5 x6 x7 1 0 0 1 1 0 0 0
The same as a byte with 8 bits.
17
Set Operations
Set UnionA B = {x: x A or x B}
A = {1, 2, 3, 4}
B = {2, 5}
A B = {x: x A or x B}
= {1, 2, 3, 4, 5}
= B A
Range of |A B|?
Max (|A|, |B|) <= |A B| <= |A| + |B|
18
Set IntersectionA B = {x: x A and x B}
A = {1, 2, 3, 4}B = {2, 5}A B = {x: x A and x B}
= {2} = B A
Range of |A B| ?0 <= |A B| <= Min(|A|, |B|)
19
Set Difference
A – B = {x: x A but x B}
A = {1, 2, 3, 4}B = {2, 5}
A – B = {x: x A but x B} = {1, 3, 4}
B - AB – A = {5}
Range of |A – B|?
20
Cartesian Product
A B = {(a, b): a A and b B}
A = {1, 2, 3, 4} B = {2, 5}A B = {(a, b): a A and b B}
= {(1, 2), (1, 5), (2, 2), (2, 5), (3, 2), (3, 5), (4, 2), (4, 5)}
A B B A
|A B| = |A| |B|
21
Cartesian Product (II) Multiple sets A1, A2, A3, …, AnA1 A2 A3 … An = {(x1, x2, x3, …, xn): xi Ai}
It is possible for some i and j, Ai = Aj.
A = {1, 2, 3, 4}B = {2, 5}A B B = {(a, b, c): a A and b B and c B}
= {(1, 2, 2), (1, 5, 2), (2, 2, 2), (2, 5, 2), (3, 2, 2), (3, 5, 2), (4, 2, 2), (4, 5, 2),
(1, 2, 5), (1, 5, 5), (2, 2, 5), (2, 5, 5), (3, 2, 5), (3, 5, 5), (4, 2, 5), (4, 5, 5)}
22
Assignment 1
Due Wednesday, January 30At beginning of classType your work and submit a hard copy.