Re: Reason for operator precedence



In article <1142342196.542632.294210@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, matt271829-news@xxxxxxxxxxx writes:

Tony wrote:
Hi all.

Hope this isn't a silly question.

I was wondering what the reason is for having multiple levels of operator
precedence?

Phrased another way, why is it that we don't just evaluate everything from
left to right?

Having multiple levels of precedence obviously adds complexity, so I assume
there must be some payback. However, I don't see what it is.


As far as addition/subtraction vs multiplication/division is concerned,
one reason is to ensure that the distributive property of
multiplication works sensibly. For example, we want 3*(4 + 6) = 3*4 +
3*6 = 3*(6 + 4) = 3*6 + 3*4.

Remember that what we're talking about here is merely a notational
convention. It has nothing whatsoever to do with the distributive
property of multiplication over addition.

You can express the distributive law for multiplication over division
using parentheses:

a*(b+c) = (a*b) + (b*c)

You can express the distributive law for multiplication over division
using a convention in which * binds tighter than +:

a*(b+c) = a*b + b*c

You can express the distributive law for multiplication over division
using a convention in which + binds tighter than *:

a*b+c = (a*b) + (b*c)

You can express the distributive law for multiplication over division
using Polish notation:

*a+bc = +*ab*bc

You can express the distributive law for multiplication over division
using Reverse Polish notation:

bc+a* = ab*bc*+

.



Relevant Pages

  • Re: Reason for operator precedence
    ... I was wondering what the reason is for having multiple levels of operator ... Having multiple levels of precedence obviously adds complexity, ... You can express the distributive law for multiplication over division ...
    (sci.math)
  • Re: Reason for operator precedence
    ... I was wondering what the reason is for having multiple levels of operator ... That's essentially the main reason. ... Higher degree polynomials would be even harder. ...
    (sci.math)
  • Re: Reason for operator precedence
    ... >> I was wondering what the reason is for having multiple levels of operator ... obviously any precedence can be enforced with parentheses. ... It is to avoid large numbers of parenthesis. ...
    (sci.math)
  • Re: Reason for operator precedence
    ... I was wondering what the reason is for having multiple levels of operator ... Having multiple levels of precedence obviously adds complexity, ... distributive property of * over + is one of the reasons - possibly the ...
    (sci.math)
  • Reason for operator precedence
    ... Hope this isn't a silly question. ... I was wondering what the reason is for having multiple levels of operator ... Having multiple levels of precedence obviously adds complexity, ...
    (sci.math)