[PYTHON MATRIX-SIG] printing complexes

Hinsen Konrad hinsenk@ere.umontreal.ca
Fri, 3 Nov 1995 16:12:53 -0500


   The reason I was worried about the precision being the same on the two sides
   (and controllable) is simply the issue of making nice output where you
   want things to line up for comparison. It is jarring if you have a list
   and successive elements are all different in appearance, and it makes
   it harder to make a nice table.

For matrices (and possibly sequence types in general) this is indeed
an issue. But what should be equal is not the precision of the real
and imaginary part of each number, but the real parts of all numbers
and the imaginary parts of all numbers.

My suggestion for formatting float and complex numbers in matrices
is the following:

Define an "order" of output formats as
1) integer
2) non-exponential floating point
3) exponential notation
Next, determine the appropriate format for each entry of the matrix,
using the same criterion as for %g-format in C to distinguish between
2 and 3. Then find the highest "order" used in the matrix (and the
widest output field if the order is 1 (integer)) and apply it to all
elements. For complex numbers, do this procedure independently for the
real and imaginary parts.

The result is a format in which all columns are lined up properly
and have equal widths, but which also is the most compact possible.

   FYI, in Basis I don't have complex constants, just IMAGINARY ones. 

That's an alternative I have considered, and if there is a general
preference for it, I am perfectly happy with it. But it should be used
equally for input and output. Still I prefer the APL2/J notation
because it can never give the impression of an arithmetic impression.
Consider printing an expression with complex constants and multiplications
in it. I am sure some people would read 2+3i * 1-7i as equivalent to
2-4i, so you'd have to print all complex numbers in parentheses (which
of course would also be obligatory for input).

-------------------------------------------------------------------------------
Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)
-------------------------------------------------------------------------------

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================