Algebra & Functions · Function

Function

A function from a set A to a set B pairs every element of A with exactly one element of B. No input may be left without an output or have more than one; several inputs may share one.

Functions in this visualization

A function ff from a set AA to a set BB, written f ⁣:A→Bf\colon A \to B, pairs every element xx of AA with exactly one element of BB, written f(x)f(x). It is also called a map or mapping. AA is the domain, the set of inputs; BB is the codomain, where the outputs may come from; the outputs actually reached form the range, or image. Here you draw the pairing as arrows from AA to BB and see the same pairs as points (x,y)(x, y) on a grid; the readout says whether they make a function and, if not, which input breaks the condition.

The two sets on this page
A={−2,−1,0,1,2},B={−2,−1,0,1,2,3,4}A = \{-2, -1, 0, 1, 2\}, \qquad B = \{-2, -1, 0, 1, 2, 3, 4\}

What the condition checks

The condition is about the inputs only. Each input needs an output, and only one: an input with no arrow, or with two or more, means the pairs are not a function from AA to BB. The outputs have no such condition. Several inputs may share an output, as −2-2 and 22 share 44 under x2x^2, and elements of BB may receive no arrow at all; a constant function sends every input to the same output.

Nor does a function need a formula: giving each input any one output defines a function, whether or not some formula describes it. And an equation does not guarantee one. On these sets y2=xy^2 = x pairs 11 with both −1-1 and 11, and gives −2-2, −1-1 and 22 nothing in BB.

The inputs come first

Whether a set of pairs is a function depends on AA. Start with the function in the first highlight and remove its arrow 0→40 \to 4. What is left is no longer a function from AA to BB, because 00 is in AA and has no output; yet the same arrows are a function on the smaller set {−2,−1,1,2}\{-2, -1, 1, 2\}. Shrinking the set of inputs only settles the inputs you leave out, though: on {−2,−1,1,2}\{-2, -1, 1, 2\}, y2=xy^2 = x is still not a function, since 11 still has two outputs and −2-2, −1-1 and 22 still have none. When a function is given only by a formula, its domain is usually taken to be every xx for which the formula makes sense. Some areas, such as computability theory, also speak of partial functions, which may leave inputs without an output; a function from AA to BB, as on this page, leaves none.

The vertical line test

On the grid, the vertical line through an input xx meets one point for each output of xx. So the pairs are a function from AA to BB exactly when, for each xx in AA, the vertical line through xx meets exactly one point; lines through numbers outside AA have nothing to check. The test is the definition read off the graph, since the arrows and the points are the same pairs.

Controls

  • Drag from a number in AA to a number in BB to draw an arrow, or to remove one already there; or click one end, then the other.
  • Click a grid cell to place or remove a point. With the keyboard, focus the picture, move with the arrow keys and press Space.

Related