Are "$a-b-c$" and "$a/b/c$" meaningful expressions or not?

129 Views Asked by At

While expressions of the form $a/bc$ are definitely ambiguous, since they can be interpreted either as $(a/b)c$ or as $a/(bc)$, what about expressions of the form $a-b-c$ or $a/b/c$?

"Subtraction" and "Division" are certainly not associative, so that, for example, if we interpret $1-1-1$ to mean $(1-1)-1$ then we get $-1$, but if we interpret it as $1-(1-1)$, we get 1.

Similarly, if we interpret $8/2/2$ as $(8/2)/2$, then we get $2$ whereas if we interpret it as $8/(2/2)$ then we get $8$.

Computers, of course will evaluate from left to right, so in that case, $1-1-1$, to a computer is equal to $-1$ and $8/2/2$ is equal to $2$.

The way I see this, subtraction and division aren't legitimate binary operations because they aren't associative, so I would say that $1-1-1$ should be interpreted as $1+(-1)+(-1)$, which agrees with the "left-to-right" rule. Is there a definite answer here, or is it just a matter of ambiguous notation?

3

There are 3 best solutions below

0
On BEST ANSWER

Subtraction and addition are done left-to-right (and simultaneously). Multiplication and division aren't, and are ambiguous if there is any division which isn't the rightmost operation.

I am not aware of any real reason for this discrepancy other than successive subtractions being much more common (for instance with polynomials), and there not being any real notational alternative (no fraction-like notation for subtraction, for instance), so having a fixed convention for subtraction is a lot more important than for division.

6
On

The left to right rule, is not just for computers. It applies, any time your operations have equal precedence in the order of operations used. The important one in use by humans across the globe is: $$\boldsymbol{B}\text{rackets}\\\boldsymbol{E}\text{xponents}\\\boldsymbol{D}\text{ivision, or }\boldsymbol{M}\text{ultiplication}\\\boldsymbol{A}\text{ddition, or }\boldsymbol{S}\text{ubtraction}$$ Though, I've also seen it written as GEMS.

0
On

Subtraction and division of real numbers are neither commutative nor associative. This means that we usually have to put parentheses to avoid ambiguity. However, since these arithmetic operations occur frequently, it is common to think of these operations as left-associative. This means we have \begin{align*} \color{blue}{a-b-c := (a-b)-c}\qquad\quad\mathrm{and}\qquad\quad \color{blue}{a/b/c := (a/b)/c=\frac{a}{bc}}\\ \end{align*} and can so reduce the number of parentheses.

  • Alternatively, if we divide a real number $a$ by a non-zero real number $b$, we can multiply by the reciprocal of $b$: \begin{align*} a/b = a\cdot \frac{1}{b}\tag{1} \end{align*} Left-associativity goes hand in hand with (1) since we have \begin{align*} a/b/c&:=(a/b)/c=\frac{a}{bc}=a\cdot\frac{1}{b}\cdot\frac{1}{c}\\ a/b/c/d&:=((a/b)/c)/d=\frac{a}{bcd}=a\cdot\frac{1}{b}\cdot\frac{1}{c}\cdot\frac{1}{d} \end{align*}

  • The left-associtivity makes it easy to correctly read seeminlgy complicated expressions as for instance \begin{align*} a/b/c\cdot d\cdot e/f\cdot g/h=\frac{adeg}{bcfh}\tag{2} \end{align*} The left-hand side in (2) contains both some multiplications and some divisions. If we agree on left-associativity, we only need to put all the terms that are multiplied ($a,d,e$ and $g$) in the numerator and all the others in the denominator.

Left-associativity in action: In this MSE answer we see a rational function \begin{align*} \frac{1}{1+\color{blue}{w/(1+w)^2/z/(1+z)}} \end{align*} where a part of the denominator uses the common left-associativity of the '$/$' operator.