Lec 05 Functions
Lec 05 Functions
Lecture 5: Functions
1
Definition of Functions
• Given any sets A, B, 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.
2
Graphical Representations
• Functions can be represented graphically in
several ways:
f A B
• •
f • •
• • • y
a b •
•
•
•
x
A
B Graph
Plot
Like Venn diagrams
3
Definition of Functions (cont’d)
• Formally: given f:A®B
“x is a function” :º (¬$x,y: x=y Ù f(x) ¹ f(y)) or
4
Some Function Terminology
• If f:A®B, and f(a)=b (where aÎA & bÎB),
then:
– 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.
• In general, b may have more than one pre-image.
– The range RÍB of f is {b | $a f(a)=b }.
5
Range vs. Codomain - Example
• Suppose that: “f is a function mapping
students in this class to the set of grades
{A,B,C,D,E}.”
• At this point, you know f’s codomain is:
__________, and its range is ________.
• Suppose the grades turn out all As and Bs.
• Then the range of f is _________, but its
codomain is __________________.
6
Function Addition/Multiplication
• We can add and multiply functions
f,g:R®R:
7
Function Composition
• For functions g:A®B and f:B®C, there is a
special operator called compose (“○”).
– It composes (i.e., creates) a new function out of f, g by
applying f to the result of g.
(f ○g): A®C, where (f ○g)(a) = f(g(a)).
– Note g(a)ÎB, so f(g(a)) is defined and ÎC.
– The range of g must be a subset of f’s domain!!
– Note that ○ (like Cartesian ´, but unlike +,Ù,È) is non-
commuting. (In general, f○g ¹ g○f.)
8
Function Composition
9
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 one pre-image.
• Only one element of the domain is mapped
to any given one element of the range.
– Domain & range have same cardinality. What
about codomain?
10
One-to-One Functions (cont’d)
• Formally: given f:A®B
“x is injective” :º (¬$x,y: x¹y Ù f(x)=f(y)) or
11
One-to-One Illustration
• Graph representations of functions that are
(or not) one-to-one:
• • • •
• • •
• • •
• • •
• •
• •
• • •
• • • •
• •
•
Not one-to-one Not even a
One-to-one function!
12
Sufficient Conditions for 1-1ness
• Definitions (for functions f over numbers):
– f is strictly (or monotonically) increasing iff
x>y ® f(x)>f(y) for all x,y in domain;
– f is strictly (or monotonically) 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 is one-to-one.
– e.g. f(x)=x3
13
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).
• An onto function maps the set A onto (over,
covering) the entirety of the set B, not just
over a piece of it.
– e.g., for domain & codomain R, x3 is onto,
whereas x2 isn’t. (Why not?)
14
Illustration of Onto
• Some functions that are or are not onto their
codomains:
•
• • • • • • • •
• • • • • •
• •
• • • •
• • • •
• • • •
• • • •
• •
Onto Not Onto Both 1-1 1-1 but
(but not 1-1) (or 1-1) and onto not onto
15
Bijections
• A function f is a one-to-one correspondence
or a bijection, or reversible, or invertible, iff
it is both one-to-one and onto.
16
Inverse of a Function
-1
f ! f =I
17
Inverse of a function (cont’d)
18
The Identity Function
• For any domain A, the identity function
I:A®A (variously written, IA, 1, 1A) is the
unique function such that "aÎA: I(a)=a.
• Some identity functions you’ve seen:
– Ùing with T, Úing with F, Èing with Æ, Çing
with U.
• Note that the identity function is both one-
to-one and onto (bijective).
19
Identity Function Illustrations
• The identity function:
•
• • y
• •
• •
• •
20
Graphs of Functions
• We can represent a function f:A®B as a set
of ordered pairs {(a,f(a)) | aÎA}.
• Note that "a, there is only one pair (a, f(a)).
• For functions over numbers, we can
represent an ordered pair (x,y) as a point on
a plane. A function is then drawn as a curve
(set of points) with only one y for each x.
21
Graphs of Functions
22
A Couple of Key Functions
• In discrete math, we frequently use the
following functions over real numbers:
– ëxû (“floor of x”) is the largest integer £ x.
– éxù (“ceiling of x”) is the smallest integer ³ x.
23
Visualizing Floor & Ceiling
• Real numbers “fall to their floor” or “rise to
their ceiling.” 3
é1.6ù=2
2 .
• Note that if xÏZ, .
1.6
.
ë-xû ¹ - ëxû & 1 ë1.6û=1
0
é-xù ¹ - éxù .é-1.4ù= -1
-1 .
• Note that if xÎZ, -2
-1.4
.
ëxû = éxù = x.
ë-1.4û= -2
-3 .. .
-3
é-3ù=ë-3û= -3
24
Plots with floor/ceiling: Example
-3 +3 x
-2
25