A variable is a named box
You already know what a variable is; you declare them all day. A math variable is the identical idea: a named box that holds a number.
The only twist is that the box plays three different roles, and conflating them is what made school algebra feel slippery:
- an unknown: a number you don’t know yet and intend to find (“solve for ”)
- a parameter: a number chosen once, then held fixed
- a free variable: a number allowed to range over a whole set of values
Same syntax, three jobs, exactly like a variable in your code is sometimes a function argument, sometimes a config constant, sometimes a loop counter.
Expression versus equation
Two things that look similar and are not:
- An expression (like ) evaluates. Give a value and it collapses to a number. It’s a question waiting for input.
- An equation (like ) asserts. It claims two expressions are the same number. It’s a statement: true, false, or a constraint that holds only for certain .
In code you know this gap cold: = assigns, == asserts. Math spells both with one = and trusts you to read the context. Step one of never being confused again: know which one you’re looking at.
Substitution: filling the box
To evaluate an expression you substitute (replace every occurrence of the variable with a number) and then climb the tree from the last lesson.
Take at , , . Substitute to get , then evaluate by precedence ( before ), which gives .
Fill the boxes
Evaluate at , , . Substitute first, then let precedence run.
What is the value?
An equation is a balance
Picture an equation as a balance scale that is currently level: the left side and the right side weigh the same. That is what the asserts.
Now the rule that makes solving safe: anything you do to one side, you must do to the other. Do that, and the scale stays level; the equation stays true.
Solve on the balance. Every move it offers is symmetric, applied to both pans at once. You literally cannot make an illegal move. Watch the left pan shed weight until a single stands alone.
Which undo, and in what order
Which operations do you apply? The inverses from lesson 2 (the undo buttons). In what order? Read the expression’s tree.
In , the variable is wrapped first by "", then by "" on the outside. To free you unwrap from the outside in: peel the first, then the .
Click the outermost node and choose its inverse. Pick the wrong one and the panel shows you the equation didn’t isolate ; no harm, try again. Pick the right one and a layer peels away.
The peel, start to finish
On :
- The outermost wrap is . Its inverse is . Subtract from both sides: .
- The remaining wrap is . Its inverse is . Divide both sides by : .
Two layers, two inverses, outside in. That is the entire method.
Solve it
Solve . Peel from the outside in: undo the first, then undo the .
What is ?
Verify: it's a free unit test
You’re not done when you have an answer. You’re done when you’ve checked it.
Substitute your back into the original equation and confirm both sides land on the same number. For in : . ✓
It costs five seconds and it catches almost every arithmetic slip. In code you’d call this an assertion. Same instinct: you ran the function, now assert the output.
Solve, then verify
Solve . Then substitute your answer back into the original equation to verify both sides match.
What is ?
What you actually learned
Look back at what “solving” turned out to be. You took an expression tree, found the operation wrapping the variable on the outside, and applied its inverse to both sides, then repeated, working inward, until the variable stood alone. Choosing inverses and applying them layer by layer through a tree.
That has a name too. The forward pass climbs the tree leaves-to-root to get an answer. Working back down it (applying inverse operations layer by layer to figure out how to change the inputs) is the backward pass. Training a neural network is exactly this move, run on a tree with billions of nodes. You just did it by hand on a tree with two.
Where this goes next
That’s module 1. You can place any number on the line, you know the two operations and their undo buttons, you can read a fraction as the single number it is, you can parse an expression into its tree, and you can solve an equation by peeling that tree.
Module 2 (Algebra) takes the lid off: expressions with many variables, functions and function composition, the full laws of exponents and logarithms, systems of equations. None of it is new in kind. It is this, with more boxes. You have the substrate now.
Lesson complete
Nice tinkering.
Before you go