4

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?

Blue
  • 75,673
user140776
  • 1,780
  • 2
    $1-1-1\neq 1-(1-1) =1-1+1$ – azif00 Jul 17 '19 at 23:12
  • 1
    It's a matter of convention that $1-1-1$ is interpreted as $1+(-1)+(-1)$, so that the minus sign doesn't really indicate subtraction. However, why do you say that only "legitimate" binary operations are associative? – saulspatz Jul 17 '19 at 23:15
  • @Azif00, mathematically, you are correct. I guess the OP means "if we apply the brackets ...". – NoChance Jul 17 '19 at 23:29
  • @NoChance, what I'm trying to say is that $ 1-1-1 $ can not be interpreted in two ways, it's wrong to see it in the second way. There is no ambiguity in this case. – azif00 Jul 17 '19 at 23:32
  • @Azif00, yes you are correct. – NoChance Jul 17 '19 at 23:40
  • @saulspatz No really good reason, other than that associativity helps to prevent this kind of ambiguity. This is kind of a personal bias. – user140776 Jul 18 '19 at 02:24

3 Answers3

4

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.

Arthur
  • 199,419
1

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.

  • 1
    I would use the term "function" instead of Exponents. Exponents is/are a subset of function. – NoChance Jul 17 '19 at 23:26
  • yes well I try to relate my answers to more basic concepts like they teach in school. –  Jul 17 '19 at 23:30
  • 2
    But if you write the expression $a/b/c$ with the hope that your human readers will dutifully apply these mechanical rules and understand what you meant, then you are in a state of sin. – Chris Culter Jul 17 '19 at 23:30
  • 2
    I'm not religious so I'll $\sin$ all I want! –  Jul 17 '19 at 23:32
  • 1
    oh and to the exponent\ function debate, so are multiplication, division, subtraction, and addition, tetration, pentation, log, etc. as an operation is a mapping between an ordered n-tuple and another set. –  Jul 17 '19 at 23:42
  • I could throw in a lot of technicality about right commutative, and left associative. I choose not to. –  Jul 18 '19 at 00:06
0

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.

Markus Scheuer
  • 108,315