caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David McClain" <dmcclain1@mindspring.com>
To: <wester@ilt.fhg.de>, <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: Complex Arithmetic
Date: Wed, 28 Mar 2001 02:20:53 -0700	[thread overview]
Message-ID: <000901c0b768$64b9bdb0$210148bf@dylan> (raw)
In-Reply-To: <200103280844.KAA29428@ilt.fhg.de>

> as far as I understood Kahan says that the complex arithmetic in
> FORTRAN and many C++ libraries is wrong. I tested:
>
> sqrt( (0.0 , -1.0)**2 )  vs. sqrt( (0.0 , 1.0)**2 )
>
> on a DEC Alpha with FORTRAN and C++ (source and output below).
> They both give the correct result. A naive approach abviously gives
> the same result (0.0, 1.0) for both expressions. Can you tell us how you
> implemented the correct behaviour in OCaml (or Nml)?

Well, well... it appears that DEC Alpha has taken Kahan to heart! I have
never used an Alpha, and perhaps I should. I understood that their
implementation of FP traps is a bit strange, using trap gates interspersed
with the code so you don't actually get the trap at the location of the
error unless you pepper your code to death with trap gates... But I have
heard many great things about the speed of these boxes!

> BTW what about sqrt( (-1.0 , -1.0)**2 ) and sqrt( (-1.0 , 1.0)**2 ), which
> result in (1.0, 1.0) and (1.0, -1.0) on the DEC Alpha. What should the
> results be in this case?

These cases again illustrate Kahan's principal about the limitations of the
language of [rectangular] pairs... (-1,-1) when squared exceeds the
principal Riemann sheet and so all attempts at representing complex
arithmetic with rectilinear coordinates of the principal sheet are doomed to
failure. Same for (-1,1).

So in these cases, even NML will fail like all the others. Only polar
representation which can display arbitrary levels of the Riemann surface
could possibly succeed in such cases.

My NML implementation [correct for the principal sheet arithmetic only] is
available to anyone, and I simply (ha!) made sure that all the algebraic
relations between 0+ and 0- were properly observed. For example, IIRC,

    x + 0+ != x  (this fails in the case where x = 0-. It succeeds
everywhere else).
    x + 0- == x

    x * 0- = 0- unless x = 0- in which case 0- * 0- = 0+ (sheesh!!)

(of course I may be mistaken here in my mental recall. I have to reexamine
my code to be certain)

When implementing NML, I actually wrote a simple-minded algebraic theorem
prover in OCaml to assist me in this process. That's another terrific thing
about OCaml - you can perform symbolic calculations very easily, perhaps
even more easily than in Lisp (although I also love Lisp). The whole prover
took less than a hundred lines of OCaml or so... and it ran correctly the
first time out!

- DM


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


      reply	other threads:[~2001-03-28  9:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-28  8:44 wester
2001-03-28  9:20 ` David McClain [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000901c0b768$64b9bdb0$210148bf@dylan' \
    --to=dmcclain1@mindspring.com \
    --cc=caml-list@inria.fr \
    --cc=wester@ilt.fhg.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).