Expanding and factoring
Why this matters
The same expression can be written in different shapes, and some shapes are more useful than others. Expanding multiplies brackets out; factoring pulls them back together. Both are the same rule run in opposite directions, and a picture of rectangles makes it obvious. In machine learning, expanding a squared error shows that it's a bowl in the weight, which is why there's a single best weight to find.
- Expand brackets with the area model, from a(b + c) to a three-term bracket
- Factor by pulling out a common factor, and factor a simple quadratic by un-expanding
- Check that two expressions are the same in Python by trying inputs and subtracting
- Expand a squared error to see it as a bowl-shaped expression in the weight
The math: one expression, two shapes
Purpose. Rewrite an expression into the shape that's most useful right now: brackets multiplied out, or pulled back in.
The key rule is the distributive law: a number outside a bracket multiplies everything inside.
In plain words: a rectangle a wide and b + c long splits into two smaller rectangles, a × b and a × c. The total area is the same either way.
So 3(x + 4) = 3x + 12: three lots of x, and three lots of 4. Multiplying brackets out like this is called expanding.