2

Is there a rule in mathematics that states that expressions shall be evaluated from left to right assuming that all operators in the expression share the same precedence?

e.g. given the expression 6 / 2 * (1 + 2)
is there a rule so that only (6 / 2) * (1 + 2) (result: 9) is a valid representation and
6 / (2 * (1 + 2)) (result: 1) is invalid?

edit: I am asking this, because I get different results on different calculators.

yas4891
  • 123

3 Answers3

4

The left-to-right rule in programming allows ambiguous expressions to be evaluated. It is a palliative! A properly-written expression will not be ambiguous. The web abounds with pointless arguments about the correct answer to nonsense; one can write whatever one wishes, but that doesn't make it a precisely-constructed expression.

4

Yes. 6 / (2 * (1 + 2)) is wrong.

Note that even though + - * / go left to right, some operators, like ^, go right to left.

Read more here: http://en.wikipedia.org/wiki/Operator_associativity

  • This answer is not correct. While left-associativity is usually utilized for developing calculators (note that the very first line of the Operator Associativity Wikipedia article states it is with relation to programming languages, and even within there says usually), it is not a mathematical rule. Tristram's answer is correct (though convincing the sea of people debating this of that... Good luck). – Ironcache Aug 03 '17 at 15:23
1

No. The answer is mostly yes, for operators at the same level of presedence, such as multiplication and division, or addition and subtraction, but some operators bind more strongly than others, so that it is wrong to read $a-b\cdot c$ as $(a-b)\cdot c$. There is also the case of nested powers: $x^{y^z}$ should be read as $x^{(y^z)}$ and not as $(x^y)^z$ – which would be more easily written as $x^{yz}$ anyhow.