[Python-Dev] return type of complex (original) (raw)
Devin Jeanpierre jeanpierreda at gmail.com
Sun Oct 21 19:15:16 CEST 2012
- Previous message: [Python-Dev] return type of __complex__
- Next message: [Python-Dev] return type of __complex__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I guess I was asking for this. (Sorry for OT conversation.)
On Sun, Oct 21, 2012 at 6:31 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
(Also, floats aren't reals and no computer can store any number that is not rational and we should stop pretending they can. (Complex numbers get a free pass because "complex numbers with rational real and imaginary parts" is not a memorable name for a type.)) Floats are not rational either, since they allow infinities and NaN as values. Both float and Decimal are approximations to the Real number set, as int and Fraction are approximations to the Integer and Rational sets.
You're missing a step here. Are you claiming that the real numbers have infinities or NaN?
Why do floats approximate the reals, while Fraction approximates the rationals? After all, for any real number, a Fraction instance can become arbitrarily close to it (given sufficient memory). The same is not true of a float, which can only get to a relative distance of machine epsilon, and then only when the real number is close to zero. It would seem as if Fractions approximate the reals and rationals, and floats do not approximate anything at all (at least, not arbitrarily closely*).
- I think "can be made arbitrarily close to the value in question" is the usual meaning of "approximates" in mathematics, but I'm not sure about numerical computing (maybe it just means "with sufficiently small difference for values we care about"?)
In all cases, they cannot express the full scope of the associated numeric concept, because they're limited by their physical representations as bit patterns inside the computer (while that limit is technically available memory for the unbounded representations, the practical limit is lower than that if you want vaguely reasonable running times for arbitrary arithmetic operations).
There is a deeper difference in how badly we can represent the rationals versus the reals. For an arbitrary rational number, we can represent it precisely on a computer with sufficiently many bytes of memory. That is not true for real numbers: the vast majority of real numbers cannot be represented precisely in any form on a computer, no matter how large it is. And while there are irrational numbers we can represent precisely on a computer, floats don't represent any of them; they only represent a selection of rational numbers, and nan/inf/-inf.
As far as the conversion operators go, I don't recall there being any discussion one way or the other - the question simply never came up, presumably because all code tested already returned complex objects from complex.
That's a fair objection to what I said. I guess the discussion is here/now.
-- Devin
- Previous message: [Python-Dev] return type of __complex__
- Next message: [Python-Dev] return type of __complex__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]