In mathematics and computer programming, the order of operations is a collection of conventions about which arithmetic operations to perform first in order to evaluate a given mathematical expression. These conventions are formalized with a ranking of the operations. The rank of an operation is called its precedence, and an operation with a higher precedence is performed before operations with lower precedence. Calculators generally perform operations with the same precedence from left to right, but some programming languages and calculators adopt different conventions. For example, multiplication is granted a higher precedence than addition, and it has been this way since the introduction of modern algebraic notation. Thus, in the expression 1 + 2 × 3, the multiplication is performed before addition, and the expression has the value 1 + (2 × 3) = 7, and not (1 + 2) × 3 = 9. When exponents were introduced in the 16th and 17th centuries, they were given precedence over both addition and multiplication and placed as a superscript to the right of their base. Thus 3 + 52 = 28 and 3 × 52 = 75. These conventions exist to avoid notational ambiguity while allowing notation to remain brief. Where it is desired to override the precedence conventions, or even simply to emphasize them, parentheses ( ) can be used. For example, (2 + 3) × 4 = 20 forces addition to precede multiplication, while (3 + 5)2 = 64 forces addition to precede exponentiation. If multiple pairs of parentheses are required in a mathematical expression (such as in the case of nested parentheses), the parentheses may be replaced by other types of brackets to avoid confusion, as in [2 × (3 + 4)] − 5 = 9. These conventions are meaningful only when the usual notation (called infix notation) is used. When functional or Polish notation is used for all operations, the order of operations results from the notation itself.
Conventional order The order of operations, that is, the order in which the operations in an expression are usually performed, results from a convention adopted throughout mathematics, science, technology, and many computer programming languages. It is summarized as:
Parentheses Exponentiation Multiplication and division Addition and subtraction This means that to evaluate an expression, one first evaluates any sub-expression inside parentheses, working from inside to outside if there is more than one set. Whether inside parentheses or not, the operation that is higher in the above list should be applied first. Operations of the same precedence are conventionally evaluated from left to right. If each division is replaced with multiplication by the reciprocal (multiplicative inverse), then the associative and commutative laws of multiplication allow the factors in each term to be multiplied together in any order. Sometimes multiplication and division are given equal precedence, or sometimes multiplication is given higher precedence than division; see § Mixed division and multiplication below. If each subtraction is replaced with the addition of the opposite (additive inverse), then the associative and commutative laws of addition allow terms to be added in any order. The radical symbol √ {\displaystyle \surd } , which signifies a square root, is traditionally extended by a bar (the vinculum) over the radicand; this avoids the need for parentheses around the radicand. Other functions use parentheses around the input to avoid ambiguity. The parentheses can be omitted if the input is a single numerical variable or constant, as in the case of sin x = sin(x) and sin π = sin(π). Traditionally this convention extends to monomials; thus, sin 3x = sin(3x) and even sin 1/2xy = sin(1/2xy), but sin x + y = sin(x) + y, because x + y is not a monomial. However, this convention is not universally understood, and some authors prefer explicit parentheses. Some calculators and programming languages require parentheses around function inputs, while others do not. Parentheses and alternate symbols of grouping can be used to override the usual order of operations or to make the intended order explicit. Grouped symbols can be treated as a single expression.
Examples Multiplication before addition:
1 + 2 × 3 = 1 + 6 = 7. {\displaystyle 1+2\times 3=1+6=7.}
Parenthetical subexpressions are evaluated first:
( 1 + 2 ) × 3 = 3 × 3 = 9. {\displaystyle (1+2)\times 3=3\times 3=9.}
Exponentiation before multiplication, multiplication before subtraction:
1 − 2 × 3 4 = 1 − 2 × 81 = 1 − 162 = − 161. {\displaystyle 1-2\times 3^{4}=1-2\times 81=1-162=-161.}
When an expression is written as a superscript, the superscript is considered to be grouped by its position above its base:
1 + 2 3 + 4 = 1 + 2 7 = 1 + 128 = 129. {\displaystyle 1+2^{3+4}=1+2^{7}=1+128=129.}
The operand of a root symbol is determined by the overbar:
1 + 3 + 5 = 4 + 5 = 2 + 5 = 7. {\displaystyle {\sqrt {1+3}}+5={\sqrt {4}}+5=2+5=7.}
A horizontal fractional line forms two grouped subexpressions, one above divided by another below:
1 + 2 3 + 4 + 5 = 3 7 + 5. {\displaystyle {\frac {1+2}{3+4}}+5={\frac {3}{7}}+5.}
… excerpt ends here. Continue reading the full article.


![Order of operations: Simplified formal grammar for arithmetical expressions in a programming language (left),[46] and derivation of the example expression (a+b)^2/2 (right). The latter corresponds to a hierarchical structure ("syntax tree") which is unique for the given expression. The compiler generates machine code from the tree in such a way that operations originating at the lowest hierarchy level are executed first.](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Algol_grammar_expr_svg.svg/500px-Algol_grammar_expr_svg.svg.png?utm_source=en.wikipedia.org&utm_campaign=parser&utm_content=thumbnail)
