Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Let's not BE NP-hard, shall we...?



NM> DZ > What I am suggesting that there is one known-in-advance-
NM> DZ > &-predictable order of evaluation.  It is the one that
NM> DZ > is written into the source.  It is THIS one that is
NM> DZ > reliably & efficiently computable, albeit with a big
NM> DZ > hit in parallelism.
NM> DZ >
NM> DZ > Most languages have either a specified or implied
NM> DZ > order of evaluation.  That's the one that's predictable.
NM>
NM> Do they?  Of the dozens that I am familiar with, only Java explicitly
NM> specifies the order of evaluation.  Most of them specify the operator
NM> precedence, but that is a syntactic concept and not a semantic one.
NM>
NM> Some people have attempted to rewrite history by claiming that the
NM> semantic order is required to follow the syntax, but that has NOT
NM> achieved consensus (for good reasons) except in a few languages like
NM> Java.
NM>
NM> DZ > I am aware that Fortran specifies that the order of
NM> DZ > evaluation is effectively NOT specified.  I am also
NM> DZ > aware that, while it IS specified in C, it is also
NM> DZ > routinely ignored.
NM>
NM> That's misleading.  It is EXPLICITLY unspecified for Fortran,


The truth is in between. The Fortran standard is more complicated than either specified or unspecified.

Within an _expression_, the standard lets the programmer use parentheses to explicitly partially specify the evaluation order or leave it unspecified. In other situations it is partly unspecified.

Examples:
a+b+c has an unspecified order and can be evaluated as (a+b)+c or as a+(b+c) or as (a+c)+b. It's up to the compiler to choose.
(a+b)+c has a specified order and must be evaluated as (a+b)+c with the a+b done first.
a+(b+c) has a specified order and must be evaluated as a+(b+c) with the b+c done first.
In these last two, the compiler has no choice (unless the user specifies some option like IBM's -qnostrict giving it a choice).
a+b+c+d has an unspecified order.
a+(b+c)+d has a partially specified order, and can be evaluated as (a+(b+c))+d or as a+((b+c)+d) or as (a+d)+(b+c) or as (b+c)+(a+d). (The last two may differ if an exception leads to a trap.)

f(x)+g(x) has an unspecified order between the f and g function calls.
f(g(x),h(x)) has an unspecified order between the g and h function calls (and if either changes x or a global variable read by the other, or does I/O, it can affect the result).
In these last two, the result is undefined.
but splitting the last one into three statements
t1 = g(x)
t2 = h(x)
f(t1,t2) has a specified order.

Some programmers do use this to control evaluation order, and all compilers must support it. Some also take advantage of unspecified ordering to improve performance.

- Ian McIntosh IBM Canada Lab Compiler Back End Support and Development


Inactive hide details for "N.M. Maclaren" ---08/04/2011 01:18:07 PM---On Aug 4 2011, Dan Zuras Intervals wrote: >"N.M. Maclaren" ---08/04/2011 01:18:07 PM---On Aug 4 2011, Dan Zuras Intervals wrote: >


From:

"N.M. Maclaren" <nmm1@xxxxxxxxx>

To:

Ian McIntosh/Toronto/IBM@IBMCA

Date:

08/04/2011 01:18 PM

Subject:

Re: Let's not BE NP-hard, shall we...?





On Aug 4 2011, Dan Zuras Intervals wrote:
>
> What I am suggesting that there is one known-in-advance-
> &-predictable order of evaluation.  It is the one that
> is written into the source.  It is THIS one that is
> reliably & efficiently computable, albeit with a big
> hit in parallelism.
>
> Most languages have either a specified or implied
> order of evaluation.  That's the one that's predictable.

Do they?  Of the dozens that I am familiar with, only Java explicitly
specifies the order of evaluation.  Most of them specify the operator
precedence, but that is a syntactic concept and not a semantic one.

Some people have attempted to rewrite history by claiming that the
semantic order is required to follow the syntax, but that has NOT
achieved consensus (for good reasons) except in a few languages like
Java.

> I am aware that Fortran specifies that the order of
> evaluation is effectively NOT specified.  I am also
> aware that, while it IS specified in C, it is also
> routinely ignored.

That's misleading.  It is EXPLICITLY unspecified for Fortran, and its
'specification' for C is (at best) of doubtful status.  I was involved
in WG14 during the standardisation of both C90 and C99 and took a
particular interest in this area.

It was not there in K&R C.

In C90, it was deliberately left ambiguous in the normative wording,
as there was no consensus.  The opponents took their eye off the ball
during the writing of the Rationale, which was written by its
proponents, so it IS there, but the Rationale is merely informative
(as well as being erroneous in its claims of what Fortran states).

In C99, it was made normative together with a huge amount of other
numeric chaos, and is one of the reasons that half of the C-using
community has rejected C99 and is continuing to use C90.  And I don't
mean just end-users - I am referring to derivative standards and major
application development.

> I don't know the solution.  Perhaps the language
> committees will accept that there must be a specified
> & obeyed order of evaluation for INTERVAL expressions.
> Perhaps not.  I know some of these guys but I haven't
> discussed it with them.  Perhaps some of you can ask
> them for us.

I am one.  While I cannot speak for WG5, I did raise that issue with
some people about 754, and got the expected response.  No way, Jose!
It is so radically incompatible with Fortran's _expression_ evaluation
model that I can't see how it could be shoehorned in, even if the will
were there.


Regards,
Nick Maclaren.