Common operator notation: Difference between revisions

Content deleted Content added
WP:CHECKWIKI error fix #8 or #105. Fix broken section header. Do general fixes and cleanup if needed. - using AWB
Line 11:
== Operator associativity ==
{{Main|Operator associativity}}
Operator associativity determines what happens when an operand is surrounded by operators of the same precedence, as in 1-2-3: An operator can be [[left-associative]], [[right-associative]], or [[non-associative]]. Left-associative operators are applied to operands in left-to-right order while right-associative operators are the other way round. The basic arithmetic operators are normally all left-associative,<ref name="Bronstein_1987" /> which means that 1-2-3 = (1-2)-3 ≠ 1-(2-3), for instance. This does not hold true for higher operators. For example, [[exponentiation]] is normally right-associative in mathematics,<ref name="Bronstein_1987" /> but is implemented as left-associative in some computer applications like Excel. In programming languages where assignment is implemented as an operator, that operator is often right-associative. If so, a statement like {{mono|1=a := b := c}} would be equivalent to {{mono|1=a := (b := c)}}, which means that the value of c is copied to b which is then copied to a. An operator which is non-associative cannot compete for operands with operators of equal precedence. In [[Prolog]] for example, the infix operator {{mono|1=:-}} is non-associative, so constructs such as {{mono|1=a :- b :- c}} are syntax errors.
Unary prefix operators such as − (negation) or sin (trigonometric function) are typically associative prefix operators. When more than one associative prefix or postfix operator of equal precedence precedes or succeeds an operand, the operators closest to the operand goes first. So −sin x = −(sin x), and sin -x = sin(-x).
 
Line 25:
Some more examples:
 
<math>: {{mono|1= 1-2+3/4*5+6+7 = (((1-2)+((3/4)*5))+6)+7</math>}}
 
<math>: {{mono|1= 4 + -x + 3 = (4 + (-x)) + 3</math>}}
 
==Generalizations of Common Operator Notation==