[PYTHON MATRIX-SIG] Let's get going

Guido van Rossum guido@CNRI.Reston.VA.US
Tue, 12 Sep 1995 21:22:17 -0400


> Speaking of complex numbers: has it ever been considered to make
> them built-in objects in Python? This would simplify the matrix
> implementation, and also make the math functions behave more
> reasonably (i.e. sqrt(-1.) would return i instead of causing
> an exception). It can't be much work and would be very useful
> for numerical work.

Hm.  I think it *would* be much work, since the standard C math
library doesn't have any functions working on complex numbers.

I have a specific objection against making sqrt(-1) returning a
complex number.  In Python, as a rule, the *type* of a function's
return value may depend on the *type* of its argument(s), but not in
their *value*.  Even though there is nothing (or at least very little)
in the language's implementation that enforces this, it is a
consistent convention throughout the language. It even has one
important visible consequence: 1/3 is calculated as truncating, as in
C (though it truncates towards -infinity rather than towards 0),
rather than returning a floating point value if the result cannot be
represented as an integer.

I believe this is an important property -- it makes reasoning about
the types of variables/arguments/functions in a Python program easier
(and sooner or later, this reasoning is going to be done by programs
as well as by people).

--Guido van Rossum <guido@CNRI.Reston.VA.US>
URL: <http://www.python.org/~guido/>

(I have more to say about the matrix discussion but I need some more
time to digest everything that's been said.)

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

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