Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reasons for order of precedence??

0 views
Skip to first unread message

Chip Pearson

unread,
Feb 17, 1999, 3:00:00 AM2/17/99
to
All of the programming languages that I've used over the years have
the same order of precedence for arithmetic operations: negation,
exponentiation, division, multiplication, addition, and finally
subtraction.

Is there a particular reason for this order, or has it just been
agreed upon through convention and history? In other words, is the
really a good reason that division takes precedence over addition?

Direct email replies are most welcome. Thank you very much.

Cordially,
Chip Pearson
cpea...@gvi.net

Virgil

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to

Firstly, not every language uses the order of preference that you have listed.
Most of the languages that I am familiar with put
(1) parentheses above any of the operators, then comes
(2) exponentiation, then
(3) multiplications and divisions at the same level prioritized from left
to right, then
(4) additions and subtractions at the same level prioritized from left to
right, and lastly
(5) negation

These rules of precedence come from the usage of mathematical practice of
mathematics done by hand as it has been developed over many years.
However, computer precedence rules ignore some of the handwriting
practices, such as the use of the vinculum (horizontal line) to indicate
grouping and precedence when used in a fraction or in a radical. they also
generally exclude the implied multiplication in expressions like "2x +
3y".

The reason for the rules taking the form they do seems to be to minimize
the need for parentheses in the most commonly occurring expressions.

Reply Posted and Emailed

--
Virgil
vm...@frii.com

Jeff Kenton

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to
vm...@frii.com (Virgil) writes:

>In article <36cba...@news.gvi.net>, "Chip Pearson" <cpea...@gvi.net> wrote:

>>All of the programming languages that I've used over the years have
>>the same order of precedence for arithmetic operations: negation,
>>exponentiation, division, multiplication, addition, and finally
>>subtraction.
>>

>The reason for the rules taking the form they do seems to be to minimize


>the need for parentheses in the most commonly occurring expressions.

And a few languages have no precedence except parentheses -- strictly
left to right otherwise.


--
-------------------------------------------------------------------------
= Jeff Kenton jke...@world.std.com =
-------------------------------------------------------------------------

Michael Quinlan

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to
jke...@world.std.com (Jeff Kenton) wrote:

>vm...@frii.com (Virgil) writes:
>
>>In article <36cba...@news.gvi.net>, "Chip Pearson" <cpea...@gvi.net> wrote:
>
>>>All of the programming languages that I've used over the years have
>>>the same order of precedence for arithmetic operations: negation,
>>>exponentiation, division, multiplication, addition, and finally
>>>subtraction.
>
>>The reason for the rules taking the form they do seems to be to minimize
>>the need for parentheses in the most commonly occurring expressions.
>
>And a few languages have no precedence except parentheses -- strictly
>left to right otherwise.

And one language, of course, is strictly right to left. But the original
poster did trigger some interesting questions: when, how, and why did the
"hand-written" rules of precedence get started? Are they (western) European
only? Do Arabic or Japanese have different rules?

--
No electrons were injured in the preparation of this message.
Michael Quinlan m...@maq.org http://www.maq.org

Virgil

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to
In article <F7DCG...@world.std.com>, jke...@world.std.com (Jeff Kenton)
wrote:

>vm...@frii.com (Virgil) writes:
>
>>In article <36cba...@news.gvi.net>, "Chip Pearson" <cpea...@gvi.net> wrote:
>
>>>All of the programming languages that I've used over the years have
>>>the same order of precedence for arithmetic operations: negation,
>>>exponentiation, division, multiplication, addition, and finally
>>>subtraction.
>>>
>
>>The reason for the rules taking the form they do seems to be to minimize
>>the need for parentheses in the most commonly occurring expressions.
>
>And a few languages have no precedence except parentheses -- strictly
>left to right otherwise.

And the RPL language used on most Hewlitt-Packard calculators has no
precedence and no parentheses, all operations are performed in left to
right order.

--
Virgil
vm...@frii.com

Andrew Reilly

unread,
Feb 19, 1999, 3:00:00 AM2/19/99
to
In article <36cc9fe3...@news.micron.net>,

m...@maq.org (Michael Quinlan) writes:
> And one language, of course, is strictly right to left. But the original
> poster did trigger some interesting questions: when, how, and why did the
> "hand-written" rules of precedence get started? Are they (western) European
> only? Do Arabic or Japanese have different rules?

Note that all the languages that care use the "traditional"
precedence (or close to it). Those that don't are just doing
what's convenient for them.

My gut feeling is that it's part of the nature of the
mathematics itself than any cultural biases. The bindings
follow the "power" of the operation itself.

--
Andrew Reilly

Nick Maclaren

unread,
Feb 20, 1999, 3:00:00 AM2/20/99
to
In article <7aia0n$3q3$1...@m2.c2.telstra-mm.net.au>,

Andrew Reilly <and...@lake.com.au> wrote:
>In article <36cc9fe3...@news.micron.net>,
> m...@maq.org (Michael Quinlan) writes:
>> And one language, of course, is strictly right to left. But the original
>> poster did trigger some interesting questions: when, how, and why did the
>> "hand-written" rules of precedence get started? Are they (western) European
>> only? Do Arabic or Japanese have different rules?
>
>Note that all the languages that care use the "traditional"
>precedence (or close to it). Those that don't are just doing
>what's convenient for them.

Are you quite sure? In particular, there are two separate sources of
modern mathematics: China and India. The latter spread via Persia
and the Islamic world generally (often called Arab) to Western Europe
and started the Renaissance.

So it would be surprising if we differed from the Arabic conventions,
because we got our mathematics from them! The very word algebra is
derived from Arabic. But we might well differ from the conventions
that derive from the Chinese development.

>My gut feeling is that it's part of the nature of the
>mathematics itself than any cultural biases. The bindings
>follow the "power" of the operation itself.

Weeble. Yes, I can just about see how you can claim that multiplication
is inherently more "powerful" than addition, but that does NOT imply
any of the other rules.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nm...@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679

Andrew Reilly

unread,
Feb 21, 1999, 3:00:00 AM2/21/99
to
In article <7am5bg$7ih$1...@pegasus.csx.cam.ac.uk>,

nm...@cus.cam.ac.uk (Nick Maclaren) writes:
> In article <7aia0n$3q3$1...@m2.c2.telstra-mm.net.au>,
> Andrew Reilly <and...@lake.com.au> wrote:
>>Note that all the languages that care use the "traditional"
>>precedence (or close to it). Those that don't are just doing
>>what's convenient for them.
>
> Are you quite sure? In particular, there are two separate sources of
> modern mathematics: China and India. The latter spread via Persia
> and the Islamic world generally (often called Arab) to Western Europe
> and started the Renaissance.

I thought we were talking about _computer_ languages here.

> So it would be surprising if we differed from the Arabic conventions,

Yes, that would be surprising.

> because we got our mathematics from them! The very word algebra is
> derived from Arabic. But we might well differ from the conventions
> that derive from the Chinese development.

'fraid I don't know anything about Chinese math conventions.

>>My gut feeling is that it's part of the nature of the
>>mathematics itself than any cultural biases. The bindings
>>follow the "power" of the operation itself.
>
> Weeble. Yes, I can just about see how you can claim that multiplication
> is inherently more "powerful" than addition, but that does NOT imply
> any of the other rules.

I know it's a weak excuse for an opinion. I was kind of hoping
that someone more knowledgeable might suggest a real reason.

--
Andrew Reilly

Herman Rubin

unread,
Feb 21, 1999, 3:00:00 AM2/21/99
to
In article <7ao0v9$eo2$1...@m2.c2.telstra-mm.net.au>,

Andrew Reilly <and...@lake.com.au> wrote:
>In article <7am5bg$7ih$1...@pegasus.csx.cam.ac.uk>,
> nm...@cus.cam.ac.uk (Nick Maclaren) writes:
>> In article <7aia0n$3q3$1...@m2.c2.telstra-mm.net.au>,
>> Andrew Reilly <and...@lake.com.au> wrote:
>>>Note that all the languages that care use the "traditional"
>>>precedence (or close to it). Those that don't are just doing
>>>what's convenient for them.

>> Are you quite sure? In particular, there are two separate sources of
>> modern mathematics: China and India. The latter spread via Persia
>> and the Islamic world generally (often called Arab) to Western Europe
>> and started the Renaissance.

>I thought we were talking about _computer_ languages here.

Fortran tried to keep to the standard mathematical usage.

It is only later that computer languages tried to make it hard to
use the standard mathematical terminology which had evolved.

There is SOME unification over the precedence rules which I have
been able to discover, but I am inclined to doubt that it is
deliberate. Multiplication is two-sided distributive over
addition and subtraction, and division is right (do I have my
terminology correct?) distributive over those operations.
Similarly, exponentiation is right distributive over
multiplication and division.

I do not believe that exponentiation notation was standardized
before the Renaissance.

>> So it would be surprising if we differed from the Arabic conventions,

>Yes, that would be surprising.

But the Arabic mathematics is essentially from the Greek.

>> because we got our mathematics from them! The very word algebra is
>> derived from Arabic. But we might well differ from the conventions
>> that derive from the Chinese development.

The WORD is derived from Arabic, but not the idea. From what I
have read of al-Khwarizmi's algorithm, which introduced the term
al-jabr meaning "the magnitude", what he did was to provide the
rule for solving a linear equation in one unknown by placing all
the terms with the unknown on one side, and the others on the
other side, and dividing. This use of a single unknown is
straight from Diophantus.

The distributive law is used here, but I believe this is in
Diophantus, if not already in Euclid; it may have been known
many centuries earlier, to the Egyptians or Babylonians. It may
have been this which gave rise to precedence; a*x+b*x = (a+b)*x,
leaving out the sign for multiplying a numerical constant by a
variable already leads to the idea of preference. For addition
and subtraction with respect to multiplication and division,
it would not take anything more. The signs for the operations
were not standard, but the juxtaposition, at least for integers,
had definitely become so.

>'fraid I don't know anything about Chinese math conventions.

>>>My gut feeling is that it's part of the nature of the
>>>mathematics itself than any cultural biases. The bindings
>>>follow the "power" of the operation itself.

>> Weeble. Yes, I can just about see how you can claim that multiplication
>> is inherently more "powerful" than addition, but that does NOT imply
>> any of the other rules.

>I know it's a weak excuse for an opinion. I was kind of hoping
>that someone more knowledgeable might suggest a real reason.

I do not believe the "power" of the operation is involved, but the
lack of standard notation might have been. Our symbols for the
operations are not taken from previous cultures.
--
This address is for information only. I do not claim that these views
are those of the Statistics Department or of Purdue University.
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
hru...@stat.purdue.edu Phone: (765)494-6054 FAX: (765)494-0558

Nick Maclaren

unread,
Feb 21, 1999, 3:00:00 AM2/21/99
to
In article <7apbmq$13...@b.stat.purdue.edu>,

Herman Rubin <hru...@b.stat.purdue.edu> wrote:
>
>>> So it would be surprising if we differed from the Arabic conventions,
>
>>Yes, that would be surprising.
>
>But the Arabic mathematics is essentially from the Greek.

As I understand it, both the Greek and Arabic conventions derive from
the Persian, and before that from the Indian. I don't think that the
Arabic conventions derive directly from the Greek ones.

But this is all nit-picking :-)

Marc Daumas

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to
Nick Maclaren wrote:
> Weeble. Yes, I can just about see how you can claim that multiplication
> is inherently more "powerful" than addition, but that does NOT imply
> any of the other rules.

Whatever the set, you can always create multiplication by a natural
number from addition eg 2x = x + x... Thereafter, if some part of your
set can be mapped to the set of natural numbers, addition has to be
defined first and it implicitly looks simpler than multiplication. The
same argument applies for exponent.

--
Marc Daumas - Charge de recherches au CNRS (LIP - ENS de Lyon)
mailto:Marc....@ENS-Lyon.Fr - http://www.ens-lyon.fr/~daumas
ENS de Lyon - 46, allee d'Italie - 69364 Lyon Cedex 07 - FRANCE
Phone: (+33) 4 72 72 83 52 - Fax: (+33) 4 72 72 80 80

Nick Maclaren

unread,
Feb 22, 1999, 3:00:00 AM2/22/99
to
In article <36D108E6...@ENS-Lyon.Fr>,

Marc Daumas <Marc....@ENS-Lyon.Fr> wrote:
>Nick Maclaren wrote:
>> Weeble. Yes, I can just about see how you can claim that multiplication
>> is inherently more "powerful" than addition, but that does NOT imply
>> any of the other rules.
>
>Whatever the set, you can always create multiplication by a natural
>number from addition eg 2x = x + x... Thereafter, if some part of your
>set can be mapped to the set of natural numbers, addition has to be
>defined first and it implicitly looks simpler than multiplication. The
>same argument applies for exponent.

Now try another approach to thinking about the properties of the natural
numbers - say, one starting from unique factorisation domains. Your
statement is one about the way that you were taught and think, and not
about the natural numbers as such. Yes, I was taught and think the
same way, but my point stands.

Be that as it may, the second part of my comment holds. The other
rules concern how the unary and binary subtraction operators fit in,
the implied associativity (think overflow) and so on. They are NOT
implied by addition being more "basic" than multiplication.

Tan Wee Yeh

unread,
Feb 27, 1999, 3:00:00 AM2/27/99
to
Virgil <vm...@frii.com> wrote:
> And the RPL language used on most Hewlitt-Packard calculators
> has no precedence and no parentheses, all operations are
> performed in left to right order.

That's because there is no ambiguity when we are talking about
prefix (or postfix for the matter).
(+ 1 (* 33 4))
Stands out very clearly while
(1 + 33 * 4)
is unclear if precedence is not defined.

(pre|post)fix notations also have the advantage of supporting
n-ary arguements when infix can support at most binary.

E.g.
(+ 1 2 3 4 5 6 7) vs (1 + 2 + 3 + 4 + 5 + 6 + 7)
as is seen in most LISP-like languages. Of course, these relies
on the parentheses to distinguish between the boundaries of
computation so we do not get ambuiguity like:
(+ 1 2 3 * 4 5 6)

where the boundary of the '*' cannot be clearly determined.

Just me,
Wire ...
--
Tan Wee Yeh wy...@pobox.com http://www.pobox.com/~wytan
For PGP public key : http://www.pobox.com/~wytan/pgp
PGP fingerprint = CB 11 61 BE 4E EF FB 84 71 15 CF 22 46 FD 4C B3


0 new messages