[Tutor] Floor and modulus for complex arguments

Tim Peters tim.peters at gmail.com
Fri Jul 3 16:18:23 CEST 2009

[Angus Rodgers]
> I'm a little confused by: (i) the definition of the modulus and
> floor division functions for complex arguments;

Perhaps you're confused by the current definitions simply because they
don't make good sense.

> (ii) the fact that these functions for complex arguments are
> now "deprecated";

And they're deprecated /because/ they never made good sense.

> and (iii) the fact that the math.floor() function is not defined
> at all for a complex argument.

The math module consists mostly of Python wrappers around the C
functions defined by the C standard in C's math.h.  C doesn't define
floor() for complex numbers, so neither does Python's math.floor().

> If I were thinking about this from scratch (in the context of
> mathematics, rather than any particular programming language),
> I /think/ I would be naturally inclined to define:
>  floor(x + yj) = floor(x) + floor(y)j     for all real x, y
>  z % w = z - floor(z / w) * w    for all complex z, w (!= 0)
> These seem like they would be mathematically useful definitions
> (e.g. in algebraic number theory, where one has to find the
> "nearest" Gaussian integer multiple of one Gaussian integer to
> another - I forget the details, but it has something to do with
> norms and Euclidean domains), and I don't understand why Python
> doesn't do it this way, rather than first defining it a different
> way (whose mathematical usefulness is not immediately apparent
> to me) and then "deprecating" the whole thing!  It seems like
> a wasted opportunity - but am I missing something?

My guess:  that in the absence of a /compelling/ reason to add
something, it's best to leave it out.  That you vaguely believe there
might be "a reason" for defining complex floor in a particular
more-or-less arbitrary way, but "forget the details" as to why /maybe/
that /might/ be useful ... well, that's not exactly compelling ;-)

> Has there been heated debate about this (e.g. in the context
> of Python 3, where the change to the division operator has
> apparently already provoked heated debate)?

Few people care about complex numbers in Python, and so no, there was
no heated debate about this.

> Also, by the way, is there some obvious reason for Python's use
> of the notation x + yj, rather than the more standard (except
> perhaps among electrical engineers) x + yi?

When complex numbers were first added to Python, there /was/ heated
debate about how to spell complex literals.  Guido got weary of the
debate, but didn't see a compelling reason to prefer "i" or "j", so
left it to a vote on comp.lang.python.  "j" got more votes.

See?  There's nothing "complex" about any of this after all ;-)

More information about the Tutor mailing list