Functions

Chapter 5: Functions

Learning objectives

  • Define a function as a special kind of relation
  • Distinguish functions from general relations using totality and well-definedness
  • Identify the domain, codomain, and range of a function
  • Compose two functions and apply the identity function

What makes "function" different from "relation"? A function imposes exactly one output for each input. Drop that requirement and you get an arbitrary relation; impose it and you get the single most important structure in mathematics. Every program is a function (input bytes → output bytes). Every API call is a function. Every neural network, every audio filter, every database query — functions all the way down. This section gives the precise set-theoretic definition that underlies all of those examples, and the algebra of composition that lets you build big functions out of small ones.

Definition

A function from AA to BB, written f:ABf: A \to B, is a relation fA×Bf \subseteq A \times B satisfying two extra requirements:

  • Total:
aA,bB,(a,b)f\forall a \in A,\, \exists b \in B,\, (a, b) \in f

— every input has at least one output.

  • Well-defined:
aA,b1,b2B,((a,b1)f(a,b2)f)b1=b2\forall a \in A,\, \forall b_1, b_2 \in B,\, ((a, b_1) \in f \wedge (a, b_2) \in f) \Rightarrow b_1 = b_2

— each input has at most one output.

Together: exactly one output. We write that unique output as f(a)f(a).

Domain, codomain, range

The domain is AA, the codomain is BB, and the range (or image) is Ran(f)={f(a)aA}B\text{Ran}(f) = {f(a) \mid a \in A} \subseteq B. The range is always a subset of the codomain but need not equal it. Example: f:RR,f(x)=x2f: \mathbb{R} \to \mathbb{R},, f(x) = x^2 has codomain R\mathbb{R} but range [0,)[0, \infty).

Equality of functions

Two functions f,gf, g are equal iff they have the same domain, the same codomain, and f(a)=g(a)f(a) = g(a) for every aa. All three conditions matter: f:ZZ,f(n)=nf: \mathbb{Z} \to \mathbb{Z},, f(n) = n and g:ZR,g(n)=ng: \mathbb{Z} \to \mathbb{R},, g(n) = n are different functions because their codomains differ.

Composition and identity

Given f:ABf: A \to B and g:BCg: B \to C, the composition gf:ACg \circ f: A \to C is defined by (gf)(a)=g(f(a))(g \circ f)(a) = g(f(a)). Composition is associative but generally not commutative. The identity function idA:AA,idA(a)=a\text{id}_A: A \to A,, \text{id}_A(a) = a satisfies fidA=ff \circ \text{id}_A = f and idBf=f\text{id}_B \circ f = f — it is the "do-nothing" function for composition.

Mapping ArrowsInteractive figure — enable JavaScript to interact.

Pause and think: Why isn’t the relation R={(1,a),(1,b),(2,c)}R = {(1, a), (1, b), (2, c)} a function from {1,2}{1, 2} to {a,b,c}{a, b, c}? Which of the two function-defining properties fails? (Hint: input 11 is paired with two different outputs.)

Try it

  • Decide whether R={(1,a),(2,a),(3,b)}R = {(1, a), (2, a), (3, b)} is a function from {1,2,3}{1, 2, 3} to {a,b}{a, b}. Justify both properties.
  • For f(x)=2x+1f(x) = 2x + 1 and g(x)=x2g(x) = x^2 on R\mathbb{R}, compute (gf)(3)(g \circ f)(3) and (fg)(3)(f \circ g)(3). Are they equal?
  • What is the range of f:ZZ,f(n)=2nf: \mathbb{Z} \to \mathbb{Z},, f(n) = 2n? Is the codomain equal to the range?
  • Prove: if f:ABf: A \to B and g:BCg: B \to C, then gf:ACg \circ f: A \to C is itself a function (verify both properties).
  • True or false: (x+1)21(x + 1)^2 - 1 and x2+2xx^2 + 2x define equal functions on R\mathbb{R}. Justify.

A trap to watch for

"Range" and "codomain" are not synonyms. The codomain is fixed by the function’s declared signature f:ABf: A \to B; it tells you the type of the output. The range is the set of outputs actually achieved. For f(x)=x2f(x) = x^2 on RR\mathbb{R} \to \mathbb{R}, the codomain is R\mathbb{R} but the range is only [0,)[0, \infty). Whether range equals codomain is the question we will study in §5.2 (it is called surjectivity).

What you now know

You can read off the data of any function (domain, codomain, range), distinguish a function from an arbitrary relation, compose functions correctly, and recognise the identity function as the do-nothing element for composition. Section 5.2 examines two special properties of functions — injectivity and surjectivity — that together make a function invertible.

References

  • Velleman, D. J. (2019). How to Prove It (3rd ed.). Cambridge University Press, §5.1.
  • Halmos, P. R. (1960). Naive Set Theory. Springer, §8.
  • Enderton, H. B. (1977). Elements of Set Theory. Academic Press, ch. 3.
  • Hammack, R. (2018). Book of Proof, ch. 12.
  • Bird, R., Wadler, P. (1988). Introduction to Functional Programming. Prentice Hall (functions as the basis of programming).

This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.