Formal Definition

What is a Function?

A function is a rule that assigns each input exactly one output.

You’ve used functions before: f(x)=x2f(x) = x^2. Put in 3, get out 9.

But what’s the formal definition?


Notation

f:ABf: A \to B

This reads: “f is a function from A to B”

  • AA is the set of inputs
  • BB is the set of possible outputs

A Function as a Set of Pairs

Remember Cartesian products? A×BA \times B gives all possible input-output pairs.

A function picks specific pairs from A×BA \times B, following one rule:

Each input appears exactly once.


Example

A={1,2},B={a,b}A = \{1, 2\}, \quad B = \{a, b\}

A×B={(1,a),(1,b),(2,a),(2,b)}A \times B = \{(1,a), (1,b), (2,a), (2,b)\}

Valid functions:

  • {(1,a),(2,b)}\{(1, a), (2, b)\} — 1 maps to a, 2 maps to b
  • {(1,b),(2,b)}\{(1, b), (2, b)\} — both map to b (that’s fine)

Not a function:

  • {(1,a),(1,b)}\{(1, a), (1, b)\} — 1 maps to two outputs (ambiguous)
  • {(1,a)}\{(1, a)\} — 2 is missing (incomplete)

The Two Rules

For ff to be a function from AA to BB:

  1. Every element of AA must have an output
  2. Each element of AA has exactly one output

Multiple inputs CAN map to the same output.

One input CANNOT map to multiple outputs.


The Formal Definition

A function f:ABf: A \to B is a subset of A×BA \times B such that for every aAa \in A, there exists exactly one bBb \in B where (a,b)f(a, b) \in f.

We write f(a)=bf(a) = b to mean (a,b)(a, b) is in ff.