Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
Well, then the calculator giving wrong results is wrong. Plain wrong. –  Kendall Frey Oct 11 '12 at 13:45

3 Answers 3

up vote 5 down vote accepted

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

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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