Introduction to Database Systems

Download Report

Transcript Introduction to Database Systems

Discrete Mathematics
Ch. 7 Functions
Today we will review sections 7.1 and 7.2
Instructor: Hayk Melikyan
[email protected]
Melikyan/DM/Fall09
1
Generic Functions
Definition: A function f from set X to a set Y is a relationship between
elements of X to elements of Y, when each element from X is related to
a unique element from Y.
The notation f: X  Y means that f is a function from X to Y.
X is called domain of f, and Y is called co-domain of f
The range of f is a subset of Y so that for each element y of this subset
there exists an element x from X such that y = f(x).
range of f = { yY| y = f(x) for some x X }(I like notation for range Im(f))
Sample functions:
f : R  R, f(x) = x2
f : Z  Z, f(x) = 2x + 1
f : Q  Z, f(x) = - 5
Melikyan/DM/Fall09
2
Generic Functions
Arrow diagrams for functions is one of possible ways to define a function
if the domain and co-domain of a such function is finite sets
Melikyan/DM/Fall09
3
Functions and Non-functions
Identify: Which of the following arrow diagrams define a
function from
X = {a, b, c} to Y = {1, 2, 3, 4 }
Melikyan/DM/Fall09
4
Equality of functions:
Definition: Two functions f and g from X to Y are said
to be equal ( we write f = g) if
f(x) = g (x) for all xX
Example :
f(x) = |x| and g(x) = sqrt(x2)
Identity function
For any set X we define a function iX: X X as follows
iX(x) =x for all x in X
Melikyan/DM/Fall09
5
More Examples of Functions
1.
Sequences as functions
2. Functions with a domain of some language
3. Encoding and decoding of characters
4. Hamming distance function:
number of differences between two encodings
Melikyan/DM/Fall09
6
Boolean Functions:
Definition: An ( n-place) Boolean function f is any
function from {0, 1}n to {0, 1} where {0, 1}n is the
Cartesian product of n copies of the set {0, 1}. Thus
f: {0, 1}n  {0, 1}
Melikyan/DM/Fall09
7
Example of Boolean function
Consider 3-place Boolean function define as
f (x1, x2, x3) = (x1+x2+x3) mod 2.
Here is the input/output table for function f
Melikyan/DM/Fall09
8
Examples_1
Melikyan/DM/Fall09
9
Finite-State Automata (FSA)
Two kind of circuits: combinatorial and sequential
Boolean functions—
combinatorial
Finite state automation-- sequential
Davit Hilbert-Alan Turing
Melikyan/DM/Fall09
10
Definition of FSA
Finite-state automata A is defined by 5 objects:
–
–
–
–
–
Set I of the input alphabet
Set S of automaton states
Designated initial state s0 from S
Designated set of accepted states from S
Next-state function N: S  I  S that associates next state to the
pair {current state, input symbol}
Descriptions of finite-state automaton:
– State-transition diagram
– Next-state table
Melikyan/DM/Fall09
11
FSA by Transition Diagram
1
1
s0
1
Melikyan/DM/Fall09
0
s1
0
s2
0
12
FSA by Next-State Table
Melikyan/DM/Fall09
a
b
c
U
Z
Y
Y
V
V
V
V
Y
Z
V
Y
Z
Z
Z
Z
13
FSA and Languages
Let A be an FSA with an input alphabet I. The set of all
strings w from I* such that A goes to accepting state on w is
called a language accepted by A : L(A)
(What is the language accepted by an automation 12)
Eventual state-function N* : S  I*  S is a function that
maps a pair {state, input string} to the state to which FSA
would lead from the original state given the symbols in the
input string as an input.
Melikyan/DM/Fall09
14
Designing FSA
Design an FSA that accepts all strings of 0’s and 1’s
such that the number of 1’s is divisible by 3
Melikyan/DM/Fall09
0
1
s0
s0
s1
s1
s1
s2
s2
s2
s0
15
Designing FSA_2
Design an FSA that accepts the set of strings that
contain exactly one 1
Design an FSA with alphabet {a, b} which accepts
strings that end on the same two characters
Simulating an FSA using software
Melikyan/DM/Fall09
16
One-to-One Functions
Definition : Function f : X  Y is called one-to-one
(injective) when for all elements x1 and x2 from X if
f(x1) = f(x2), then x1 = x2
A
B
a, a  A.
Melikyan/DM/Fall09
( f (a)  f (a '))  (a  a ')
17
Not One_to_One
Melikyan/DM/Fall09
18
Examples:
Determine whether the following functions are
one-to-one (on infinite set)
– f : R  R, f(x) = 4x – 1
– g : Z  Z, g(n) = n2
Hash functions (Applications)
Melikyan/DM/Fall09
19
Onto Functions
Definition: Function f : X  Y is called onto (surjective)
when given any element y from Y, there exists x in X so
that f(x) = y
Symbolically:
f: XY is onto 
Melikyan/DM/Fall09
(  y  Y, x  X such that f(x) = y
20
Surjections (Onto)
f : AB
is a surjection iff every element of B is f of
something
f( ) =
A
B
b  B a  A. f (a)  b
Melikyan/DM/Fall09
21
Example:
Determine whether the following functions are
on_to
– f : R  R, f(x) = 4x – 1
– f : Z  Z, g(n) = 4n – 1
Melikyan/DM/Fall09
22
Not Onto:
Co-domain of function and range of function are not equal
Melikyan/DM/Fall09
23
Bijections
f : AB
is a bijection iff it is surjection and injection.
exactly one arrow in
f( ) =
A
Melikyan/DM/Fall09
B
24
In-Class Exercises
Function
Domain
Codomain
f(x)=sin(x)
Real
Real
f(x)=2x
Real
Positive
real
f(x)=x2
Real
Positive
real
Reverse
string
Bit strings
of length n
Bit strings
of length n
Melikyan/DM/Fall09
Injective?
Subjective? Bijective?
25
Inverse Functions
If f : X  Y is a bijective function, then it is possible to
define an inverse function f-1: Y  X so that f-1(y) = x
whenever f(x) = y
Find an inverse for the following functions:
– String-reverse function
– f : R  R, f(x) = 4x – 1
Inverse function of a bijective function is a bijective
function itself
Melikyan/DM/Fall09
26
Inverse Function Theorem
Theorem: If f:XY is one-to=one and onto, then
inverse function f-1 YX exists and is also one-toone and onto.
Let F: Z  Z  Z and G: Z  Z  Z,
F(n, m) = 3n6m and G(n, m) = 3n5m.
Is F one-to-one?
Is G one-to-one?
Melikyan/DM/Fall09
27
Exercises
Let cm,n be the number of onto functions from a set
of m elements to a set of n elements. Find a
relationship between cm,n, cm-1,n and cm-1,n-1
Melikyan/DM/Fall09
28
Composition of Functions
Two functions f:X->Y’, g:Y->Z so that Y’ is a subset of Y, then the composition
of f and g is the function g。f: X->Z, where
g。f(x) = g(f(x)).
Y’
Z
X
Melikyan/DM/Fall09
Y
29
Example
Melikyan/DM/Fall09
30
Composition of Functions
Let f : X  Y and g : Y  Z, let range of f be a subset of the
domain of g. The we can define a composition of g o f : X 
Z
Let f, g : Z  Z, f(n) = n + 1, g(n) = n2. Find f o g and g o f.
Composition with identity function
Composition with an inverse function
Composition of two one-to-one functions is one-to-one
Composition of two onto functions is onto
Melikyan/DM/Fall09
31
Pigeonhole Principle
If n pigeons fly into m pigeonholes and n > m, then at least one
hole must contain two or more pigeons
Melikyan/DM/Fall09
32
Pigeonhole Principle
If more pigeons
than pigeonholes,
Melikyan/DM/Fall09
33
Pigeonhole Principle
then some hole must have at least two pigeons!
Pigeonhole principle
A function from a larger set to a smaller set cannot be oneto-one injective.
(There must be at least two elements in the domain that
havethe same image in the codomain.)
Melikyan/DM/Fall09
34
Examples:
A function from one finite set to a smaller finite set cannot be
one-to-one
In a group of 13 people must there be at least two who have
birthday in the same month?
A drawer contains 10 black and 10 white socks. How many
socks need to be picked to ensure that a pair is found?
Let A = {1, 2, 3, 4, 5, 6, 7, 8}. If 5 integers are selected must at
least one pair have sum of 9?
There is no FSA that accepts the following language: L = {s =
akbk, for positive k}
Melikyan/DM/Fall09
35
Pigeonhole Principle
Generalized Pigeonhole Principle: For any function f : X  Y
acting on finite sets, if n(X) > k * n(Y), then there exists some
y from Y so that there are at least k + 1 distinct x’s so that
f(x) = y
Generalized Pigeonhole Principle( contrapositive form): For any
function f : X  Y acting on finite sets and any positive integer k, if
for each y Y, f-1(y) has at most k elements, then X has at most
k * n(Y) elements
There are 42 students who are to share 12 computers. Each student uses
exactly 1 computer and no computer is used by more than 6 students.
Show that at least 5 computers are used by 3 or more students.
Melikyan/DM/Fall09
36
Generalized Pigeonhole Principle
If n pigeons and h holes,
then some hole has at least
♠
Melikyan/DM/Fall09
♥
n
 h 
♣
♦
Cannot have < 3 cards in every hole.
37
Exercises
Let f : X  Y and n(X) = n(Y), then f is bijective iff f is surjective
Let A be a set of 6 integers less than 13. Show that there must be two
distinct subsets of A whose sum of elements adds up to the same
number
Given 52 distinct integers, show that there must be two whose sum or
difference is divisible by 100
Show that if 101 integers are chosen from 1 to 200 inclusive, there must
be two with the property that one is divisible by the other
Suppose a1, a2, …, an is a sequence of n integers none of which is
divisible by n. Show that at least one difference ai – aj is divisible by n
Melikyan/DM/Fall09
38
Cardinality and Countability
Up to now cardinality has been the number of elements in a finite
sets. Really, cardinality is a much deeper concept. Cardinality
allows us to generalize the notion of number to infinite
collections and it turns out that many type of infinities exist.
EG:
– {,}
– {
,
}
– {Ø , {Ø,{Ø,{Ø}}} }
These all share “2-ness”.
Melikyan/DM/Fall09
39
39
Cardinality and Countability
For finite sets, can just count the elements to get cardinality.
Infinite sets are harder.
First Idea: Can tell which set is bigger by seeing if one
contains the other.
– {1, 2, 4}  N
– {0, 2, 4, 6, 8, 10, 12, …}  N
So set of even numbers ought to be smaller than the
set of natural number because of strict containment.
Q: Any problems with this?
L6
Melikyan/DM/Fall09
40
40
Cardinality and Countability
Set of even numbers is obtained from N by multiplication by 2.
I.e.
{even numbers} = 2•N
For finite sets, since multiplication by 2 is a one-to-one
function, the size doesn’t change.
EG: {1,7,11} – 2  {2,14,22}
Another problem: set of even numbers is disjoint
from set of odd numbers. Which one is bigger?
L6
Melikyan/DM/Fall09
41
41
Cardinality and Countability – Finite Sets
Definition: Two sets A and B have the same cardinality if
there’s a bijection f : A  B
For finite sets this is the same as the old definition:
{, }
{
L6
Melikyan/DM/Fall09
,
}
42
42
Cardinality and Countability – Infinite Sets
Definition: If S is finite or has the same cardinality as N,
S is called countable
Notation , the Hebrew letter Aleph  is often used to denote
0
infinite cardinalities. Countable sets are said to have cardinality
Intuitively, countable sets can be counted in the sense that if
you allocate 1 second to count each member, eventually any
particular member will be counted after a finite time period.
Paradoxically, you won’t be able to count the whole set in a
finite time period!
Melikyan/DM/Fall09
43
.
43
Countability – Examples
Q: Why are the following sets countable?
1.
{0,2,4,6,8,…}
2.
{1,3,5,7,9,…}
{1,3,5,7, 100100
Z
1.
2.
L6
Melikyan/DM/Fall09
100
100100
}
44
44
Countability – Examples
1.
2.
3.
4.
{0,2,4,6,8,…}: Just set up the bijection f (n ) = 2n
{1,3,5,7,9,…} : Because of the bijection f (n ) = 2n +1
{1,3,5,7, 100100
} has cardinality 5 so is
therefore countable
Z: This one is more interesting. Continue on next
page:
100
100100
L6
Melikyan/DM/Fall09
45
45
Countability of the Integers
Let’s try to set up a bijection between N and Z. One way is to
just write a sequence down whose pattern shows that every
element is hit (onto) and none is hit twice (one-to-one). The
most common way is to alternate back and forth between the
positives and negatives. I.e.: 0,1,-1,2,-2,3,-3,…
It’s possible to write an explicit formula down for this
sequence which makes it easier to check for bijectivity:
 i  1
ai  (1) i 

 2 
Melikyan/DM/Fall09
46
46
Demonstrating Countability. Useful Facts
Because 0 is the smallest kind of infinity, it turns out that to
show that a set is countable one can either demonstrate an
injection into N or a surjection from N.
Theorem: Suppose A is a set. If there is an one-to-one
function f : A  N, or there is an onto function g :
N  A then A is countable.
The proof requires the principle of mathematical induction.
Melikyan/DM/Fall09
47
47
Uncountability of R
A: This is not a trivial matter. Here are some typical reasoning:
1.
R strictly contains N so has bigger cardinality. What’s
wrong with this argument
1.
R contains infinitely many numbers between any two
numbers. Surprisingly, this is not a valid argument. Q has
the same property, yet is countable.
1.
Many numbers in R are infinitely complex in that they
have infinite decimal expansions. An infinite set with
infinitely complex numbers should be bigger than N.
Melikyan/DM/Fall09
48
48
Uncountability of R
Last argument is the closest.
Here’s the real reason: Suppose that R were countable. In
particular, any subset of R, being smaller, would be countable
also. So the interval [0,1] would be countable. Thus it would
be possible to find a bijection from Z+ to [0,1] and hence list
all the elements of [0,1] in a sequence.
What would this list look like?
r1 , r2 , r3 , r4 , r5 , r6 , r7, …
Melikyan/DM/Fall09
49
49
Uncountability of R Cantor’s Diabolical Diagonal
So we have this list
r1 , r2 , r3 , r4 , r5 , r6 , r7 , …
supposedly containing every real number between 0 and 1.
Cantor’s diabolical diagonalization argument will take this
supposed list, and create a number between 0 and 1 which is
not on the list. This will contradict the countability
assumption hence proving that R is not countable.
L
Melikyan/DM/Fall09
50
50
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
:
revil
Melikyan/DM/Fall09
0.
51
51
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
1
2
3
4
5
6
7
:
revil
L6
Melikyan/DM/Fall09
0.
52
52
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
1
1
2
1
3
1
4
1
5
1
6
1
7
1
:
revil
L6
Melikyan/DM/Fall09
0.
53
53
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
1
1
2
2
1
5
3
1
4
4
1
2
5
1
0
6
1
9
7
1
0
:
revil
Melikyan/DM/Fall09
0.
54
54
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
1
1
2
7
2
1
5
8
3
1
4
9
4
1
2
0
5
1
0
6
6
1
9
2
7
1
0
3
:
revil
Melikyan/DM/Fall09
0.
55
55
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
0.
1
2
3
4
5
6
7
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
1
2
7
0
5
5
8
1
1
4
9
1
1
2
0
0
1
0
6
1
1
9
2
0
1
0
3
1
:
revil
L6
Melikyan/DM/Fall09
0.
56
56
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
1
1
2
7
0
5
2
5
5
8
1
5
3
1
4
9
1
5
4
1
2
0
0
5
5
1
0
6
1
5
6
1
9
2
0
5
7
1
0
3
1
5
:
revil
L6
Melikyan/DM/Fall09
0.
57
57
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
1
1
2
7
0
5
7
2
5
5
8
1
5
6
3
1
4
9
1
5
7
4
1
2
0
0
5
9
5
1
0
6
1
5
5
6
1
9
2
0
5
4
7
1
0
3
1
5
4
:
revil
Melikyan/DM/Fall09
0.
58
58
Cantor's Diagonalization Argument
 Decimal expansions of ri 
r1
r2
r3
r4
r5
r6
r7
0.
0.
0.
0.
0.
0.
0.
1
1
2
7
0
5
7
2
5
5
8
1
5
6
3
1
4
9
1
5
7
4
1
2
0
0
5
9
5
1
0
6
1
5
5
6
1
9
2
0
5
4
7
1
0
3
1
5
4
0.
5
4
5
5
5 59 4
5
:
revil
L6
Melikyan/DM/Fall09
59
Uncountability of R Cantor’s Diabolical
Diagonal
GENERALIZE: To construct a number not on the list
“revil”, let ri,j be the j ’th decimal digit in the fractional part of ri.
Define the digits of revil by the following rule:
The j ’th digit of revil is 5 if ri,j  5.
Otherwise the j’ ’th digit is set to be 4.
his guarantees that revil is an anti-diagonal. I.e., it does not
share any elements on the diagonal. But every number on the
list contains a diagonal element. This proves that it cannot be
on the list and contradicts our assumption that R was countable
so the list must contain revil.
//QED
Melikyan/DM/Fall09
60
60
Impossible Computations
Notice that the set of all bit strings is countable. Here’s how
the list looks:
0,1,00,01,10,11,000,001,010,011,100,101,110,111,0000,…
DEF: A decimal number
0.d1d2d3d4d5d6d7…
Is said to be computable if there is a computer program that
outputs a particular digit upon request.
EG:
1.
0.11111111…
2.
0.12345678901234567890…
3.
0.10110111011110….
Melikyan/DM/Fall09
61
61
Impossible Computations
Claim: There are numbers which cannot be computed by any
computer.
Proof : It is well known that every computer program may be
represented by a bit-string (after all, this is how it’s stored
inside). Thus a computer program can be thought of as a bit
string. As there are bit-strings yet R is uncountable, there can
be no onto function from computer programs to decimal
numbers. In particular, most numbers do not correspond to
any computer program so are incomputable!
Melikyan/DM/Fall09
62
62