Why not assign each arithmetic operator a distinct precedence?

60 Views Asked by At

The internet is filled with confusing PEMDAS/BEDMAS/BODMAS/BIDMAS puzzles. A minimal example which requires one to avoid misinterpreting any of these mnemonic rules to mean "addition first, subtraction afterward" is: $0 - 0 + 1$. The correct (by convention) answer is $1$. This requires us to recognise that as the expression involves only operators of the same precedence level, we should evaluate left-to-right.

Why not assign each of the common arithmetic operators a distinct precedence level?

2

There are 2 best solutions below

4
On

Assigning each operator a distinct level of precedence would be messy. Trivial algebraic manipulations (changing the order of terms) would require us to put parentheses everywhere to get right, and that would make them not trivial any more. Also, it would make it non-trivial to swap $1 + (-2)\cdot x$ for $1-2x$ in the middle of an expression, as you would have to add parentheses to it to make it consistent. All in all it's a terrible idea whose minor increase in consistency not in any way outweighs the reduction in readability and manipulability.

Also, it would make the meaning of an expression stray further from how we would naturally interpret it when we say it out loud. For instance,

I have three apples, then I eat two of them, then I buy four more

immediately becomes

$3a - 2a + 4a$

just by swapping out words for symbols. And the fact that $+$ and $-$ share operator precedence (and also that multiplication has higher precedence) is exactly what allows for that translation to happen painlessly, without having to put any thought into it.

1
On

Another way to think about it, is we'd have to define things differently.

Subtraction can currently be thought of, as addition of additive inverses. But, if it had to under all circumstances be a different precedence; we'd have to pick an order for doing additions, that relied on what set they were from. Or, we'd no longer be able to think of subtraction as addition of additive inverses.

Division has a similar notion with multiplcative inverses. This leads to the same conundrum for multiplication as it did with addition.

This all may carry into higher operations.