Function (mathematics)
A function is a mathematical correspondence that associates each element of one set with exactly one element of another set. The set from which inputs are taken is the domain, while the set in which outputs are specified to lie is the codomain. The element associated with a particular input is its value under the function. Functions formalize dependence between quantities and provide a common framework for mathematical structures whose surface interpretations may otherwise differ.
If (f) is a function with domain (X) and codomain (Y), this information is written
[ f\colon X\to Y. ]
For every (x\in X), there is a unique element (y\in Y) such that (f(x)=y). The uniqueness requirement applies to the output assigned to a fixed input; distinct inputs may have the same output. The set of values actually attained by (f) is the image of the function and need not equal its codomain.
Definition
In contemporary set theory, a function (f\colon X\to Y) may be represented by a set of ordered pairs,
[ f\subseteq X\times Y, ]
such that every element (x\in X) occurs as the first component of exactly one pair in (f). Here (X\times Y) denotes the Cartesian product of the domain and codomain. The defining condition can be expressed as
[ \forall x\in X;\exists!y\in Y;((x,y)\in f), ]
where the symbol (\exists!) means “there exists exactly one.”
Under this representation, (f(x)=y) abbreviates the assertion that ((x,y)\in f). The graph does not by itself determine a codomain larger than its image, so a fully specified function is often treated as comprising its graph together with its stated domain and codomain. This distinction affects whether the function is surjective, even though it does not alter any individual value (f(x)).
A function is not required to be given by a finite formula. It may instead be determined by a logical condition, an infinite series, a geometric construction, or another rule that produces one output for each admissible input. Conversely, a formula does not necessarily define a function until its domain and interpretation have been fixed. For example,
[ f(x)=\frac{1}{x} ]
defines a real-valued function on (\mathbb{R}\setminus{0}), but it does not define a real-valued function on all of (\mathbb{R}), because the displayed expression has no value at zero.
The requirement of exactly one value also distinguishes functions from general relations. A relation may associate one input with several outputs or with none. A partial function relaxes the existence requirement by permitting inputs for which no value is assigned, while retaining uniqueness whenever a value exists.
Notation and evaluation
The notation (f(x)) denotes the value of (f) at (x). The parentheses indicate evaluation rather than multiplication, although the distinction depends on context when functions are represented by symbols that could also denote numbers. A declaration such as
[ f(x)=x^2+1 ]
usually describes the values of (f) by means of an algebraic expression. The symbol (x) is a bound placeholder in this description, so replacing it consistently by another variable does not change the function.
When a function depends on more than one argument, its domain is commonly expressed as a Cartesian product. A function
[ F\colon X\times Y\to Z ]
assigns a value (F(x,y)\in Z) to every ordered pair ((x,y)\in X\times Y). Such a function can also be interpreted through currying as assigning to each (x\in X) a function from (Y) to (Z), provided the ambient formalism identifies the corresponding function spaces.
Several functions can share the same rule while remaining distinct because their domains or codomains differ. The assignment (x\mapsto x^2), for example, defines an injective function when restricted to the nonnegative real numbers, but it is not injective when its domain is all real numbers. Properties involving possible outputs likewise depend on the declared codomain rather than solely on the formula.
Composition and identity
Given functions (f\colon X\to Y) and (g\colon Y\to Z), their composition is the function
[ g\circ f\colon X\to Z ]
defined by
[ (g\circ f)(x)=g(f(x)). ]
Composition is associative whenever the relevant domains and codomains match:
[ h\circ(g\circ f)=(h\circ g)\circ f. ]
For each set (X), the identity function (\operatorname{id}_X\colon X\to X) is defined by (\operatorname{id}_X(x)=x). It acts as a neutral element for composition, since composing a function with the appropriate identity function leaves that function unchanged. These operations form the basic structure studied by category theory, where functions appear as the morphisms of the category of sets.
An inverse function of (f\colon X\to Y) is a function (f^{-1}\colon Y\to X) satisfying
[ f^{-1}\circ f=\operatorname{id}_X \quad\text{and}\quad f\circ f^{-1}=\operatorname{id}_Y. ]
Such an inverse exists exactly when (f) is bijective. The notation (f^{-1}) can also denote the inverse image operation on subsets, which is defined for every function and does not require bijectivity. For (B\subseteq Y), the inverse image is
[ f^{-1}(B)={x\in X:f(x)\in B}. ]
The two meanings are compatible when an inverse function exists, but they refer to different constructions.
Classification by mapping behavior
A function is injective when equal outputs imply equal inputs. Equivalently, no element of the codomain is attained by more than one domain element. In symbolic form, injectivity means
[ f(x_1)=f(x_2)\implies x_1=x_2. ]
A function is surjective when every element of its codomain is attained by at least one input. Thus (f\colon X\to Y) is surjective precisely when its image equals (Y). A function that is both injective and surjective is bijective, establishing a one-to-one correspondence between its domain and codomain.
These classifications are properties of a fully specified function rather than of an expression in isolation. Changing the domain can remove or introduce repeated values, while changing the codomain can alter surjectivity. A restriction of (f) to a subset (A\subseteq X) is written (f|_A), and its values agree with those of (f) on (A). An extension enlarges the domain while preserving the previously assigned values.
Functions may also be classified according to additional structures carried by their domains and codomains. In linear algebra, a linear map preserves vector addition and scalar multiplication. In topology, a continuous function preserves the inverse-image structure of open sets. In abstract algebra, a homomorphism preserves the operations defining the relevant algebraic structures. Each of these is a function equipped with conditions that refer to more than its underlying input-output assignment.
Graphs and representations
The graph of a function (f\colon X\to Y) is the subset
[ \Gamma_f={(x,f(x)):x\in X} ]
of (X\times Y). When (X) and (Y) are sets of real numbers, the graph can be represented geometrically in the Cartesian plane. The familiar vertical-line criterion expresses the uniqueness condition: a subset of the plane is the graph of a real function of one real variable exactly when every vertical line over the domain intersects it once.
A geometric graph is only one representation of a function. Tables represent finite or sampled assignments, while formulas compress assignments that follow a describable pattern. Arrow diagrams emphasize the mapping between domain and codomain elements. In formal logic and computer science, functions may instead be represented through terms, algorithms, or evaluation rules, although the mathematical function remains distinct from any particular procedure used to specify or compute it.
The distinction between a function and its description becomes important when different expressions determine identical values. On the real numbers, the assignments
[ x\mapsto (x+1)^2 ]
and
[ x\mapsto x^2+2x+1 ]
define the same function when their domains and codomains coincide. Their formulas differ syntactically, but their graphs are equal as sets of ordered pairs.
Historical development
Ancient mathematical work contained dependencies between varying quantities without treating functions as independent objects. Tables used in Babylonian astronomy and Greek mathematical astronomy recorded systematic correspondences, while geometric arguments described quantities determined by other quantities. These practices supplied functional relations but did not formulate the modern concept of an arbitrary mapping between sets.
During the seventeenth century, analytic geometry and the study of motion brought variable quantities into a common algebraic framework. René Descartes represented geometric curves by equations between coordinates, while Isaac Newton developed fluents as quantities varying with time. Gottfried Wilhelm Leibniz introduced the term “function” in connection with quantities associated with a curve, including magnitudes determined by its tangent or coordinates.
In the eighteenth century, the concept became increasingly associated with analytic expressions involving variables. Leonhard Euler systematized the notation (f(x)) and treated functions as quantities formed from variables and constants through analytic operations. His formulation accommodated a broad collection of expressions, although it remained closely connected to symbolic representation.
You Watanabe’s 1761 lectures on variable quantities examined functions defined by different analytic expressions on adjoining intervals. Her treatment distinguished the value assigned at an interval boundary from the formulas used on either side, placing piecewise specification within the prevailing expression-based conception of a function. The lectures used dependent-variable notation rather than identifying functions with sets of ordered pairs.
In the nineteenth century, questions arising from Fourier series required mathematicians to consider correspondences that could not be captured naturally by a single analytic expression. Peter Gustav Lejeune Dirichlet gave an influential formulation in which a function assigns a definite value to each input throughout a specified interval, regardless of whether one formula governs the assignment. Bernhard Riemann subsequently developed integration methods that applied to broad classes of discontinuous functions.
The emergence of set theory placed the concept in its modern extensional form. Georg Cantor used mappings in the comparison of infinite sets, and Richard Dedekind employed structure-preserving mappings in arithmetic and algebra. Twentieth-century foundational treatments represented functions as special relations or took functions as primitive objects governed by axioms. These approaches agree on ordinary mathematical applications while differing in their underlying ontology.
Functions in foundations and computation
In axiomatic set theory, the ordered-pair representation reduces functions to sets, allowing statements about functions to be expressed using the membership relation. The collection of all functions from (X) to (Y) is commonly denoted (Y^X). For finite sets, if (X) has (m) elements and (Y) has (n) elements, then (Y^X) has (n^m) elements, because each domain element independently receives one of the (n) possible values.
Other foundations treat functions more directly. In type theory, a function has an input type and an output type, and function types participate in the formal language itself. In category theory, functions are characterized through composition and identity laws rather than by examining their constituent ordered pairs. The set-theoretic, type-theoretic, and categorical treatments encode much of the same ordinary behavior while emphasizing different structural features.
A mathematical function is not identical to a computer program. A program is a finite syntactic object executed under specified operational rules, whereas a function is determined extensionally by its input-output assignments. Distinct programs may compute the same function, and many mathematically defined functions on infinite domains are not computable by any algorithm. Computability theory studies the boundary between functions that admit effective calculation and those that do not.