Basic Structures: Sets, Functions, Sequences, and Sums
CSC-2259 Discrete Structures
Konstantin Busch - LSU 1
Sets
A set is an unordered collection of objects English alphabet vowels: V {a,e,i,o,u}
Odd positive integers less than 10:
} 9 , 7 , 5 , 3 , 1 {
O elements of set members of set
V
a b V
Konstantin Busch - LSU 3
Other set representations
Set of positive integers less than 100:
} 99 , , 3 , 2 , 1
{
Odd positive integers less than 10:
} 9 , 7 , 5 , 3 , 1 {
O
10}
than less
integer positive
odd an is
| {x x O
10}
and odd is
|
{
x Z x x
O
omitted elements
Venn Diagram
1 3
5 7 9
2
4 6
8
10}
than less
integer positive
odd an is
| {x x O
10}
than less
integer positive
a is
| {x x U
U
O
Universe
Konstantin Busch - LSU 5
Useful sets }
, 3 , 2 , 1 , 0
{
N
} , 2 , 1 , 0 , 1 , 2 ,
{
Z
} , 3 , 2 , 1
{
Z
} 0 ,
,
| /
{
p q p Z q Z q Q
} numbers Real
of set {
R
Natural numbers Integers
Positive integers
Rational numbers Real numbers
Empty set
{}
} {
Konstantin Busch - LSU 7
Cardinality (size) of set
} , , , ,
1 {a e i o u S
} 99 , , 3 , 2 , 1
3 {
S
} , 3 , 2 , 1 , 0
{
N
} , , , ,
2 {a b c z
S
0
| {}
|
|
| |{}|1 5
|
|S1 26
|
|S2
Number of elements
99
|
| S3
infinite size Finite sets
Infinite set
Equal sets B A
) (x A x B x
Examples: {1,3,5}{3,5,1}
} 5 , 5 , 5 , 5 , 3 , 3 , 3 , 1 { } 5 , 3 , 1
{
10}
and odd is
| {
} 9 , 7 , 5 , 3 , 1
{ xZ x x
Konstantin Busch - LSU 9
Subset
B A
) (x A x B x
Examples: {1,3,5}{0,1,3,5} N Z
For any set :
A
B
S S
S S
Proper Subset
B A
)) (
(x A x B y y B y A
x
Examples: {1,3,5}{0,1,3,5} N Z
A B
B A B
A
yKonstantin Busch - LSU 11
B A
A B
B
A
is equivalent to
Power set
The power set of contains all possible subsets of (and the empty set)
S S
} 3 , 2 , 1 {
S
}}
3 , 2 , 1 { }, 3 , 1 { }, 3 , 2 { }, 2 , 1 { }, 3 { }, 2 { }, 1 { , { )
(S P
8 2
2
| ) (
| P S
|S|
3
Size of power set
Power set
Special cases } { )
( P
}}
{ , { })
({ P
Konstantin Busch - LSU 13
Ordered tuples (relations) Ordered n-tuple
( a
1, a
2, , a
n)
ordered list of elements
) , , , ( ) , , ,
( a
1a
2 a
n b
1b
2 b
n iff i ( a
i b
i)
) 1 , 2 ( ) 2 , 1
(
Example:
Cartesian product
Cartesian product of two sets
A, B }
| ) ,
{( a b a A b B B
A
Example:
A { 1 , 2 } B { a , b , c }
)}
, 2 ( ), , 2 ( ), , 2 ( ), , 1 ( ), , 1 ( ), , 1
{( a b c a b c
B A
)}
2 , ( ), 2 , ( ), 2 , ( ), 1 , ( ), 1 , ( ), 1 ,
{(a b c a b c
A B
A B B
A For this case:
6 3 2
|
|
|
|
|
|AB A B Size:
Konstantin Busch - LSU 15
Cartesian product of sets
A
1, A
2, , A
n}
| ) , , , {(
1 22
1
A A
na a a
na
iA
iA
Example:
A { 1 , 2 } B { a , b , c }
)}
, , 2 ( ), , , 2 ( ), , , 2 ( ), , , 1 ( ), , , 1 ( ), , , 1 (
), , , 2 ( ), , , 2 ( ), , , 2 ( ), , , 1 ( ), , , 1 ( ), , , 1 {(
y c y b y a y c y b y a
x c x b x a x
c x b x a C
B A
12 2 3 2
|
|
|
|
|
|
|
| ABC A B C Size:
} , { x y C
|
|
|
|
|
|
|
| A1A2An A1 A2 An
Sets and propositions
)) ( ( P x S
x
shorthand for x ( x S P ( x )) ))
( ( P x S
x
shorthand for x ( x S P ( x ))
Truth set of proposition
P (x ) )}
(
| Domain
{ x P x
all elements of the domain which satisfy
P (x )
Set operations
Konstantin Busch - LSU 17
Union
A B { x | x A x B }
A B
U
} 5 , 3 , 1 {
A B { 1 , 2 , 3 } A B { 1 , 2 , 3 , 5 }
Intersection
}
|
{ x x A x B B
A
U
} 5 , 3 , 1 {
A B { 1 , 2 , 3 } A B { 1 , 3 }
B
A
A B
Konstantin Busch - LSU 19
Disjoint sets
B A
A B
U
} 5 , 3 , 1 {
A B { 2 , 9 } A B B
A,
Set difference
}
|
{ x x A x B B
A
A
B
U
} 5 , 3 , 1 {
A B { 1 , 2 , 3 } A B { 5 } B
A
Konstantin Busch - LSU 21
Complement
}
|
{ x x A
A
A
U
} 5 , 3 , 1 {
A U { 1 , 2 , 3 , 4 , 5 } A { 2 , 4 }
|
|
|
|
|
|
|
| A B A B A B
A B
U
} 5 , 3 , 1 {
A B {1,2,3}
Size of union
4 2 3 3
|
|
|
|
|
|
|
| AB A B AB
} 3 , 1 {
B A } 5 , 3 , 2 , 1 {
B A
B A
Konstantin Busch - LSU 23
De Morgan’s laws
B A
B
A B A
B
A
Show that and Theorem:
A B A B
Proof: AB AB AB AB
B A B
A
Part 1:
) (
) (
) (
) (
) (
) (
) (
)) (
) ((
) (
B A x
B x A x B
x A x
B x A
x B
x A x
B A x B
A x
B A x
De Morgan’s law from logic
Konstantin Busch - LSU 25
Part 2:
B A x
B A x
B x A x B
x A
x
B x A x B
x A x
B A x
) (
)) (
) ((
) (
) (
) (
) (
) (
) (
) (
B A B
A
End of Proof
De Morgan’s law from logic
Set identities
A U A
A A
Identity laws
A
U U A
Domination laws
A A A
A A A
Idempotent laws
A A
Complementation law
Complement laws
A A
U A A
De Morgan’s laws
B A B A
B A B A
Konstantin Busch - LSU 27
A B B A
A B B A
Commutative laws
C B A C
B A
C B A C
B A
) (
) (
) (
) (
Associative laws
A B A A
A B A A
) (
) (
Absorption laws
) (
) (
) (
) (
) (
) (
C A B
A C
B A
C A B
A C
B A
Distributive laws
Generalized unions and intersections
i n
i
n
A
A A
A
1 2
1
i n
i
n
A
A A
A
1 2
1
Konstantin Busch - LSU 29
Example:
A
i { i , i 1 , i 2 , }
} , 3 , 2 , 1 { }
, 2 , 1 ,
{ 1
1 1
A i
i i A
n
i i n
i
} , 2 ,
1 , { }
, 2 , 1 , {
1 1
n n
n A
i i i
A n
n
i i n
i
Computer representation of sets
} 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 {
U
} 9 , 7 , 5 , 3 , 1 {
A 1010101010
Represent sets as binary strings
} 10 , 8 , 6 , 4 , 2 {
B 0101010101
Konstantin Busch - LSU 31
Set operations become binary string operations
} 5 , 4 , 3 , 2 , 1 {
A
1010101010
} 9 , 7 , 5 , 3 , 1 {
B
1111100000
} 9 , 7 , 5 , 4 , 3 , 2 , 1 {
B A
} 5 , 3 , 1 {
B A
1111101010 1010100000
Bitwise OR
Bitwise AND
1111111111
:
0100000000 :
} {
1000000000 :
} {
0000000000
:
2 1
S a a
Powerset of S {a1,a2,a3,,an1,an}
bits n
ns combinatio 2
n) (S P
elements n
|
2
|2
| ) (
| P S
n
S) (S P
Functions
Konstantin Busch - LSU 33
Adams Chou Goodfriend
Rodriguez Stevens
A B C D F
Names Grades
C
f ( Chou) f ( Rodriguez) A
B A
f :
A B
a f ( a ) b
f
f
Domain Codomain
Image of
a
Every element of domain has exactly one image
maps to
A B
Konstantin Busch - LSU 35
Adams Chou Goodfriend
Rodriguez Stevens
A B C D F
Stevens}
Rodriguez, ,
Goodfriend Chou,
{Adams, Domain
F}
D, C, B, {A, Codomain
F}
C, B, {A,
Range set of all images
Domain Codomain
f f
f
Z Z
f :
)
2( x x
f
Z Domain
Z Codomain
} {0,1,4,9,
Range
Konstantin Busch - LSU 37
Equal functions
B A
f : g : C D
g f
B A
D B
) ( )
(
, f x g x A
x
same domain same codomain
same mapping
In some programming languages,
domain and codomain are explicitly defined
int f(int a) { return a*a;
}
Konstantin Busch - LSU 39
Add and multiply functions
R A
f
1:
Real numbers
R A
f
2:
) ( )
( )
)(
( f
1 f
2x f
1x f
2x ) ( ) ( )
)(
( f
1f
2x f
1x f
2x
Example:
f
1( x ) x
2f
2( x ) x x
2x x
x x x f x f x f
f )( ) ( ) ( ) ( )
( 1 2 1 2 2 2
4 3 2
2 2
1 2
1 )( ) ( ) ( ) ( )
(f f x f x f x x xx x x
Image of set
}
| ) ( {
))}
( (
| { ) (
S x x f
x f t S x t S
f
Example:
f ( x ) x
2} 9 , 4 , 1 { }) 3 , 2 , 1
({
f
Set
S
Konstantin Busch - LSU 41
One-to-one (injection) function
) ( )
( x f y
f
impliesx y
For every in domain
x, y
Examples:
f ( x ) x 1
is one-to-one)
2( x x
g
is not one-to-one: g(1) g(1)1a 1
b 2
c d
3 4 5
Each element of range is image of one element of domain
Increasing function:
x y f ( x ) f ( y )
Strictly increasing:
x y f ( x ) f ( y )
Strictly increasing functions are one-to-one
Konstantin Busch - LSU 43
Onto (surjection) function
y x
f ( )
For every there is such that
B y
Examples:
f ( x ) x 1
is onto)
2( x x
g
is not onto: xZ,g(x) 1a 1
b 2
c d
3
B A
f : B x
Range = Codomain
One-to-one correspondence (bijection) function
Examples:
f ( x ) x 1
is bijection)
2( x x
g
is not bijectiona 1
b 2
c d
3
a function which is one-to-one and onto
4
x x )
(
is bijection Identity functionKonstantin Busch - LSU 45
a 1
b 2
c 3
4
one-to-one not onto
a 1
b 2
c 3
not one-to-one onto
d
a 1
b 2
c d
3 4
one-to-one onto
a 1
b 2
c d
3 4
not one-to-one not onto
a 1
b 2
c 3
4
not a function
Inverse of a bijection function
f x
y
f
1( )
whenf ( x ) y
1
f
a 1
b 2
c d
3 4
domain
f
codomaina 1
b 2
c d
3 4 1
f
codomain domain
f
is invertible functionExample:
f ( x ) x 1 f
1( y ) y 1
Konstantin Busch - LSU 47
A B
)
1
( b f
a
b f (a )
) (a f
)
1
( b f
Composition of functions
C B
f : B A
g : ( f g )( x ) f ( g ( x )) C A
g
f :
Example:
f ( x ) 2 x g ( x ) x
22 2
) 2 (
)) ( ( )
)(
( f g x f g x f x x
2
2
4
) 2 ( ) 2 ( ))
( ( )
)(
( g f x g f x g x x x
Konstantin Busch - LSU 49
i f f
f
f
1
1
identity function
y x
f y
f f y f
f
)( ) (
( )) ( )
(
1 1x y
f x
f f x f
f
)( )
( ( ))
( )
(
1
1 1Suppose
f ( x ) y
Floor and Ceiling
Floor function:
Let be real
x
x
largest integer less or equal tox
Ceiling function:
x
smallest integergreater or equal to
x
Examples: 0
2 1
1
2 1
3.14 3.13
Konstantin Busch - LSU 51
Factorial function
Z
N
f : f ( n ) n ! 1 2 3 ( n 1 ) n 1
! 0 ) 0
( f
1
!
1 2 ! 1 2 2 6 ! 1 2 3 4 5 6 760 000 , 640 , 176 , 008 , 902 , 432 , 2 20 19 3
2 1
!
20
Stirling’s formula:
n
e n n
n
2
!
Sequences
2, 4, 6, 8, 10 1,3,9,27,81,…
Finite sequence Infinite sequence
function from a subset of integers to a set
S
Sequence:
a
nn f ( )
1,
1,3,9,27,8
, , , , , }
{
1 2 3 4 5
a a a a a a
n2 )
1
( a
1 f
10 )
5
( a
5 f
5 4 3 2
1,a ,a ,a ,a a
Alternate representation
0 ,
3
k
a
n kKonstantin Busch - LSU 53
a
na
a
1,
2, , a
na a
a
1 2 3
n a
a
a
n|
|
1 2
Length of string:
finite sequence:
Empty string (null):
| | 0
String:
all elements of sequence concatenated
Arithmetic progression
, ,
, 2 ,
, a d a d a nd
a
Initial term
a
Common difference
d
Example:
{ s
n} 1 4 n , 11 , 7 , 3 , 1
0
start with
n
Konstantin Busch - LSU 55
Geometric progression
, , ,
,
, ar ar
2ar
na
Initial term
a
Common ratio
r
Example:
{ c
n} 2 5
n, 1250 ,
250 , 50 , 10 , 2
0
start with
n
Summations
n m
m
m
a a a
a ,
1,
2, ,
n
m i
i n
m m
m
a a a a
a
1 2
Sum:
Sequence:
Example:
1 2 3 4 5
255
5
1
2 2 2 2
2
i
i
Konstantin Busch - LSU 57
Theorem:
2 ) 1 (
1
n i n
n
i
Proof:
1 1
1 1
1 1
} {
1 2
3 2
1 }
{
1 4
3 2
1 }
{
n n
n n
n n
c
n n
n n b
n n
a
n n n
n
i i n
i i n
i
b a
i S
1 1
1
S b a
c n
n
n
i i n
i i n
i
i 2
) 1 (
1 1
1
2 ) 1
n( n S
End of Proof
Theorem: If are real numbers and , then
r a,
} 1 , 0 {
r
1
1
0
ar ar r a
n n
i
i
Proof:
n
i
ar
iS
0
Let
Konstantin Busch - LSU 59
) (
) (
1
1 0
1
1 0
1 0
a ar
S
a ar
ar ar ar ar r rS
n
n n
k k n
k k n
i i n
i i
rS S ( ar
n1 a )
1
1
r
a S ar
n
End of Proof
Useful Summation Formulas
1
|
| 1 ,
1
} 1 , 0 { 1 ,
6
) 1 2 )(
1 (
2 ) 1 (
0
1
0 1
2 1
x x x
r r
a ar ar
n n
i n
n i n
i i n n
i
i n
i n
i
Countable Sets
Konstantin Busch - LSU 61
Any finite set is countable by default
An infinite set is countable if there is a one-to-one correspondence from to
S
S
Countable finite set:
Countable infinite set:
Z
Positive integers
Even positive integers:
2 , 4 , 6 , 8 ,
Positive integers:
One-to-one
Correspondence:
, 4 , 3 , 2 , 1
n
corresponds to2 n
Theorem: Even positive integers are countable
Proof:
Konstantin Busch - LSU 63
The set of rational numbers is countable
all rational numbers:
, 8
, 7 4 , 3 2 1
Theorem:
Proof:
We need to find a method to list
Naïve Approach
Rational numbers: , 3 , 1 2 , 1 1 1
Positive integers:
One-to-one
correspondence:
, 3 , 2 , 1
Doesn’t work:
we will never list
numbers with nominator 2:
, 3 , 2 2 , 2 1 2
Start with nominator=1
Konstantin Busch - LSU 65
Better Approach: scan diagonals
1 1
2 1
3 1
4 1
1 2
2 2
3 2
1 3
2 3
1 4
Nomin.=1
Nomin.=2
Nomin.=3
Nomin.=4
1 1
2 1
3 1
4 1
1 2
2 2
3 2
1 3
2 3
4
first diagonal
Konstantin Busch - LSU 67
1 1
2 1
3 1
4 1
1 2
2 2
3 2
1 3
2 3
1 4
second diagonal
1 1
2 1
3 1
4 1
1 2
2 2
3 2
1 3
2 3
4
third diagonal
Konstantin Busch - LSU 69
1 1
2 1
3 1
4 1
1 2
2 2
3 2
1 3
2 3
1 4
Every element will be eventually scanned
fourth diagonal…
Rational Numbers:
,
2 , 2 3 , 1 1 , 2 2 , 1 1 1
One-to-one
correspondence:
Positive Integers:
1 , 2 , 3 , 4 , 5 ,
End of Proof Diagonal listing
Konstantin Busch - LSU 71
Theorem: Set is uncountable
S ( 0 , 1 ) R
Proof: Assume that is countable,
S
then we can list its elements
} , , ,
{ s
1s
2s
3 S
Elements of
S
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
List the elements of
S ( 0 , 1 )
Konstantin Busch - LSU 73 10
9 8 7 6 5 4 3 2
. 1
0 x x x x x x x x x x
t
Create new element based on diagonal
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
10
9 8 7 6 5 4 3
1 2
.
0 x x x x x x x x x
t
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
If diagonal element is 0 then set digit to 1
Konstantin Busch - LSU 75 10
9 8 7 6 5 4
0 3
1 .
0 x x x x x x x x
t
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
If diagonal element is not 0 then set digit to 0
10
9 8 7 6 5
1 4
0 1 .
0 x x x x x x x
t
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
If diagonal element is 0 then set digit to 1
Konstantin Busch - LSU 77 10
9 8 7 6
1 5
1 0 1 .
0 x x x x x x
t
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
If diagonal element is 0 then set digit to 1
10
9 8 7
0 6
1 1 0 1 .
0 x x x x x
t
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
If diagonal element is not 0 then set digit to 0
Konstantin Busch - LSU 79
1 0 1 1 0 1 . 0
t
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s
By repeating process we obtain new number
) 1 , 0 (
1 0 1 1 0 1 . 0
t
1 2 5 1 2 4 8 1 6 4 . 0
3 1 1 2 3 0 0 1 2 3 . 0
4 8 1 3 5 0 2 0 3 1 . 0
1 3 7 5 1 2 3 1 2 1 . 0
6 1 2 4 9 2 5 4 1 0 . 0
5 4 3 2 1
s s s s s