A f - Homepages | The University of Aberdeen

Download Report

Transcript A f - Homepages | The University of Aberdeen

CS3518 Functions
Functions and
infinite sets
(Approx 2-3 lectures. Initial sections adapted from
slides for a course by Michael P. Frank)
4/9/2015
Kees van Deemter
1
CS3518 Functions
Reading: relevant chapters of any book on Discrete
Maths. For example, Rosen 5th ed., §1.8
4/9/2015
Kees van Deemter
2
CS3518 Functions
Functions
• From calculus, you know the concept of a realvalued function f,
which assigns to each number xR
one particular value y=f(x), where yR.
• Example: f defined by the rule f(x)=x2
• Roughly, functions say “the so-and-so of …”
• Functions are also called operations, mappings,
etc.
4/9/2015
Kees van Deemter
3
CS3518 Functions
Functions
• To understand functions more precisely, one needs
the mathematical notion of a set
• We assume you are familiar with “naïve set
theory” (as opposed to axiomatic set theory).
• In a nutshell:
4/9/2015
Kees van Deemter
4
CS3518 Functions
Reminder of main set concepts
• , , , , , S
• =, , , , , , etc.
• {a,b,...} (def. of a set by enumeration)
{x | P(x)} (def. by set builder notation)
• xS, ST, S=T, ST.
• P(S) (power set of S),
• AB (Cartesian product of A and B)
4/9/2015
Michael P. Frank / Kees van Deemter
5
CS3518 Functions
Reminder of main set concepts
• Important sets of numbers: N, Z, Q, R
• A relation on A is a subset of AxA. E.g.,
on, N, the relation < is {(0,1),(0,2), (1,2),…}
• Set equality proof techniques
E.g., to prove A=B, prove each of:
AB
BA
4/9/2015
Michael P. Frank / Kees van Deemter
6
CS3518 Functions
Function: Formal Definition
• A function f from (or “mapping”) A to B
(f:AB) is an assignment of exactly one
element f(x)B to each element xA.
• Generalisations:
– Functions of n arguments:
f: (A1 x A2... x An)  B.
– A partial (non-total) function f assigns zero or
one elements of B to each element xA.
4/9/2015
Kees van Deemter
7
CS3518 Functions
Functions precisely
• We can represent a function f:AB as a set of
ordered pairs f ={(a,f(a)) | aA}.
• This makes f a relation between A and B:
f is a subset of A x B. But functions are special:
– for every aA, there is at least one pair (a,b). Formally:
aAbB((a,b)f)
– for every aA, there is at most one pair (a,b). Formally:
a,b,c((a,b)f  (a,c)f  bc)
• A relation over numbers can be represent as a set of
points on a plane. (A point is a pair (x,y).)
– A function is then a curve (set of points),
with only one y for each x.
4/9/2015
Kees van Deemter
8
CS3518 Functions
Useful diagrams
• Functions can be represented graphically in
several ways:
f
a•
A
f
•
b
B
Like Venn diagrams
4/9/2015
A
•
•
•
•
•
B
•
•
•
•
y
Bipartite Graph
Kees van Deemter
x
Plot
9
CS3518 Functions
Functions that you’ve seen before
• A set S over universe U can be viewed as a
function from the elements of U to …
4/9/2015
Kees van Deemter
10
CS3518 Functions
Still More Functions
• A set S over universe U can be viewed as a
function from the elements of U to …
… {T, F}, saying for each element of U
whether it is in S. (This is called the
characteristic function of S)
Suppose U={0,1,2,3,4}. Then
S={1,3}
S(0)=S(2)=S(4)=F, S(1)=S(3)=T.
4/9/2015
Kees van Deemter
11
CS3518 Functions
Still More Functions
• A set operator, such as  or , can be
viewed as a function from … to …
4/9/2015
Kees van Deemter
12
CS3518 Functions
Still More Functions
• A set operator such as  or  can be
viewed as a function …
… from (ordered) pairs of sets,
to sets.
– Example: (({1,3},{3,4})) = {3}
4/9/2015
Kees van Deemter
13
CS3518 Functions
A new notation
• YX is the set F of all possible functions f:
XY.
• Thus, f  YX is another way of saying
f: XY.
• (This notation is especially appropriate,
because for finite X, Y, we have |F| = |Y||X|. )
4/9/2015
Kees van Deemter
14
CS3518 Functions
Some Function Terminology
• If f:AB, and f(a)=b (where aA & bB),
then we say:
–
–
–
–
A is the domain of f.
B is the codomain of f.
b is the image of a under f.
a is a pre-image of b under f.
We also say
the signature
of f is A→B.
• In general, b may have more than 1 pre-image.
– The range RB of f is R={b | a f(a)=b }.
4/9/2015
Kees van Deemter
15
CS3518 Functions
Range versus Codomain
• The range of a function may not be its whole
codomain.
• The codomain is the set that the function is
declared to map all domain values into.
• The range is the particular set of values in the
codomain that the function actually maps elements
of the domain to.
4/9/2015
Kees van Deemter
16
CS3518 Functions
Choosing the right (co)domain
Consider the function f such that f (x) = 100/x
Is f a (total) function from Int to R?
• f is a partial function from Int to R
• f is a (total) function from Int-{0} to R
Consider the function g such that g(x) = √x
Is g a (total) function from R to R?
g is a total function from R+ to RxR
e.g. g(4)= (2,-2)
4/9/2015
Kees van Deemter
17
CS3518 Functions
Images of Sets under Functions
• Given f:AB, and SA,
• The image of S under f is the set of all
images (under f) of the elements of S.
f(S) : {f(s) | sS}
: {b | sS: f(s)=b}.
• The range of f equals
the image (under f) of ...
4/9/2015
Kees van Deemter
18
CS3518 Functions
Images of Sets under Functions
• Given f:AB, and SA,
• The image of S under f is the set of all
images (under f) of the elements of S.
f(S) : {f(s) | sS}
: {b | sS: f(s)=b}.
• The range of f equals
the image (under f) of f’s domain.
4/9/2015
Kees van Deemter
19
CS3518 Functions
One-to-One Functions
• A function is one-to-one (1-1), or injective, or an
injection, iff every element of its range has only 1
pre-image.
– Formally: given f:AB,
“f is injective” : (x,y: xy  f(x)f(y)).
• In other words: only one element of the domain is
mapped to any given one element of the range.
– In this case, domain & range have same cardinality.
What about codomain?
4/9/2015
Kees van Deemter
20
CS3518 Functions
• Codomain may be larger.
4/9/2015
Kees van Deemter
21
CS3518 Functions
One-to-One Illustration
• Are these relations one-to-one functions?
•
•
•
•
4/9/2015
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Kees van Deemter
•
•
•
•
•
•
•
•
•
22
CS3518 Functions
One-to-One Illustration
• Are these relations one-to-one functions?
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
One-to-one
4/9/2015
Kees van Deemter
23
CS3518 Functions
One-to-One Illustration
• Are these relations one-to-one functions?
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Not one-to-one
•
•
•
•
•
•
•
•
•
One-to-one
4/9/2015
Kees van Deemter
24
CS3518 Functions
One-to-One Illustration
• Are these relations one-to-one functions?
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Not one-to-one
One-to-one
4/9/2015
Kees van Deemter
•
•
•
•
•
•
•
•
•
Not even a
function!
25
CS3518 Functions
Sufficient Conditions for 1-1ness
• For functions f over numbers, we say:
– f is strictly increasing iff x>y  f(x)>f(y) for
all x,y in domain;
– f is strictly decreasing iff x>y  f(x)<f(y) for
all x,y in domain;
• If f is either strictly increasing or strictly
decreasing, then f must be one-to-one.
– Does the converse hold?
4/9/2015
Kees van Deemter
26
CS3518 Functions
Onto (Surjective) Functions
• A function f:AB is onto or surjective or a
surjection iff its range is equal to its
codomain (bB, aA: f(a)=b).
• Consider “country of birth of”: AB,
where A=people, B=countries.
Is this a function?
Is it an injection?
Is it a surjection?
4/9/2015
Kees van Deemter
27
CS3518 Functions
Onto (Surjective) Functions
• A function f:AB is onto or surjective or a
surjection iff its range is equal to its
codomain
• Consider “country of birth of”: AB,
where A=people, B=countries.
Is this a function? Yes (always 1 c.o.b.)
Is it an injection? No (many have same c.o.b.)
Is it a surjection? Probably yes ..
4/9/2015
Kees van Deemter
28
CS3518 Functions
Onto (Surjective) Functions
• A function f:AB is onto or surjective or a
surjection iff its range is equal to its
codomain
• In predicate logic:
4/9/2015
Kees van Deemter
29
CS3518 Functions
Onto (Surjective) Functions
• A function f:AB is onto or surjective or a
surjection iff its range is equal to its
codomain.
• In predicate logic:
bBaA f(a)=b
4/9/2015
Kees van Deemter
30
CS3518 Functions
Onto (Surjective) Functions
• A function f:AB is onto or surjective or a
surjection iff its range is equal to its
codomain (bBaA f(a)=b).
• E.g., for domain & codomain Z, the
function x.x+1 is injective and surjective.
4/9/2015
Kees van Deemter
31
CS3518 Functions
Claim: if f:ZZ and f(x) = x+1 then
f is 1-to-1 and also onto.
(Z is the set of all integers)
• Proof that f is onto: Consider any arbitrary
element a of Z. We have f(a-1)=a, where a  Z.
• Proof that f is 1-to-1: Suppose f(u)=f(w)=a. In
other words, u+1=a and w+1=a. It follows that
u=w.
4/9/2015
Kees van Deemter
32
CS3518 Functions
Onto/surjective functions
• Are these functions onto their depicted codomains?
•
•
•
•
•
4/9/2015
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Kees van Deemter
•
•
•
•
•
•
•
•
•
•
•
•
•
33
CS3518 Functions
Onto/surjective functions
• Are these functions onto?
•
•
•
•
•
4/9/2015
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Kees van Deemter
•
•
•
•
•
•
•
•
•
•
•
•
•
34
CS3518 Functions
Onto/surjective functions
• Are these functions onto?
•
•
•
•
•
•
•
•
•
onto
4/9/2015
•
•
•
•
•
•
•
•
•
•
•
•
•
not onto
Kees van Deemter
•
•
•
•
onto
•
•
•
•
•
•
•
•
•
not onto
35
CS3518 Functions
1-1/injective functions
• Are these functions 1-1?
•
•
•
•
•
•
•
•
•
onto
4/9/2015
•
•
•
•
•
•
•
•
•
•
•
•
•
not onto
Kees van Deemter
•
•
•
•
onto
•
•
•
•
•
•
•
•
•
not onto
36
CS3518 Functions
1-1/injective functions
• Are these functions 1-1?
•
•
•
•
•
4/9/2015
•
•
•
•
not 1-1
onto
•
•
•
•
•
•
•
•
•
not 1-1
not onto
•
•
•
•
Kees van Deemter
•
•
•
•
1-1
onto
•
•
•
•
•
•
•
•
•
1-1
not onto
37
CS3518 Functions
Bijections
• A function is said to be a one-to-one
correspondence, or a bijection iff it is
both one-to-one and onto.
4/9/2015
Kees van Deemter
38
CS3518 Functions
Two terminologies for talking
about functions
1. injection = one-to-one
2. surjection = onto
3. bijection = one-to-one correspondence
3 = 1&2
4/9/2015
Kees van Deemter
39
CS3518 Functions
Bijections
• For bijections f:AB, there exists a
function that is the inverse of f,
written f 1: BA
• Intuitively, this is the function that undoes
everything that f does
• Formally, it’s the unique function such that
...
4/9/2015
Kees van Deemter
40
CS3518 Functions
Bijections
• For bijections f:AB, there exists an
inverse of f, written f 1: BA
• Intuitively, this is the function that undoes
everything that f does
• Formally, it’s the unique function such that
f 1  f  I A
(the identity function on A)
4/9/2015
Kees van Deemter
41
CS3518 Functions
Bijections
• Example 1: Let f: ZZ be defined as f(x)=
x+1. What is f1 ?
• Example 2: Let g: ZN be defined as g(x)=
|x|. What is g1 ?
4/9/2015
Kees van Deemter
42
CS3518 Functions
Bijections
• Example 1: Let f: ZZ be defined as
f(x)=x+1. What is f1 ?
• f1 is the function (let’s call it h)
h: ZZ defined as h(x)=x-1.
• Proof:
h  f I
h(f(x)) = (x+1)-1 = x
4/9/2015
Kees van Deemter
43
CS3518 Functions
Bijections
• Example 2: Let g: ZN be defined as
g(x)=|x|. What is g1 ?
• This was a trick question: there is no such
function, since g is not a bijection:
There is no function h such that
h(|x|)=x and h(|x|)=x
• (NB There is a relation h
for which this is true.)
4/9/2015
Kees van Deemter
44
CS3518 Functions
Cardinality (informal)
• The cardinality of a finite set is its number
of elements
• E.g., card({a,b,c}) = card({e,f,g}) = 3
• Note: for finite sets X and Y,
card(X)=card(Y) if and only if there exists a
bijection between X and Y
4/9/2015
Kees van Deemter
45
CS3518 Functions
infinity
• This is straightforward if a set has 0 or 1 or
2 or … n (any natural number) elements
• But what if the set has more elements than
that? Some examples:
–
–
–
–
4/9/2015
The set of all natural numbers itself
The set of all even natural numbers
L(1*) = 1, 11,111,1111,11111, etc.
L(0*1*) = 01,001,011,0001,0011, etc
Kees van Deemter
46
CS3518 Functions
•
The
Diagonalisation
Method
Georg Cantor (1873): What’s the size of an
infinite set?
• E.g., is card(L(1*)) = card(L(0*1*))?
– Both are infinite
– But is one larger than the other?
• Cantor’s idea:
– The size (cardinality) of a set should not depend on
the identity of its elements
– Two finite sets A and B have the same size if we can
pair the elements of A with elements of B
– Formally: there exists a bijection between A and B
4/9/2015
Kees van Deemter
47
CS3518 Functions
• Example: Let
Correspondences
(Cont’d)
– N be the set of pos. natural numbers {1, 2, 3, …}
– E the set of even pos. natural numbers {2, 4, 6, …}
• Using Cantor’s definition of size, we can show
that N and E have the same size:
n f (n)
2
4
6
…
• Intuitively, E is smaller than N, but
1
2
3
…
– Bijection (!): f (n) = 2n
– Pairing each element of N with its corresponding
element in E is possible,
– So we declare these two set to be the same size
– This even though E  N (E is a real subset of N )
4/9/2015
Kees van Deemter
48
CS3518 Functions
• A set X is finite if it has n elements,
Countable
sets
for some n in N.
• A set is countable if either
– It is finite or
– It has the same size as N, the natural numbers
• For example,
– N is countable, and so are all its subsets
– E is countable
– {0,1,2,3} is countable
–  is countable
• How about supersets of N ?
4/9/2015
Kees van Deemter
49
CS3518 Functions
• Let Q be the set of positive rational numbers
An Even Stranger Example…
Q = { m/n | m,n N }
• Just like E, the set Q has the same size as N !
– We show this giving a bijection from Q to N
– Q is thus countable
• One way is to enumerate (i.e., to list) Q’s
elements.
– Pair the first element of Q with 1 (first elt. of N )
– And so on, making sure every member of Q
appears only once in the list
4/9/2015
Kees van Deemter
50
CS3518 Functions
An
Even
Example…
• To
build
a list Stranger
with the elements
of Q
–
–
–
–
make inf. matrix
with all positive rational numbers
(Cont’d)
i -th row contains all numbers with numerator i
j -th column has all numbers with denominator j
i /j is in i -th row and j -th column 1/1 1/2 1/3 1/4 1/5
2/1 2/2 2/3 2/4 2/5
3/1 3/2 3/3 3/4 3/5
4/1 4/2 4/3 4/4 4/5
5/1 5/2 5/3 5/4 5/5
...
4/9/2015
Kees van Deemter
51
CS3518 Functions
AnweEven
Stranger
Example…
• Now
turn the
previous matrix
into a list
• A bad way: begin(Cont’d)
list with first row
– Since rows are infinite, we will never get to 2nd row!
4/9/2015
Kees van Deemter
52
CS3518 Functions
An Even
• Instead,
we listStranger
the elementsExample…
along diagonals:
(Cont’d)
1/2
1/3
1/4
1/5
2/1
2/2
2/3
2/4
2/5
3/1
3/2
3/3
3/4
4/1
4/2
4/3
4/4
3/5 . . .
We should, however,
eliminate repeated elements
4/5
5/1
5/2
5/3
5/4
5/5
...
1/1
4/9/2015
Kees van Deemter
53
CS3518 Functions
An
Stranger
Example…
• We
listEven
elements
along diagonals
w/o repetitions:
(Cont’d)
1/1
1/2
1/3
1/4
2/1
2/2
2/3
2/4
3/1
3/2
3/3
4/1
4/2
1/5
...
1/1, 2/1, 1/2, 3/1, 1/3, …
...
5/1
4/9/2015
Kees van Deemter
54
CS3518 Functions
Uncountable sets
• Some sets have no correspondence with N
• These sets are simply too big!
– They are not countable: we say uncountable
• Theorem:
– The set of real numbers between 0 and 1
(e.g., 0.244, 0.3141592323....) is uncountable
Call this set R0,1
(Some sets are even larger. “Serious” set theory is
all about theorems that concern infinite sets. –
Most of this is irrelevant for this course.)
4/9/2015
Kees van Deemter
55
CS3518 Functions
Theorem: | R0,1 | > |N|. Proof strategy:
| R0,1 |>=|N|. Suppose | R0,1 |=|N| and derive
a contradiction: Each member of R0,1 can
be written as a zero followed by a dot and
a countable sequence of digits. Suppose
there existed a complete enumeration of R,
(using whatever order) <e1,e2,e3,...>.
4/9/2015
Kees van Deemter
56
CS3518 Functions
showing how an arbitrary list might start:
e1. 0.0000000000000000000000....
e2. 0.0100000000000000000000....
e3. 0.8200000000000000000000....
e4. 0.1710000000000000000000....
...
4/9/2015
Kees van Deemter
57
CS3518 Functions
Now construct a Real number n
that’s not in the enumeration:
n’s first digit (after the dot) =
[e1’s first digit] + 1
n’s second digit = [e2’s second digit] + 1 ...
General: n’s i-th difit = [e-i’s i-th digit] + 1
i: n differs from e-i in its i-th digit
Contradiction: <e1,e2,e3,...> is not a
(complete) enumeration after all. QED
4/9/2015
Kees van Deemter
58
CS3518 Functions
• This proof of the non-countability of the set
of Real numbers is known as Cantor’s
diagonalisation argument
• It proved to be the start of a large new area
of set theory, involving the cardinalities of
infinite sets
4/9/2015
Kees van Deemter
59
CS3518 Functions
The Russell Paradox
For example, read Rosen 5th ed.,
§1.6
especially ex. 30 on p. 86
4/9/2015
Kees van Deemter
60
CS3518 Functions
Basic Set Notations
• Set enumeration {a, b, c}
and set-builder {x|P(x)}.
•  relation, and the empty set .
• Set relations =, , , , , , etc.
• Venn diagrams.
• Cardinality |S| and infinite sets N, Z, R.
• Power sets P(S).
4/9/2015
Kees van Deemter
61
CS3518 Functions
Axiomatic set theory
• Various axioms, e.g., saying that the union of a set of sets
is a set; the intersection of a set of sets is a set; etc.
• One key axiom: Given a Predicate P, one can construct a
set. It consists of all those elements x such that P(x) is true.
• But, the resulting theory turns out to be logically
inconsistent!
– This means, there exists set theory proposition p such that
both p and p follow logically from the axioms of the theory!
–  The conjunction of the axioms is a contradiction
– This makes the theory is fundamentally uninteresting, because any
possible statement in it can be (very trivially) proven!
4/9/2015
Kees van Deemter
62
CS3518 Functions
Prove:
Theorem: Given a contradiction, any statement can be
proven
4/9/2015
Kees van Deemter
63
CS3518 Functions
Prove:
Theorem: Given a contradiction, any statement can be
proven
Proof: Let your contradiction be p &p
(the assumption is you’ve proven it before)
Suppose you want to prove q
(p &p) --> q is a tautology of propositional logic
(Check truth table of the formula, given p &p is false)
You’ve proven p &p
q follows with Modus Ponens. Note that q is arbitrary!
4/9/2015
Kees van Deemter
64
CS3518 Functions
This version of
Set Theory is inconsistent
Russell’s paradox:
• Consider the set that corresponds with the
predicate x  x :
S = {x | xx }.
• Now ask: is SS?
4/9/2015
Kees van Deemter
65
CS3518 Functions
Russell’s paradox
• Let S = {x | xx }. Is SS?
• If SS, then S is one of those x for which xx. In
other words, SS
With Proof by Contradiction, we have SS
• If SS, then S is not one of those x for which xx.
In other words, SS
With Proof by Contradiction, we have SS
• We conclude that both SS nor SS
• Paradox!
4/9/2015
Kees van Deemter
66
CS3518 Functions
• To avoid inconsistency, set theory had to
somehow change
4/9/2015
Kees van Deemter
Bertrand Russell
1872-1970
67
CS3518 Functions
One technique
to avoid the problem:
• Given a set S and a predicate P, construct a
new set, consisting of those elements x of S
such that P(x) is true.
• You’ll seen this technique in use when we
get to the programming language Haskell,
where we can write
[x | x  [1..] , even x], but not
[x | even x].
4/9/2015
Kees van Deemter
68
CS3518 Functions
Another technique
to avoid the problem:
• Russell’s paradox arises from the fact that
we can write funny things like xx (or xx,
for that matter). One solution:
forbid such expressions using types.
• You’ll seen this technique in use as well:
Haskell’s use of typing.
4/9/2015
Kees van Deemter
69
CS3518 Functions
Our focus: computability
• We shall not worry about “saving” set
theory from paradoxes like Russell’s
• Instead, we shall use the Russell paradox in
a different setting
• But first we need to talk about Formal
Languages, Haskell, and Turing Machines
4/9/2015
Kees van Deemter
70
CS3518 Functions
4/9/2015
Kees van Deemter
71