home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.parallel
- Path: sparky!uunet!destroyer!gatech!hubcap!fpst
- From: maniattb@cs.rpi.edu (Bill Maniatty)
- Subject: Re: Wanted: Folk Theormes in Fortran Programming
- Message-ID: <1993Jan28.142743.24324@hubcap.clemson.edu>
- Apparently-To: comp-parallel@cis.ohio-state.edu
- Sender: fpst@hubcap.clemson.edu (Steve Stevenson)
- Nntp-Posting-Host: sage.cs.rpi.edu
- Organization: Clemson University
- References: <1993Jan27.123645.8334@hubcap.clemson.edu>
- Date: Thu, 28 Jan 1993 03:12:31 GMT
- Approved: parallel@hubcap.clemson.edu
- Lines: 28
-
- Horner's method for polynomial evaluation is usually a good idea.
-
- (I'm not a Fortran Expert, so I'll use psuedocode)
- f = a[0] + a[1] * x + a[2] * x**2 + a[3] * x**3 + ... + a[n] * x ** n
-
- The brute force method takes 0 + 1 + 2 + ... + n multiplies, to compute the
- various powers of x, that is O(n**2) multiplications.
-
- We now consider a smarter way, which uses intermediate results:
-
- f = a[0] + x * (a[1] + x *( a[2] + x * ( ... )))
-
- We see that we have O(n) multiplications, with no extra additions.
- I suspect that this has the added bonus of being better numerically in that
- fewer multiplications will tend to reduce roundoff error.
-
- You can also do some smart things like eliminating induction variables,
- constant subexpression elimination, common subexpression elimination,
- dead code elimination, etc. This can be found in the Red Dragon book
- by Aho, Sethi, and Ullman. The basic ideas are simple, but the implementation
- details can be a bit tricky.
-
- Bill
- --
- |
- | maniattb@cs.rpi.edu - in real life Bill Maniatty
- |
-
-