Order of operations
In mathematics and computer programming, the order of operations (or operator precedence) is a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.
For example, in mathematics and most computer languages, multiplication is granted a higher precedence than addition, and it has been this way since the introduction of modern algebraic notation.[1][2] Thus, the expression 2 + 3 × 4 is interpreted to have the value 2 + (3 × 4) = 14, not (2 + 3) × 4 = 20. With the introduction of exponents in the 16th and 17th centuries, they were given precedence over both addition and multiplication and could be placed only as a superscript to the right of their base.[1] Thus $3 + 5^2 = 28 $and 3 × 5^2 = 75.
These conventions exist to eliminate ambiguity while allowing notation to be as brief as possible. Where it is desired to override the precedence conventions, or even simply to emphasize them, parentheses ( )
(sometimes replaced by brackets [ ]
or braces { }
for readability) can indicate an alternate order or reinforce the default order to avoid confusion. For example, (2 + 3) × 4 = 20 forces addition to precede multiplication, and (3 + 5)^2 = 64 forces addition to precede exponentiation.