Sub topic 8
Nested Parentheses and Brackets
Prerequisites and the main idea
This chapter assumes that you can add, subtract, multiply, and divide integers, and that you know the basic order of operations. A grouping symbol marks an expression that must be treated as one unit. Parentheses ( ), brackets [ ], and braces { } can all group expressions.
When grouping symbols are nested, one pair appears inside another. Evaluate the innermost group first. Then use its result in the surrounding group.
For example:
\[ 3[2 + (5 - 1)] \]
The parentheses are inside the brackets, so calculate (5 - 1) first:
\[ 3[2 + 4] = 3[6] = 18 \]
The brackets do not mean multiplication by themselves. In this expression, 3[6] means 3 × 6.
A systematic method
Use this sequence:
- Find the deepest grouping symbols.
- Evaluate the expression inside them.
- Replace that group with its result.
- Continue outward until no grouping symbols remain.
- Apply the remaining order of operations.
Consider:
\[ 20 - 2[3 + (4 - 7)] \]
Work from the inside out:
\[ 4 - 7 = -3 \]
\[ 3 + (-3) = 0 \]
\[ 20 - 2(0) = 20 \]
The calculation can be organized like this:
| Step | Expression | Result |
|---|---|---|
| 1 | \(4 - 7\) | \(-3\) |
| 2 | \(3 + (-3)\) | \(0\) |
| 3 | \(20 - 2(0)\) | \(20\) |
The different symbols make the structure easier to read. They do not create different arithmetic rules.
Several nested levels
A group can contain another group several times:
\[ 2\{5 + [3(2 + 1) - 4]\} \]
Start with the innermost parentheses:
\[ 2\{5 + [3(3) - 4]\} \]
Then evaluate the multiplication inside the brackets:
\[ 2\{5 + [9 - 4]\} \]
Next simplify the brackets:
\[ 2\{5 + 5\} \]
Finally evaluate the braces:
\[ 2(10) = 20 \]
Braces, brackets, and parentheses can be replaced by ordinary parentheses when typing an expression in a calculator or program, as long as the grouping remains clear.
# Python uses parentheses for every grouping level.
result = 2 * (5 + (3 * (2 + 1) - 4))
print(result) # 20Checking the structure
Before calculating, mark the matching pairs. Every opening symbol must have a corresponding closing symbol. If a closing symbol appears too soon, the expression is malformed or has been copied incorrectly.
A useful habit is to rewrite one level at a time instead of trying to calculate everything mentally.
Exercise
Evaluate \(4[2 + \{6 - (3 + 1)\}]\).
Show answer
Start inside: \(3 + 1 = 4\). Then \(6 - 4 = 2\), \(2 + 2 = 4\), and \(4 \times 4 = 16\).