caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Complex Arithmetic
@ 2001-03-28  7:37 David McClain
  0 siblings, 0 replies; 5+ messages in thread
From: David McClain @ 2001-03-28  7:37 UTC (permalink / raw)
  To: caml-list

...however... the fact that so many scientists and engineers use the
"broken" code in Fortran and other languages demonstrates

1. Few if any scientists understand this arithmetic
2. Few if any do conformal mapping where its "broken-ness" would become
immediately apparent
3. Nearly all applications of complex arithmetic are of a nature in which
these broken elements do not contribute. E.g., impedance calculations,
phasor relations, FFT analyses, etc.

So what!? (I still like having a correct implementation...)

- DM

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Caml-list] Complex Arithmetic
@ 2001-03-28 16:14 David McClain
  0 siblings, 0 replies; 5+ messages in thread
From: David McClain @ 2001-03-28 16:14 UTC (permalink / raw)
  To: caml-list

Hi!

I want to thank all of you on this topic for helping point out the wider
meaning of Kahan's statement. After getting some sleep I now realize the
"Eureka!" that I missed in the wider sense, along with every other language
(that I know about) that uses rectangular mapping of the complex plane. I
need to stop working all night into the red-eye zone so that these things
become a bit more apparent on first glimpse...

Indeed a rectangular representation *IS* insufficient and something which
also encodes the Riemann sheet is needed to properly handle all
possibilities.

Will I fix NML in this regard? Probably not... simply because letter-perfect
complex arithmetic is so rarely needed in practice. But I might play around
with a limited class of compelx numbers that do things correctly. I wouldn't
want to hose down the performance of my FFT's and such.

- DM

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Complex Arithmetic
  2001-03-28  7:47 ` Bruce Hoult
@ 2001-03-28  8:16   ` David McClain
  0 siblings, 0 replies; 5+ messages in thread
From: David McClain @ 2001-03-28  8:16 UTC (permalink / raw)
  To: Bruce Hoult, caml-list

> But how do you deal with all the other complementary pairs?  I mean,
> how do you distinguish the results of, say (4 + 5i)^2 and (-4 - 5i)^2
> -- both of which are (-9 + 40i) -- so that when you do sqrt(-9 + 40i)
> you get the number you started with rather than always the principle
> one?

I think the easiest way to begin is to convert to polar form in your head.
Then you can see where the results belong. Take (4+5i) for example. This is
a ray in Quadrant I of the complex plane. Squaring it puts it into Quadrant
II, and the subsequent square root moves it back to Quadrant I.

On the other hand, (-4-5i) is a ray in Quadrant  III. Depending on how you
view it, in terms of Riemann sheets you can either see this as r *
Exp[theta] with theta > pi, or else r * Exp[theta] with -pi < theta < 0. By
convention we use the principal sheet with angles between -pi <= theta <=
pi. So in this interpretation, squaring this number would put you on the
next sheet down (in the negative theta direction, which lies beneath
Quadrant II. Taking the square root moves you right back into Quadrant III
on the principal sheet.

Translating this into rectangular form... this particular example is
problematic, because we have gone beyond the principal Riemann sheet. And so
rectangular representation cannot give the correct answer and Kahan's
principal is clearly illustrated -- i.e., that the language of pairs is
insufficient for complex arithmetic.

Borda's Mouthpiece represents a boundary case in which arithmetic stays
entirely in the prinicipal Riemann sheet. and so all arithmetic should
behave itself in rectangular form as long as proper attention is paid to the
nature of zero. Your example pushes beyond even this. And so only the polar
form can be used to get the correct answer.

- DM



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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Complex Arithmetic
  2001-03-28  7:21 David McClain
@ 2001-03-28  7:47 ` Bruce Hoult
  2001-03-28  8:16   ` David McClain
  0 siblings, 1 reply; 5+ messages in thread
From: Bruce Hoult @ 2001-03-28  7:47 UTC (permalink / raw)
  To: David McClain, caml-list

At 12:21 AM -0700 3/28/01, David McClain wrote:
>Borda's Mouthpiece requires taking the square root of the square of values
>along the negative imaginary axis. When you square (0 - 1i) you get (-1).
>...but actually you get (-1 + 0-). Most languages simply accept the square
>as (-1) = (-1 + 0+).
>
>Taking the subsequent square root when you have made this incorrect
>assumption gives the value sqrt(-1) -> (0+1i). And so the stream line mapped
>from the negative imaginary axis ends up cutting across all the other stream
>lines when this condition is encountered. An obvious error!
>
>The correct answer is obtained by noting that (0 - 1i)^2 -> (-1 + 0-) and
>sqrt(-1 + 0-) -> (0 -1i) again. Only by properly considering the nature of
>floating point zero (i.e., which of the two you really have) can you perform
>this computation correctly.

I guess I'm just dense, but I don't see how you generalize this.

I mean, OK, if you want to also say that (-1, 0)^2 -> (1, 0-) so that 
you can then do sqrt(1, 0-) -> (-1, 0) instead of (1, 0) then I guess 
I could live with this.

But how do you deal with all the other complementary pairs?  I mean, 
how do you distinguish the results of, say (4 + 5i)^2 and (-4 - 5i)^2 
-- both of which are (-9 + 40i) -- so that when you do sqrt(-9 + 40i) 
you get the number you started with rather than always the principle 
one?

I'm afraid I just don't see it.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Caml-list] Complex Arithmetic
@ 2001-03-28  7:21 David McClain
  2001-03-28  7:47 ` Bruce Hoult
  0 siblings, 1 reply; 5+ messages in thread
From: David McClain @ 2001-03-28  7:21 UTC (permalink / raw)
  To: caml-list

... now that my memory has been jogged...

I believe Kahan actually stated "The language of pairs is insufficient in
the complex domain." (Cryptic enough for you?)

His demonstration was called "Borda's Mouthpiece" and was a simple conformal
mapping problem from linear rays in the right half complex plain to the
streamlines associated with a fluid flow at hypersonic speeds in a tube.

Specifically, the problem in other languges is the following:

Borda's Mouthpiece requires taking the square root of the square of values
along the negative imaginary axis. When you square (0 - 1i) you get (-1).
...but actually you get (-1 + 0-). Most languages simply accept the square
as (-1) = (-1 + 0+).

Taking the subsequent square root when you have made this incorrect
assumption gives the value sqrt(-1) -> (0+1i). And so the stream line mapped
from the negative imaginary axis ends up cutting across all the other stream
lines when this condition is encountered. An obvious error!

The correct answer is obtained by noting that (0 - 1i)^2 -> (-1 + 0-) and
sqrt(-1 + 0-) -> (0 -1i) again. Only by properly considering the nature of
floating point zero (i.e., which of the two you really have) can you perform
this computation correctly.

Whew! That was a bloody difficult two weeks to go from the cryptography of
Kahan to a correctly working implementation... And BTW, you DON'T want to
use polar representation -- that eats away seriously at your arithmetic
precision, dropping from 15 digits to something like 6-8 digits in double
precision math. You have to stay in the rectangular representation to
preserve arithmetic precision -- and that requires a full understanding of
the nature of 0+ and 0-.

- DM


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-03-28 16:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-28  7:37 [Caml-list] Complex Arithmetic David McClain
  -- strict thread matches above, loose matches on Subject: below --
2001-03-28 16:14 David McClain
2001-03-28  7:21 David McClain
2001-03-28  7:47 ` Bruce Hoult
2001-03-28  8:16   ` David McClain

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).