Subject: Re: Floating complex numbers
From: Bruno Haible <[email-masked]>
To: [email-masked], [email-masked]
Cc: [email-masked]
Date: Thu, 16 Jan 2014 03:16:27 +0100 (CET)

Replying to
<http://www.ginac.de/pipermail/ginac-devel/2014-January/002078.html>:

I can't speak for GiNaC. But for CLN the attached patch would go against
documented behaviour and principles of CLN.

Documented behaviour in http://www.ginac.de/CLN/cln_3.html#SEC14 is:
"A complex number whose imaginary part is the *exact* number 0 is automatically
converted to a real number."
The eq(b,0) test implements this comparison.

The principle behind is the distinction between exact numbers and
floating-point numbers. See http://www.ginac.de/CLN/cln_3.html#SEC12

What is the difference between the complex numbers, say, x = 3.0 + 0 * i
and f = 3.0 + 0.0 * i ?
- For x the information that Im(x) is *exactly* zero is implied.
- For f all we know that the absolute value of Im(f) is so small that it
  is negligible when compared to floating-point numbers of the same type.

The difference is important in number theory, for example. A rational
number and a real number (possibly a transcendental one) are very different
beasts in number theory.

Even in quantum physics the difference is important. When a result of a
simulation of 1000 atoms returns that the average charge of the atoms is
0.0, you know that the total charge is small. When it returns 0, you know
that the total charge is 0.

Similarly, when a computation returns that a spin is 0, it is zero.
If the computation's result for the spin is 0.0, you know that you need to
repeat the computation with interval arithmetic in order to know the possible
error.

If you are in a situation where all numbers are real numbers, and rational
numbers don't play a particular role, then you can use complex numbers with
real and imaginary parts of floating-point type (CL_F) everywhere. You may
then simplify 3.0 + 0.0 * i to 3.0. But CLN has a broader scope than this
restricted domain of computation, therefore such a simplification doesn't
belong in CLN.

Bruno