Functions as Special Relations

What exactly is a function? Calculus students learn to think of a function as a rule, a formula, or a machine. It takes inputs and produces outputs. This picture works well enough for polynomials and sines and cosines. But it collapses the moment we ask about functions with no formula at all. Consider a function assigning to each person their birth mother. Or a function encoding an infinite binary sequence. Foundations demands a single precise object that covers every case uniformly. It must do so without appeal to the vague word "rule." The resolution comes from the set-theoretic reworking of mathematics in the early twentieth century. It is to identify a function with its graph: the set of all input–output pairs it produces. A set of ordered pairs is precisely a relation. So a function becomes a special kind of relation. It obeys a single-valuedness condition that forbids one input from having two different outputs. This move is quietly radical. It means "function" is not a primitive concept but a derived one. It is built entirely out of sets and the membership relation. This reduction matters because it makes function into a genuinely rigorous, checkable notion. Given any candidate set of ordered pairs, we can verify whether it is a function. We do this by checking one condition, rather than debating whether it "counts" as a legitimate rule. It also unifies functions given by formulas, functions given by infinite tables, and functions defined by cases or by recursion. All fall under one definition. This uniformity is exactly what is needed later. We need it when we classify functions by their behavior — into injections, surjections, and bijections. We also need it when we compare the sizes of infinite sets via cardinality. This article gives the precise definition of a function as a relation with the single-valued property. It carefully distinguishes domain, codomain, and range. It proves the basic existence-and-uniqueness theorem that licenses "function value" notation. It works through examples designed to expose the traps students most often fall into. Especially the confusion between codomain and range. Also the subtlety of when a relation defined by a formula actually deserves to be called a function on its stated domain.

Key takeaways
  • A function is a relation ff in which every element of the domain is related to exactly one element of the codomain.
  • Formally: f⊆A×Bf \subseteq A \times B is a function from AA to BB if for every a∈Aa \in A there is a unique b∈Bb \in B with (a,b)∈f(a,b) \in f.
  • The graph of ff is ff itself as a set of ordered pairs; "f(a)=bf(a) = b" is just shorthand for "(a,b)∈f(a,b)\in f."
  • The domain is fixed by the definition of f:A→Bf: A \to B; the range (image) can be a proper subset of the codomain BB.
  • Single-valuedness is what separates a function from an arbitrary relation; it is the only extra axiom imposed.
  • Key idea: a function is nothing more than a set of ordered pairs satisfying "no two pairs share a first coordinate with different second coordinates," together with a specified domain and codomain.

Where this lives today

The relational definition of function is the silent backbone of essentially all of modern mathematics and its applications, precisely because it is the only definition precise enough to survive contact with infinite, arbitrary, or algorithmically inexpressible correspondences.

  • Set theory and cardinality. Comparing the sizes of infinite sets — the subject this chapter is heading toward — is done entirely via functions between them: injections and surjections are defined as extra properties layered on top of the single-valuedness condition developed here, and cardinal arithmetic is built from bijections, which are functions that are simultaneously injective and surjective.
  • Computer science. In functional programming and formal semantics, a program's meaning is often modeled as a (possibly partial) function from inputs to outputs; the totality/partiality distinction traces directly back to whether clause (1) above holds on the stated domain, and type systems are designed precisely to catch "undefined at some inputs" errors at compile time.
  • Database theory. A relational database table enforces "functional dependencies" — constraints stating that one column's value determines another's — which are exactly instances of the single-valuedness clause applied to projections of a relation.
  • Cryptography. Hash functions, encryption maps, and pseudorandom generators are all functions in this exact sense: total, single-valued maps between finite sets (bit-strings of fixed length), and security proofs frequently hinge on properties like injectivity (collision-resistance) built on top of this base definition.
  • Probability and statistics. Random variables are defined as measurable functions from a sample space to R\mathbb{R}; the single-valuedness clause is what guarantees a random variable assigns one, not several, numerical outcomes to each sample point.
  • Physics and engineering. Physical laws expressed as functions of state (e.g., pressure as a function of volume and temperature) implicitly rely on this same single-valuedness: a genuine state function cannot take two different values for one and the same state, which is exactly the mathematical content of clause (2).

Ask the tutor: How does the definition of function as a relation change when we move to partial functions, and why do computer scientists care about that distinction?

DefinitionFunction as a Relation

Let AA and BB be sets. A function from AA to BB, written f:A→Bf : A \to B, is a triple (A,B,G)(A, B, G) where G⊆A×BG \subseteq A \times B is a set of ordered pairs — called the graph of ff — satisfying two conditions: 1. (Totality on AA) For every a∈Aa \in A, there exists b∈Bb \in B such that (a,b)∈G(a,b) \in G. 2. (Single-valuedness) For every a∈Aa \in A and all b1,b2∈Bb_1, b_2 \in B, if (a,b1)∈G(a,b_1) \in G and (a,b2)∈G(a,b_2) \in G, then b1=b2b_1 = b_2. The set AA is called the domain of ff, written dom⁡(f)\operatorname{dom}(f). The set BB is called the codomain. The set

ran⁡(f)={ b∈B:(a,b)∈G for some a∈A }\operatorname{ran}(f) = \{\, b \in B : (a,b) \in G \text{ for some } a \in A \,\}

is called the range (or image) of ff; in general ran⁡(f)⊆B\operatorname{ran}(f) \subseteq B, with equality not required. By conditions (1) and (2) together, for each a∈Aa \in A there is a unique b∈Bb \in B with (a,b)∈G(a,b)\in G; this unique element is denoted f(a)f(a), and we write (a,b)∈G  ⟺  f(a)=b(a,b) \in G \iff f(a) = b. Two functions f:A→Bf : A \to B and g:C→Dg : C \to D are equal iff A=CA = C, B=DB = D, and they have the same graph — equivalently, iff they have the same domain, same codomain, and f(a)=g(a)f(a) = g(a) for every aa in that common domain.

Intuition

Think of a relation R⊆A×BR \subseteq A \times B as a bipartite "wiring diagram": draw the elements of AA on the left, elements of BB on the right, and an edge from aa to bb whenever (a,b)∈R(a,b) \in R. An arbitrary relation allows any pattern of wires whatsoever — an element of AA might have no wires, one wire, or five wires leaving it. A function is the special case where the wiring is tidy on the left: every element of AA has exactly one wire coming out of it. There is no restriction at all on the right-hand side — an element of BB may have zero incoming wires (it lies outside the range), one incoming wire, or many incoming wires (several elements of AA can share the same output). This is precisely what "single-valued and total" is encoding, and it is worth internalizing as a picture: totality forbids missing wires from the left, single-valuedness forbids forked wires from the left. Neither condition says anything about the right side of the diagram — that asymmetry is exactly what later gets named and studied as injectivity (no two left-elements share a wire) and surjectivity (every right-element receives a wire).

Figure
A relation that is a function (left) versus one that is not (right): every dot in AA sends exactly one arrow out on the left; on the right, a2a_2 sends two arrows and a4a_4 sends none.
Function f : A → B Not a function a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ a₂ has two arrows; a₄ has none

The central theorem

TheoremExistence and Uniqueness of Function Value

Let f:A→Bf : A \to B be a function with graph G⊆A×BG \subseteq A \times B, in the sense of the definition above. Then for every a∈Aa \in A there exists a unique b∈Bb \in B such that (a,b)∈G(a,b) \in G. Consequently the notation f(a)f(a), defined by "f(a)f(a) is the unique bb with (a,b)∈G(a,b) \in G," is well-defined: it names exactly one object of BB for every input a∈Aa \in A, and this assignment a↦f(a)a \mapsto f(a) recovers the graph, in the sense that

G={ (a,f(a)):a∈A }.G = \{\, (a, f(a)) : a \in A \,\}.
Proof

Technique: direct proof from the two defining clauses, followed by a set-equality argument (double inclusion) for the closing identity. Existence. Fix a∈Aa \in A. By clause (1) of the definition (totality), there exists at least one b∈Bb \in B with (a,b)∈G(a,b) \in G. This establishes existence of a bb witnessing membership. Uniqueness. Suppose b1,b2∈Bb_1, b_2 \in B both satisfy (a,b1)∈G(a, b_1) \in G and (a,b2)∈G(a, b_2) \in G. By clause (2) of the definition (single-valuedness), applied to this same aa, we conclude b1=b2b_1 = b_2. Hence any two witnesses coincide, so the witness is unique. Having shown existence and uniqueness of a bb with (a,b)∈G(a,b) \in G, for each a∈Aa\in A, the description "the unique b∈Bb \in B such that (a,b)∈G(a,b) \in G" picks out a single well-defined element of BB; this justifies introducing the symbol f(a)f(a) for that element, with the defining property

(a,b)∈G  ⟺  b=f(a).(∗)(a, b) \in G \iff b = f(a). \tag{$\ast$}

(The forward direction of (∗)(\ast) is uniqueness; the backward direction holds because f(a)f(a) is one of the witnesses, by existence.) Closing identity. We show G={(a,f(a)):a∈A}G = \{(a, f(a)) : a \in A\} by mutual inclusion. (⊆\subseteq) Let (a,b)∈G(a,b) \in G. Since G⊆A×BG \subseteq A \times B, we have a∈Aa \in A. By the forward direction of (∗)(\ast), b=f(a)b = f(a). Hence (a,b)=(a,f(a))(a,b) = (a, f(a)), which lies in the right-hand set. (⊇\supseteq) Let (a,f(a))(a, f(a)) be an arbitrary element of the right-hand set, where a∈Aa \in A. By the backward direction of (∗)(\ast) (existence, restated), (a,f(a))∈G(a, f(a)) \in G. Both inclusions hold, so the two sets are equal. ■\blacksquare

∎
CorollaryFunction Equality Criterion

Two functions f:A→Bf : A \to B and g:A→Bg : A \to B with the same domain and codomain are equal as functions if and only if f(a)=g(a)f(a) = g(a) for every a∈Aa \in A.

Proof

Technique: unfold the definition of equality of graphs using the theorem above. By the closing identity of the theorem, ff's graph is {(a,f(a)):a∈A}\{(a,f(a)) : a \in A\} and gg's graph is {(a,g(a)):a∈A}\{(a,g(a)) : a \in A\}, both subsets of A×BA \times B. (⇒\Rightarrow) If f=gf = g as functions their graphs coincide as sets. Fix a∈Aa \in A; then (a,f(a))(a, f(a)) lies in ff's graph, hence in gg's graph, so by uniqueness of the gg-witness for input aa (the theorem applied to gg), f(a)=g(a)f(a) = g(a). (⇐\Leftarrow) Suppose f(a)=g(a)f(a) = g(a) for all a∈Aa \in A. Then {(a,f(a)):a∈A}={(a,g(a)):a∈A}\{(a,f(a)) : a\in A\} = \{(a,g(a)) : a \in A\} termwise, hence as sets (any element of the left set is (a,f(a))=(a,g(a))(a,f(a)) = (a,g(a)), an element of the right set, and symmetrically). By the theorem's closing identity applied to both ff and gg, their graphs are equal, and since domain and codomain were assumed equal, f=gf = g. ■\blacksquare

∎

Worked examples

Example 1 (a genuinely finite, asymmetric function). Let A={1,2,3,4}A = \{1, 2, 3, 4\} and B={p,q,r,s,t}B = \{p, q, r, s, t\}. Define

G={(1,q),(2,q),(3,t),(4,p)}.G = \{(1,q), (2,q), (3, t), (4, p)\}.

Check totality: every element of AA — namely 1,2,3,41,2,3,4 — appears as a first coordinate in some pair of GG. Indeed 11 appears in (1,q)(1,q), 22 in (2,q)(2,q), 33 in (3,t)(3,t), 44 in (4,p)(4,p). Totality holds. Check single-valuedness: we must confirm no first coordinate appears twice with different second coordinates. Scanning GG, the first coordinates used are 1,2,3,41,2,3,4, each occurring exactly once. So there is no possibility of a conflict; single-valuedness holds vacuously well (there is simply nothing to conflict). Hence GG is (the graph of) a function f:A→Bf : A \to B, with f(1)=qf(1) = q, f(2)=qf(2) = q, f(3)=tf(3) = t, f(4)=pf(4) = p. Now examine domain, codomain, range carefully, since this is where the asymmetry of the example matters:

  • dom⁡(f)=A={1,2,3,4}\operatorname{dom}(f) = A = \{1,2,3,4\}.
  • Codomain is the declared target B={p,q,r,s,t}B = \{p,q,r,s,t\}, a set of size 55.
  • ran⁡(f)={q,t,p}\operatorname{ran}(f) = \{q, t, p\}, a set of size 33.

Note r,s∈Br, s \in B are never hit: ran⁡(f)⊊B\operatorname{ran}(f) \subsetneq B. Note also qq is hit twice (by both 11 and 22) — this is completely permitted, since single-valuedness constrains only the left side of the wiring diagram. This example shows concretely that codomain and range are different objects in general: a codomain is a choice made when the function is declared, while the range is computed after the fact from the graph.

Example 2 (when a "formula" fails to define a function on a stated domain, and how to fix it). Let A=ZA = \mathbb{Z}, B=QB = \mathbb{Q}, and consider the candidate rule

h(n)=nn2−4.h(n) = \frac{n}{n^2 - 4}.

Set G={(n,h(n)):n∈Z, n≠±2}G = \{(n, h(n)) : n \in \mathbb{Z},\ n \neq \pm 2\}, i.e. we attempt to make G⊆Z×QG \subseteq \mathbb{Z} \times \mathbb{Q} by including a pair for every integer nn where the formula is defined. Test totality on A=ZA = \mathbb{Z}: does every n∈Zn \in \mathbb{Z} appear as a first coordinate? Take n=2n = 2: the formula gives 24−4=20\frac{2}{4-4} = \frac{2}{0}, undefined, so there is no pair (2,b)∈G(2, b) \in G for any bb. Totality on A=ZA = \mathbb{Z} fails. Hence, strictly, GG is not a function from Z\mathbb{Z} to Q\mathbb{Q} — the formula does not deserve to be called "h:Z→Qh : \mathbb{Z} \to \mathbb{Q}" as declared, and a homework answer asserting this without comment is an error of exactly the kind this article is built to catch. The fix: restrict the domain to A′=Z∖{2,−2}A' = \mathbb{Z} \setminus \{2, -2\} and declare h:A′→Qh : A' \to \mathbb{Q}. Now recheck both clauses.

  • Totality on A′A': for every n∈A′n \in A' (so n≠±2n \neq \pm 2), n2−4≠0n^2 - 4 \neq 0, so h(n)=n/(n2−4)h(n) = n/(n^2-4) is a well-defined rational number; a pair (n,h(n))(n, h(n)) exists in GG. Totality holds.
  • Single-valuedness: for fixed nn, the expression n/(n2−4)n/(n^2-4) names one specific rational number (division of specific integers by a specific nonzero integer produces one rational number, by the definition of Q\mathbb{Q} as equivalence classes of pairs, per Quotient Sets and Well-Definedness). So there cannot be two different b1≠b2b_1 \neq b_2 both equal to h(n)h(n). Single-valuedness holds.

So h:Z∖{2,−2}→Qh : \mathbb{Z}\setminus\{2,-2\} \to \mathbb{Q} is a function. Let's compute a few values to see the range is a proper, and rather sparse, subset of Q\mathbb{Q}:

h(0)=0−4=0,h(1)=1−3=−13,h(3)=35,h(−1)=−1−3=13.h(0) = \frac{0}{-4} = 0, \qquad h(1) = \frac{1}{-3} = -\tfrac13, \qquad h(3) = \frac{3}{5}, \qquad h(-1) = \frac{-1}{-3} = \tfrac13.

Notice h(−n)=−h(n)h(-n) = -h(n) for all nn in the domain — a genuine algebraic fact about this particular function, not something guaranteed by the definition of "function" itself; it is a special feature (oddness) of this graph, illustrating that the bare definition of function says nothing about such symmetries — they must be proved separately from the formula.

CounterexampleWhy single-valuedness cannot be dropped

Claim under attack: "A relation R⊆A×BR \subseteq A \times B satisfying only totality (every a∈Aa\in A has some bb with (a,b)∈R(a,b)\in R) already deserves to be called a function, and the function-value notation R(a)R(a) can be used safely."

Why this fails. Take A={1,2}A = \{1,2\}, B={x,y}B = \{x,y\}, and

R={(1,x),(1,y),(2,x)}.R = \{(1,x), (1,y), (2,x)\}.

Totality holds: 11 has a partner (xx, or indeed yy), and 22 has a partner (xx). But single-valuedness fails at a=1a=1: both (1,x)∈R(1,x) \in R and (1,y)∈R(1,y) \in R, with x≠yx \neq y. If we tried to use the notation "R(1)R(1)" as in the Existence and Uniqueness theorem, we would be asserting there is one object deserving that name — but the proof of that theorem used single-valuedness essentially, in the uniqueness half, to rule out exactly this situation. Concretely: is R(1)R(1) supposed to be xx or yy? Both are equally licensed by membership in RR, and nothing in the data of RR breaks the tie. Any further reasoning that manipulates "R(1)R(1)" as though it names a single fixed object — for instance, substituting it into another expression, or asserting R(1)=R(1)R(1) = R(1) trivially as if this pins down one value — becomes unsound, because the symbol secretly denotes two different things depending on which occurrence of R(1)R(1) you mean. This is not a pathological edge case: it is exactly the failure mode of "multi-valued rules" that beginners sometimes propose, such as "let g(n)g(n) be a square root of nn" over the reals — for n>0n>0 there are two square roots, and without single-valuedness, "g(4)g(4)" is ambiguous between 22 and −2-2. The fix is always the same: either restrict to a genuine single-valued selection (e.g., "the nonnegative square root," recovering a true function), or abandon function notation and work with the relation RR directly, quantifying over all pairs (a,b)∈R(a,b) \in R rather than writing R(a)R(a).

Scope, edge cases & common traps

SituationWhat to checkCommon error
Function given by explicit list of pairsTotality and single-valuedness on the stated domainAssuming totality without checking every domain element is covered
Function given by a formulaDomain must exclude every input where the formula is undefinedDeclaring f:R→Rf:\mathbb{R}\to\mathbb{R}, f(x)=1/xf(x)=1/x, and forgetting x=0x=0
Range vs. codomainRange is computed from the graph; codomain is chosenTreating "range" and "codomain" as synonyms
Multi-valued "functions" (e.g. square root, arcsine before branch choice)Must pick a single-valued branch to get a genuine functionWriting 4=±2\sqrt{4} = \pm 2 and calling ⋅\sqrt{\cdot} a function on R≥0\mathbb{R}_{\ge0} without fixing sign
Two functions with same formula, different declared domain/codomainThese are formally different functionsClaiming f:Z→Zf:\mathbb{Z}\to\mathbb{Z}, f(n)=nf(n)=n equals g:N→Zg:\mathbb{N}\to\mathbb{Z}, g(n)=ng(n)=n
Empty domainThe empty relation ∅⊆∅×B\varnothing \subseteq \varnothing \times B is (vacuously) a function ∅→B\varnothing \to BAssuming a function must have nonempty domain

The mathematician behind it

Origins · 1 minRichard Dedekind and how this was discovered
RD
Richard Dedekind
1831–1916 · Foundations of arithmetic and the modern set-theoretic definition of function

Richard Dedekind, a German mathematician working at Braunschweig and closely associated with Göttingen, was among the first to insist on treating a function purely extensionally — as determined entirely by its input–output pairs rather than by any expression or "law" producing them. In Was sind und was sollen die Zahlen? (1888), Dedekind develops the theory of mappings ("Abbildungen") between sets in essentially the modern style, laying groundwork that Ernst Zermelo and later set theorists would formalize fully within axiomatic set theory, where a function is literally identified with its graph — a set of ordered pairs satisfying single-valuedness. This reduction of "function" to "special relation" is the culmination of a longer historical shift, from Euler's functions-as-formulas, through Dirichlet's and Riemann's arbitrary correspondences, to Dedekind's and Zermelo's fully extensional, set-theoretic object.

History
- 1837: Dirichlet articulates the "arbitrary correspondence" conception of function, decoupling it from formulas.
- 1888: Dedekind's Was sind und was sollen die Zahlen? treats mappings between sets extensionally, via their effect on elements.
- 1908: Zermelo axiomatizes set theory, providing the framework (pairing, subsets of Cartesian products) in which "function as a set of ordered pairs" becomes fully rigorous.
- 1910–1913: Whitehead and Russell's Principia Mathematica develops functions-as-relations within a type-theoretic framework, cementing the relational viewpoint in logic.
- 1939: Bourbaki's treatise formally defines a function as a triple (graph, domain, codomain) satisfying single-valuedness, the version most textbooks use today.
Is a function literally the same thing as its graph, or are they different objects?

In the strict Bourbaki-style formalization used here, a function is the triple (A,B,G)(A,B,G) — domain, codomain, and graph — not the graph GG alone. Two functions with the same graph but different declared codomains are formally different objects, even though they agree on every input. In practice, many textbooks (and this one, informally) speak of "the graph of ff" as if it were ff, because the graph determines everything about the input–output behavior; the codomain is extra bookkeeping that matters mainly for defining surjectivity later. When precision is needed — e.g., asking whether a function is surjective — you must remember the codomain is part of the data, not recoverable from the graph alone.

Why does the definition require totality — why not allow a "function" to be undefined at some domain points?

If you allow this, you get the useful but distinct notion of a partial function: a relation satisfying single-valuedness but not necessarily totality on AA, together with the convention that it is a genuine (total) function on the smaller set {a∈A:some b exists}\{a \in A : \text{some } b \text{ exists}\}, called its domain of definition. Foundationally, "function from AA to BB" is reserved for the total notion precisely so that dom⁡(f)\operatorname{dom}(f) unambiguously equals the declared set AA; partial functions are a useful generalization but are named differently to avoid exactly the domain-restriction confusion illustrated in Example 2 above.

Can two different formulas give the same function?

Yes, and this is expected, since equality of functions is decided by equality of graphs (equivalently, agreement of all values, by the Function Equality Criterion), not by syntactic similarity of formulas. For instance f(x)=(x+1)2−2x−1f(x) = (x+1)^2 - 2x - 1 and g(x)=x2g(x) = x^2, both as functions R→R\mathbb{R}\to\mathbb{R}, are the same function, because f(x)=g(x)f(x)=g(x) for every real xx — even though the formulas look different before algebraic simplification. This is exactly why the graph, not the formula, is taken as the true identity of a function.

Does single-valuedness say anything about elements of the codomain being hit only once?

No — that is a completely separate condition, called injectivity, which will be defined and studied on its own once functions are classified further (see Injections, Surjections). Single-valuedness constrains only how many outputs a single input can have (exactly one); it places no constraint on how many inputs may share a single output. In Example 1 above, both 11 and 22 map to qq, and this is entirely consistent with ff being a function — it merely means ff is not injective.

How does this relational definition interact with equivalence classes and well-definedness, as in quotient constructions?

When a function is defined on a quotient set A/∼A/{\sim} by a formula referencing representatives, e.g. hˉ([a])=h(a)\bar h([a]) = h(a), one must prove single-valuedness explicitly: if [a1]=[a2][a_1] = [a_2] (i.e. a1∼a2a_1 \sim a_2) then h(a1)=h(a2)h(a_1) = h(a_2) must be checked, precisely because the graph of hˉ\bar h is only legitimately a function if no two representative choices for the same class produce different outputs. This is exactly the Quotient Sets and Well-Definedness issue: "well-definedness" of a function on a quotient is single-valuedness of its would-be graph, checked at the level of equivalence classes rather than raw elements.

Is the empty set a function?

The empty set ∅\varnothing is a function from ∅\varnothing to any set BB: totality holds vacuously (there is no a∈∅a \in \varnothing to produce a counterexample), and single-valuedness holds vacuously for the same reason. However, ∅\varnothing is generally not a function from a nonempty AA to BB, since totality then fails outright — some a∈Aa \in A has no partner at all. This shows domain matters even when the graph itself, as a bare set, is the same object (∅\varnothing) in both cases.

Why bother with codomain at all if only the range matters for "what values are actually produced"?

The codomain records the space the function was declared to land in, which matters for composing functions and for defining surjectivity. If f:A→Bf:A\to B and g:B→Cg:B\to C, the composite g∘fg\circ f is only guaranteed sensible because every output of ff lies in BB, the stated domain of gg — a fact guaranteed by the codomain declaration, not by the (possibly much smaller) range. Surjectivity is likewise a statement about the codomain ("range equals codomain"), so discarding the codomain would make that entire classification impossible to state.

Before this