On Mon, Oct 14, 2019 at 3:46 PM Andrew Barnert via Python-ideas
<python-ideas@python.org> wrote:
>
> On Oct 13, 2019, at 18:39, Steven D'Aprano <st...@pearwood.info> wrote:
> >
> > Even when the class can be identified as equivalent to
> > its set of values, such as for numeric types, there are all sorts of
> > complexities that will only lead to confusion:
> >
> >    from numbers import Real
> >    1.0 in Real  # okay, unproblematic
> >    2+3j in complex  # also okay
> >    1 in complex  # mathematically true, but isinstance-wise false
> >    float('INF') in Real  # isinstance-wise true, but mathematically false.
>
> I agree with your conclusion, but I think this is the wrong way to argue it.
>
> `1 in complex` is _not_ mathematically true. Simplifying a bit, the elements 
> of the algebra of complex numbers are ordered pairs of real numbers, and `1` 
> is not a pair. When you’re working in, say, complex analysis, you just assume 
> the usual morphism that maps every real to a unique complex (and some 
> complexes to a unique real), and you can loosely multiply a real by a complex 
> and so on. But when you’re working on the actual algebras or the sets/types 
> beneath them, you can’t do that. `R` is not a subset of `C`, and `1 in C` is 
> just not true. In other words, the distinction in Python—that 1 and 1+0j are 
> in some sense “the same number” but in another sense not even the same type 
> of number—is exactly the same as in math; you don’t need anything extra to 
> justify it.
>

Mathematically, what's the difference between '1' and '1+0j' (or
'1+0i')? Everything I've seen has said that a complex number with its
imaginary part zero is equivalent to a real number, which would mean
that '1' is as valid a way of representing that number as any other.
It's the same as considering 42 to be rational, because it can be
written as 42/1.

You're absolutely right that Python's floats aren't actually
representing reals (aside from inf/nan, they're all rationals), but I
don't see a problem with calling 1 a member of the Complex numbers, as
Python does:

>>> isinstance(1, numbers.Complex)
True

Explain the difference?

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NWYPDHNT75VKHMQWFX27GPHFROAQZXTM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to