Order of operations

As operator precedence, valency, priority or precedence, is called in mathematics, logic and computer science, a defined partial order in which the operators of this in infix notation expression to be evaluated.

No total order but a partial order, it is because there is no strict order between all operators. Also, several are on the same rank. For example, the rank of multiplication and division is the same, but higher than the rank of addition and subtraction ( " dots before dashes" ). You can save money by Ranking explicit parentheses. So is tantamount if the multiplication operator has higher precedence. However, this is always a matter of definition.

A bracketing provides the ability to selectively set the default precedence overrides the rule. When you write, is only applied to the sum of and. An order is not yet given, because the expression can be evaluated either from left to right and from right to left ( or any). That depends on the particular definition.

Ranking of unique operators

For the standard arithmetic operations of mathematics following ( in descending priority) ranking is common:

In programming languages ​​and computer programs for formula evaluation (eg, the Unix utility bc) there are additional categories. One of these is the sign that an even higher priority enjoys usually before the potentiation. Thus, while it Read in mathematical formulas of expression, in the terms of such evaluation programs but often.

In logic there is not always customary to define an operator precedence. Where that happens, is usually chosen the following ( in descending priority):

After application of the operator ranking is evaluated, for example, the arithmetic expression as, as the logical expression.

Order equivalent operators

In addition, for operations associativity are defined, is determined by the order in which side by side, equivalent operators are acted on. An operator is called left-associative if A op B op C op D is evaluated as ( (A op B) op C) op D; an operator is called right-associative if A op B op C op D is evaluated as A op ( B op ( C op D)). Of these arithmetic operators potentiation is defined as right-associative, ie:

Similarly, the arrow operator:

The remaining two -digit operators are left-associative as defined, ie for example.

In the logic connectives are defined mostly left-associative, but there are definitely some authors at least use the conditional right-associative.

There are also programming languages ​​such as Occam, who put all operators on the same rank and evaluate from left to right.

Outline characters

To change within an expression defined operator precedence and to make clear in the absence of definition of a ranking expressions, different forms of structure characters. In mathematics and in modern logic are the brackets.

In the history of logic punctures were often especially at the beginning used to disambiguate or to change a possibly defined operator precedence expressions. A Punktierungssystem, the obtained by the fundamental work Principia Mathematica a certain distribution was more common until the 1970s in different modified form in introductory logic books. In this system, a point is instead of imaginary closing parenthesis in front of a connective or instead of the imaginary opening bracket after a connective set. For example, would take

The following expression is written:

If several imaginary brackets on each other, then instead of a single point or two more set points, so for example, instead of

The following expression would be written:

Another system weights occurring in an expression connectives with points. Are more points over an operator, the weaker is its binding strength, ie the lower is its priority. Under this system, for example, would a conjunction with two points weaker binding as a conjunction with a point, which in turn is weaker than a conjunction with no points.

Others

In programming languages, a weight and associativity is usually set for all operators to ensure that the structure of all expressions is also unique if no parentheses are used. Thus, the evaluation of an expression without side effects, this is always the same value.

The operator precedence is normally only on expressions in infix notation of importance. Spellings such as the Polish Notation or the Reverse Polish Notation was developed so that the expressions without precedence and clip free are unique. Also in the first predicate logic notation, the Begriffsschrift notation and graphical notations such as the Existential Graphs, the interpretation of an expression is uniquely determined and requires no outline characters or conventions.

In programming languages ​​which allow for side effects in terms of, the order / are carried out in this side-effects effective, important. Some programming languages ​​present this evaluation order strictly fixed, others ( such as C or C ) allow the order of evaluation in most infix operands undefined. example:

Int f1 ( void); int f2 ( void); int f3 ( int);   int g ( void) {return f3 (f1 () * f2 ()); } It is not defined whether f1 or f2 is performed first (and thus side effects are effective). In contrast, stipulates that f3 is called only after f1 and f2 are complete ( with their side effects). literature

  • Florian Cajori: A History of Mathematical Notations. Open Court, Chicago, 1928-1929, Dover, New York 1993. ISBN 0-486-67766-4
  • William Kneale, Martha Kneale: The Development of Logic. Clarendon Press, Oxford 1962. ISBN 0-19-824773-7
  • Programming
  • Logic
  • Mathematical notation
6608
de