Why This Matters
In arithmetic you work with concrete numbers, but algebra introduces variables -- letters that stand in for unknown or changeable values. This single idea unlocks the ability to describe general patterns. Instead of saying "add 3 to 5 and multiply by 2," you can write 2(x + 3) and let x be anything. Variables are the bridge between specific calculations and universal rules.
An algebraic expression combines variables, numbers, and operations into a compact formula. When you write 3x + 7, the number 3 is the coefficient of x. In programming, evaluating expressions is something you do on every line of code -- assigning values to variables, computing formulas, and passing results into functions. Algebra gives you the vocabulary and reasoning tools to think about those computations abstractly.
Understanding how to manipulate expressions -- combining like terms, distributing, and substituting values -- is the foundation for every topic that follows in algebra. Equations, inequalities, functions, and graphing all build on the skill of reading and rewriting expressions fluently.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
An algebraic expression is built from variables, coefficients, and constants, then evaluated by substitution.
Code Example
// Evaluating algebraic expressions
function evaluate(coefficients, x) {
// coefficients = [a0, a1, a2, ...] for a0 + a1*x + a2*x^2 + ...
let result = 0;
for (let i = 0; i < coefficients.length; i++) {
result += coefficients[i] * Math.pow(x, i);
}
return result;
}
// 3x + 7 is [7, 3] (constant first, then x coefficient)
console.log("3(4) + 7 =", evaluate([7, 3], 4)); // 19
console.log("3(0) + 7 =", evaluate([7, 3], 0)); // 7
console.log("3(-2) + 7 =", evaluate([7, 3], -2)); // 1
// 2x^2 - 5x + 1 is [1, -5, 2]
console.log("2(3)^2 - 5(3) + 1 =", evaluate([1, -5, 2], 3)); // 4
// Combining like terms: 2x + 3x = 5x
function addExpressions(a, b) {
const maxLen = Math.max(a.length, b.length);
const result = [];
for (let i = 0; i < maxLen; i++) {
result.push((a[i] || 0) + (b[i] || 0));
}
return result;
}
const expr1 = [0, 2]; // 2x
const expr2 = [0, 3]; // 3x
console.log("2x + 3x =", addExpressions(expr1, expr2)); // [0, 5] = 5xInteractive Experiment
Try these exercises:
- Evaluate 5x - 3 for x = 0, 1, 2, 10, and -1. What pattern do you see in the outputs?
- Write the expression for "double a number and add six" using a variable. Evaluate it for several values.
- Create two expressions and add them together by combining like terms. Verify with code.
- What happens when you evaluate an expression at x = 0? Which term survives?
- Try evaluating a quadratic expression like 2x^2 + 3x + 1 at x = -1, 0, 1, 2, 3. Plot the results mentally.
Quick Quiz
Coding Challenge
Write a function called `evaluatePolynomial` that takes an array of coefficients and a value x, and returns the result of the polynomial. The coefficients array is ordered from the constant term to the highest power: [a0, a1, a2, ...] represents a0 + a1*x + a2*x^2 + ... For example, evaluatePolynomial([1, -5, 2], 3) should return 2(9) - 5(3) + 1 = 4.
Real-World Usage
Variables and expressions are the backbone of all mathematical computing:
- Spreadsheets: Every cell formula like
=A1*0.08 + B1is an algebraic expression with cell references as variables. - Physics simulations: Equations like F = ma or d = vt + 0.5at^2 are polynomial expressions evaluated at each time step.
- Financial calculations: Compound interest A = P(1 + r/n)^(nt) is evaluated by substituting principal, rate, and time.
- Game development: Position updates like
x = x + velocity * deltaTimerun 60 times per second in game loops. - Machine learning: A linear model predicts y = w1x1 + w2x2 + ... + b, which is a multi-variable expression.