Operator Precedence and PEMDAS
When operators have equal precedence, they are evaluated from left to right, not right to left.
The Tie in the Middle
An expression can contain several operators with equal precedence. When that happens, precedence alone does not decide which operator comes first. The tie is broken by evaluating from left to right. This rule is especially important for subtraction and division, because changing their grouping can change the result.
What do you think happens?
What result should you expect from 5 - 3 - 1?
Reveal answer
Answer: 1
The subtraction operators have equal precedence, so evaluation proceeds from left to right: first 5 - 3 produces 2, then 2 - 1 produces 1.
Reading Equal-Precedence Operators
Operator precedence describes which operations are considered first when an expression contains different operators. When two or more operators share the same precedence level, the left-to-right rule decides the order. The computer processes the operator that appears farther left before the equal-precedence operator to its right.
Left-to-right evaluation breaks a precedence tie. It does not mean that every operation in every expression is always performed from left to right; it applies here when the operators being compared have equal precedence.
Tracing 5 - 3 - 1
Evaluating the expression step by step
Evaluate 5 - 3 - 1 using the left-to-right rule.
Step 1: Both subtraction operators have equal precedence. Start with the leftmost subtraction, 5 - 3, which produces 2.
Step 2: Replace the completed part of the expression with its result. The remaining expression is 2 - 1.
Step 3: Evaluate the remaining subtraction: 2 - 1 produces 1.
5 - 3 - 1 equals 1.
Why Grouping Changes the Answer
Subtraction is not associative. That means changing the grouping can change the result. The left-to-right grouping of 5 - 3 - 1 is (5 - 3) - 1, which equals 1. A different grouping, 5 - (3 - 1), equals 3. These are different expressions because the parentheses tell the computer to evaluate a different sub-expression first.
| Grouping | First operation | Result |
|---|---|---|
| (5 - 3) - 1 | 5 - 3 | 1 |
| 5 - (3 - 1) | 3 - 1 | 3 |
Addition and multiplication are associative in the source examples: (a + b) + c equals a + (b + c), and (a * b) * c equals a * (b * c). Subtraction and division are not associative, so their grouping requires particular care.
Parentheses as an Override
Parentheses explicitly group a sub-expression and force that sub-expression to be evaluated first, even when it appears later in the expression. Use them when the intended grouping differs from the normal left-to-right order or when you want the grouping to be unmistakable.
Controlling the grouping
Compare 10 - 5 + 2 with 10 - (5 + 2).
Expression without parentheses: The operators have equal precedence, so evaluate from left to right: 10 - 5 produces 5, and then 5 + 2 produces 7.
Expression with parentheses: The parentheses force 5 + 2 to be evaluated first, producing 7. Then evaluate 10 - 7, which produces 3.
10 - 5 + 2 equals 7, while 10 - (5 + 2) equals 3.
Add parentheses when you need a grouping other than the default left-to-right grouping. This makes the intended evaluation order explicit and helps prevent calculation errors.
Mistakes with Equal Operators
Evaluating the rightmost subtraction first in 5 - 3 - 1.
The subtraction operators have equal precedence, so the tie is resolved from left to right.
Fix:
Evaluate 5 - 3 first, then evaluate the remaining expression 2 - 1.Assuming that equal-precedence operators can be grouped in either direction.
Subtraction is not associative, so different groupings can produce different results.
Fix:
Use the left-to-right rule unless parentheses explicitly request a different grouping.Ignoring parentheses when determining the first operation.
Parentheses force their enclosed sub-expression to be evaluated first.
Fix:
Evaluate 5 + 2 first, then subtract that result from 10.
Check Your Reasoning
Evaluate 10 - 5 + 2 without parentheses. Then evaluate 10 - (5 + 2). State which operation is performed first in each expression and explain why the results differ.
Hints
- For the expression without parentheses, look for equal-precedence operators and apply the left-to-right rule.
- For the expression with parentheses, evaluate the enclosed sub-expression first.
Explain why 5 - 3 - 1 produces 1 rather than 3. Write the two intermediate expressions created during left-to-right evaluation.
Hints
- Begin with the leftmost subtraction.
- After evaluating 5 - 3, write the remaining expression before calculating the final result.
The Rule to Remember
- When operators have equal precedence, evaluate them from left to right.
- The expression 5 - 3 - 1 equals 1 because 5 - 3 is evaluated before the remaining subtraction.
- Subtraction and division are not associative, so changing their grouping can change the result.
- Parentheses override the normal left-to-right grouping and force a chosen sub-expression to be evaluated first.
- Use parentheses when you need to control or clarify the evaluation order.
Key Takeaways
- Equal-precedence operators are evaluated from left to right.
- 5 - 3 - 1 is evaluated as (5 - 3) - 1, producing 1.
- Subtraction and division require careful grouping because they are not associative.
- Parentheses force a sub-expression to be evaluated first and can change the final result.