(j3.2006) mathematical equivalence and MATMUL

Robert Corbett robert.corbett
Tue Oct 25 05:40:51 EDT 2016


I do not see how your conclusion can be derived from the statements
you quote.  The expression

       2.0 * MATMUL(A, B)

is a numeric operation.  The text you quote says that the once the
interpretation has been established, the processor may evaluate any
mathematically equivalent expression.  The paragraph following the
sentence you quoted states

       Two expressions of a numeric type are mathematically
       equivalent if, for all possible values of their primaries
       their mathematical values are equal.

For any given A and B, the expression

       MATMUL(2.0*A, B)

produces the same mathematical result as the original
expression.  Therefore, a standard conforming processor is
allow to evaluate the latter expression in place of the former.

The only text that casts any doubt whether the substitution is
permitted is in the Subclause titled "Integrity of parentheses".
It states "any expression in parentheses is treated as a data
entity".  An argument list is "in parentheses", but I do not
think that is what the text means.

You are correct that the standard does not appear to give
license to apply the mathematical equivalence rule to an
expression other than a numeric intrinsic operation.
However, the expression in question is a numeric intrinsic
operation, so the mathematical equivalence rule applies.
The second expression does not have the form of a numeric
intrinsic operation, and so it appears the standard would
not permit a standard-conforming processor to substitute the
first expression for the second.

Robert Corbett

On 10/25/2016 1:06 AM, Van Snyder wrote:
> I have pointed out several times that the license to substitute a
> mathematically equivalent expression applies only to intrinsic
> operations, which are in turn denoted by intrinsic operators.
>
> For example, 10.1.5.2.4 states "Once the interpretation of a numeric
> intrinsic operation is established, the processor may evaluate any
> mathematically equivalent expression, provided that the integrity of
> parentheses is not violated."
>
> 10.1.5.1 states "A numeric intrinsic operation 1 is an intrinsic
> operation for which the intrinsic-operator is a numeric operator (+, -,
> *, /, or **).
>
> Similar pairs of statements apply to other intrinsic operations.
>
> I have found no license to apply the "mathematical equivalence" rule to
> intrinsic functions.
>
> On Mon, 2016-10-24 at 20:33 -0700, Robert Corbett wrote:
>> A user recently complained about an "optimization"
>> performed by Oracle Developer Studio Fortran.  The
>> user's expression
>>
>>         2.0 * MATMUL(A, B)
>>
>> was "optimized" into the mathematically equivalent
>> expression
>>
>>         MATMUL(2.0*A, B)
>>
>> Moving the multiplication into the first argument
>> resulted in an overflow that would not have occurred
>> for the original expression.
>>
>> Is the optimization shown allowed by the Fortran standard?
>>
>> If the integrity of parentheses rule applies to the
>> parentheses around an actual argument list, the
>> optimization shown would be prohibited.  Many
>> desirable optimizations would also be prohibited.
>>
>> If the original expression had been written as
>>
>>         2.0 * (MATMUL(A, B))
>>
>> would the optimization be allowed by the Fortran
>> standard?  I think not, but Oracle Developer Studio
>> Fortran still does the optimization in this case.
>>
>>




More information about the J3 mailing list