Hello, and welcome to the first lesson in the algebra foundation for machine learning and data science. This module builds the numerical reliability you will need before working with formulas, functions, vectors, and model loss calculations. A small change in the order of a calculation can completely change a result, so today’s goal is to evaluate numerical expressions consistently using the agreed order of operations.
By the end, you should be able to look at an expression containing brackets, powers, multiplication, division, addition, and subtraction, decide what must be calculated first, and show clear intermediate steps.
Why an agreed order matters
Consider:
If someone adds first, they get . If someone multiplies first, they get . Both people may have done their individual arithmetic correctly, but only one result can be the conventional meaning of the written expression.
The order of operations is mathematics’ shared grammar. It ensures that a calculation has one agreed interpretation, whether you work it out by hand, enter it in a calculator, or write it in Python. This consistency becomes particularly important later when expressions represent data transformations or machine-learning loss functions.
Watch this short explanation and its worked examples before continuing.
Math Antics - Order Of Operations
“Math Antics – Order Of Operations” by mathantics introduces why a shared evaluation order is necessary, then explains each priority level with clear visual examples.
Watch why order matters to see how the same expression can produce conflicting answers without a convention. Then watch grouping symbols for the highest-priority rule, followed by powers. Finish with equal priorities, paying particular attention to why multiplication and division, and also addition and subtraction, must be performed from left to right. The final recap is a useful summary.
The priority system: PEMDAS or BIDMAS
Two common mnemonics describe the same convention:
- PEMDAS: Parentheses, Exponents, Multiplication and Division, Addition and Subtraction
- BIDMAS: Brackets, Indices, Division and Multiplication, Addition and Subtraction
“Indices” means powers, such as . “Brackets” and “parentheses” both mean grouping symbols: , , and sometimes .
The essential hierarchy is:
- Grouping symbols: calculate inside brackets or parentheses first.
- Exponents: calculate powers next.
- Multiplication and division: these have equal priority, so work left to right.
- Addition and subtraction: these also have equal priority, so work left to right.
The point most often missed is that PEMDAS does not say “multiply before divide” or “add before subtract.” The letters in each pair share a priority level.

A useful way to think about the structure is that brackets establish a temporary local calculation. Once you enter a pair of brackets, apply the same full priority system inside it.
For example:
The parentheses are highest priority, but that does not mean simply calculating from left to right inside them. First evaluate the exponent, then multiplication, then addition:
A dependable method for working on paper
Order of operations becomes much easier when you do not try to hold every step in your head. Use this routine:
- Scan the entire expression for grouping symbols.
- Simplify one part at the current highest priority.
- Rewrite the entire remaining expression on the next line, changing only that part.
- Scan again from the top of the priority list.
- Continue until one ordinary arithmetic operation remains.
Rewriting the untouched parts is not busywork. It is a check against accidentally dropping a minus sign, changing a number, or calculating a lower-priority operation too early.
Example 1: multiplication before addition
Evaluate:
There are no brackets or exponents. Multiplication comes before addition:
It would be incorrect to calculate first, because that addition has lower priority than the multiplication.
Example 2: operations with equal priority
Evaluate:
Division and multiplication have equal priority, so begin with the operation that occurs first when reading left to right:
Do not multiply and first. That would silently change the expression into a different one:
The parentheses in that version create a different calculation, whose value is , not .
The same rule applies to addition and subtraction. For instance:
You should not add first, since addition and subtraction are peers; follow their written order from left to right.
Brackets, nesting, and powers
Brackets tell you to treat a part of an expression as a unit. Compare these two expressions:
In the first expression, the bracketed addition is completed first:
In the second expression, multiplication has priority:
So parentheses are not decoration: they alter the meaning.
A power such as means repeated multiplication:
Powers are evaluated after grouping symbols but before ordinary multiplication or division. Here is a complete example:
First calculate the power:
Then calculate multiplication:
Finally subtract:
The next lesson will examine powers and roots in more depth. For now, the key point is simply their place in the evaluation order.
When grouping symbols are nested, work from the innermost set outward. For example:
Start with the parentheses:
Then complete the square brackets:
The brackets here mean multiplication:
Fractions contain implicit grouping
A fraction bar groups the entire numerator and the entire denominator. Treat it as though there are invisible parentheses around both:
First simplify the top and bottom separately.
For the numerator:
For the denominator:
Only after both are simplified should you divide:
This habit will be useful when formulas become more complex. In data science, ratios often represent quantities such as averages, rates, normalized values, or probabilities. Simplifying the top and bottom independently prevents many avoidable errors.
A brief Python check
Python follows the same basic priority structure:
- Parentheses:
() - Exponents:
** - Multiplication and division:
*and/ - Addition and subtraction:
+and-
For a quick five-minute check, run these expressions in a Python notebook or interpreter:
8 + 3 * 6
40 / 4 * 5
60 - (4**2 + 2 * 5)
(30 + 10 * 2) / (6 * 4 + 1)
The outputs should be , , , and , respectively. Python displays the last result as because / performs ordinary division and returns a decimal-style number, even when the value is exactly .
For now, use Python as a way to verify your handwritten reasoning, not as a substitute for it. If a result surprises you, write out the intermediate steps and locate the first point where your hand calculation and Python’s interpretation differ.
Common errors to catch before they happen
Reading strictly from left to right.
This fails whenever a later operation has higher priority. In , multiplication must be handled before addition.
Treating PEMDAS as “multiply, then divide.”
Multiplication and division are equal. Work left to right.
Treating PEMDAS as “add, then subtract.”
Addition and subtraction are equal. Again, work left to right.
Dropping the rest of the expression.
After calculating one piece, copy every untouched number and operation into the next line.
Ignoring the fraction bar.
A numerator and denominator are grouped expressions. Fully simplify each before dividing.
Using parentheses that were not written.
Do not add invisible grouping based on what feels natural. The given notation determines the calculation.
A fast final check is to ask: Did I handle all brackets, then powers, then multiplication or division, and only then addition or subtraction? When equal-priority operations appeared, did I move left to right?
Key takeaways
The order of operations gives every numerical expression one shared meaning:
- Evaluate grouping symbols first, moving from inner groups outward.
- Evaluate powers next.
- Evaluate multiplication and division from left to right.
- Evaluate addition and subtraction from left to right.
- Treat a fraction’s numerator and denominator as grouped expressions.
Clear line-by-line rewriting is the most reliable habit you can build now. In the next lesson, you will focus on exponents and roots: what powers mean, how to calculate them, and how they interact with numerical expressions.
Can't find a good explanation? Sign up and we'll make it for you
Sign up