A function from a set A to a set B is a rule that assigns to each element of A exactly one element of B. Written . The set A is the domain — what the function accepts. The set B is the codomain — where the output lives. For every , there is exactly one such that . Exactness is the defining constraint: every input gets an output, and that output is unique.
A function is a special kind of relation. A relation between A and B is any subset of — any collection of pairs. A function is a relation where each element of A appears in exactly one pair. Every function is a relation. Most relations are not functions.
Functions compose. If and , the composition sends each to . Composition is associative: . Every set A has an identity function sending each element to itself. Identity is neutral under composition: and .
A function is not an operation. An operation maps a set into itself: . A function maps between sets that may be different. The distinction is between internal transformation (operation) and external mapping (function). Both are present in any nontrivial algebraic structure — the operations give a set its internal structure, and the functions relate it to other sets.
A function can be injective (different inputs always give different outputs), surjective (every element of the codomain is hit), or bijective (both). A bijection has an inverse: a function such that and .
In the category Set, sets are objects and functions are morphisms. Composition of functions is composition of morphisms. The identity function is the identity morphism. This is the standard example of a category — and the reason category theory generalizes set-theoretic reasoning.