Order of operations
From Exampleproblems
In arithmetic and elementary algebra, certain rules are used for the order in which the operations in algebraic expressions are to be evaluated. These precedence rules (which are mere notational conventions, not mathematical facts) are also used in many programming languages and by most modern calculators. In computing, the standard algebraic notation is known as infix notation. This article assumes the reader is familiar with addition, division, exponential powers, multiplication, and subtraction.
Contents |
The standard order of operations
- 1. Evaluate subexpressions contained within parentheses, starting with the innermost expressions. (Brackets [ ] are used here to indicate what is evaluated next.)
- 2. Evaluate exponential powers; for iterated powers, start from the right:
- 3. Evaluate multiplications and divisions, starting from the left:
- 4. Evaluate additions and subtractions, starting from the left:
The expression: 2 + 3 × 4 is evaluated to 14, and not 20, because multiplication precedes addition. If the intention is to perform the addition first, parentheses must be used: (2 + 3) × 4 = 20.
In Australia and Canada, an acronym BEDMAS is often used as a mnemonic for Brackets, Exponents, Division, Multiplication, Addition, and Subtraction.
In the UK and New Zealand, the acronym BODMAS is used for Brackets, Orders, Division, Multiplication, Addition, Subtraction. This is sometimes written as BOMDAS, BIDMAS or BIMDAS where I stands for Indices.
In the US, the acronym PEMDAS (for Parentheses, Exponentiation, Multiplication/Division, Addition/Subtraction) is used instead, sometimes expressed as the mnemonic "Please Excuse My Dear Aunt Sally".
Example
- Given:
- Evaluate the innermost subexpression (7 + 1):
- Evaluate the subexpression within the remaining parentheses (5 − 8):
- Evaluate the power of (−3)2:
- Evaluate the multiplication 9 × (−5):
- Evaluate the subtraction 3 − (−45):
- Evaluate the addition 48 + 2:
Proper use of parentheses and other grouping symbols
When you are restricted to using a straight text editor, parentheses (or more generally "grouping symbols") must be used generously to make up for the lack of graphics, like square root symbols. Here are some rules for doing so:
1) Whenever there is a fraction formed with a slash, put the numerator (the numbers on top of the fraction) in one set of parentheses, and the denominator (the numbers on the bottom of the fraction) in another set of parentheses. This is not required for fractions formed with underlines:
- y = (x+1)/(x+2)
2) Whenever there is an exponent using the caret (^) symbol, put the base in one set of parentheses, and the exponent in another set of parentheses:
- y = (x+1)^(x+2)
3) Whenever there is a trig function, you may put the argument of the function, typically shown in bold and/or italics, in parentheses:
- y = sin(x+1)
4) The rule for trig functions also applies to any other function, such as "sqrt". That is, the argument of the function should be contained in parentheses:
- y = sqrt(x+1)
5) An exception to the rules requiring parentheses applies when only one item is present. While correct either way, it is more readable if these parentheses are omitted:
- y = (3)/(x) or y = 3/x
- y = (3)/(2x) or y = 3/(2x)
- y = (x)^(5) or y = x^5
- y = (2x)^(5) or y = (2x)^5
- y = (x)^(5z) or y = x^(5z)
Note that this exception does not apply to trig functions or any other function, which should use parentheses even if only one value is present:
- y = sqrt(2)
- y = tan(30)
6) Whenever anything can be interpreted multiple ways, put the part to be done first in parentheses, to make it clear.
7) You may alternate use of the different grouping symbols (parentheses, brackets, and braces) to make it more readable. For example:
- y = { 2 / [ 3 / ( 4 / 5 ) ] }
is more readable than:
- y = ( 2 / ( 3 / ( 4 / 5 ) ) )
Note that certain applications, like computer programming, will restrict you to certain grouping symbols.
Special cases
In the case that a factorial is in an expression, it is evaluated after parentheses or other grouping symbols, but before everything else (the common mnemonics would be BFEDMAS, BFODMAS, BFIMDAS, and PFEMDAS, if an F were included for factorials).
When new operations are defined they are generally presumed to take precedence over other operations unless defined otherwise. In the case where repeated operators of the same type are used, such as in
- a / b / c
the expression is evaluated from left to right, as
- ((a / b) / c)
See also
- Common operator notation (for a more formal description)
- associativity
- commutativity
- distributivity
External links
- Order of operations on PlanetMath.
- For a rationale behind the use of the order of operations, see MathandText.da:Operatorprioritet
