“Evaluate at .” You learned this in first-year algebra. It is the basic move behind nearly everything on this site. The name is substitution. Functions, beta-reduction, and much of programming use the same operation. This article gives you the short version for the substitution exercises, then points to the fuller treatment in algebra you forgot.
A variable is a placeholder, not a box
Start with what a variable is. In algebra, a variable such as is a name that stands for a value. The expression is a template, not a statement about one particular . It means “double whatever this name stands for, then add one.” A variable is a hole to fill. It is not a storage location that changes later.
That differs from how most programming languages describe a variable. In JavaScript, let x = 3 puts a value in a box that you can reassign. In algebra - and in Elixir - a name is a pure stand-in: the same name in two places in one expression refers to the same value in both places. Reading it again does not produce a new value.
Substitution is the fill-the-hole move
Substitution replaces a variable with a value (or another expression) everywhere it appears. To evaluate at , replace with :
That is the operation. It has three steps, and each one is a common source of mistakes:
- Replace every occurrence. If the name appears twice, you replace it twice. at becomes , not .
- Substitute the whole value. When the value is negative, wrap it in parentheses so the sign travels with it. at is , which is . Compute the sign carefully - the leading minus applies to the whole product, not to one factor alone, and that is exactly where the substitution exercises plant their traps.
- Do it simultaneously when there are several names. Substituting and into means both replacements happen at once, on the original expression: . You do not substitute , simplify, then substitute .
It is the same move as calling a function
Calling a function performs substitution. The function is a template; the call fills its hole:
function f(x) { return x * x + 1; }
f(3); // substitute 3 for x, then evaluate: 3 * 3 + 1 = 10
The parameter x is the variable, and the call f(3) is the substitution. Programming copied this idea from algebra. Elixir makes the connection explicit: f(3) and “evaluate the template at ” are the same idea. In Elixir, x = x + 1 does not increment a box. It rebinds the name to a new value while the old one disappears.
Why this matters here
The substitutions exercises practice this one move until it is fluent. The evaluate and substitute_expression exercises ask for one thing - “substitute this value into this expression and give the number” - because the move is the lesson, not the surrounding arithmetic. The exercise set treats a variable as a placeholder you fill in, never as “the unknown you solve for.” The harder exercises make the three slip points above (every occurrence, negative signs, simultaneous substitution) automatic.
This deserves an exercise set because substitution is the operation a formal system can be built from. It also leads into lambda calculus. Lambda calculus has exactly one rule, beta-reduction: apply a function to an argument, substitute the argument for the variable throughout the body, repeat. If “evaluate at ” feels automatic, beta-reduction is the same move in different notation. If it does not, use this practice until it is automatic.
Where to go next
-
Equivalence: are two expressions the same for every value?
- the next question substitution opens: once you can fill the hole, you can ask whether two templates always fill to the same thing.
-
Factoring: rewriting an expression into an equivalent form
- substitution run backwards: rewriting a sum as a product without changing what it means.
-
Algebra you forgot, and why it’s the on-ramp to lambda calculus
- the wider algebra context this move lives in, and where it hands off to lambda calculus.