Sub topic 1
Why the same expression needs one answer
Prerequisites
This chapter assumes you can already do the following:
- Add, subtract, multiply, and divide whole numbers.
- Place positive and negative integers on a number line.
- Read a fraction as a numerator over a denominator.
You do not need to know the full order of operations yet. This chapter explains why one is needed. Later chapters cover each rule in detail.
The problem: one string, several readings
Look at this expression:
2 + 3 × 4
A reader can process it in two reasonable ways.
- Work from left to right. Add 2 and 3 to get 5, then multiply by 4 to get 20.
- Multiply 3 and 4 first to get 12, then add 2 to get 14.
Both readings follow a rule that someone could defend. They give different numbers, so the symbols alone do not determine a value. Something outside the symbols has to decide.
An expression is a string of numbers and operators. An operator is a symbol such as +, −, ×, ÷, or an exponent that tells you to combine values. A value is a single number. Evaluating an expression means reducing it to one value. For that to be a well-defined task, every competent reader must reach the same value. Otherwise the same worksheet, spreadsheet, or program would give different results to different people.
What a convention is
The agreed order is a convention. It is a rule people adopted so that written mathematics is unambiguous. It is not a fact derived from nature, and you cannot prove it. A close comparison is driving on the right or left side of the road. Either choice works, but a road with both is dangerous.
The convention does have reasons behind it. Multiplication is repeated addition, so 3 × 4 means 4 + 4 + 4. In 2 + 3 × 4, treating 3 × 4 as one chunk is the natural reading: two plus "three fours". Exponents are repeated multiplication, so they rank above multiplication. Polynomials such as 3x² + 2x + 5 depend on this. Under the convention they are written with no extra parentheses, and each term is a product that gets added to the others.
In summary, the standard convention ranks operations from strongest to weakest:
- Grouping symbols (parentheses and brackets).
- Exponents.
- Multiplication and division, with equal rank, left to right.
- Addition and subtraction, with equal rank, left to right.
This list is a preview. Later chapters build each level, and they also show where a memory aid such as PEMDAS can mislead.
Showing the disagreement in code
You can reproduce both readings in Python. Python follows the standard convention, so its normal arithmetic gives 14. The function below deliberately ignores the convention and works strictly left to right, to show the other reading.
import operator
OPS = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv}
def left_to_right(tokens):
"""Evaluate a flat list like [2, '+', 3, '*', 4] with no precedence."""
value = tokens[0]
for i in range(1, len(tokens), 2):
op, number = tokens[i], tokens[i + 1]
value = OPS[op](value, number)
return value
print(left_to_right([2, "+", 3, "*", 4])) # 20: (2 + 3) * 4
print(2 + 3 * 4) # 14: Python uses the standard convention
print((2 + 3) * 4) # 20: parentheses force the other readingThe last line matters. The other reading is not forbidden. If you want to add first, you say so with parentheses, and the convention then gives 20. The convention sets the default meaning when you write nothing extra.
The same trap appears at every level
The ambiguity is not limited to mixing + and ×. Each rank in the hierarchy exists because some pair of operations would otherwise be unclear. Here are three examples that later chapters treat in detail.
| Expression | One reading | Another reading | Standard value |
|---|---|---|---|
| 10 − 4 + 3 | 10 − (4 + 3) = 3 | (10 − 4) + 3 = 9 | 9 |
| 24 ÷ 4 × 3 | 24 ÷ (4 × 3) = 2 | (24 ÷ 4) × 3 = 18 | 18 |
| −3² | (−3)² = 9 | −(3²) = −9 | −9 |
Two points stand out in this table.
- Operations of equal rank, such as subtraction and addition, still need a rule. That rule is "left to right". Without it, 10 − 4 + 3 would be ambiguous even though no operator outranks another.
- In the third row, the minus sign can mean "the negative number −3" or "the operation of negating". Convention treats it as the operation, which applies after the exponent.
You can confirm each standard value with code:
print(10 - 4 + 3) # 9
print(24 / 4 * 3) # 18.0
print(-3 ** 2) # -9
print((-3) ** 2) # 9The float 18.0 appears because / in Python always returns a float. The value is the same as 18.
Why this matters beyond homework
Evaluation order is not only a school topic. Every calculator, spreadsheet, and programming language has to pick an order, and a mistake in one produces wrong results that are hard to spot. Three practical consequences follow.
- Programs and formulas copied between tools must agree. Most languages follow the same ranking for + − × ÷ and exponents. A few differ in details, such as how a leading minus interacts with exponents, so check the documentation when moving a formula to a new tool.
- Formulas typed from a textbook can silently change meaning. A written fraction groups its top and bottom, but a typed
3 + 5 / 2 + 2does not. You will see this in a later chapter. - When a reader might disagree about your intent, extra parentheses cost nothing. Writing
2 + (3 * 4)gives the same value as2 + 3 * 4, and it removes doubt.
Not every expression is settled by the convention
The convention resolves most written expressions, but a few forms are still argued over. An example is 8 ÷ 2(2 + 2), where the multiplication sign is left out. Different textbooks and calculators treat the implied multiplication differently, and no single answer is accepted everywhere. A later chapter covers this. For now, treat such expressions as badly written rather than as hard puzzles. Rewrite them with explicit parentheses before evaluating.
What you should be able to do now
By the end of this chapter you can state that an expression has a unique value only because of an agreed rule. You can produce two plausible values for a short expression such as 2 + 3 × 4, and you can say which one the standard convention selects. You can also use parentheses to select either reading on purpose.
Exercise
Evaluate 18 − 6 ÷ 3 in two ways: first by working strictly from left to right with no precedence, then by the standard convention. Which value is standard, and what parentheses would make the other reading explicit?
Show answer
Strictly left to right: 18 − 6 = 12, then 12 ÷ 3 = 4. Standard convention: division ranks above subtraction, so 6 ÷ 3 = 2 first, then 18 − 2 = 16. The standard value is 16. To force the left-to-right reading, write (18 − 6) ÷ 3, which equals 4.
Exercise
The code print(10 - 4 + 3) prints 9. A student claims it should print 3 because "addition comes before subtraction". Explain what is wrong with the claim and write the expression that does give 3.
Show answer
Addition and subtraction have equal rank, so neither comes first. They are evaluated left to right: 10 − 4 = 6, then 6 + 3 = 9. The student's reading is 10 − (4 + 3) = 3, which needs parentheses. The expression that gives 3 is 10 - (4 + 3).