A function assigns exactly one output to each input
From set X to set Y, a function pairs every element of X with precisely one element of Y. Domain and codomain name those sets; f(x) names the value. Graphs of pairs (x,f(x)) make the rule visible—and central to modern math.
Given two sets X and Y, a function attaches to every element of X exactly one element of Y. X is the domain and Y the codomain; the element paired with x is written f(x) and called the value or image of x, and the set of all images is the image, sometimes called the range. Functions usually get single-letter names such as f, g, or h, and when one is defined by a formula, some computation, known as evaluation, may be needed to find a particular value.
The idea began as an idealization of one changing quantity depending on another, such as a planet's position depending on time. It was developed alongside infinitesimal calculus at the end of the seventeenth century, but the working definition used by Leibniz, Newton, and Euler, an 'assignment' of outputs to inputs, could not be made rigorous because assignment itself had no mathematical definition. Only at the end of the nineteenth century did set theory supply a formal version.
That formal version treats a function as a binary relation between X and Y, a subset of their Cartesian product, meeting two conditions: every x is paired with some y, and no x is paired with two different values. Given the domain and codomain, the set of all pairs (x, f(x)) is the function's graph; for real numbers each pair is a point in the plane, which is why graphs are such a popular illustration. The 'maps to' arrow even lets a function be defined without a name, as with the square function sending x to x².
Domains are not always known in advance. Finding where a real function built from another is defined can require knowing that function's zeros, which is why analysts sometimes say 'a function from X to Y' when the domain is only part of X. A function 'on a set S' may leave the codomain unstated, or mean that it maps S to itself. Functions pervade science and engineering, and some writers describe them as the main thing that most branches of mathematics study.
Source: Function (mathematics)