Re: Haskell 98 - Standard Prelude - Floating Class

On Mon, Oct 15, 2001 at 03:52:06PM +0200, Kent Karlsson wrote:
Simon Peyton-Jones:
Russell O'Connor suggests: | but sinh and cosh can easily be defined in terms of exp | sinh x = (exp(x) - exp(-x))/2 | cosh x = (exp(x) + exp(-x))/2 ... This looks pretty reasonable to me. We should have default methods for anything we can. Mathematically, yes. Numerically, no. Even if 'exp' is implemented with high accuracy, the suggested defaults may return a very inaccurate (in ulps) result. Take sinh near zero. sinh(x) with x very close to 0 should return x. With the above 'default' sinh(x) will return exactly 0 for a relatively wide interval around 0, which is the wrong result except for 0 itself.
Hmm, on these grounds the current default definition for tanh x is even worse behaved: tanh x = sinh x / cosh x For moderately large floating point x, this will overflow. Frankly, I don't think the whole discussion matters very much; nobody who cares will use the default definitions. But remember to think about branch cuts. And why not go further? cos x = (exp (i*x) + exp (-i*x))/2 where i = sqrt (-1) etc.
In general, this is why LIA-2 (Language Independent Arithmetic, part 2, "Elementary numerical functions", ISO/IEC 10967-2:2001) rarely attempts to define one numerical operation in terms of other numerical operations. That is done only when the relationship is exact (even if the operations themselves are inexact). That is not the case for the abovementioned operations. But it is the case for the relationship between the complex sin operation and the complex sinh operation, for instance. (Complex will be covered by LIA-3.)
This sounds like a very interesting standard. I am constantly annoyed by ISO's attempts to hide their standards; one might wonder what the purpose is of having unavailable "standards". Is the content available somewhere? Best, Dylan Thurston

In general, this is why LIA-2 (Language Independent Arithmetic, part 2, "Elementary numerical functions", ISO/IEC 10967-2:2001) [. . .] This sounds like a very interesting standard. I am constantly annoyed by ISO's attempts to hide their standards; one might wonder what the purpose is of having unavailable "standards". Is the content available somewhere?
You have to pay for it. I too find this exceedingly annoying, but it stems from the notion that any body that provides something useful should make money from it. The standards bodies (ISO, BS in particular) are expected to recoup costs by selling the documents. That this makes the standards less effective doesn't seem to matter. I don't know what could be done to persuade them to behave differently. Jón -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk 31 Chalmers Road jf@cl.cam.ac.uk Cambridge CB1 3SZ +44 1223 570179 (after 14:00 only, please!)

----- Original Message -----
From: "Dylan Thurston"
cos x = (exp (i*x) + exp (-i*x))/2 where i = sqrt (-1)
Disregarding that Haskell does not (yet) have Imaginary types (as distinct from Complex): Any reasonable specification and implementation would go the other way around: exp(i*x) (exponentiation on Imaginary t, returning a Complex t) would be defined (exactly) in terms of the cos and sin operations (on reals, i.e. on the type t here). If you by the above meant giving a 'default' for cos in general, then as a special case defining real cos (and sin) in terms of complex exp gives rather low accuracy. Too low to be used as default definitions in my opinion. Default definitions may be inefficient, but in my opinion, default definitions for approximate operations should not give drastically lower accuracy, and should certainly not violate any other reasonable expectations (like that sin x returns x for x close to 0).
In general, this is why LIA-2 (Language Independent Arithmetic, part 2, "Elementary numerical functions", ISO/IEC 10967-2:2001) rarely ... This sounds like a very interesting standard. I am constantly annoyed by ISO's attempts to hide their standards; one might wonder what the
Even the few ones that are publically available are hard to find. But see: http://isotc.iso.ch/livelink/livelink/fetch/2000/2489/Ittf_Home/PubliclyAvai... (log in as guest). However LIA-2 is not found there, since one has not gone through the motions of getting it published that way.
purpose is of having unavailable "standards". Is the content available somewhere?
In this particular instance I can offer, without violating ISO copyright rules, a select few to get draft versions of LIA-2 (post-publication, it's an editors draft for a possible future second edition; 184 pages) and LIA-3 (post registration ballot; 158 pages, changes to normative text between published and post-publication draft of LIA-2(!) listed here). Editors drafts are not copyrighted by ISO. Format:DVI. Those who have a special interest in these matters, e-mail me. Comments are welcome. LIA-1 and IEC 60559 (a.k.a. IEEE floating point, IEEE 759) are frequently referenced, and sometimes also of interest here are the Ada95 and C99 standards. /kent k

Kent Karlsson wrote:
Default definitions may be inefficient, but in my opinion, default definitions for approximate operations should not give drastically lower accuracy, and should certainly not violate any other reasonable expectations (like that sin x returns x for x close to 0).
I agree. The idea of giving defaults was that class mathods are not always independent, so no harm is done by defining some in terms of others, but there is no obligation to supply them. This thinking did not take into account problems of numerical accuracy with types with fixed-size floating-point representations. If a default definition can have seriously bad numerical behaviour then it should never be used, and I see no point in supplying it. To do so would just encourage users to accept the definition and get bad results. --brian
participants (4)
-
Brian Boutel
-
Dylan Thurston
-
Jon Fairbairn
-
Kent Karlsson