# [J3] function references and optimization

Van Snyder Van.Snyder at jpl.nasa.gov
Tue Oct 9 20:36:37 EDT 2018

```On Wed, 2018-10-10 at 09:26 +0900, Malcolm Cohen via J3 wrote:
> Robert Corbett writes:
>
> <<<
>
> Suppose
> a program contains the statement
> function
>
> f(x) = y
>
> and the assignment statement
>
> x = y - f(1.0)
>
> Does the mathematical equivalence
> rule allow the expression to be
> replaced with 0.0?
>
> >>>
>
>
>
> Yes.
>
>
>
> No matter what kind of function F is, if the processor “knows” that
> the value of the function is y, it need not evaluate the function
> reference at all.
>
>
>
> This reduces the statement to the well-known
>
>
>
> x = y – y
>
>
>
> and by the mathematical equivalence rule, y-y is zero so no need to
> evaluate Y either, giving us x = zero.
>
>
>
> It is absolutely standard-conforming to do mathematically equivalent
> transformations.

Does the permission in 10.1.5.2.4p2, under the rubric "Evaluation of
numeric intrinsic operations" include statement functions?  Are
statement functions numeric intrinsic operations?  If we intend the
permission to extend beyond "visible" numeric intrinsic operations, we
ought at least to have a note that says something like "if statement
function references are materialized in line, mathematically equivalent
transormations may be applied to numeric intrinsic operations."

> Bob continues:
>
> > A better example would be the
> >statement function
> >
> >f(x) = x - 1.0
> >
> >and the assignment statement
> >
> >y = f(z) + 1.0
>
>
>
> I don’t really see why the expression “x – 1 + 1” is particularly
> interesting.  Without parentheses (which it is – function reference
> syntax is not expression parentheses) it looks highly likely to be
> turned into “x”.  Even if you put parentheses around the subtraction,
> mathematical equivalence allows computation of the whole thing in a
> higher precision which will likely remove or at least change the
> rounding error from the subtraction.  If you want to force rounding to
> a specific precision, there are many ways which work, and some which
> are even guaranteed by the standard to work!
>
>
>
> Cheers,
>
> --
>
> ..............Malcolm Cohen, NAG Oxford/Tokyo.
>
>

```