Re: Reason for operator precedence
- From: Bill Dubuque <wgd@xxxxxxxxxxxxxxxxxxxx>
- Date: 14 Mar 2006 13:09:49 -0500
matt271829-news@xxxxxxxxxxx wrote:
briggs@xxxxxxxxxxxxxxxxx wrote:
matt271829-news@xxxxxxxxxxx writes:
Tony wrote:
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.
And, to elaborate a bit more, I venture to disagree and suggest that
the convention *does* have to do with this property. I suggest that the
distributive property of * over + is one of the reasons - possibly the
main reason - why it is "natural" to view multiplication as "tighter"
than addition, and to want to interpret, say, 3*4 + 3*6 as (3*4) +
(3*6) rather than as ((3 * 4) + 3) * 6 or whatever.
Expanding (X+Y)*Z -> X*Z+Y*Z is easy and leads to normal forms.
Factoring (X+Y)*Z <- X*Z+Y*Z is hard and leads to non-normal forms.
Therefore X+Y*Z = X+(Y*Z) not (X+Y)*Z (i.e. expanded, not factored).
E.g. compare representational forms for integers and polynomials.
It's easy to compute the normal expanded form of polynomials and
the radix form of integers (= expanded polynomial in the radix)
but its much harder to compute factorizations. Further, poly
factorizations needn't be unique if the coef ring isn't a UFD.
Performing arithmetic operations in expanded form is easy but
is much harder in factored form, e.g. the sum of prime powers
p^m + q^n must be completely factored to retain factored form.
Given such a preference for expanded vs. factored representations
it is only natural to specify a notation that is more efficient
at representing the preferred expanded form.
--Bill Dubuque
.
- References:
- Reason for operator precedence
- From: Tony
- Re: Reason for operator precedence
- From: matt271829-news
- Re: Reason for operator precedence
- From: briggs
- Re: Reason for operator precedence
- From: matt271829-news
- Reason for operator precedence
- Prev by Date: Re: Finite groups generetad by two elements
- Next by Date: Re: JSH: New core argument then
- Previous by thread: Re: Reason for operator precedence
- Next by thread: Re: Reason for operator precedence
- Index(es):