[Tutor] Comparing complex numbers for order doesn't work

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Tue Jun 3 14:55:03 2003


On Tue, 3 Jun 2003, Bob Gailer wrote:

> OOPS I did not do my homework. So it turns out that Python % and divmod
> DO modulo, and the documentation is in error when it says "remainder".
> It sort of redeems itself later "The integer division and modulo
> operators are connected by the following identity: x == (x/y)*y +
> (x%y)."


Hi Bob,


Python does get some mathematics right, a lot more than I expected.  One
obscure thing that I find cool (if obscure) is the fact that Python
doesn't allow for comparisons between complex numbers:

###
>>> x = 1 + 0j
>>> y = -1 + 0j
>>> x < y
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: cannot compare complex numbers using <, <=, >, >=
###


And, although this seems a little weird, this is exactly the right thing
to do, because the complex numbers are not an "ordered field".  The term
"Ordered field" is math lingo for the idea that our set of things don't
support support the '<' operator.  In an ordered field, if we have a
number 'x', then:

    x**2 > 0

is a given.  (positive * positive is positive, negative * negative is
positive).  But that's exactly the axiom that complex numbers violate.


Talk to you later!