Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!nrl-cmf!ames!amelia!lemming.nas.nasa.gov!fouts
From: fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts)
Newsgroups: comp.lang.fortran
Subject: Re: intrinsic functions, math operators (was: i++, i+=1, i=i+1)
Message-ID: <1033@amelia.nas.nasa.gov>
Date: 22 Sep 88 15:34:30 GMT
References: <1031@amelia.nas.nasa.gov> <3976@lanl.gov>
Sender: news@amelia.nas.nasa.gov
Reply-To: fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts)
Organization: NASA Ames Research Center
Lines: 57

In article <3976@lanl.gov> jlg@lanl.gov (Jim Giles) writes:
>From article <1031@amelia.nas.nasa.gov>, by fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts):
>> [...]                                  My reading of the draft shows
>> any of these to be allowed; provided that in all cases the user is
>> allowed to override the standard version with a private version.
>
>
>Yes, but the method of overriding the standard version is different for
>each of the implementation methods that you mention.  This means that
>a code which really does override a standard procedure definition will
>not be portable.  It is this lack of portability that I object to.
>

Hmm.  Good point.  I agree.

>[comment on my comment about not wanting the compiler to know
  semantics in advance . . .], I still
>won't be able to optimize SIN(x)*SIN(x)+COS(x)*COS(x) as well as a compiler
>could do if it had the semantics of trig functions built-in (the optimal
>evaluation strategy is to replace the whole expression with the constant 1).
>

This is true, but only accurate when the expression evaluates to a
constant.  You couldn't (because of finite precision) replace
1-COS(X)*COS(X) with SIN(x)*SIN(x) and guarentee the same results.
Although, if you can determine at compile time that COS is
deterministic in X then you can replace 1-COS(X)*COS(X) with
(t=COS(X),1=t*t) The case that evaluates to another function is much
more common than the case that evaluates to a constant.

For now, I'm willing to give up the occasional constant-replacement
win for the optimizations I can get by concentrating on manipulating
on the fly knowledge, and leave the level of algabric sophistication
that you are contemplating to Macsyma, Mathematic, et al.

Eventually, I want the optimizer for my language to be two optimizers.
The first one should be Knuth's "program rewritter" which rewrites my
program in my source language making substitutions such as the above.
This one should mostly be an algebraic rewriting system and should be
concerned only with the kind of transformations that your example
represent.  The second one would do only the optimizations that
can't/shouldn't be done at the source level such as strength reduction
and cse on adress arithmentic.  It would be part of the compiler.

[Knuth wanted the program rewritter to be interactive - asking if it
 was OK to apply various transformations.  Pacific Sierra Research has
 done a product along these lines for vectorizing Fortran called
Forge.]


Marty

+-+-+-+     I don't know who I am, why should you?     +-+-+-+
   |        fouts@lemming.nas.nasa.gov                    |
   |        ...!ames!orville!fouts                        |
   |        Never attribute to malice what can be         |
+-+-+-+     explained by incompetence.                 +-+-+-+