1
$\begingroup$

Customary operator precedence has addition prior to subtraction. Apart from historical convention and notational consistency, is there a rationale for this?

$\endgroup$
4
  • 2
    $\begingroup$ Wait ... if + has precedence over - , then $3-4+7$ would evaluate to $3-11=-8$ ....but all of us would evaluate that to $-1+7=6$ $\endgroup$ – Bram28 Nov 11 '18 at 17:05
  • 1
    $\begingroup$ I think you're wrong about "Customary operator precedence has addition prior to subtraction" both in math and in most programming languages. Is there a particular context that would override that? For instance, in math a mnemonic like PEMDAS/BEDMAS doesn't mean addition comes before subtraction - you also have to remember that they have the same precedence and addition/subtraction is resolved from left to right, as Bram28 commented. $\endgroup$ – Mark S. Nov 11 '18 at 17:07
  • 2
    $\begingroup$ See Order of operations for the "customary" conventions. The rational reason for the conventions is that we need a rule. $\endgroup$ – Mauro ALLEGRANZA Nov 11 '18 at 17:12
  • 2
    $\begingroup$ It is common convention not to define subtraction and to interpret $a-b$ as $a+(-b)$, where $-$ is a unary operator. Since unary operators have precedence over binary ones, there is no ambiguity in what $3-4+7$ means. “Multiplicative unary symbols” have precedence over “additive” ones, so $-3^2$ is $-9$. $\endgroup$ – egreg Nov 11 '18 at 17:27
1
$\begingroup$

I fully agree with @egreg, so let me elaborate on his comment.

The notation is rational because it is coherent with group theory. Indeed, $(\mathbb{Z}, + , 0)$ is an additive group, but it is interesting to first look at a multiplicative notation. If you write $xy^{-1}z$, where $x$, $y$ and $z$ are elements of a group, there is no ambiguity on the interpretation and nobody would interpret this as $x(yz)^{-1}$. If the group is commutative and comes with an additive notation, you would write $x - y + z$ instead, but again, it should not be interpreted as $x - (y +z)$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.