[PYTHON MATRIX-SIG] Let's get going
Hinsen Konrad
hinsenk@ere.umontreal.ca
Wed, 13 Sep 1995 09:45:03 -0400
Hm. I think it *would* be much work, since the standard C math
library doesn't have any functions working on complex numbers.
True, but complex libraries are easily available (e.g. GNU-C comes
with one).
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)
There is no need to make real and complex numbers different types. A
real number would just be a complex number with an imaginary part of
zero. Of course internally there should be a difference for efficiency
reasons, but the user need not see it. Contrary to integers, reals
numbers need not have a special type since any operation on complex
numbers with zero imaginary part is exactly equivalent to an operation
on real numbers (for integers there is a difference in division).
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.
And I am sure this feature has already led to some surprises for
people who thought they could use Python like a pocket calculator.
For languages like Python, where numerical efficiency does not have
top priority, I'd consider it more useful to have a number model that
reflects mathematical categories instead of internal storage format
categories. There should be only one type "number" with
representations for integers, fractions, floating point numbers, and
complex numbers, the latter having real and imaginary parts that can
be of any of the basic representations. Then 1/3 would return a
fraction. This is what anyone without programming experience would
expect.
Of course I realize that it is much too late to introduce such a
change...
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).
I certainly agree on that.
-------------------------------------------------------------------------------
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. A | 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
=================