Pre-algebra Refresh · 28 min

Variables, expressions, equations

A variable is a named box. An equation is a constraint. Solving is pressing undo buttons on the expression tree, from the outside in.

0 / 0

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 xx”)
  • 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 3x+73x + 7) evaluates. Give xx a value and it collapses to a number. It’s a question waiting for input.
  • An equation (like 3x+7=193x + 7 = 19) asserts. It claims two expressions are the same number. It’s a statement: true, false, or a constraint that holds only for certain xx.

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 f(a,b,c)=a×b+cf(a,b,c) = a \times b + c at a=2a=2, b=3b=-3, c=10c=10. Substitute to get (2)(3)+10(2)(-3) + 10, then evaluate by precedence (×\times before ++), which gives 6+10=4-6 + 10 = 4.

Fill the boxes

Evaluate a×b+ca \times b + c at a=2a = 2, b=3b = -3, c=10c = 10. 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.

3x + 7 = 19
x-blockunit-block

Solve 3x+7=193x + 7 = 19 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 xx 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 3x+73x + 7, the variable xx is wrapped first by "×3\times 3", then by "+7+ 7" on the outside. To free xx you unwrap from the outside in: peel the +7+7 first, then the ×3\times 3.

Peel the Equation
3·x + 7 = 19
Apply to both sides: undo the + 7 layer
Verification
3·x + 7 = solve to see

Click the outermost node and choose its inverse. Pick the wrong one and the panel shows you the equation didn’t isolate xx; no harm, try again. Pick the right one and a layer peels away.

The peel, start to finish

On 3x+7=193x + 7 = 19:

  1. The outermost wrap is +7+7. Its inverse is 7-7. Subtract 77 from both sides: 3x=123x = 12.
  2. The remaining wrap is ×3\times 3. Its inverse is ÷3\div 3. Divide both sides by 33: x=4x = 4.

Two layers, two inverses, outside in. That is the entire method.

Solve it

Solve 5x4=215x - 4 = 21. Peel from the outside in: undo the 4-4 first, then undo the ×5\times 5.

What is xx?

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 xx back into the original equation and confirm both sides land on the same number. For x=4x = 4 in 3x+7=193x + 7 = 19: 3(4)+7=193(4) + 7 = 19. ✓

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 2x+9=3-2x + 9 = 3. Then substitute your answer back into the original equation to verify both sides match.

What is xx?

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.