Title: DISCRETE STRUCTURES
1DISCRETE STRUCTURES
- Lecture 4 Chapter 2
- CS 216
- Washington State University
- Winter/Spring 2009
- Dr. Sarah Mocas
2Chapter 2
- Sets, set operators
- Functions, relations and their properties
- Sequences and tuples
- Little on summations
3Chapter 2 - Set Theory
- Set Collection of objects (elements)
- a?A a is an element of
A a is a member
of A - a?A 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.
4Set Equality
- Sets A and B are equal if and only if they
contain exactly the same elements. - Examples
- A 9, 2, 7, -3, B 7, 9, -3, 2
A B
- A dog, cat, horse, B cat, horse,
squirrel, dog
A ? B
- A dog, cat, horse, B cat, horse, dog,
dog
A B
5Examples for Sets
- Standard Sets
- Natural numbers N 0, 1, 2, 3,
- Integers Z , -2, -1, 0, 1, 2,
- Positive Integers Z 1, 2, 3, 4,
- Real Numbers R 47.3, -12, ?,
- Rational Numbers Q 1.5, 2.6, -3.8, 15,
(correct definition will follow)
6Examples for Sets
- A ? empty set/null
set - A z Note z?A, but z ? z
- A b, c, c, x, d
- A x, y Note x, y ?A, but x, y ? x,
y - set builder notation
- A x P(x) set of all x such that P(x)
- A x x?N ? x 7 8, 9, 10, set of
all natural numbers greater than 7
7Examples for Sets
- We are now able to define the set of rational
numbers Q - Q a/b a?Z ? b?Z or
- Q a/b a?Z ? b?Z ? b?0
- And how about the set of real numbers R?
- R r r is a real numberThat is the best we
can do.
8Subsets
- A ? B A is a subset of B
- A ? B if and only if every element of A is
also an element of B. - We can completely formalize this
- A ? B ? ?x (x?A ? x?B)
- Examples
A 3, 9, B 5, 9, 1, 3, A ? B ?
true
A 3, 3, 3, 9, B 5, 9, 1, 3, A ? B ?
true
false
A 1, 2, 3, B 2, 3, 4, A ? B ?
9Subsets
A equal B if and only if A is a subset of B and B
is a subset of A
- Useful rules
- A B ? (A ? B) ? (B ? A)
- (A ? B) ? (B ? C) ? A ? C (see Venn Diagram)
A is a subset of B and B is a proper subset of C
implies A is a proper subset of C
10Subsets
- Useful rules
- ? ? A for any set A
- A ? A for any set A
- Proper subsets
- A ? B A is a proper subset of B
- A ? B ? ?x (x?A ? x?B) ? ?x (x?B ? x?A)
- or
- A ? B ? ?x (x?A ? x?B) ? ??x (x?B ? x?A)
11Cardinality of Sets
- If a set S contains n distinct elements, n?N, we
call S a finite set with cardinality n. - Examples
- A Mercedes, BMW, Porsche, A 3
B 1, 2, 3, 4, 5, 6
B 4
C ?
C 0
D x?N x ? 7000
D 7001
E x?N x ? 7000
E is infinite!
12The Power Set
- 2A or P(A) power set of A
- 2A B B ? A (contains all subsets of A)
- Examples
- A x, y, z
- 2A ?, x, y, z, x, y, x, z, y, z,
x, y, z - A ?
- 2A ?
- Note If A ? then A 0 and 2A 1
13The Power Set
- Cardinality of power sets
- 2A 2A
- Imagine each element in A has an on/off switch
- Each possible switch configuration in A
corresponds to one element in 2A
- For 3 elements in A, there are 2?2?2 8
elements in 2A
14Cartesian Product
- The ordered n-tuple (a1, a2, a3, , an) is an
ordered collection of objects. - Two ordered n-tuples (a1, a2, a3, , an) and
(b1, b2, b3, , bn) are equal if and only if
they contain exactly the same elements in the
same order, i.e. ai bi for 1 ? i ? n. - The Cartesian product of two sets is defined as
- A?B (a, b) a?A ? b?B
- Example A x, y, B a, b, cA?B (x, a),
(x, b), (x, c), (y, a), (y, b), (y, c)
15Cartesian Product
- Note that A?? ?
- ??A ?
- For non-empty sets A and B
- A?B ? A?B ? B?A
- A?B A?B
- Says - the cardinality of A?B is the
multiplication of A and B - The Cartesian product of two or more sets is
defined as - A1?A2??An (a1, a2, , an) ai?Ai for 1 ? i ?
n
16Cartesian Product
- Example Cartesian product of two or more sets
is A1?A2??An (a1, a2, , an) ai?Ai for 1 ?
i ? n - A 1, 4, 5, 6 so A 4
- B 1,2, 3 so A 3
- A?B (1,1), (1,2), (1,3), (4,1), (4,2),
(4,3), (5,1), (5,2), (5,3), (6,1), (6,2),
(6,3) - so A?B A?B 4?3 12
17Set Operations
- Union A?B x x?A ? x?B
- Example A a, b, B b, c, d
- A?B a, b, c, d
- Intersection A?B x x?A ? x?B
- Example A a, b, B b, c, d
- A?B b
18Set Operations
- Two sets are called disjoint if their
intersection is empty, that is, they share no
elements - A?B ?
- The difference between two sets A and B contains
exactly those elements of A that are not in B
A-B x x?A ? x?B - Example A a, b, B b, c, d, A-B a
19Set Operations
- The complement of a set A contains exactly those
elements under consideration that are not in A - -A U - A
- Box is U the universal
- set the elements
- under consideration
- Example U N, B 250, 251, 252,
- -B 0, 1, 2, , 248,
249
B
-B
20Set Operations
- Table 1 in Section 2.2 (6Th edition) shows many
useful equations. - How can we prove A?(B?C) (A?B)?(A?C)?
- Method I
- x?A?(B?C)
- x?A ? x?(B?C)
- x?A ? (x?B ? x?C)
- (x?A ? x?B) ? (x?A ? x?C) (distributive law for
logical expressions) - x?(A?B) ? x?(A?C)
- x?(A?B)?(A?C)
Definitions used are Union A?B x x?A ?
x?B Intersection A?B x x?A ? x?B
21- Prove A?(B?C) (A?B)?(A?C)
- Method II Membership table
- 1 means x is an element of this set0 means x
is not an element of this set
22Venn Diagrams
A?B
A?B
A-B x x?A ? x?B
(A?B)
A
A
-A U - A
A?B ?
23Venn Diagrams
- Generalization of Union and Intersection
- What is A?B?C ?
- What is A?B?C ?
- General Definition
- A1?A2 ? ?An U Ai where the union is from 1
to n - A1?A2 ? ? An n Ai where the union is from 1
to n - Also
- U Ai where the union is from 1 to infinity
- n Ai where the union is from 1 to infinity
U
A
C
B
24Chapter 2 Sets with Quantifiers
- Quantifiers are used with predicates and a
universe of discourse U.D. - Example P(x) is true if x mod 2 0 where U.D.
N - This truth set for P(x) can be defined as
- EVEN x ?N P(x)
- EVEN x x ?N and x mod 2 0
- We can also make statements like
- ?x?N (x mod 2 0)
- ?x?N (x mod 2 0)
25Sets in Computers
Use a bit string to represent a set Let U a1,
a2, , an. Then some S ? U can be represented as
a bit string where a bit bi 1 if and only if si
?S Example Let U Boston, New York, Hong
Kong, Moscow Then S New York, Hong
Kong can be represented as a bit string bits
0110
26Chapter 2 - Functions
- A function f from a set A to a set B is an
assignment of exactly one element of B to each
element of A. - We write f(a) b if b is the unique element of
B assigned by the function f to the element a of
A. - If f is a function from A to B, we write
- f A?B
- (note Here ? has nothing to do with if then)
27Functions
- If fA?B, we say that A is the domain of f and B
is the codomain of f. - If f(a) b, we say that b is the image of a and
a is the pre-image of b.
f(a) b
a
b
B
A
28Functions
- The range of fA?B is the set of all images of
elements of A. - We say that fA?B maps A to B.
f(a) b
a
b
B
A
29Functions
- Let us take a look at the function fP?C with
- P Linda, Max, Kathy, Peter
- C Boston, New York, Hong Kong,
Moscow - f(Linda) Moscow
- f(Max) Boston
- f(Kathy) Hong Kong
- f(Peter) New York
- Here, the range of f is C.
30Functions
- Let us re-specify f as follows
- f(Linda) Moscow
- f(Max) Boston
- f(Kathy) Hong Kong
- f(Peter) Boston
- Is f still a function?
yes
Moscow, Boston, Hong Kong
What is its range?
31Functions
- Other ways to represent f
32Functions
- If the domain of our function f is large, it is
convenient to specify f with a formula, e.g. - fZ?R
- f(x) 2x
- This leads to
- f(0) 0
- f(1) 2
- f(-1) -2
33Functions
- Let f1 and f2 be functions from A to R.
- Then the sum and the product of f1 and f2 are
also functions from A to R defined by - (f1 f2)(x) f1(x) f2(x)
- (f1f2)(x) f1(x) f2(x)
- Example
- f1(x) 3x, f2(x) x 5
- (f1 f2)(x) f1(x) f2(x) 3x x 5 4x
5 - (f1f2)(x) f1(x) f2(x) 3x (x 5) 3x2 15x
34Functions
- We already know that the range of a function
fA?B is the set of all images of elements a?A. - If we only consider a subset S?A, the set of all
images of elements s?S is called the image of S. - We denote the image of S by f(S)
- f(S) f(s) s?S
35Functions
- Let us look at the following well-known function
- f(Linda) Moscow
- f(Max) Boston
- f(Kathy) Hong Kong
- f(Peter) Boston
- What is the image of S Linda, Max ?
- f(S) Moscow, Boston
- What is the image of S Max, Peter ?
- f(S) Boston
36Properties of Functions
- A function fA?B is said to be one-to-one (or
injective or 1-1), if and only if - ?x, y?A (f(x) f(y) ? x y)
- So f is one-to-one if and only if it does not map
two distinct elements of A onto the same element
of B.
f(a) b
a
b
B
A
37Properties of Functions
- And again
- f(Linda) Moscow
- f(Max) Boston
- f(Kathy) Hong Kong
- f(Peter) Boston
- Is f one-to-one?
- No, Max and Peter are mapped onto the same
element of the image.
g(Linda) Moscow g(Max) Boston g(Kathy)
Hong Kong g(Peter) New York Is g
one-to-one? Yes, each element is assigned a
unique element of the image.
38Properties of Functions
- How can we prove that a function f is not
one-to-one? - Whenever you want to prove something, first take
a look at the definition(s) - Definition f is 1-1 if
- ?x, y?A (f(x) f(y) ? x y)
39Properties of Functions
- Statement The function f(x) x2 is not
one-to-one for every mapping. - Proof Assume that f(x) x2 is one-to-one where
fZ?R. But then by definition of 1-1 - ?x, y?A (f(x) f(y) ? x y)
- Now let x 3 and y -3.
- Then f(3) f(-3) 9, but 3 ? -3, so f is not
one-to-one. Disproofed by counterexample. - Done.
40Properties of Functions
- and yet another example
- fR?R
- f(x) 3x
- One-to-one by definition ?x, y?A (f(x) f(y) ?
x y) - To show f(x) ? f(y) whenever x ? y
- Let x ? y
- ? 3x ? 3y (multiply through by 3)
- ? f(x) ? f(y),
- so if x ? y, then f(x) ? f(y), that is, f is
one-to-one.
41Properties of Functions
- A function fA?B with A,B ? R is called strictly
increasing, if - ?x,y?A (x
- and strictly decreasing, if
- ?x,y?A (x f(y))
- A function that is either strictly increasing or
strictly decreasing is one-to-one.
42Properties of Functions
- strictly increasing ?x,y?A (x
- 0
- strictly decreasing ?x,y?A (x f(y))
NOT strictly increasing
NOT strictly decreasing
43Properties of Functions
- A function fA?B is called onto, or surjective,
if and only if for every element b?B there is an
element a?A with f(a) b. - In other words, f is onto if and only if its
range is its entire codomain. - A function f A?B is a one-to-one correspondence,
or a bijection, if and only if it is both
one-to-one and onto. - If f is a bijection and A and B are finite sets,
then A B.
44Properties of Functions
Let fN ?N f(x) x2
2
4
3
9
4
14
B
A
Let gN ?N g(x) ? lg x ?
2
1
3
- one-to-one or injective
- onto, or surjective
- bijection, both one-to-one and onto.
2
4
B
A
45Properties of Functions
- Examples
- In the following examples, we use the arrow
representation to illustrate functions fA?B. - In each example, the complete sets A and B are
shown.
46Properties of Functions
- Is f injective?
- No.
- Is f surjective?
- No.
- Is f bijective?
- No.
- one-to-one or injective
- onto, or surjective
- bijection, if and only if it is both one-to-one
and onto.
47Properties of Functions
- Is f injective?
- No.
- Is f surjective?
- Yes.
- Is f bijective?
- No.
Paul
- one-to-one or injective
- onto, or surjective
- bijection, if and only if it is both one-to-one
and onto.
48Properties of Functions
- Is f injective?
- Yes.
- Is f surjective?
- No.
- Is f bijective?
- No.
- one-to-one or injective
- onto, or surjective
- bijection, if and only if it is both one-to-one
and onto.
49Properties of Functions
- Is f injective?
- No! f is not evena function!
- one-to-one or injective
- onto, or surjective
- bijection, if and only if it is both one-to-one
and onto.
50Properties of Functions
Linda
Boston
- Is f injective?
- Yes.
- Is f surjective?
- Yes.
- Is f bijective?
- Yes.
Max
New York
Kathy
Hong Kong
Peter
Moscow
Lübeck
Helena
- one-to-one or injective
- onto, or surjective
- bijection, if and only if it is both one-to-one
and onto.
51Inversion
- An interesting property of bijections is that
they have an inverse function. - The inverse function of the bijection fA?B is
the function f-1B?A with - f-1(b) a whenever f(a) b.
- Example
- f(x) x2 then f-1(y) x-2
52Inversion
Linda
Boston
Max
New York
Kathy
Hong Kong
Peter
Moscow
Lübeck
Helena
53Inversion
The inverse function f-1 is given
by f-1(Moscow) Linda f-1(Boston)
Max f-1(Hong Kong) Kathy f-1(Lübeck)
Peter f-1(New York) Helena Inversion is only
possible for bijections( invertible functions)
Example f(Linda) Moscow f(Max)
Boston f(Kathy) Hong Kong f(Peter)
Lübeck f(Helena) New York Clearly, f is
bijective.
54Inversion
Linda
Boston
Max
New York
- f-1C? P is not a function, because it is not
defined for all elements of C and assigns two
images to the pre-image New York.
Kathy
Hong Kong
Peter
Moscow
Lübeck
Helena
55Composition
- The composition of two functions gA?B and
fB?C, denoted by f?g, is defined by - (f?g)(a) f(g(a))
- This means that
- first, function g is applied to element a?A,
mapping it onto an element of B, - then, function f is applied to this element of B,
mapping it onto an element of C. - Therefore, the composite function maps from
A to C.
56Composition
- Example (f?g)(a) f(g(a))
- f(x) 7x 4, g(x) 3x,
- fR?R, gR?R
- (f?g)(5) f(g(5)) f(15) 105 4 101
- (f?g)(x) f(g(x)) f(3x) 21x - 4
57Composition
- Composition of a function and its inverse
- (f-1?f)(x) f-1(f(x)) x
- The composition of a function and its inverse is
the identity function i(x) x. - Example Let f(x) 2x so f-1(y) y/2 now
- f-1(f(x)) (2x)/2 x
- Example Let f(x) 2x so f-1(y) lg y now
- f-1(f(x)) lg(2x) x lg2 x
58Graphs
- The graph of a function fA?B is the set of
ordered pairs - (a, b) a?A and f(a) b
- The graph is a subset of A?B that can be used to
visualize f in a two-dimensional coordinate
system.
59Graphs
- The graph of a function fA?B is the set of
ordered pairs (a, b) a?A and f(a) b - f(x) x3 x2
                                               Â
                        Â
60Floor and Ceiling Functions
- The floor and ceiling functions map the real
numbers onto the integers (R?Z). - The floor function assigns to r?R the largest z?Z
with z ? r, denoted by ?r?. - Examples ?2.3? 2, ?2? 2, ?0.5? 0, ?-3.5?
-4 - The ceiling function assigns to r?R the smallest
z?Z with z ? r, denoted by ?r?. - Examples ?2.3? 3, ?2? 2, ?0.5? 1, ?-3.5?
-3
61Chapter 2 - Sequences
- Sequences represent ordered lists of elements.
- A sequence is defined as a function from a subset
of N to a set S. We use the notation an to denote
the image of the integer n. We call an a term of
the sequence. - Example S is the sequence of even numbers
- subset of N 1 2 3 4 5
62Sequences
- We use the notation an to describe a sequence.
- Important Do not confuse this with the used
in set notation. - It is convenient to describe a sequence with a
formula. - For example, the sequence on the previous slide
can be specified as an, where an 2n.
63The Formula Game
What are the formulas that describe the following
sequences a1, a2, a3, ?
an 2n - 1
-1, 1, -1, 1, -1,
an (-1)n
2, 5, 10, 17, 26,
an n2 1
0.25, 0.5, 0.75, 1, 1.25
an 0.25n
3, 9, 27, 81, 243,
an 3n
64Strings
- Finite sequences are also called strings, denoted
by a1a2a3an. - The length of a string S is the number of terms
that it consists of. - The empty string contains no terms at all. It has
length zero.
65Summations
- It represents the sum am am1 am2 an.
- The variable j is called the index of summation,
running from its lower limit m to its upper limit
n. We could as well have used any other letter to
denote this index.
66Summations
How can we express the sum of the first 1000
terms of the sequence an with ann2 for n 1,
2, 3, ?
It is so much work to calculate this
67Summations
Called a closed form
- It is said that Friedrich Gauss came up with the
following formula
When you have such a formula, the result of any
summation can be calculated much more easily, for
example
68Cardinality Again
- Sets A and B have the same cardinality if and
only if there is a one-to-one correspondence from
A to B. - If a set is finite or has the same cardinality as
N then it is called countable, other wise it is
called uncountable. - In mathematics, the cardinality of a set is a
measure of the "number of elements of the set". - Cardinality of set S is denoted S .
- The cardinality of the natural numbers is denoted
aleph-null ?0
69Cardinality Again
Comments on set theory and transfinite numbers
- Poincaré a "grave disease" infecting the
discipline of mathematics - Kronecker's "scientific charlatan", a
"renegade" and a "corrupter of youth. - Wittgenstein mathematics is "ridden through and
through with the pernicious idioms of set
theory," which he dismissed as "utter nonsense"
that is "laughable" and "wrong. - Hilbert defended it from its "No one shall
expel us from the Paradise that Cantor has
created. http//en.wikipedia.org/wiki/Georg_Canto
r
Georg Cantor
70Chapter 2
Cantor Diagonalization Proof Method.
- The set EVEN of even numbers is countable so it
has the same cardinality as N - Proof We need to give a one-to-one
correspondence (mapping) from N to EVEN n n
mod 2 0. - f(n) 2n
- Mapping is 0 1 2 3 4 5 6
- 0 2 4 6 8 10 12.
EVEN n n mod 2 0
71Chapter 2
- The set of Integers is countable so it has the
same cardinality as N - Proof Need to give a one-to-one correspondence
from N to Integers -2 , -1, 0, 1, 2,
. f(n) n/2 if N is even and (n-1)/2 if odd - Mapping is 0 1 2 3 4 5 6 7
- 0 -0 1 -1 2 -2 3 -3.
72Chapter 2
Q m/n m, n ? N
- The set of Positive Rational numbers is countable
so it has the same cardinality as N - Proof Need to give a one-to-one correspondence
from N to Positive Rationales (positive
fractions) - 1/1 2/1 3/1 4/1 5/1 .
- 1/2 2/2 3/2 4/2 5/2
- 1/3 2/3 3/3 4/3 5/3
- 1/4 2/4 3/4 4/4 5/4
-
- 1/1, 1/2, 2/1, 3/1, 2/2, 1/3, 1/4, 2/3, 3/2,
4/1,
73Chapter 2
- Cantor Diagonalization Proof Method.
- Example Show that the set of real numbers is
uncountable. - Proof
- Assume that the set of real numbers is countable.
- (We will contradict this later).
- Then the subset S of numbers from 0 to 1 is also
countable. Because every subset of a countable
set is also countable. - Since S is countable we can list it as r1, r2,
r3,
74Chapter 2
- Since S is countable we can list it as r1, r2,
r3, - Now list the digits of each of these numbers in a
table - r1 0.d11 d12 d13 d14 d15
- r2 0.d21 d22 d23 d24 d25
- r3 0.d31 d32 d33 d34 d35
- r4 0.d41 d42 d43 d44 d45
- Example if r1 0.23794 then d11 2 etc.
- Claim the following defines a NEW real number
- di 4 if dii ? 4 and di 5 if dii 4
75Chapter 2
- r1 0.d11 d12 d13 d14 d15
- r2 0.d21 d22 d23 d24 d25
- r3 0.d31 d32 d33 d34 d35
- r4 0.d41 d42 d43 d44 d45 .
- Claim the following defines a NEW real number
- di 4 if dii ? 4 and di 5 if dii 4
- Suppose that di is already in the list so it is
some number rk. But it can not be rk because if
digit dkk in rk is 4 then digit dkk in rk is 5.
And if dkk in rk is not 4 then digit dkk in rk is
4. They can not be the same number so rk must not
be in the list.
76Chapter 2
- Since rk is different from all of the numbers in
the list of numbers between 0 to 1 then the list
is incomplete. - This contradicts that subset S of numbers from 0
to 1 (the set r1, r2, r3, ) is countable. If it
were countable we could make a complete list. - That contradicts that the set of real numbers is
countable since it has an uncountable subset. - DONE
77Chapter 2
- Cantor Diagonalization Proof Method.
- Facts from before -
- In mathematics, the cardinality of a set is a
measure of the "number of elements of the set". - Cardinality of set S is denoted S .
- Definition If a set is finite or has the same
cardinality as N then it is called countable,
other wise it is called uncountable. - Sets A and B have the same cardinality if and
only if there is a one-to-one correspondence from
A to B. - The cardinality of the natural numbers is denoted
aleph-null. - The set of REALS does not have the same
cardinality as N.
78How to setup a proof using contradiction and
diagonalization
- STEPS to prove a set is not countable using proof
by contradiction combined with diagonalization. - Assume the opposite
- Assume the set is countable (has a 1-1
correspondence to N) THIS GIVES A METHOD FOR
LISTING THE SET - Create a listing
- Construct a new object that can not be in the
list - A new number or maybe a new infinite set
- Explain why the new object is not in the list
the contradiction - Conclude that the original assumption was wrong
79How to setup a proof using contradiction and
diagonalization
- Prove Some set S has some property P.
- Proof
- Assume that the set S does not have property P.
So assume S has property P. (Contradict this
later). - Two possible cases
- The set S is countable.
- The set S is not countable in this case
generally P is the set is uncountable and we
assumed that it is countable via P. - Since S is countable we can list it as x1, x2,
x3,
80How to setup a proof using contradiction and
diagonalization
- Since S is countable we can list it as x1, x2,
x3, - Now list the members of S in a table
- Claim the following defines a NEW member of S
di z if dii ? z and di y if dii z - Explain why the NEW object is not in the list
this is the contradiction - Conclude that the original assumption was wrong
1 2 3 4 6 x1 d11 d12 d13 d14 d15
x2 d21 d22 d23 d24 d25 x3 d31 d32
d33 d34 d35 x4 d41 d42 d43 d44 d45