[Python-ideas] Yet another sum function (fractions.sum)

Stephen J. Turnbull stephen at xemacs.org
Thu Aug 22 05:13:29 CEST 2013


Steven D'Aprano writes:

 > The test I think you want is:
 > 
 > py> type(1) is type(1+0j)
 > False

Thank you for the correction.  For some reason, I took 'random's
emphasis on duck-typing more seriously than I should have.

 > As far as whether some hypothetical sqrt method should return a
 > complex number or raise an exception, I'd like to point out that as
 > of Python 3.x, math.sqrt is now the odd-man-out:

Sure, but from a pure mathematics standpoint, the transcendental
functions are inherently complex functions.  So it doesn't surprise
*me* that 25 ** 0.5 returns a complex number.  And since the reals can
be naturally embedded in the complex domain, *I'm* not surprised that
cmath.sqrt(25) returns a complex result, rather than raising a domain
error.  Speaking only for myself about "what's surprising".

Nevertheless, clearly it makes mathematical sense to distinguish real
numbers from complex numbers.  Complex analysis goes back before
Riemann, yet (smart) mathematicians have continued doing real analysis
to this day.  So having real and complex math separated in Python is
not nonsense; it's a design choice, and it's not clear to me that
"odd-man-out" indicates that the choice has really been made -- there
are reasons why it might be so that are compatible with both ways of
thinking about the issues.



More information about the Python-ideas mailing list