Functions as Machines — Input, Output & Composition
A function isn't a formula sitting on a page. It's a machine: feed it something, it hands something back, and every rule you'll meet from here on — limits, derivatives, gradients — is really a question about how that machine behaves.
Intuition First
Picture a vending machine. You put in a code — B4 — and out drops one specific snack, every time, no exceptions. That's the whole idea of a function: a machine that takes one input and always returns exactly one output for it. Feed it the same input twice, you get the same output twice. That's not a bonus feature — it's the definition.
This should feel familiar. In Module 0, a matrix was exactly this kind of machine: feed it a vector, it hands back a new vector, same input always lands in the same place. A function is that same idea stripped down to its bones — instead of moving arrows through space, it just turns one number into another. And machines can be chained: the output of one becomes the input of the next. That chaining — called composition — is how simple machines build up everything from sound filters to entire neural networks, one small step wired into the next.
A Machine You Can Run by Hand
Let f(x) = 2x + 1 be a "double, then add one" machine, and g(x) = x² be a "square it" machine. What comes out if you feed 3 into f, then feed that result into g?
Notice the order matters: g(f(3)) means "run f first, then feed its output into g" — read right to left, like unwrapping a package from the outside in. Swap the order and f(g(3)) gives a completely different machine, and a different answer (19, if you check).
Try It — Chain Two Machines
Pick an input x, then choose the slope and shift of f, and the scale of g. Watch the value travel through f first, then through g, and see how the final output changes.
Formal Definition
A function f maps every element of a set of allowed inputs (its domain) to exactly one element of a set of possible outputs (its range):
Chaining two machines — running g on whatever f produces — is called composition, written with a small circle: