Upload
maude-horn
View
214
Download
0
Embed Size (px)
Citation preview
Discrete Structure
Sets
2
Set Theory• Set: Collection of objects (“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…”
• Order of elements is meaningless
• It does not matter how often the same element is listed.
SetsCurly braces “{“ and “}” are used to denote
sets.Java note: In Java curly braces denote
arrays, a data-structure with inherent ordering.
Mathematical sets are unordered so different from Java arrays. Java arrays require that all elements be of the same type.
Mathematical sets don’t require this, however. EG: { }
Standard Numerical SetsThe natural numbers:N = { 0, 1, 2, 3, 4, … }
The integers:Z = { … -3, -2, -1, 0, 1, 2, 3, … }
The positive integers:Z+ = {1, 2, 3, 4, 5, … }
The real numbers: R --contains any decimal number of arbitrary precision The rational numbers: Q --these are decimal numbers whose decimal expansion repeats
Q: Give examples of numbers in R but not Q.
Set Theory
(a) Z=the set of integers={0,1,-1,2,-1,3,-3,...}(b) N=the set of nonnegative integers or natural numbers(c) Z+=the set of positive integers(d) Q=the set of rational numbers={a/b| a,b is integer, b not zero}(e) Q+=the set of positive rational numbers(f) Q*=the set of nonzero rational numbers(g) R=the set of real numbers(h) R+=the set of positive real numbers(i) R*=the set of nonzero real numbers(j) C=the set of complex numbers
-NotationThe Greek letter “” (epsilon) is used to denote that
an object is an element of a set. When crossed out “” denotes that the object is not an element.”
EG: 3 S reads:“3 is an element of the set S ”.
Q: Which of the following are true:1. 3 R2. -3 N3. -3 R4. 0 Z+
5. x xR x2=-5
7
Examples for Sets• A = or A={ } “empty set/null
set”
• A = {z} Note: zA, but z {z}
• A = {{b, c}, {c, x, d}}
• A = {{x, y}} Note: {x, y} A, but {x, y} {{x, y}}
• A = {x | P(x)}“set of all x such that P(x)”
• A = {x | xN x > 7} = {8, 9, 10, …}“set builder notation”
Set Builder NotationUp to now sets have been defined using the
curly brace notation “{ … }” or descriptively “the set of all natural numbers”. The set builder notation allows for concise definition of new sets. For example { x | x is an even integer } { 2x | x is an integer }
are equivalent ways of specifying the set of all even integers.
9
Set Operations
Union: AB = {x | xA xB}
Example: A = {a, b}, B = {b, c, d} AB = {a, b, c, d}
Intersection: AB = {x | xA xB}
Example: A = {a, b}, B = {b, c, d} AB = {b}
Set Builder Notation.Examples.
A1: U = N. { x | y (y x ) } = { 0 }A2: U = Z. { x | y (y x ) } = { }
A3: U = Z. { x | y (y R y 2 = x )}
= { 0, 1, 2, 3, 4, … } = N
A4: U = Z. { x | y (y R y 3 = x )} = Z
A5: U = R. { |x | | x Z } = NA6: U = R. { |x | } = non-negative reals.
L4 11
-NotationDEF: A set S is said to be a subset of the set T iff
every element of S is also an element of T. This situation is denoted by
S TA synonym of “subset” is “contained by”.Definitions are often just a means of establishing
a logical equivalence which aids in notation. The definition above says that:
S T x (xS ) (xT )We already had all the necessary concepts, but
the “” notation saves work.
L4 12
-NotationWhen “” is used instead of “”, proper
containment is meant. A subset S of T is said to be a proper subset if S is not equal to T. Notationally:
S T S T x (x S xT )
Q: What algebraic symbol is reminiscent of?
13
SubsetsUseful rules:
• A = B (A B) (B A) • (A B) (B C) A C (see Venn Diagram)
UU
AABB CC
Union
AB = { x | x A x B }
Elements in at least one of the two sets:
A B
U
AB
Intersection
AB = { x | x A x B }
Elements in exactly one of the two sets:
A B
U
AB
Disjoint SetsDEF: If A and B have no common elements, theyare said to be disjoint, i.e. A B = .
A B
U
Set Difference
AB = { x | x A x B }
Elements in first set but not second:
A
B
U
AB
Symmetric Difference
A B
UAB
AB = { x | x A x B }
Elements in exactly one of the two sets:
Complement
A = { x | x A }
Elements not in the set (unary operator):
A
U
A
Set Identities
Identity laws Domination laws Idempotent laws Double complementation Commutativity Associativity Distribuitivity DeMorgan
logical identities rewriting as follows: disjunction “” becomes union “” conjunction “” becomes intersection “” negation “” becomes complementation “–” false “F” becomes the empty set true “T” becomes the universe of reference U
Set Identities
In fact, the logical identities create the set identities by applying the definitions of the various set operations. For example:
LEMMA: (Associativity of Unions) (AB )C = A(B C )
Proof : (AB )C = {x | x A B x C } (by def.)= {x | (x A x B ) x C } (by def.)= {x | x A ( x B x C ) } (logical
assoc.)= {x | x A (x B C ) } (by def.)= A(B C ) (by def.)
�Other identities are derived similarly.
L5 22
Visual DeMorgan
=BA
BA
Cardinality
The cardinality of a set is the number of distinct elements in the set. |S | denotes the cardinality of S.
Q: Compute each cardinality.1. |{1, -13, 4, -13, 1}|2. |{3, {1,2,3,4}, }|3. |{}|4. |{ {}, {{}}, {{{}}} }|
L4 24
Cardinality
Hint: After eliminating the redundancies just look at the number of top level commas and add 1 (except for the empty set).
A:1. |{1, -13, 4, -13, 1}| = |{1, -13, 4}| = 32. |{3, {1,2,3,4}, }| = 3. To see this, set S =
{1,2,3,4}. Compute the cardinality of {3,S, }
3. |{}| = || = 04. |{ {}, {{}}, {{{}}} }|
= |{ , {}, {{}}| = 3
L4 25
Cardinality
DEF: The set S is said to be finite if its cardinality is a nonnegative integer. Otherwise, S is said to be infinite.
EG: N, Z, Z+, R, Q are each infinite.
Note: We’ll see later that not all infinities are the same. In fact, R will end up having a bigger infinity-type than N, but surprisingly, N has same infinity-type as Z, Z+, and Q.
Set Theory
Counting and Venn Diagrams
In a class of 50 college freshmen, 30 are studyingBASIC, 25 studying PASCAL, and 10 are studying both. How
many freshmen are studying either computer language?
U A B
10 1520
5| | | | | | | |A B A B A B
Set Theory
Counting and Venn Diagrams
Given 100 samplesset A: with D1
set B: with D2
set C: with D3
Defect types of an AND gate:D1: first input stuck at 0
D2: second input stuck at 0D3: output stuck at 1
with |A|=23, |B|=26, |C|=30,
| | , | | , | | ,| |A B A C B CA B C
7 8 103 , how many samples have defects?
A
B
C
11 4
35
7
12
15
43
Ans:57
| | | | | | | | | || | | | | |A B C A B C A B
A C B C A B C
Power Set
DEF: The power set of S is the set of all subsets of S.
Denote the power set by P (S ) or by 2s .
The latter weird notation comes from the following.
Lemma: | 2s | = 2|s|
Power Set –ExampleTo understand the previous fact consider
S = {1,2,3}Enumerate all the subsets of S :0-element sets: {} 1 1-element sets: {1}, {2}, {3} +32-element sets: {1,2}, {1,3}, {2,3} +33-element sets: {1,2,3} +1Therefore: | 2s | = 8 = 23 = 2|s|
Cartesian ProductThe most famous example of 2-tuples are points
in the Cartesian plane R2. Here ordered pairs (x,y) of elements of R describe the coordinates of each point. We can think of the first coordinate as the value on the x-axis and the second coordinate as the value on the y-axis.
DEF: The Cartesian product of two sets A and B –denoted by A B– is the set of all ordered pairs (a, b) where aA and bB .
Q: Describe R2 as the Cartesian product of two sets.
Cartesian ProductA: A = {1,2}, B = {3,4}, C = {5,6,7}A B C ={ (1,3,5), (1,3,6), (1,3,7),
(1,4,5), (1,4,6), (1,4,7), (2,3,5), (2,3,6), (2,3,7), (2,4,5), (2,4,6), (2,4,7) }
Lemma: The cardinality of the Cartesian product is the product of the cardinalities:
| A1 A2 … An | = |A1||A2| … |An| Q: What does S equal?
Set Theory
Set Operations and the Laws of Set Theory
The Laws of Set Theory
A)BA(A
Laws Absorption A)BA(A (10)
Laws Domination =A ,UUA (9)
Laws Inverse AA ,UAA (8)
Laws Identity AUA ,AA (7)
Laws Idempotent AAA ,AAA (6)
Set Theory
Set Operations and the Laws of Set Theory
The Laws of Set Theory
)()()(
Laws )()()( (5)
)()(
Laws )()( (4)
Laws (3)
Laws ' (2)
of Law )1(
CABACBA
veDistributiCABACBA
CBACBA
eAssociativCBACBA
ABBA
eCommutativABBA
BABA
sDemorganBABA
ComplementDoubleAA
Generalized Union
Binary union operator: ABn-ary union:AA2…An : ((…((A1 A2) …) An)(grouping & order is irrelevant)“Big U” notation:
Or for infinite sets of sets:
n
iiA
1
XA
A
Generalized Intersection
Binary intersection operator: ABn-ary intersection:AA2…An((…((A1A2)…)An)(grouping & order is irrelevant)“Big Arch” notation:
Or for infinite sets of sets:
n
iiA
1
XA
A
Mutual subsetsExample: Show A(BC)=(AB)(AC).
Show A(BC)(AB)(AC). Assume xA(BC), & show x(AB)(AC). We know that xA, and either xB or xC.
Case 1: xB. Then xAB, so x(AB)(AC). Case 2: xC. Then xAC , so x(AB)(AC).
Therefore, x(AB)(AC). Therefore, A(BC)(AB)(AC).
Show (AB)(AC) A(BC). …
Membership Table Exercise
Prove (AB)C = (AC)(BC).A B C AABB ((AABB)) CC AA CC BB CC ((AA CC))((BB CC))0 0 00 0 10 1 00 1 11 0 01 0 11 1 01 1 1
Ordered n-tuplesNotationally, n-tuples look like sets except
that curly braces are replaced by parentheses: ( 11, 12 ) –a 2-tuple aka ordered pair ( , , ) –a 3-tuple ( , , , 11, Leo ) –a 5-tuple
Java: n -tuples are similar to Java arrays “{…}”, except that type-mixing isn’t allowed in Java.As opposed to sets, repetition and ordering do matter with n-tuples. (11, 11, 11, 12, 13) ( 11, 12, 13 ) ( , , ) ( , , )
39
Exercises
Question 1:
Given a set A = {x, y, z} and a set B = {1, 2, 3, 4}, what is the value of | 2A 2B | ?
Question 2:
Is it true for all sets A and B that (AB)(BA) = ?Or do A and B have to meet certain conditions?
Question 3:
For any two sets A and B, if A – B = and B – A = , can we conclude that A = B? Why or why not?
Blackboard Exercise
Prove the following:If A B and B C then A C .
Set Theory
BABABA
ABxAxxBA
BA
B }|{
. Negate Ex.
BABA
BABABAAB
BBAABABABA
BABABABABA
BABABABA
BAxBAxxBA
BA
)()()()(
])[(])[()()(
)()()(
)()()()(
}|{
. Negate Ex.