[an error occurred while processing this directive]
Reading: §§ 1.5(proof methods), 1.8(functions)
Reminder on ways to construct new sets out of old:
-
set-difference -
-
intersect ∩
-
union ∪
-
big-union (indexed) … index set!
may not be integers:
∪{p \in PPG} p.enemies() (where PPG is the set of all powerpuff-girls objects in my program)
the union of a set-of-sets.
-
power set
-
cross product;
-
(as a segue:)
function spaces
f: X → Y
speaking of…
Functions
Def'n:
For sets X,Y,
a (unary) function is
an assignment from X (the ``domain'') to Y (the ``codomain'').
Examples of (unary) functions:
length(•); car-color(•); colorname->rgb(•)
(partial functions: functions which throw an error on some inputs;
often this is because our type system doesn't let us
specify the input-set better.
Formally, we might write
``f(17) = ⊥''
and add ⊥ to the codomain; may also represent inf. loop)
In java.util, there is a class which actually implements
unary functions.
Can you guess
what
it is?
-
Exercise: describe each of the class's methods using standard
function-terminology (``domain'', etc).
-
Discuss: Are instances of these objects total functions, or partial?
What about mutability — in the math world, values are values
(you can't change the value of pi or of the function + or sqrt).
Does this class implement mutable or immutable functions?
This is actually another method of constructing new sets from old:
A → B is a set. Really, the ``:'' should be ``∈'' symbol.
It is also a type, in computer languages
(which you write down in the function's contract).
In programming languages, ``contract'' or ``type''
is sometimes also called ``signature''
(well, technically the signature includes the name of the function too).
What is the type of the function deriv?
(ℜ→ℜ) → (ℜ→ℜ)
Other functions in this set?
-
∫719
-
the identity function;
-
Given a stock over time,
return a function: the historical doubling time:
from when you invested $1, to how long until you have $2.
Actually this function is ℜ→(ℜ ∪ ∞)
What is the type of ∫ (indefinite integral)?
Def'n:
a function f:A→A is idempotent if ∀ a ∈ A, f(f(a))=f(a).
Consider an installer program: what is its input? What does idempotency mean?
Building new functions from old
-
Sum,product of functions:
(f+g), (f*g), (fg).
When do these make sense?
Only when +,* defined on their domains
(well, the cross-prod of their domains)
-
Composing functions. Commutative? (What's the signature of ``compose''?)
-
Conversely, Extending functions from elements onto sets:
If A = {2,3,5}, then 4*A = {8,12,20}.
Really, ``4*'' is just a function which happens to be defined
on the elements of A.
Consider also:
A = {Barland,Cooper,Leebron}; numKids(A) = { 0, 2 }.
In general, what do we mean by f(A)?
We can extend f:A → B to a new function
f*: P(A) → P(B),
where f*(a*) = { b | exists a ∈ a* such that f(a)=b }
Equivalently: f*(a*) = ∪a∈a* {f(a)}.
[What is the code for this? (Btw, for list-represent, Cf. map)]
What about binary functions?
{2,3,5} ^ {-1,2} = {1/2,1/3,1/5, 4,9,25}.
What is size of A^B ? Not |A|^|B|, certainly! Beware 22 vs 41?
We can now phrase ``rationals closed under addition?'' as ``Q+Q ⊆? Q''
Is the set {Jan,Apr,Jul,Oct} closed under tax-refund-return-month?
More useful definitions:
-
Image, f(S)
-
codomain; the term ``range'' is deprecated these days.
-
How might we define ``pre-image''?
-
A set A is ``closed under f'' if f:A→A and f*(A) ⊆ A.
-
def'n onto: (everything gets mapped to at least once)
for each y ∈ Y, there is some x ∈ X s.t. f(x)=y
Equivalently: f's image = f's entire co-domain.
-
def'n 1-1, or into:
(nothing is mapped to more than once)
∀x,y, f(x)=f(y) iff x=y.
-
Inverse (def'n):
A function f: X → Y is invertable iff:
there exists some function g such that
-
for any x ∈ X, g(f(x)) = x [``g is a left-inverse of f''], and
-
for any y ∈ Y, f(g(y)) = y [``g is a right-inverse of f''].
Example: keybindings:
Consider a program where it's possible to configure which key corresponds
to which action (text editors, video games
[ian: link to the appropriate lines of
http://www.owlnet.rice.edu/~comp210/01fall/Assignments/Hw10/hw10-soln.ss,
if public.]
Discuss:
Is this best described as a function, or as a relation?
In each case, what is the domain/codomain?
If a function: Is it 1-1, onto, invertible?
What about a keyboard-map (Qwerty, Dvorak; foreign-language glyphs)?
What does it mean if a Xkeyboard map is not invertible?
Not ∈ text:
Th'm: f: X → Y is invertable, iff f is 1-1,onto.
Proof: Outline: prove two directions (one of which as two parts):
-
-
If f is invertable, then f is 1-1.
-
If f is invertable, then f is onto.
-
If f is 1-1 and onto, then it's invertable.
Each of these parts is straightforward,
but we'll keep reminding ourselves where we are and what we're trying to show:
-
-
Suppose g is the inverse of f. We'll show f is 1-1:
That is, we'll show: if f(xa) = f(xb), then xa = xb (for arbitray xa, xb).
If f(xa) = f(xb), then g(f(xa)) = g(f(xb)) (apply g to equal things gives equal output).
But because g is a (left) inverse, g(f(xa)) = xa and g(f(xb)) = xb,
so we have that xa = xb, which completes the requirement for 1-1.
-
Suppose g is the inverse of f. We'll show f is onto:
That is, we'll show that for any y0 ∈ Y, there is
some x0 ∈ X such that f(x0) = y0.
Given an arbitrary y0, which x0 ∈ X will do the trick?
g(y0) will!, since f(g(y0)) = y0.
[Note that g(y0) is indeed an element of X, since g: Y → X.]
[Interesting, a nice symmetry: this used g being a right-inverse of f.]
-
Suppose f is 1-1 and onto; we'll show that f has an inverse.
We'll construct a function g:Y → X as follows, and then confirm that this
particular g really does meet the requirements of ``inverse of f''.
For any y0 ∈ Y, we define g(y0) as: the element x0 such that f maps x0 to y0
— such an x0 exists because f is onto!
Is this function g really an inverse of f? Let's look at the def'n of inverse:
for any x ∈ X, what is g(f(x))? g(f(x)) is the element of X which f maps to f(x); this is x.
So g(f(x)) = x, and our constructed function g is indeed a left-inverse to f.
Similarly: for any y ∈ Y, what is f(g(y))? Well by our construction of g,
g(y) is thing which f maps to y, so therefore f(g(y)) = y.
Woo-hoo! Um, wait a minute — in this second part, we used f being
onto, but we didn't prove that f is 1-1. What gives? We'll use our
debugging skills: Have we proven something stronger — that if f is
onto, then it's invertable? If so, can we come up with a
test-input? That is, make a function that is onto but not 1-1; does
it have an inverse? Why not? What was the bug in our proof?
Upshot: In English, Beware the ``the''!
The word implies uniqueness and existence:
What a beautiful work of modern art — I'll marry the painter who created this!
-
What if the work had been created by a team of several people [``the painter'' non-unique]
-
What if a bucket had just been tipped over by the wind? [``the painter'' non-existent]
[Unless of course the artist set up the bucket in a windy area,
anticipating nature to complete their vision for them …
or, they consider chance as ``art'', when you let it evoke an emotional reaction.]
For example, in our proof that 90=100, we
glibly said ``let C be the point where two lines intersect'';
technically we needed to add that such a point exists (easy to show
the lines were non-parallel), and such a point is unique (clear, since
two lines only intersect at most once, at least in Euclidean
geometry.)
A few numeric functions:
⌊floor⌋, ⌈ceiling⌉; round-to-even; truncate-towards-0.
Reducing functions to sets: graphs!
Which is more fundamental: sets, or functions?
Between graphs and indicator functions: either!
[well okay — in a graph you need to lookup ]
[an error occurred while processing this directive]
[an error occurred while processing this directive]