What is a function? It would be tempting to answer this question by writing a function. It probably involves a variable, a couple exponents, some additions and products; maybe, to make the heart content, top this up with a bevy of trigonometric functions, logarithms, and other exponentials. What do we get? Well, some kind of monster surely. But is that a function? Not quite, as there are a bunch of ingredients missing. But let us pretend for a second, because this chimera would surely and rightfully be called a function by most. Nonetheless, do we get an archetypical function, something that is a good representation of what functions really are?
Undoubtedly, no. For what is a function? It is, in general, a mechanism (or a machine, a black box, a magic wand) which transforms something into something. You input some stuff into your function, and it will output some other stuff (which could be the same). Usual functions are given by a formula, as above:
In a typical calculus class, there would often be a follow-up question: “what is the domain of this function?” In other words, what is the set of for which this formula is well-defined? Here, you want what is inside the logarithm to be strictly positive, and the denominator to be non-zero. Good luck getting an explicit description for that! In any case, the set of points where this formula makes sense is the following well-defined subset of
:
Now, we indeed have a true function: it takes any element of , applies the given formula, and returns some real number.
Definition, kinda
In general, to define a function, we need three ingredients.
- What objects it can take as an input.
- What type of objects it outputs.
- What happens to the input objects.
The point is that all of these can be pretty much anything. In calculus, functions often input some real numbers, and output real numbers. In multivariable calculus, functions input a vector of real numbers, and output a real number or a vector of real numbers. In linear algebra, functions take vectors to vectors. In more advanced analysis, functions input functions and output functions. Computer functions take as input some keyboard strokes, and can output a whole bunch of things: text, images, sound, etc.
A usual class of functions in computer science are “codes”: you enter a text, and the code turns into some gibberish. This would define a function from the set of all texts to the set of all texts, by some well-defined procedure. How exactly does this procedure work? Hopefully, this is extremely complicated! Otherwise, this means that the code is easy to crack.
We are now ready to make a general, abstract, almost precise definition.
A function is the data of
- a set
, called the domain;
- a set
, called the codomain;
- a rule which assigns, to each element
of
, one unique element of
, called the image of
and denoted by
.
We then say that is a function from
to
, and write
.
The only thing which is not quite precise is the meaning of “rule”. A perfectly rigorous definition is given at the end of this post, but sadly, it cannot really be called enlightening. In any case, think of such a rule as a procedure that unambiguously tells us how to transform something in to something in
. “Unambiguously” does not mean “explicitly”:
does not need to be given by some formula (and more often than not, it is not).
Consider the function , which inputs a natural number
and outputs the
-th prime number. It is perfectly well-defined, for instance
However, there is no (known) formula for
. If there were, pretty much all the online security would be doomed!
Consider the function , defined for
by
Check that for every , the equation
has a unique solution
. This defines a function
, by
“the unique solution
to the equation
“. It turns out that there is no explicit formula for this solution.
There is a philosophical question hidden here: what does “explicit” even mean? The sentence “the only positive solution to ” does not seem very explicit. But “
” seems quite explicit. Is it “explicit” to write
, even though its decimal expansion is a mess? What about
?
Similarly, it is perfectly acceptable to describe a function using plain English, as long as it is clear and everyone understands without ambiguity. Using a formula often makes things much less clear, even for simple functions. For instance, a usual type of continuous functions is called “piecewise linear“: it is a function whose graph is a broken line, as below.

Write a precise definition of a piecewise linear function defined on an interval .
Isn’t it more clear to just write a sentence in English and draw a figure?
Let us consider the Caesar cypher. It is a very simple code: take a word, and change each A in B, B in C, … Y in Z, Z in A. For instance, “MATH” becomes “NBUI”. How would we describe this as a function? We first need a domain. It makes sense to choose the set of all possible words. But what is a word? The set of actual words seems quite complicated indeed: should we include “IRREGARDLESS”? “BAE”? “ANATIDAEPHOBIA”? “FGDSARWCOBFQPLM”? Well, why not? The cypher is just as easy to define for these “words”. So we might as well consider all words, and get a domain which is much easier to describe. But then what do we call a word? It could be any finite sequence of letters, say to simplify a letter of the alphabet . A sequence (or ordered couple) of two letters is then an element of
, according to standard notation. Finally, we want to take the domain to be
After coding, we get also another word, so the codomain should be . What about the transformation rule? Well, we explained it at the beginning! Probably everyone can understand how this work, so this is good enough! Whatever formula that we could write would just be terrible and incomprehensible.
The BMP format stores image in a computer as a table of pixels with rows and
columns. The color of each pixel is given by three integer numbers from
to
, giving the scale of red, blue, and green. If a function takes such an image as input, what would its domain be?
Many words of caution
The domain
The domain of a function is a data. It should be given along with all the other ingredients, i.e. the codomain and the “rule”. It is the set of values that we want to consider, not necessarily all those that we could consider. If our variable is time, we may want time to only move forward, and consider a domain . If it is an angle, we may want only angles in
or
. Its choice is extremely important, and can change drastically the properties of a function.
Define with
for
. For each
or
, find a domain
for which the equation
has exactly
solutions.
The other important property is that needs to be defined for all
. In other words, the rule that assigns
to
has to make sense for any
that we choose in
. And this is true however we define this “rule”: by a formula, implicitly, in plain English, etc.
Which of the following define a bona fide function? The codomain is implied.
-
for
.
-
for
.
-
for
.
-
for
.
-
is the number of digits of
.
-
is the temperature on December 31st, 1999, at some point
, where
is the surface of the earth.
-
is the
-th digit after the dot of
, for
.
-
is the birth date of
, for
being all the people in the world.
-
is the name of the first child of
, for
being all the people in the world.
In calculus, it is customary to define the “domain” of a “function” as the set of points where a formula makes sense, as in our first example. It is more proper to call it the natural domain. In such a question, what is actually given in such a question is not a function, but an expression or a formula. Once we have determined the natural domain , we get a true function with domain
, codomain (usually)
, and where
is indeed well-defined for all
by the formula given. It is worth noting than more often than not, the natural domain is too large for all intents and purposes, and choosing a smaller domain is more suitable.
The codomain
The codomain is the type of objects that our
become, after going through the machine
. It is also a data of the problem, but it is usually an obvious one. All the usual functions given by some formula output a real number, so the co-domain is often chosen to be
. In Example I.1, we would naturally choose the codomain to be
. But we could just as well choose it to be the set of prime numbers, or
, or
. In any case, there is often a natural choice: the answer to the (often very simple) question “what type of object do we get after applying the function?”. This should not be confused with the much more difficult question “what are all the objects that we get after applying the function?”.
In Exercise II.2, natural choices of co-domain would be as follows.
for #1, 4.
for #5.
for #6 (if we measure in Celsius or Fahrenheit),
if we measure in Kelvins. In Celsius,
would also probably work.
for #7, or
could work too.
- The set of all calendar dates for #8.
In any case, only one thing needs to be true: any for
must belong to the codomain
. Therefore, we can enlarge the codomain as much as we want, but we cannot shrink it too much.
A word of vocabulary: we say that a function is from its domain to its codomain. Sometimes to is replaced by into. However, it does not mean that the function takes all the values in the co-domain. Consider for instance for
.
- If we say
, we say that the
outputs real values. We know this.
- If we say
, we say that the
outputs real values between
and
. This is more precise, but this is absolutely not a way to say that it takes all values between
and
.
The rule
We already mentioned that the rule that assigns to
should be defined for all elements
, and provide an element
. However we define it, it should make sense for whatever
that we choose in
, and the result should be something that belongs to
.
Now, what is important is that is defined unambiguously. In other words, there cannot be different choices. It is unique. If we let
, and define
to be “
such that
“, then we do not have a function, for several reasons.
- If
, then there is no such
. This is an issue with the definition of the domain.
- If
, then there is such a
. But there is an ambiguity, as there are two different choices. This is an issue with the rule.
To solve the first issue, we instead define the domain to be . To solve the second issue, we lift the ambiguity by demanding, arbitrarily but naturally, that the
in question should be positive. This being done, we have indeed, for all
, a number
which is defined in a unique way. We have defined the function “square root“. It has domain
, and we can choose the range to be
or
or anything in between.
Which of the following define a bona fide function? If it is not, explain precisely the issue. The codomain is implied.
-
such that
, for
.
-
such that
, for
.
-
such that
, for
.
-
is the temperature at day
, where
is the set of all days from 1 AD to 2000 AD.
-
if
,
if
, for
.
-
is the number of digits of
.
-
is the name of
‘s grandmother, where
and
is the set of all the people in the world.
A matter of notation
Function and image
Take a function from a domain
to a codomain
. The following additional vocabulary is standard.
If and
, then
-
is called the argument or input of the function;
-
is called the value or output of the function, or the image of
by
.
It is important to distinguish between the function itself and the image of an element. The first one is denoted by : it has a domain, a codomain, and provides a procedure to turn some
into some
. The second one is written
, and it is an element of
Therefore, one should say “the function
” 🙂 and not “the function
” 😦 It is at best a poor choice of words, at worst an open door for mistakes.
Define to be the set of all differentiable functions defined on
, and
the set of all functions on
. For a function
, we can define
. This defines a function
from
to
: it inputs a differentiable function, and outputs its derivative.
Take the function defined by
for
. Then
, where
is the function defined by
for all
. It would be correct (but clumsy) to write that
Usual functions are the trigonometric functions , the exponential
, and the logarithm
. To say that the derivative of the sine is the cosine, the most compact way is to write
. Other tempting options are the following.
-
for all
🙂
-
😐
😦
The first choice is correct but cumbersome. The second one is imprecise. The third one is an aberration, and doom awaits the blasphemers.
In calculus, when there is no issue with the domain, it is often acceptable to define a function by just giving a formula, such as “The function is strictly increasing”. Nonetheless, afterwards, we should still say “the function
“.
Sequences
A sequence is merely a function with domain . It is customary to make the following notation.
- Instead of
, we write
or
(or sometimes merely
).
- Instead of
or
, we write
.
Therefore, we should say “the sequence “. The notation
denotes the
-th term of the sequence, where
should be given.
As above, it is often acceptable to define a sequence by just giving a formula, such as “The sequence “. Nonetheless, afterwards, we should still say “the sequence
” or “the sequence
“.
Arrow and arrow
When we write that a function goes from a domain
to a codomain
, we often write
. In
, this arrow is given by “\to” or by “\rightarrow”.
To specify how an element of is transformed into an element of
via
, we often write “
(some formula) for all
“. It is necessary to add “for all
“: otherwise, we are talking about some
that is not introduced. It is similar to saying “John aced his calculus exam” to someone who does not know who John is.
Now, this is quite unwieldy. To circumvent this, we can instead write (some formula)”. Careful of the different arrow! In
, this arrow is given by “\mapsto”. If you did some Python, it is the same as writing a lambda function. Therefore, we always have
In general, the most economical way to fully define a function from
to
, where
is given by some formula, is to write the following.
The function of Exercise 3 can be written
Bonus: formal definition
In order to define a function perfectly rigorously, we need to associate one and only one
to each
. This can be done by giving the graph of the function, i.e. the set of points
Formally, we can proceed as follows.
A function is the data of
- a set
, called the domain;
- a set
, called the codomain;
- a set
, such that, for any
, there exists a unique
. We write then
.
This encapsulates both important points discussed before.
- each
has an image
;
- this image is unique, i.e. defined unambiguously.
Formally, a function is the domain + the codomain + the graph. In practice, naturally, we should think as we usually do, while bearing in mind the aforementioned points.