language-icon Old Web
English
Sign In

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. 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. 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. Thus 3 + 52 = 28 and 3 × 52 = 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. The order of operations used throughout mathematics, science, technology and many computer programming languages is expressed here: This means that if, in a mathematical expression, a subexpression appears between two operators, the operator that is higher in the above list should be applied first. The commutative and associative laws of addition and multiplication allow adding terms in any order, and multiplying factors in any order—but mixed operations must obey the standard order of operations. In some contexts, it is helpful to replace a division by multiplication by the reciprocal (multiplicative inverse) and a subtraction by addition of the opposite (additive inverse). For example, in computer algebra, this allows manipulating fewer binary operations and makes it easier to use commutativity and associativity when simplifying large expressions – for more details, see Computer algebra § Simplification. Thus 3 ÷ 4 = 3 × 1/4; in other words, the quotient of 3 and 4 equals the product of 3 and 1/4. Also 3 − 4 = 3 + (−4); in other words the difference of 3 and 4 equals the sum of 3 and −4. Thus, 1 − 3 + 7 can be thought of as the sum of 1 + (−3) + 7, and the three summands may be added in any order, in all cases giving 5 as the result. The root symbol √ is traditionally prolongated by a bar (called vinculum) over the radicand (this allows avoiding parentheses for eliminating the radicand). Other functions use parentheses around the input to avoid ambiguity. The parentheses are sometimes omitted if the input is a monomial. Thus, sin 3x = sin(3x), but sin x + y = sin(x) + y, because x + y is not a monomial. Some calculators and programming languages require parentheses around function inputs, some do not. Symbols of grouping can be used to override the usual order of operations. Grouped symbols can be treated as a single expression. Symbols of grouping can be removed using the associative and distributive laws, also they can be removed if the expression inside the symbol of grouping is sufficiently simplified so no ambiguity results from their removal.

[ "Algorithm", "Theoretical computer science", "Algebra", "Programming language", "Operator associativity" ]
Parent Topic
Child Topic
    No Parent Topic