A function is a rule that assigns exactly one output to each input from a given set. Functions are one of the most fundamental and unifying concepts in mathematics — appearing in algebra, calculus, computer science, and beyond. Formally, a function is a special kind of relation between two sets.
Imagine a vending machine: you press button "B4," and it always gives you the same snack. Press it again, same snack comes out. That's exactly what a function is — a rule where every input has one, and only one, output.
Something is not a function if one input could give two different outputs. For example, "the square root of x" is tricky — is √9 equal to 3 or −3? Both work! To make it a function, mathematicians agree that √x always means the positive square root. That's a rule that fixes the ambiguity.
We write f(x) to mean "the output of function f when the input is x." So if f(x) = x², then f(3) = 9, f(5) = 25, and f(−2) = 4.
A function f from set A (the domain) to set B (the codomain), written f : A → B, assigns to each element a ∈ A exactly one element f(a) ∈ B. The set of actual outputs {f(a) : a ∈ A} is the range (or image).
| Function | Formula | Domain |
|---|---|---|
| Linear | f(x) = mx + b | All reals |
| Quadratic | f(x) = ax² + bx + c | All reals |
| Exponential | f(x) = aˣ | All reals |
| Logarithmic | f(x) = logₐ(x) | x > 0 |
| Trigonometric | f(x) = sin(x) | All reals |
Given f : A → B and g : B → C, the composition g∘f : A → C is defined by (g∘f)(a) = g(f(a)). Function composition is associative but not generally commutative: f∘g ≠ g∘f in general.
If f : A → B is bijective, its inverse f⁻¹ : B → A satisfies f⁻¹(f(a)) = a and f(f⁻¹(b)) = b. Not every function has an inverse — only bijective ones. For example, f(x) = x² on all reals is not injective (both 2 and −2 map to 4), so it has no inverse unless the domain is restricted (e.g. to x ≥ 0).
In modern set theory, a function f : A → B is formally defined as a subset of the Cartesian product A × B — a set of ordered pairs (a, b) — satisfying: for every a ∈ A, there is exactly one b ∈ B with (a,b) ∈ f. This reduces the function concept entirely to set theory, with no extra primitive notion needed. This definition, standard since the early 20th century, resolves earlier ambiguities about what a function "really is."
The word "function" was introduced by Leibniz (1673) in a geometric context. Euler (1748) gave the first algebraic definition, treating a function as any expression built from variables and constants using algebraic operations. Dirichlet (1837) gave the modern, general definition — a function is any rule assigning outputs to inputs, without requiring an algebraic formula. This was radical: it allowed functions like the Dirichlet function (1 if x is rational, 0 if irrational), which cannot be written as any single "nice" formula and is discontinuous everywhere.
In category theory, functions between sets are the prototypical example of morphisms — the abstract notion of "structure-preserving map" that generalises to morphisms between groups (homomorphisms), topological spaces (continuous maps), and more. This perspective, developed by Eilenberg and Mac Lane (1945), treats objects and their maps as more fundamental than the internal structure of the objects themselves.
Not every mathematically definable function is computable — able to be evaluated by an algorithm in finite time. The Church-Turing thesis identifies "computable function" with "function computable by a Turing machine." The halting problem shows there exist well-defined functions (e.g., "does program P halt on input x?") that provably cannot be computed by any algorithm.