Sub topic 1
What Is an Algebraic Expression?
Prerequisites
This chapter assumes you can already do the following:
- Do arithmetic with integers and fractions, including negative numbers.
- Apply the order of operations (parentheses, exponents, multiplication and division, addition and subtraction).
- Read an exponent such as 3^2 as 3 × 3 = 9.
You do not need any earlier algebra. If you can compute 2 + 3 × 4 correctly, you are ready.
The working model
An algebraic expression is a mathematical phrase built from numbers, letters, and operation symbols. The letters stand for numbers that are not fixed yet. An expression has no equals sign and makes no claim. It is a recipe that produces a number once you decide what the letters mean.
Here are three examples:
7 + 53x + 42a - b + 9
The first uses only numbers. The other two contain letters, so their value depends on the letters.
The main idea of this chapter is that an expression is a phrase, not a sentence. A phrase such as "three more than a number" names a quantity. A sentence such as "three more than a number is ten" states a fact that can be true or false. Algebra has both, and mixing them up causes many early errors.
Three kinds of mathematical objects
Three related objects are easy to confuse.
| Object | Example | Contains a letter? | Has an `=` sign? | Can you "solve" it? |
|---|---|---|---|---|
| Numerical expression | `4 × (6 - 1)` | No | No | No, you evaluate it to get 20 |
| Algebraic expression | `4(x - 1)` | Yes | No | No, you simplify or evaluate it |
| Equation | `4(x - 1) = 20` | Usually | Yes | Yes, you find the values that make it true |
A numerical expression has exactly one value. An algebraic expression has a value only after you substitute numbers for its letters, and different substitutions give different values. An equation compares two expressions and asks which substitutions make the comparison true.
The vocabulary matters because the verbs differ:
- You evaluate a numerical expression, or an algebraic one once you know the letter values.
- You simplify an algebraic expression, which means rewriting it in a shorter, equivalent form.
- You solve an equation.
If you write 3x + 2x = 5x, you have written an equation, but it is true for every value of x. That kind of statement is called an identity. This tutorial will use that idea later, when you check that a simplified expression matches the original.
The parts of an expression
Every algebraic expression is made from a small set of parts. The later chapters give each part its own treatment, so this section only names them.
- A variable is a letter that stands for a number that can change or is unknown. In
3x + 4, the letterxis the variable. - A constant is a number on its own, with no variable attached. In
3x + 4, the number 4 is the constant. - A coefficient is the number multiplied by a variable. In
3x + 4, the coefficient ofxis 3. - A term is one piece of an expression that is added or subtracted. The expression
3x + 4has two terms:3xand4. - An operation is addition, subtraction, multiplication, division, or an exponent.
The diagram shows how these pieces fit together in one example.
Notation conventions
Algebra uses a compact way of writing multiplication. Knowing these rules lets you read an expression without guessing.
- Juxtaposition means multiplication. Writing a number next to a letter, or two letters next to each other, means multiply. So
3xmeans 3 × x, andabmeans a × b. - The number comes first. Write
5x, notx5. This is a convention, not a rule of logic, but everyone follows it. - A coefficient of 1 is not written. The term
1xis writtenx. Likewise-1xis written-x. - Avoid the symbol × between letters. It looks too much like the letter x. Use a dot (
3 · x), parentheses (3(x)), or juxtaposition. - Division is usually written as a fraction. The expression
x ÷ 4is normally writtenx/4. - A number next to parentheses means multiply. So
4(x - 1)means 4 times the quantityx - 1.
Rule 1 has a trap. Between two digits, juxtaposition does not mean multiplication. The string 35 is thirty-five, not 3 × 5. Between a number and a letter, or between letters, it does.
The order of operations still applies
An expression is read using the same order of operations you already know. Consider 2 + 3x. Multiplication comes before addition, so you compute 3x first and then add 2.
Compare these two expressions:
2 + 3x: multiply x by 3, then add 2.(2 + 3)x: add first, giving5x.
If x is 4, then 2 + 3x is 14, while (2 + 3)x is 20. Parentheses change which operation happens first, so they change the value.
Exponents bind more tightly than multiplication. In 3x^2, only x is squared, so it means 3 × (x × x). To square the whole product you would write (3x)^2, which is 9x^2.
A first look with SymPy
SymPy is a Python library for symbolic math. It treats letters as true symbols instead of numbers, so it can hold an algebraic expression without computing a value. The following program creates two symbols and builds an expression from them.
from sympy import symbols
x, y = symbols('x y')
expr = 3*x + 2*y + 5*x - y
print(expr) # 8*x + ySymPy has already combined the terms automatically when it printed the result. The next chapters explain exactly why 3x + 5x becomes 8x. For now, notice two things. The Python code needs * for every multiplication, because Python does not allow 3x. And expr is an expression object, not a number.
To turn an expression into a number, you substitute values for the symbols:
from sympy import symbols
x, y = symbols('x y')
expr = 3*x + 2*y + 5*x - y
print(expr.subs({x: 2, y: 1})) # 17Check by hand: with x = 2 and y = 1, the original is 3(2) + 2(1) + 5(2) - 1 = 6 + 2 + 10 - 1 = 17. The simplified form is 8(2) + 1 = 17. Both agree.
Why expressions are useful
A single expression describes a whole family of calculations. Suppose a taxi charges a flat fee of 4 dollars plus 2 dollars per kilometer. If k is the number of kilometers, the cost is
2k + 4
Substituting k = 3 gives 10 dollars. Substituting k = 10 gives 24 dollars. You wrote the rule once, and it works for any distance. That is the main reason to use a letter: it lets you state a general pattern instead of one case.
from sympy import symbols
k = symbols('k')
cost = 2*k + 4
for distance in [3, 10]:
print(distance, cost.subs(k, distance))
# 3 10
# 10 24Edge cases and common confusions
The following situations come up often in the first week of algebra.
- A single number is an expression. The number
7is a constant expression. It is allowed and has one term. - A single letter is an expression. The letter
xalone is an expression with one term and an unwritten coefficient of 1. - The same letter means the same number inside one expression. In
x + x, both letters stand for the same value. If you want two possibly different values, you need two different letters, as inx + y. - Different letters may still hold the same number. Writing
x + ydoes not forbid x and y from both being 3. It only means you have not committed to that. - Expressions are not true or false. Writing "
3x + 4is wrong" makes no sense. An expression can be simplified correctly or incorrectly, but it cannot be false. - An equals sign inside a simplification chain is a claim. When you write
3x + 5x = 8x, you are claiming both sides are equal for every x. That claim must stay true at each step. - Letters are not always x. Any letter can be a variable. Choosing a letter that suggests the meaning, such as
tfor time ornfor a count, helps readability.
Checking that you can read an expression
Take the expression 5x^2 - 3y + 8. Work through it with the vocabulary of this chapter.
- It contains no equals sign, so it is an expression and not an equation.
- It has two variables,
xandy. - It has three terms:
5x^2,-3y, and8. - The coefficient of
x^2is 5, and the coefficient ofyis -3. The sign belongs to the term that follows it. - The constant is 8.
To evaluate it at x = 2 and y = 4, replace the letters and follow the order of operations:
5(2)^2 - 3(4) + 8 = 5(4) - 12 + 8 = 20 - 12 + 8 = 16
from sympy import symbols
x, y = symbols('x y')
expr = 5*x**2 - 3*y + 8
print(expr.subs({x: 2, y: 4})) # 16Notice that Python writes the exponent as **, not ^. In Python, ^ means something unrelated, so using it here would give a wrong result or an error.
Summary of the working model
- An algebraic expression combines numbers, letters, and operations, and contains no equals sign.
- Its value depends on what numbers the letters stand for.
- You simplify or evaluate an expression, but you solve an equation.
- Writing conventions (juxtaposition, hidden coefficient 1, fraction bars) are shortcuts for multiplication and division.
- The order of operations applies to expressions in the same way as to numbers.
Exercise
Look at 4(n + 2) - 7. (a) Is it an expression or an equation? (b) What is its value when n = 5? (c) How would you write it in SymPy?
Show answer
(a) It is an algebraic expression, because it has no equals sign. (b) Substitute n = 5: 4(5 + 2) - 7 = 4(7) - 7 = 28 - 7 = 21. (c) from sympy import symbols, then n = symbols('n'), then expr = 4*(n + 2) - 7. Calling expr.subs(n, 5) returns 21.
Exercise
A gym charges a 20-dollar joining fee and 15 dollars per month. Write an expression for the total cost after m months, then find the cost after 6 months. Is 20 + 15m = 110 an expression or an equation?
Show answer
The total cost is 15m + 20 (or 20 + 15m). After 6 months, 15(6) + 20 = 90 + 20 = 110 dollars. The statement 20 + 15m = 110 is an equation, because it contains an equals sign. It asks for the value of m that makes the cost 110, and that value is 6.
Exercise
Explain why 3x^2 and (3x)^2 give different values when x = 2.
Show answer
In 3x^2, only x is squared, so the value is 3 × (2 × 2) = 12. In (3x)^2, the whole product is squared, so the value is (3 × 2)^2 = 6^2 = 36. Parentheses change which part the exponent applies to.