Learning Objectives
After this section you will be able to:
- State what a function is in plain English, then in precise mathematics, and explain why both definitions agree.
- Read the notation and identify the input, the rule, and the output without confusion.
- Apply the vertical line test to decide whether any given curve is a function.
- Find the domain and range of a function from its formula or its graph.
- Translate between three representations: formula, table of values, and graph.
- Implement a function in plain Python and in NumPy, and verify the function property in code.
The Problem Functions Were Invented to Solve
How does the position of a thrown ball depend on time? How does the area of a circle depend on its radius? How does my electricity bill depend on the kilowatt-hours I used last month?
Every quantity in science, engineering, economics, and machine learning is tied to other quantities by some rule of dependence. The ball's height depends on time. The circle's area depends on the radius. A neural network's loss depends on its weights. Before we can do calculus on any of these, we need a precise way to write “output depends on input” as mathematics. That precise object is called a function.
Why we cannot skip this
A derivative is the rate at which a function's output changes when its input changes. An integral is the accumulated effect of a function over an interval. Both ideas presume that “the output” is unambiguous for every input. That single requirement — one input, one output — is what makes a relationship a function, and it is the bedrock everything else in this book is built on.
Intuition: The Function Machine
Picture a machine with a single slot on the left for the input and a single chute on the right for the output. Drop a number in the slot; the machine grinds for a moment, then spits exactly one number out the chute. Drop the same number in again and the machine returns the same number — every time, forever, without exception. That is what a function is.
The machine's personality is its rule. One machine might square its input. Another might subtract four, then halve. A third might look up a value in a giant table. We do not care how the machine works internally — only that it is deterministic: same input, same output, always.
Two intuitions, one idea
Mathematicians use four mental pictures interchangeably for the same concept. They all mean exactly the same thing.
- The machine. Drop in , out comes .
- The arrow. ; the arrow says “send each point of to a point of .”
- The table. A two-column list of pairs (input, output) with no repeated inputs.
- The curve. The graph of in the plane, where every vertical line meets the curve in at most one point.
Interactive — The Function Machine
Pick a rule, then drag the slider. The green dot is your input sliding along the horizontal axis. The indigo dot rides on the curve, and the amber dot reads off the output on the vertical axis. The green and amber strips show the domain (allowed inputs) and range (reachable outputs).
Things to try
- Pick Parabola. Drag from -3 to +3. Notice and give the same output. Two different inputs can share an output — that is allowed.
- Pick Square root. Try to drag below . The dot turns red and the rule refuses — there is no real . The domain has a hard wall.
- Pick Reciprocal. Drag toward . The output blasts off to . The rule is undefined exactly at zero — the domain has a hole there.
- Pick Sine. Notice the output bar never leaves no matter how far you slide . The range is bounded even though the domain is all of .
The Formal Definition
Definition (function)
Let and be sets. A function is a rule that assigns, to each element , exactly one element .
Three words in that sentence are doing all the work. Strike any one of them and the definition collapses.
- each. The rule must produce an answer for every input in the declared domain — no skipped inputs.
- exactly one. The rule must produce one answer per input — never two, never an “either-or.”
- element of Y. The output must live in a declared target set (called the codomain). For the calculus we will do this term, the codomain is almost always — the real numbers.
Vocabulary you will see again and again:
| Symbol / Phrase | Means |
|---|---|
| x | the input (a.k.a. argument, independent variable) |
| f | the rule (the function itself, NOT a number) |
| f(x) | the output produced when the rule is applied to x |
| y = f(x) | names the output y so we can plot it on a vertical axis |
| X (domain) | the set of ALLOWED inputs |
| Y (codomain) | the set the outputs are declared to live in |
| f(X) (range / image) | the set of outputs ACTUALLY produced |
f and f(x) are different things
is the function (the rule, the machine, the arrow). is the number that comes out when you feed in. Saying “the function ” is sloppy but common; it really means “the function whose value at the generic input is .”
Three Equivalent Views of a Function
The same function can be described in three completely different languages. A skilled calculus student can flip between them effortlessly — each one makes some questions easy and other questions hard.
View 1 — The formula
The compact, algebraic description:
Tells you the rule in five symbols. Best for computation and for proving things. Useless if you don't know algebra.
View 2 — The table
A finite list of (input, output) pairs:
| x | f(x) = x² − 4 |
|---|---|
| −3 | 5 |
| −2 | 0 |
| −1 | −3 |
| 0 | −4 |
| 1 | −3 |
| 2 | 0 |
| 3 | 5 |
Tells you the function's behaviour at a handful of points. Best for hand calculations and spotting patterns (notice the symmetry around ). Useless if you need information at a point not in the table.
View 3 — The graph
The set of all points drawn in the plane. For our example this is a parabola opening upward, sliding down to its lowest point at and crossing the x-axis at . The Function Machine visualiser above is one such graph.
The graph is the most visual view — you see the whole shape at a glance. It is also where calculus lives: derivatives are the slopes of tangent lines to graphs, integrals are areas under graphs. The graph is the bridge between algebra and geometry.
The three are interchangeable
Given any one of the three (formula, table, graph), you can in principle recover the other two: tabulate the formula, plot the table, read coordinates off the graph. Different problems favour different views — and learning to switch quickly is half of what it means to be fluent in calculus.
The Vertical Line Test
Suppose someone draws a curve in the plane and asks “is this the graph of a function?” The formal check would be: for every input , is there exactly one output paired with it? That phrasing is awkward to apply visually.
Here is the geometric reformulation. Fix any vertical line . The points on the curve that share this x-coordinate are exactly the outputs the curve assigns to . The function rule demands at most one output per input. So:
Vertical Line Test
A curve in the plane is the graph of a function (of ) if and only if every vertical line meets the curve in at most one point.
Why “at most” and not “exactly”? Because a vertical line at an outside the domain hits the curve zero times — and zero is fine. The forbidden situation is two or more.
The classic counter-example: the circle
Consider , the unit circle. At the equation gives , so . Two outputs for one input. The circle is not a function of . It is a beautiful curve — it is just not a function.
Don't throw curves away
Non-functions are not bad math. The circle, the sideways parabola, and many parametric curves are essential objects. They simply need richer tools (parametric equations, implicit differentiation, multivariable functions) to be handled with calculus. We will get there — but the cleanest case, and the one we start with, is the single-output function.
Interactive — Vertical Line Test
Pick a curve from the gallery, then drag the dashed vertical line. The orange dots are the intersection points. If you ever see two or more orange dots on the same vertical line, the curve fails the test.
Domain and Range
Two halves of a function's identity:
- Domain. The set of inputs the rule is defined on. For the domain is ; negative inputs have no real square root. For the domain is ; zero would require dividing by zero.
- Range. The set of outputs the rule actually produces. For the range is ; squaring can never be negative. For the range is ; sine is bounded.
Finding the domain is usually a hunt for forbidden moves:
| Operation | Forbidden when |
|---|---|
| division a/b | denominator b = 0 |
| square root √u (over the reals) | u < 0 |
| log u (over the reals) | u ≤ 0 |
| tan u | u = π/2 + kπ |
| arcsin u, arccos u | u outside [−1, 1] |
For each constraint you find, exclude the offending inputs. Whatever remains is the domain.
Quick worked drill
Find the domain of .
- The square root needs , i.e. .
- The denominator needs , i.e. .
- Combine: . Every input works except .
Worked Example — Tracing a Function by Hand
Before we trust any plot or any script, let us trace one function from formula to table to graph using nothing but a pencil.
Click to expand — full hand trace of
“Take the input, square it, then subtract four.” The instructions are unambiguous; we will do exactly that for every input we choose.
Spread them out so we see the function's personality. Symmetric inputs around zero will reveal symmetry (or its absence). We choose .
Look at the column of outputs: 5, 0, −3, −4, −3, 0, 5. It is a palindrome — that is the algebraic fingerprint of an even function (one for which ). The graph will be symmetric about the y-axis.
x-intercepts are where . From our table that is and (the table doesn't miss them because we were lucky in our choices, but algebraically we'd solve giving the same answers).
The y-intercept is .
The vertex (lowest point of an upward parabola) sits at the symmetric centre of the x-intercepts — here — and has y-value .
Plot the seven points, plus the vertex . Connect them with a smooth upward-opening parabola. You have just hand-drawn the graph of . Compare it to the indigo curve in the Function Machine visualiser above — they are the same shape.
Squaring and subtracting are defined everywhere, so the domain is . The minimum output is (at the vertex), and there is no maximum because we can square arbitrarily large numbers. The range is .
Look at the table: every appears exactly once on the left, with one number on the right. The vertical line test (every vertical line meets the parabola once) confirms it geometrically. We have a function.
Python: Building a Function from Scratch
Mathematics and code mean almost the same thing here: a Python def is a function in our sense, and calling it with f(3) is exactly applying the rule. The snippet below defines , evaluates it at four inputs, prints a table, and verifies the function property with assert statements. Click any line to see the actual values flowing through it.
Running this prints a four-row table that matches our hand trace, and the three asserts pass silently. Silence is the loudest possible confirmation: every property a function is supposed to have, this code has.
NumPy: Vectorised Evaluation
Plain Python needs a for-loop to evaluate at many points. NumPy lets us apply the same rule to a thousand inputs in a single line — and the speedup is the foundation of every scientific-computing library you will use later (NumPy, PyTorch, JAX, TensorFlow, scikit-learn).
The key insight is that the same source code we wrote above keeps working. We never touch the function definition — only the input becomes a vector. NumPy quietly broadcasts the rule over every element.
The same idea powers deep learning
When a neural network applies its activation function to a tensor of shape , it is doing exactly what we just did — applying one rule to every element of a giant array. PyTorch and JAX are NumPy with extra superpowers (GPU execution, automatic differentiation), but the conceptual model is identical. Mastering “a function applied to a tensor” in NumPy is mastering it everywhere.
Why This Matters for Calculus
Every concept in the chapters ahead is a question about a function:
- Limits (Chapter 2) ask: what value is the output approaching as the input approaches some target?
- Continuity (Chapter 3) asks: can the graph of be drawn without lifting the pencil?
- Derivatives (Chapter 4) ask: how fast is the output changing per unit change in input?
- Integrals (Chapter 8) ask: what is the total accumulation of over an interval?
- Differential equations (Chapters 19+) ask: which function satisfies a given equation relating and its derivatives?
Without a precise notion of function, none of those questions can even be stated. With it, the whole edifice of calculus becomes a careful study of how outputs respond to inputs — sometimes locally (limits, derivatives), sometimes globally (integrals, equations). The same word — function — supports both.
Common Pitfalls
- Confusing with . is the rule; is a specific output. Writing “differentiate ” means differentiate the rule; writing “the value ” means a single number.
- Allowing two outputs for one input. The expression is not a function — for it returns both and . To get an honest function you must pick a sign: or , but not both.
- Forgetting to state the domain. A formula alone is not a function — it is a function once you commit to a domain. Writing “the function ” quietly means “on .” Always know what set your inputs live in.
- Treating the graph as the function instead of as a picture of the function. The graph is a visual aid; the rule is the real object. Two functions with different rules can have visually similar graphs (e.g. vs. a narrow gaussian near zero) — only the rule disambiguates.
- Confusing range with codomain. The codomain is where outputs are declared to live (often ). The range is which of those values actually appear. For , codomain , range . The distinction matters when we discuss invertibility.
Summary
- A function is a deterministic rule sending each input to exactly one output .
- Functions live in three interchangeable forms: a formula, a table of (input, output) pairs, and a graph in the plane.
- The vertical line test: a curve is a function of iff every vertical line crosses it in at most one point.
- The domain is the set of allowed inputs; the range is the set of outputs the rule actually produces.
- Two different inputs may share an output (e.g. ) — but a single input may not have two outputs.
- A Python
def(or a NumPy expression) implements a function literally — and the function property (same input → same output) is automatically true for pure arithmetic code.
What's next
§1.2 introduces linear functions — the simplest non-trivial functions, and the ones that hold the seed of the derivative idea. From there we will climb through polynomials, exponentials, logarithms, and trigonometric functions before the limit machinery of Chapter 2 sets calculus in motion.