Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » sci.math.* » sci.math

Topic: Reason for operator precedence
Replies: 15   Last Post: Mar 15, 2006 8:56 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
matt271829-news@yahoo.co.uk

Posts: 2,136
Registered: 1/25/05
Re: Reason for operator precedence
Posted: Mar 14, 2006 1:13 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


briggs@encompasserve.org wrote:
> In article <1142344511.262841.322440@p10g2000cwp.googlegroups.com>, matt271829-news@yahoo.co.uk writes:
> >
> > bri...@encompasserve.org wrote:

> >> In article <1142342196.542632.294210@i39g2000cwa.googlegroups.com>, matt271829-news@yahoo.co.uk 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)

> >
> > Obviously you can. I meant to make it work without needing parentheses,
> > but it seems that wasn't clear.

>
> Ok. Try doing it using infix notation and the operator precedence
> convention of your choice. Remember your rule: no parentheses
>
> Left to right doesn't work.
>
> b+c*a = a*b... and we're stuck
>
> Right to left doesn't work.
>
> b+c*a = ...b*c and we're stuck.
>
> Multiplication has precedence over addition doesn't work.
>
> a*... and we're stuck
>
> Addition has precedence over multiplication doesn't work.
>
> a*b+c = a*b+... and we're stuck
>
> Accordingly, trying to point to this case as a motivation for some
> particular choice of operator precedence seems ill conceived.
>
> According to your argument, it follows that we are all using either
> Polish (prefix) or Reverse Polish (postfix) notation.


Sorry, you've lost me. I was agreeing with you that even without any
precedence convention we could still represent the distributive law as
a*(b + c) = (a*b) + (a*c). However, the convention makes the
parentheses redundant, because a*b + a*c is understood to mean (a*b) +
(a*c). That's all I meant... possibly you are going into it at a deeper
level than my simple observation warranted.




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.