[comp.lang.misc] Lisp vs APL for numeric work

barmar@think.com (Barry Margolin) (12/13/90)

In article <13615@chaph.usc.edu> jeenglis@alcor.usc.edu (Joe English Muffin) writes:
>  The numerical facilities in Common
>Lisp are second only to those in APL among the most
>common languages (well, those that I know of
>anyway), including Fortran.

I'd hazard to say that they're even better than APL.  Does APL have
arbitrary precision rational numbers, complex numbers (I think they're an
experimental feature in some APLs), and multiple floating point formats?

I think the actual set of numerical functions that CL and APL provide are
about the same.  And many of the definitions of CL numerical functions are
based on the corresponding APL functions.
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

mrys@bernina.ethz.ch (Michael Rys) (12/20/90)

In article <1990Dec12.175323.8958@Think.COM> barmar@think.com (Barry Margolin) writes:
>In article <13615@chaph.usc.edu> jeenglis@alcor.usc.edu (Joe English Muffin) writes:
>>  The numerical facilities in Common
>>Lisp are second only to those in APL among the most
>>common languages (well, those that I know of
>>anyway), including Fortran.
>
>I'd hazard to say that they're even better than APL.  Does APL have
>arbitrary precision rational numbers, complex numbers (I think they're an
>experimental feature in some APLs), and multiple floating point formats?


APR numbers - no, you would have to write your own functions.
complex numbers - yes, it should be in the upcoming extended APL
standard. All modern APL dialects (APL II, SAX, J etc) have them.
What do you mean with multiple floating point formats? IEEE and such?

I have never seen that in an APL dialect, but I have never come across
the situation where I could use different formats.

>
>Barry Margolin, Thinking Machines Corp.
>
>barmar@think.com
>{uunet,harvard}!think!barmar

Cheers.../Michael
+---------------------------------------------------------------+
| Michael Rys, V. Conzett Str. 34; CH-8004 Zuerich; Switzerland |
+---------------------------------------------------------------+
| UUCP:  mrys@ethz.UUCP or       EAN:     mrys@ifi.ethz.ch	|
|        mrys@bernina.UUCP       IPSANet: mrys@ipsaint		|
| Voice: +41 1 242 35 87	 DECNet:  ETHZ::mrys		|
+---------------------------------------------------------------+
-- Wovon man nicht sprechen kann, darueber muss man schweigen. --
       Ludwig Wittgenstein, Tractatus logico-philosophicus

barmar@think.com (Barry Margolin) (12/20/90)

In article <1990Dec19.201059.16458@bernina.ethz.ch> mrys@bernina.UUCP (Michael Rys) writes:
>What do you mean with multiple floating point formats? IEEE and such?
>I have never seen that in an APL dialect, but I have never come across
>the situation where I could use different formats.

No, I mean multiple precisions/ranges.  Common Lisp provides a portable
interface to up to four floating point formats, referred to as short-float,
single-float, double-float, and long-float.  C supports float and double.
It's been a long time since I've used APL, but I don't recall it having a
way to specify single- vs. double-precision.
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

mjs@hpfcso.HP.COM (Marc Sabatella) (12/21/90)

>C supports float and double.

... and "long double" in ANSI C.

abeals@autodesk.com (Only 5 more shopping days until Christmas) (12/21/90)

barmar@think.com (Barry Margolin) writes:
>It's been a long time since I've used APL, but I don't recall it having a
>way to specify single- vs. double-precision.

Just change quad-CT or )FUZZ for you APL\360 fans.  I still have my
primer.


--
Andrew Scott Beals
abeals@autodesk.com

dgil@pa.reuter.COM (Dave Gillett) (12/21/90)

In <1990Dec20.050320.23027@Think.COM> barmar@think.com (Barry Margolin) writes:

>In article <1990Dec19.201059.16458@bernina.ethz.ch> mrys@bernina.UUCP (Michael Rys) writes:
>>What do you mean with multiple floating point formats? IEEE and such?

>It's been a long time since I've used APL, but I don't recall it having a
>way to specify single- vs. double-precision.

     That's because it's a high-level language!  In APL, "numeric" means "in
the minimum available precision sufficient to represent the value in question.

     There are occasional exceptions.  If you subtract the fractional part of 
A from A, the result may not collapse to integer internal representation
because either (a) the floating-point subtraction might not leave an exact 
integer result (hardware dependent) and/or (b) the interpreter, unless it is
doing some unusual optimiization, cannot know when it starts the subtraction
that the results will, in fact, be representable as integers.  The built-in
floor and ceiling primitives, though, know that their results will be integer,
and so can collapse the representation unless an element has a magnitude
outside the machine's integer range.
     This is the next best thing to arbitrary precision, but provides
considerably better performance over the most common data ranges.  (Yes, I
do understand that arbitrary precision allows exact representations over 
humonguous ranges; implementing it in APL is probably easier than in any
other language which doesn't have it built in, and the question comes down
to whether you need it or not.  If it were added to APL, it would transparently
replace double-precision, probably if the print-precision setting werre beyond
a certain threshold.)

     One way to look at it is that APL hides numeric representation from all but
the nosiest programmers.  Resort to an extended or arbitrary precision
representation is left as an implementation issue rather than a language
issue, and the fact that implementors have not provided this is no reflection
on the design of the language.
                                                   Dave

barmar@think.com (Barry Margolin) (12/22/90)

In article <634@saxony.pa.reuter.COM> dgil@pa.reuter.COM (Dave Gillett) writes:
>In <1990Dec20.050320.23027@Think.COM> barmar@think.com (Barry Margolin) writes:
>
>>It's been a long time since I've used APL, but I don't recall it having a
>>way to specify single- vs. double-precision.
>     That's because it's a high-level language!  In APL, "numeric" means "in
>the minimum available precision sufficient to represent the value in question.
...
>     One way to look at it is that APL hides numeric representation from all but
>the nosiest programmers.  Resort to an extended or arbitrary precision
>representation is left as an implementation issue rather than a language
>issue, and the fact that implementors have not provided this is no reflection
>on the design of the language.

Unfortunately, for numerical applications it is often important to be able
to have more precise control over floating point representation, because
you need control over the precision vs performance properties.  Someone
mentioned quadCT and )FUZZ, but I think these are global parameters,
whereas the control is generally wanted on a per-variable basis; in fact,
I'm not even sure that these are supposed to affect representation, but
only the behavior of comparison builtins, because I can change these
parameters after creating objects.  Some variables contain values where the
required precision is known to be low, and it is preferable that operations
on these values be fast, while other variables contain values whose
precision is more important than the speed.

I'm not a numerical analyst, so don't ask me for specific examples.  But
Fortran has had REAL*<n> for decades for a reason, and it's not only to
allow space saving (although I'm sure that's part of it).

--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

tneff@bfmny0.BFM.COM (Tom Neff) (12/28/90)

In article <634@saxony.pa.reuter.COM> dgil@pa.reuter.COM (Dave Gillett) writes:
>In <1990Dec20.050320.23027@Think.COM> barmar@think.com (Barry Margolin) writes:
>>It's been a long time since I've used APL, but I don't recall it having a
>>way to specify single- vs. double-precision.
>
>     That's because it's a high-level language!  In APL, "numeric" means "in
>the minimum available precision sufficient to represent the value in question.

Terrific, Dave!

Tell me, what's the minimum precision necessary to represent (1/3) in
binary floating point?

-- 
France is a country where the money falls apart and   }{  Tom Neff
  you can't tear the toilet paper. -- Billy Wilder    }{  tneff@bfmny0.BFM.COM