Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: Confused about optimizing 1-COS(X)*COS(X) Message-ID: <4090@lanl.gov> Date: 23 Sep 88 20:33:21 GMT References: <1041@amelia.nas.nasa.gov> Organization: Los Alamos National Laboratory Lines: 17 From article <1041@amelia.nas.nasa.gov>, by fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts): > Hmm. Sounds like this is not in the same spirit as the fortran > requirement that (A-B)-C be treated differently than A-(B-C) because > they would produce different numerical results. [...] Subtract isn't associative! (A-B)-C is _mathematically_ different from A-(B-C). In any case, Fortran is not allowed to optimize across parenthesis. Fortran _is_ allowed to optimize expressions to any _mathematically_ identical result (so long as it doesn't optimize across parenthesis). So, 1-COS(x)*COS(x) may be optimized to SIN(x)**2. But, 1-(COS(x)*COS(x)) may only be optimized to 1-(COS(x)**2). Meanwhile, A-B-C _must_ be implemented as (A-B)-C. Read chapter 6 of the standard: it's all in there! J. Giles Los Alamos