Hi,

attached is a draft of an interp for J3. I hope I have summarized
both standpoints correctly.

If this is OK, I would then send it to J3. Toon, do you know how to
send an interp request?

Best regards

        Thomas
To: J3
From: Thomas Koenig
Subject Interp on reassociation

QUESTION:

Consider the following procedure:

REAL FUNCTION add4_v1 (a, b, c, d)
  REAL, INTENT(IN) :: a, b, c, d
  REAL :: t1, t2
  t1 = a + b
  t2 = t1 + c
  add4_v1 = t2 + d
END FUNCTION add4_v1

Is a processor allowed to reassociate this as if the user had written

REAL FUNCTION add4_v2 (a, b, c, d)
  REAL, INTENT(IN) :: a, b, c, d
  add4_v2 = (a + b) + (c + d)
END FUNCTION add4_v2

10.1.5.2.4 Evaluation of numeric intrinsic operations has

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.

Since there are no parentheses in add4_v1, this would lead to
the conclusion that this transformation is valid.

On the other hand, 5.3.5 Execution sequence states

With the following exceptions, the effect of execution is as if the
executable constructs are executed in the order in which they appear
in the main program or subprogram [... exceptions not relevant]

Reading this, one might conclude that the t = a + b statement must
appear to the user to be executed first, so that the processor is
forced into evaluating the expression as if it had been written as
(((a +b) + c) + d.  It would also require

   t1 = (a + b)
   t2 = (t1 + c)

in add_v1.

Which interpretation is correct?

Reply via email to