What is a Function?
A function is a rule that assigns each input exactly one output.
You’ve used functions before: . Put in 3, get out 9.
But what’s the formal definition?
Notation
This reads: “f is a function from A to B”
- is the set of inputs
- is the set of possible outputs
A Function as a Set of Pairs
Remember Cartesian products? gives all possible input-output pairs.
A function picks specific pairs from , following one rule:
Each input appears exactly once.
Example
Valid functions:
- — 1 maps to a, 2 maps to b
- — both map to b (that’s fine)
Not a function:
- — 1 maps to two outputs (ambiguous)
- — 2 is missing (incomplete)
The Two Rules
For to be a function from to :
- Every element of must have an output
- Each element of has exactly one output
Multiple inputs CAN map to the same output.
One input CANNOT map to multiple outputs.
The Formal Definition
A function is a subset of such that for every , there exists exactly one where .
We write to mean is in .