Mappings from inputs to outputs. Domain, range, and function notation.
Deep-dive lesson - accessible entry point but dense material. Use worked examples and spaced repetition.
A “function” is the idea behind almost everything in math and computing: you give a rule an input, and it gives you an output. Once you can name inputs, name outputs, and write the rule down clearly, you can build calculus, probability, recursion, and data structures on top of it.
A function is a mapping that assigns each allowed input exactly one output. The domain is the set of allowed inputs. The range (also called the image) is the set of outputs the function actually produces. We write a function as (“f of x”).
In both math and programming, we constantly model a situation where one thing depends on another:
A function is the cleanest way to describe that dependency.
A function is a rule that takes an input and returns an output.
But math is picky about one key property:
A function must give exactly one output for each input in its domain.
That means:
1) Doubling: input a number, output twice that number.
2) Square: input a number, output its square.
Suppose we claim a “rule” that maps 1 to both 2 and 3.
This violates the “exactly one output” requirement. So it is not a function.
We often name a function with a letter like .
Example:
Let .
Notice the pattern: the parentheses are not multiplication. is “evaluate at 3.”
To decide if something is a function, ask:
1) What are the allowed inputs?
2) For each allowed input, is there exactly one output?
If yes, it’s a function.
A big source of confusion is that a “rule” is not complete until you know what inputs it is willing to accept.
Example: .
So we need vocabulary for “what inputs are allowed” and “what outputs come out.”
The domain of a function is the set of inputs you are allowed to plug in.
Examples:
In discrete math and CS, the domain is often a finite or countable set:
The range is the set of outputs the function actually produces when you feed it every input in the domain.
Example 1:
Let with domain ℝ.
Example 2:
Let the domain be {−1, 0, 2} and define .
Sometimes people informally say “range” when they mean “all outputs we intend the function to land in.” In more formal math, there is also the codomain (the target set). To keep difficulty at 1/5, we’ll focus on:
If you later see notation like , the set is often the codomain, while the range is the subset of that actually hits. You don’t need that distinction yet to use functions correctly day-to-day.
In discrete math, a function from a small set can be shown as a table.
Example:
Let domain A = {a,b,c}. Define by:
| x | f(x) |
|---|---|
| a | 2 |
| b | 2 |
| c | 5 |
This is a valid function because each input appears once and has exactly one output.
Note: multiple inputs are allowed to share the same output (a and b both map to 2). That is still a function.
Function notation is like a tiny language. If you can read and write it, you can:
A common way to define a function is with an equation like:
This means: take input , multiply by 2, then add 1.
Evaluate at a specific input:
You can also define a function in words, especially in CS.
Example:
In math, we might call it and write .
Sometimes a single formula doesn’t cover the rule cleanly. Then we use a piecewise definition.
Example:
Evaluate:
A piecewise rule is still a function if:
Example of a problem:
If x = 2, which output should it give—0 or 1? Not a function (as written).
In discrete math, inputs and outputs are often objects.
Examples:
The function idea is the same: each input has one associated output.
Imagine a machine labeled :
If you feed in the same x again, you must get the same output again (for a deterministic function).
Once you understand “input → output with a rule,” many topics become simple variations:
Below are a few concrete connections.
In calculus, you study what value a function approaches as the input approaches a point.
Even stating a limit requires function language:
You can’t talk about that without knowing what means and what inputs are allowed.
A random variable is literally a function in the math sense:
Example:
That’s a function from outcomes → {0,1,2}.
A recursive definition defines a function using itself on smaller inputs.
Example idea:
To read that, you must be comfortable with function evaluation and domain restrictions (e.g., nonnegative integers).
A relation can connect an input to many outputs.
A function is a special kind of relation that connects each input to exactly one output.
This is why functions are often introduced early in discrete math: they’re “well-behaved” relations.
A hash function maps a key (like a string) to a bucket index (like an integer).
Even though collisions exist (different keys can map to the same output), it is still a function because:
| Area | Typical input | Typical output | Function idea |
|---|---|---|---|
| Algebra | number x | number f(x) | compute a value |
| Probability | outcome ω | number X(ω) | measure an outcome |
| Algorithms | instance | answer | compute a result |
| Data structures | key | bucket/value | lookup mapping |
Notice the repeating theme: define the domain, ensure one output per input, then use the notation to compute and reason.
Let the domain be A = {−1, 0, 2, 4}. Define for x ∈ A.
1) Compute f(x) for each x in A.
2) State the range (set of outputs).
Compute each output:
Collect outputs into a set (remove duplicates if any):
Range = {2, 1, 5, 17} = {1,2,5,17}
Insight: On a finite domain, the range is easy: evaluate at every input and list the outputs. The range is a set, so duplicates collapse to one element.
Consider the mapping from A = {a,b,c} to numbers defined by the pairs:
(a, 1), (b, 1), (c, 2).
Then consider a second mapping defined by:
(a, 1), (a, 2), (c, 2).
For each mapping, decide if it is a function from A to numbers.
Mapping 1: (a,1), (b,1), (c,2)
Check each input in A:
So each input has exactly one output ⇒ this IS a function.
Mapping 2: (a,1), (a,2), (c,2)
Check each input in A:
Therefore this is NOT a function as a mapping from A.
(Also, b has no output listed, so even “at least one output” fails if we require the whole domain A.)
Insight: Two common ways to fail being a function: (1) one input maps to two outputs, or (2) an input in the declared domain has no output at all.
Let .
1) Explain why x = 0 cannot be in the domain (over real numbers).
2) Compute f(2), f(−4), and describe the range over the domain ℝ \ {0}.
Check x = 0:
f(0) = 1/0 is undefined (division by zero). So 0 must be excluded from the domain.
Domain (over ℝ) is {x ∈ ℝ : x ≠ 0}.
Evaluate:
Describe the range:
Can the output ever be 0?
If 1/x = 0, then 1 = 0·x = 0, impossible.
So 0 is never produced.
Range is {y ∈ ℝ : y ≠ 0}.
Insight: Domain restrictions often come from “operations that can break,” like division by zero or square roots of negative numbers (over reals). The range can also exclude values for algebraic reasons.
A function is a mapping that assigns each input in its domain exactly one output.
Function notation: means “the output of f at input x,” not multiplication.
The domain is the set of allowed inputs.
The range/image is the set of outputs actually produced by the function.
Different inputs may share the same output; that does not violate being a function.
A mapping fails to be a function if an input has two different outputs or if some input in the declared domain has no output.
Functions can map non-numeric objects too (strings, people, files, outcomes).
Thinking means (multiplication) instead of “evaluate f at x.”
Forgetting to state or check the domain, especially when formulas can be undefined (like division by zero).
Assuming a function must have different outputs for different inputs (it doesn’t).
Mixing up domain and range: domain is what goes in; range is what comes out.
Let . Compute f(0), f(2), and f(−1).
Hint: Substitute each input into 3x−2 and simplify.
f(0)=3·0−2=−2
f(2)=3·2−2=6−2=4
f(−1)=3·(−1)−2=−3−2=−5
Domain/range practice: Domain A = {1,2,3,4}. Define by the table: g(1)=2, g(2)=2, g(3)=5, g(4)=5. What is the range of g?
Hint: List the outputs and remove duplicates.
Outputs are {2,2,5,5}. As a set, the range is {2,5}.
Is it a function? Consider the relation on A = {a,b,c} given by pairs (a,1), (b,2), (b,3), (c,4). Decide whether this is a function from A to numbers.
Hint: Check whether any input has more than one output, and whether every input has at least one output.
Input b maps to both 2 and 3, so the mapping gives two outputs for the same input. Therefore it is NOT a function from A.