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 to , written , is a relation satisfying two extra requirements:
- Total:
— every input has at least one output.
- Well-defined:
— each input has at most one output.
Together: exactly one output. We write that unique output as .
Domain, codomain, range
The domain is , the codomain is , and the range (or image) is . The range is always a subset of the codomain but need not equal it. Example: has codomain but range .
Equality of functions
Two functions are equal iff they have the same domain, the same codomain, and for every . All three conditions matter: and are different functions because their codomains differ.
Composition and identity
Given and , the composition is defined by . Composition is associative but generally not commutative. The identity function satisfies and — it is the "do-nothing" function for composition.
Pause and think: Why isn’t the relation a function from to ? Which of the two function-defining properties fails? (Hint: input is paired with two different outputs.)
Try it
- Decide whether is a function from to . Justify both properties.
- For and on , compute and . Are they equal?
- What is the range of ? Is the codomain equal to the range?
- Prove: if and , then is itself a function (verify both properties).
- True or false: and define equal functions on . Justify.
A trap to watch for
"Range" and "codomain" are not synonyms. The codomain is fixed by the function’s declared signature ; it tells you the type of the output. The range is the set of outputs actually achieved. For on , the codomain is but the range is only . 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).