In mathematics, a function[note 1] is a binary relation between two sets that associates every element of the first set to exactly one element of the second set. Typical examples are functions from integers to integers, or from the real numbers to real numbers.

Functions were originally the idealization of how a varying quantity depends on another quantity. For example, the position of a planet is a function of time. Historically, the concept was elaborated with the infinitesimal calculus at the end of the 17th century, and, until the 19th century, the functions that were considered were differentiable (that is, they had a high degree of regularity). The concept of a function was formalized at the end of the 19th century in terms of set theory, and this greatly enlarged the domains of application of the concept.

A function is a process or a relation that associates each element x of a set X, the domain of the function, to a single element y of another set Y (possibly the same set), the codomain of the function. It is customarily denoted by letters such as , and .[1]

If the function is called f, this relation is denoted by y = f(x) (which reads "f of x"), where the element x is the argument or input of the function, and y is the value of the function, the output, or the image of x by f.[2] The symbol that is used for representing the input is the variable of the function (e.g., f is a function of the variable x).[3]

A function is uniquely represented by the set of all pairs (x, f(x)), called the graph of the function.[note 2][4] When the domain and the codomain are sets of real numbers, each such pair may be thought of as the Cartesian coordinates of a point in the plane. The set of these points is called the graph of the function; it is a popular means of illustrating the function.

Functions are widely used in science, and in most fields of mathematics. It has been said that functions are "the central objects of investigation" in most fields of mathematics.[5]

Schematic depiction of a function described metaphorically as a "machine" or "black box" that for each input yields a corresponding output
The red curve is the graph of a function, because any vertical line has exactly one crossing point with the curve.
A function that associates any of the four colored shapes to its color.