[comp.lang.fortran] Re Dumb behaviour in Sun Fortran v1.3.1

steveh@lion.inmos.co.uk (Steven Huggins) (02/21/91)

In article <1991Feb16.011005.4289@cs.olemiss.edu> randy@tacky.cs.olemiss.edu
(Randy Zagar) writes:

>Sun's F77 v1.3.1 evaluates expressions involving complex numbers inefficiently.
>The offending expressions are of the type
>
>    (complex expression) / (real expression)
>
>which are converted to
>
>    (complex expression) / (complex expression)
>
>and then evaluated by complex division.  The expression should be evaluated a
>
>  (complex expression) * (1.0 / real expression)
>
>which only involves a real division and a real multiply.

Well, although this may increase speed on the Sun, it may also decrease the
accuracy of the answer because two roundings are made rather than one ( for
both real and imaginary parts ).  The reasoning is as follows:


   a + ib      ac + bd         bc - ad
  -------- = ----------- + i -----------
   c + id    c**2 + d**2     c**2 + d**2

                     d                d
              a + b( - )       b - a( - )
                     c                c
           = ------------ + i ------------ , for c <> 0
                     d                d
              c + d( - )       c + d( - )
                     c                c


which, if d = 0, becomes, as expected,


              a     b
           =  - + i -
              c     c


It is this final expression that the compiler should be evaluating -
two divisions, each only rounded once.  Zagar's formula would generate at
least one division and two multiplications, and use double rounding.


     By the way, talking of complex numbers in FORTRAN, does anybody
know what sort of applications would use the following:

    complex / complex

and expecially

    complex ** complex


Steven R Huggins, Software Development Group, INMOS Ltd., 1000 Aztec West,
Almondsbury, Bristol, United Kingdom. BS12  4SQ           Tel: 0454 616616
JANET: steveh@uk.co.inmos    INTERNET: steveh@inmos.com
Other possibility: steveh@inmos.co.uk

john@ghostwheel.unm.edu (John Prentice) (02/22/91)

In article <14423@ganymede.inmos.co.uk> steveh@inmos.co.uk () writes:
>
>
>     By the way, talking of complex numbers in FORTRAN, does anybody
>know what sort of applications would use the following:
>
>    complex / complex
>
>and expecially
>
>    complex ** complex
>
>

complex/complex is hardly unusual!  Pick up a book on complex mathematics
and just glance through the pages.  A couple examples,
   1) expressing the analytical result of many series expansions
   2) most (?) complex valued integrals
   3) quantum scattering theory (just to give an example from physics)
etc...

As for complex**complex, it is again not particularly uncommon.  I
don't have an example handy right now, but look in a good integral table
(say Gradshteyn and Ryzhik) and see how many cases they show of this
type of integral.  They are there for a reason!

John


--
John K. Prentice    john@unmfys.unm.edu (Internet)
Dept. of Physics and Astronomy, University of New Mexico, Albuquerque, NM, USA
Computational Physics Group, Amparo Corporation, Albuquerque, NM, USA