Numbers & Functions · 3 Functions as Machines

3.7 The trick that tells you ``yes, this is a function''

Remember the one unbreakable law? Same input, same output — one input can never give two different outputs. On a graph, the horizontal direction is the input and the vertical is the output. So “one input gives two different outputs” would look like a single spot on the horizontal axis having two dots stacked above it. Which gives us a dead-simple test: The vertical line test. Sweep a vertical line across the graph. If it ever touches the graph in two places at once, it’s not a function — that single input is trying to produce two outputs.

x y a function one hit x y not a function two hits × The vertical line test = same input, same output, seen sideways Figure 3.4. The vertical line test is just the “same input, same output” law seen sideways. The parabola passes (every vertical line hits once); the sideways parabola fails (a vertical line hits twice).

It isn’t a separate rule to memorize. It’s the “same input, same output” law seen sideways. That’s the payoff of understanding why the law exists — the test stops being mysterious and becomes something you could have invented yourself.

3.8 Chaining machines together (composition)

Here’s where functions start to feel powerful. What if you took the output of one machine and fed it straight into another? Bolt the spout of the first onto the funnel of the second. Now you’ve built a bigger machine out of two smaller ones. Say machine one adds 1: g(x) = x + 1. And machine two squares: f(x) = x2. Drop in 3. The first machine makes it 4. The second squares that into 16. We write this chaining as f(g(x)) — read “f of g of x” — and you read it from the inside out, just like the order the number actually travels. This is called composition, and it is, quietly, one of the biggest ideas you’ll ever meet. Why so big? Because everything complicated is made of simple things chained together. A long, intimidating formula is almost always just a handful of tiny, boring machines bolted end to end. And when an artificial intelligence “thinks,” Functions as Machines x px domain x ≥0 machine jams g(x) = px x 1/x jams: divide by 0 h(x) = 1/x Figure 3.5. Two classic domain jams: √x refuses negative inputs (it jams for x < 0), and 1/x jams at x = 0 where you’d divide by zero. The domain is exactly the set of inputs that don’t jam the machine.

3 ADD 1 4 SQUARE 16 Figure 3.6. Composition: two machines in series. The intermediate value 4 travels from one spout to the next funnel. We write this f(g(x)) and read it inside-out. (This is the future neural-network motif — keep the visual in mind.)

what it is really doing is passing a number through a staggeringly long chain of simple machines, one feeding the next, thousands deep.

One warning: order matters. Squaring-then-adding-1 is a different machine from adding-1-then-squaring. Try 3 the other way: square first to get 9, then add 1 to get 10 — not 16. Exactly like putting on socks-then-shoes is not the same as shoes-then-socks.

All 8 chapters of Numbers & Functions · Foundations · All courses