Sub topic 2
Variables: letters that stand for numbers
This chapter assumes you are comfortable with integer and fraction arithmetic (including negatives), the order of operations, and basic exponents such as 3^2. The previous chapter defined an algebraic expression as a combination of numbers, letters, and operations. Here we look at the letters. A solid model of what a variable is prevents most of the errors in later chapters.
What a variable is
A variable is a symbol, usually a letter, that stands for a number. The number can be unknown, or it can change from one situation to another. The expression 3x + 2 does not describe one fixed quantity. It describes a rule: take a number, multiply it by 3, and add 2.
Variables are useful for three reasons:
- They let you write a rule once instead of listing many cases. The perimeter of a square with side
sis4s, whateversis. - They stand in for a number you do not know yet.
- They let you do arithmetic on a value before you have a value to use.
The same letter can play different roles depending on context.
| Role | Example | What the letter means |
|---|---|---|
| Unknown | `x + 3 = 10` | One specific number you want to find |
| Varying quantity | `d = 60t` (distance at 60 km/h) | Any value in a range, and the answer changes with it |
| Placeholder in a rule | `a + b = b + a` | Any numbers at all, and the statement stays true |
In this tutorial we mostly use the second and third roles. We write and simplify expressions without solving for anything.
The core rules for using a variable
Four rules cover almost everything you will do with variables in this tutorial.
- A variable holds one value at a time. Within a single expression, a letter has one value. If
x = 4, everyxin the expression is 4. - The same letter means the same number. In
x + x, both letters are the same number, so the result is2x. This is whyx + x = 2xis always true. - Different letters may be different, but are not required to be. In
x + y, the letters can stand for different numbers. They can also stand for the same number. Nothing forbidsx = y = 5. - Letters are case-sensitive.
xandXare different variables. Many textbooks use lowercase for most variables, but a problem may use both. Treat them as separate.
Rule 3 is the one learners most often get backwards. A different letter does not guarantee a different value. It only says that the expression does not force them to match.
Same letter, same value
Consider x · x. Because both factors are the same number, it equals x². Compare x · y, which has no such shortcut because x and y are not tied together. You will see why this matters in the chapter on like terms: x² and xy are different kinds of quantity even though both are products of two letters.
You can check this with SymPy, a Python library for symbolic algebra. SymPy treats x and y as separate symbols, and it merges repeated uses of one symbol.
from sympy import symbols
x, y = symbols('x y')
print(x + x) # 2*x
print(x * x) # x**2
print(x * y) # x*y
print(x + y) # x + ySymPy collects x + x into 2*x because both are the same variable. It leaves x + y alone because it cannot merge two different symbols.
Writing multiplication with variables
Algebra drops the multiplication sign wherever the meaning is clear.
3xmeans 3 timesx.xymeansxtimesy.ab²meansatimesb². The exponent applies only tob.3(x + 1)means 3 times the quantityx + 1.
The reason is practical. The symbol × looks like the letter x, so writing 3 × x is confusing. A dot (3 · x) or no symbol at all avoids the problem.
Note that this convention applies to letters and numbers. It does not apply to two digits. 35 means thirty-five, not 3 times 5. And a number goes before a letter: write 3x, not x3.
Programming languages need the multiplication sign written out. In Python, 3x is a syntax error, and you must write 3*x.
from sympy import symbols
x = symbols('x')
expr = 3*x + 2
print(expr) # 3*x + 2Choosing and reading variable names
Any letter can be a variable. Some habits make expressions easier to read:
- Use
x,y,zwhen the letters have no particular meaning. - Use
nfor a count of items, a whole number. - Use a letter that suggests the quantity:
tfor time,dfor distance,rfor rate or radius,pfor price. - Avoid
l(lowercase L) andOwhen you can, because they look like1and0. - Use subscripts to tell related quantities apart:
x₁,x₂, orx_old,x_new.
The letter itself carries no value. Choosing t for time is a convention, not a rule. 3t + 2 and 3x + 2 describe the same rule.
When a problem says "let n be the number of apples", the statement fixes what n means. Always state your variables before using them in a word problem. A later chapter on translating words into expressions builds on this habit.
How variables get values
A variable has a value only when a problem gives it one, or when you substitute one. Until then it stands for any number you could choose, and you work with it symbolically.
Substitution replaces each occurrence of a variable with its value. The expression x + 2y with x = 3 and y = 4 becomes 3 + 2(4), which is 3 + 8 = 11. Notice the parentheses around the 4: they keep the multiplication 2 · 4 intact. If you write 3 + 24 by pasting the digit next to the 2, you get a different number. Substituting into expressions is covered fully in the chapter on evaluating, so here we only note the idea.
from sympy import symbols
x, y = symbols('x y')
expr = x + 2*y
print(expr.subs({x: 3, y: 4})) # 11The following diagram shows the relationship. An expression is a rule, and each choice of values produces one number.
Change the chosen values and the same expression gives a different result. The expression stays the same while the number it produces changes. That is the sense in which a variable "varies".
What values can a variable take?
Unless a problem says otherwise, a variable can stand for any real number: positive, negative, zero, a fraction, or a decimal. Sometimes the context restricts the values.
- If
nis a number of apples, it should be a whole number, 0 or greater. - If
tis a time in hours for a running trip, it should not be negative. - If an expression contains division by
x, thenxcannot be 0 because division by zero is undefined.
The last case matters later. When you simplify expressions that contain fractions with variables, you must remember which values are excluded. For the expressions in this tutorial (sums, differences, products, and powers), any real number is allowed.
Common errors with variables
Treating a letter as a label instead of a number. Writing "3a + 2b = 5ab" treats a and b like units, as if you were counting apples and bananas into a single pile. A variable is a number, and the rule for adding such terms is stricter. Later chapters explain exactly when terms combine.
Assuming different letters must differ. If x + y = 10, you cannot conclude that x and y are different. They could both be 5.
Changing the value partway through. If x = 4 at the start, it is 4 in every place it appears in the same problem. Some learners substitute 4 in one place and then treat another x as a new unknown.
Mixing up x and X, or 1 and l. Handwriting causes many errors. Write the letter x so that it does not resemble ×, and make a visible difference between the digit 1 and the letter l.
Forgetting the implied multiplication. 2x with x = 5 is 2 · 5 = 10, not 25. The digits are not placed side by side. Using parentheses, 2(5), keeps this clear.
You can see this error directly in Python, where the precedence rules are the same:
x = -3
print(x**2) # 9, because x holds -3 and is squared as a whole
print(-3**2) # -9, because ** binds tighter than the minus signKey points
- A variable is a letter that stands for a number, either unknown or changing.
- One letter has one value within an expression, so
x + x = 2x. - Different letters can hold equal values, but do not have to.
- Case matters:
xandXare separate variables. - Multiplication is implied by writing a number and letter together, or two letters together. Programming languages require
*. - Use parentheses when substituting, so that products and negatives keep their meaning.
Exercise
Let x = 2 and y = 2. Evaluate x + y and 2x. Then let x = 2 and y = 5. Evaluate both again. What does this show about the two expressions x + y and 2x?
Show answer
With x = 2 and y = 2: x + y = 4 and 2x = 4, so they agree. With x = 2 and y = 5: x + y = 7 and 2x = 4, so they disagree. The two expressions are equal only when x and y happen to have the same value. They are not equivalent in general, because the letters x and y are different variables that are allowed to differ.
Exercise
A student substitutes x = -4 into x² and writes -4² = -16. Explain the error and give the correct value.
Show answer
Writing -4² means -(4²), which is -16, because the exponent applies only to the 4. Substituting a negative value for x should use parentheses: (-4)² = (-4)(-4) = 16. The correct value of x² when x = -4 is 16.
Exercise
Write the expression "5 times n, plus 3 times m" using implied multiplication. Then evaluate it for n = 2 and m = 4.
Show answer
The expression is 5n + 3m. Substituting gives 5(2) + 3(4) = 10 + 12 = 22.