How Mathematics Works

What a Function Is and Why It Organizes Modern Mathematics

A function gives each input exactly one output. See what that rule allows, how functions combine and why so many ideas are built on them.

Key takeaways

  • A function has a domain of inputs, a codomain where outputs live and exactly one output for every input.
  • A function does not need a formula, and its inputs and outputs do not need to be numbers.
  • Functions can be composed, and a function can be undone only if it pairs inputs and outputs perfectly.
  • Many objects, including sequences, transformations and random variables, are functions in disguise.

A function is a rule or correspondence that assigns to each element of one set exactly one element of another set. Put in an allowed input, and there is one definite output.

That modest idea has become the common language of mathematics. Sequences, graphs, geometric motions, probabilities and arithmetic operations can all be described as functions, so facts proved about functions in general apply to all of them.

The definition, piece by piece

Writing f : A → B means that f is a function from the set A to the set B. A is the domain, the collection of inputs. B is the codomain, the collection in which outputs are required to lie. For an input x, the output is written f(x) and read "f of x".

Two requirements do all the work:

  1. Every element of the domain gets an output.
  2. No element gets more than one.

Nothing forbids two inputs from sharing an output. Squaring sends both 3 and −3 to 9, and it is a perfectly good function.

The range or image is the set of outputs actually produced. For f(x) = x² from the real numbers to the real numbers, the codomain is all reals, but the range is only the numbers that are 0 or larger.

The domain is part of the function. The rule 1/x does not define a function on all real numbers, because there is no output at 0. It does define one on the nonzero reals.

No formula required

School examples such as f(x) = 2x + 3 can suggest that a function is a formula. The definition asks for much less.

  • A table listing the high temperature for each of seven days is a function from days to temperatures.
  • Assigning to each person in a room their birth month is a function from people to months.
  • The rule "output 1 if x is rational and 0 if x is irrational" is a function on the real numbers, although no graph you draw can show it faithfully.

Formally, a function can be described as a set of ordered pairs (input, output) in which each input appears exactly once. The graph of a real function is just that set of pairs, drawn in the plane. This is why the vertical line test works: if some vertical line meets a curve twice, one input has two outputs. The circle x² + y² = 1 fails the test, so it is not the graph of y as a function of x, though its upper half, y = √(1 − x²) for −1 ≤ x ≤ 1, is.

The broad modern definition took a long time to emerge, a story told in how the concept of a function changed.

Reading a function in several forms

One function can be presented in several ways, and each makes something different easy to see. Take the rule that doubles a number and subtracts 1, with domain {0, 1, 2, 3}.

Form What it looks like
Formula f(x) = 2x − 1
Table 0 → −1, 1 → 1, 2 → 3, 3 → 5
Ordered pairs (0, −1), (1, 1), (2, 3), (3, 5)
Words double the input, then subtract 1
Graph four separate points that lie on a straight line

The graph has only four points because the domain has only four elements. Drawing a solid line through them would picture a different function, one whose domain is an interval of real numbers.

Two functions are equal when they have the same domain and codomain and agree at every input. The way they are described is irrelevant. On the domain {0, 1}, the rules x and x² define the same function, since 0² = 0 and 1² = 1. On all real numbers they are plainly different.

The notation also deserves care. The letter f names the function as a whole, while f(x) names one output, although people often blur the two. And f(a + b) is usually not f(a) + f(b). With f(x) = x², f(1 + 2) = 9, while f(1) + f(2) = 5.

Composing functions

If the outputs of one function are legal inputs for another, you can run them in sequence. The composition g ∘ f sends x to g(f(x)): first apply f, then g.

Order matters. Let f(x) = x + 1 and g(x) = x².

g(f(2)) = g(3) = 9
f(g(2)) = f(4) = 5

In general g(f(x)) = (x + 1)², while f(g(x)) = x² + 1.

Composition is associative: h ∘ (g ∘ f) = (h ∘ g) ∘ f, because both mean "do f, then g, then h". There is also an identity function on every set, which returns its input unchanged. Those two features are the starting point of category theory, which studies mathematics largely through the way maps compose.

Undoing a function

When can you recover the input from the output? Two properties are involved.

Property Meaning
Injective (one-to-one) Different inputs always give different outputs
Surjective (onto) Every element of the codomain is hit
Bijective Both at once, a perfect pairing

A function has an inverse exactly when it is bijective. For f(x) = 2x + 3 on the real numbers, solve y = 2x + 3 to get x = (y − 3)/2. Check: f(4) = 11, and (11 − 3)/2 = 4.

Squaring on all reals is not injective, so it has no inverse. Restrict the domain and codomain to the nonnegative reals, and the inverse is the square root. Much of the care in defining inverse trigonometric functions is this same restriction. More examples are in injective, surjective and bijective functions.

Familiar objects that are functions
f : A → B One output for each input Network walk time Pair of places → minutes Derivative Function → new function Random variable Outcome → number Sequence Position number → term Operation Pair of numbers → result Motion Point → moved point f : A → B One output for each input Sequence Position number → term Operation Pair of numbers → result Motion Point → moved point Random variable Outcome → number Derivative Function → new function Network walk time Pair of places → minutes

Functions in disguise

Here is why the idea organizes so much.

A sequence such as 1, 4, 9, 16 is a function on the positive integers, with value n² at n.

Addition is a function that takes a pair of numbers and returns one number. So are multiplication and many abstract operations studied in algebra.

A geometric transformation, such as a rotation or reflection, is a function from the plane to itself. Doing one motion after another is composition, which is the route into group theory and symmetry.

In probability, a random variable is a function that assigns a number to each outcome of an experiment. If you toss two coins, "number of heads" sends HH to 2, HT and TH to 1, and TT to 0.

In calculus, differentiation is itself a function whose inputs and outputs are functions: it sends x³ to 3x².

Even the size of infinite sets is defined with functions. Two sets have the same cardinality when there is a bijection between them. The rule n → 2n pairs the positive integers with the positive even integers, showing the two sets are the same size.

Counting functions

For finite sets, you can count every possible function. Each input independently chooses one output, so if A has m elements and B has n, there are nᵐ functions from A to B.

With three inputs and two possible outputs there are 2³ = 8 functions. Of these, six are surjective, since only the two constant functions miss an output. None is injective, because three inputs cannot receive three different values from a set of two.

That last observation is the pigeonhole principle in function form: if the domain of a function between finite sets is larger than the codomain, two inputs must collide.

Is it well defined?

Sometimes an input has several names, and a rule depends on which name you use. Try defining a "function" on fractions by f(a/b) = a + b. Then f(1/2) = 3, but f(2/4) = 6. Since 1/2 and 2/4 are the same number, one input has received two outputs, so no function has been defined.

By contrast, g(a/b) = a/b + 1 gives the same answer for every way of writing the fraction. Mathematicians say it is well defined. This check appears whenever objects are formed by treating different things as the same, the subject of equivalence relations.

Common questions

Is every equation in x and y a function?

No. An equation describes a set of points. It defines y as a function of x only if each allowed x goes with exactly one y. The equation y = x³ does. The equation y² = x does not, because x = 4 goes with both 2 and −2.

Can a function have several inputs?

Yes, in the sense that the single input can be a pair or a longer list. The area of a rectangle, A(w, h) = wh, is a function whose domain consists of pairs of positive numbers. It still returns exactly one output for each pair.

Can the output be a list?

It can. A function giving the position of a moving point at time t returns two or three coordinates together, which count as one element of the codomain. The rule of one output per input is untouched.

How to examine a new function

When you meet an unfamiliar function, a short routine helps.

  1. Identify the domain and codomain. What kind of object goes in, and what comes out?
  2. Evaluate it on a few simple inputs.
  3. Ask whether two inputs can give the same output.
  4. Ask which outputs can never occur.
  5. If numbers are involved, sketch a graph and look for jumps, turning points and long-run behavior.
  6. Ask what the function preserves. Does it keep order, distances or the results of addition?

The last question leads far. Functions that respect structure, such as distance-preserving motions in geometry or addition-preserving maps in algebra, let mathematicians compare whole systems. A reader who learns to ask "what are the maps here?" has a reliable way into almost any new branch of the subject.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 32 articles in How Mathematics Works →

Latest news on this topic