Home

Functions

Functions are a fundamental concept in mathematics and computer science. In mathematics, a function f from a set X (the domain) to a set Y (the codomain) assigns to every element x in X exactly one element f(x) in Y. The notation f: X → Y and the value f(x) are standard. The domain specifies where the function is defined; the codomain is the target set. The range, or image, is the set of outputs actually produced, a subset of the codomain. A function is often described as a rule or a correspondence between inputs and outputs.

Key properties include injectivity (one-to-one), where different inputs yield different outputs; surjectivity (onto), where every element

In computer science, a function is a named block of code that accepts inputs and returns a

of
the
codomain
has
a
preimage;
and
bijectivity,
where
both
hold.
A
function
is
invertible
on
its
domain
when
it
is
bijective,
with
an
inverse
function.
Functions
can
be
composed:
if
f:
X
→
Y
and
g:
Y
→
Z,
then
g
∘
f:
X
→
Z.
The
graph
of
a
real-valued
function
is
the
set
of
ordered
pairs
(x,
f(x));
notions
of
monotonicity,
continuity,
and
limits
describe
its
behavior.
Common
examples
include
linear
functions
f(x)
=
ax
+
b,
polynomial
functions,
exponential,
logarithmic,
and
trigonometric
functions.
value.
Functions
may
be
pure
(no
side
effects)
or
impure;
they
can
be
higher-order,
taking
or
returning
other
functions.
Closures
capture
surrounding
state.
Functions
underlie
most
programming
languages
and
contrast
with
subroutines
by
emphasizing
value
return
and
composability.