From: jbrock@csfb1.fir.fbc.com (John Brock)
Subject: Re: REXX math functions
Reply-To: uunet!csfb1!jbrock
Organization: First Boston Corporation
Date: Thu, 8 Oct 1992 06:35:28 GMT

A number of people have asked to see my RXMATH math package
for REXX.  I've gotten permission to post it and will do so
today.  The whole thing is about 1000 lines (two execs and
one help file) and about 32K in size.  This isn't big enough
to break my News software, but I really don't know much
about these things, so if you see this note but not the
main post let me know, and I'll try to mail it to you
directly.

In addition, Ian Collier has raised some questions, which
I will address here.

My original post had three purposes:  to request information
about the current state of REXX math functions, to argue
that arbitrary precision math functions should be built in
to the interpreter and that they should take a certain form,
and to let people know about my math package, which frankly
I am very proud of and would like to see other people using.

I think it is kind of silly to argue whether REXX ought to
have a built in math package.  If it is not too difficult,
of course it should!  One of the reasons FORTRAN is so
popular among scientists is the built in math functions.
Not everyone will use them, but then not everyone will ever
need to calculate 22 / 7 to 1000 places, and yet REXX lets
you do it if you need to.  A math package for REXX that is not
arbitrary precision is simply out of keeping with the spirit
of REXX!  As for efficiency, there is no reason someone
who is writing an interpreter should not use the hardware
datatypes when appropriate, as long as he switches over
transparently to the arbitrary precision code when greater
precision is requested.  I didn't do this because I
wanted a pure REXX solution, and because I wanted to keep
the complexity of the program manageable.

As for the format, this is just a personal preference.
I think it makes sense to bundle all the math functions
into a single call simply because there are many people
who will never use them, and this will keep the functions
out of their way.  At the very least, if math functions are
implemented individually, they should not be scattered
alphabetically throughout the manual along with the other
REXX functions!  For the record, my ideal built in REXX
math function calls would look something like this:

   x = math('POW', 5, 3.8)  /* = 5 ** 3.8 */
   y = math('LN', 3.5)      /* = natural log of 3.5 */
   z = math('PI')           /* = 6 * arcsin(0.5)  :-) */

RXMATH is optimized for accuracy, not for speed, and I am
sure there are things that could be done to speed it up.
However I do have a fairly strong math background (Columbia
physics ABD), and I paid close attention to the convergence 
of the various series expansions I used.  For example, if
RXMATH is asked for sqrt(1200000), what it actually calculates
is sqrt(1.2) * 1000, and similar adjustments are made for
other functions.  I hard code values for pi and e, and
only recalculate them when the hard coded precision is
inadequate.  And I found a better series expansion for
pi than the one listed in all the handbooks (which may
be interesting mathematically but is totally pathetic
convergence-wise).  As a result the efficiency of RXMATH,
if not quite comparable to FORTRAN in a tight loop, is
still quite good, especially if the program is compiled.
(And EXECLOADING won't hurt if you're on VM).

It's been years since I benchmarked RXMATH, and I am not
going to redo it now.  I will mention again what I noted
in my first post, that when I used RXMATH to calculate pi
to 1000 places it took 20 seconds elapsed and 16 seconds
VIRTCPU.  This is the compiled version running on what
I believe to be the latest and greatest IBM big iron, so
this is probably as fast as it's going to go!  

One the whole I think I have a very clean, convenient,
and exceptionally accurate REXX math package, which adheres
very closely to the "REXX spirit".  I sincerely hope people
will find it useful.

-- 
John Brock (212) 909-4662
The First Boston Corporation
12 East 49th Street
New York, NY 10017
uunet!csfb1!jbrock
jbrock@csfb1.fir.fbc.com
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU