Definition and Notation of Functions
You'll learn what a function means in mathematics and CS, and how to write it formally using domain/codomain notation.
What Is a Function?
A function is a special kind of relation that assigns exactly one output to each input. Think of it like a reliable vending machine: you press button A3, you always get the same snack—never two different things, never nothing.
In set theory terms (building on what you know about relations and Cartesian products), a function pairs every element from one set (the domain) with exactly one element in another set (the codomain).
Formal Notation
We write:
f: A → B
This reads as "f is a function from set A to set B."
- A is the domain (the set of all possible inputs)
- B is the codomain (the set where outputs live)
- f is the name of the function
- For each element x in A, we write f(x) to mean "the output when x is the input"
Example
Let A = {1, 2, 3} and B = {apple, banana}.
We can define: f(1) = apple, f(2) = apple, f(3) = banana
This is written as f: {1,2,3} → {apple, banana}.
Notice: every input has exactly one output. Input 1 can't map to both apple and banana.
Why "Function" ≠ Just "Relation"
Remember relations from earlier lessons? Functions are relations with a strict rule: no input can map to multiple outputs. The relation {(1, apple), (1, banana)} is not a function because 1 maps to two things.
Key Takeaway: A function f: A → B is a mapping where every element in the domain A gets assigned exactly one element in the codomain B, written as f(x).