[Numpy-discussion] [Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)

Jeffrey Yasskin jyasskin@gmail....
Fri Apr 27 09:58:43 CDT 2007


On 4/27/07, Guido van Rossum <guido@python.org> wrote:
> On 4/27/07, Jan Grant <jan.grant@bristol.ac.uk> wrote:
> > On Thu, 26 Apr 2007, Dan Christensen wrote:
> >
> > > Note also that double-precision reals are a subset of the rationals,
> > > since each double precision real is exactly representable as a
> > > rational number, but many rational numbers are not exactly
> > > representable as double precision reals.  Not sure if this means
> > > that reals should be a subclass of the rationals.
> >
> > Not quite all: the space of doubles include a small number of things
> > that aren't representable by a rational (+/- inf, for instance).
>
> This suddenly makes me think of a new idea -- perhaps we could changes
> the type of Inf and NaNs to some *other* numeric type? We could then
> reserve a place in the numeric hierarchy for its abstract base class.
> Though I don't know if this extends to complex numbers with one or
> both parts NaN/Inf or not.

From the Fortress spec: "The trait Q ( QQ ) encompasses all finite
rational numbers, the results of dividing any integer by any nonzero
integer. The trait Q∗ ( QQ_star ) is Q with two extra elements, + ∞
and −∞ . The trait Q# ( QQ_splat ) is Q∗ with one additional element,
the indefinite rational (written 0/0 ), which is used as the result of
dividing zero by zero or of adding −∞ to +∞."

So separating Inf and NaN into other types has some precedent.

I'd also point out that A being a subset of B doesn't make it a
subtype also. If operations on A behave differently than the
specification of the operations on B, then As aren't substitutable for
Bs and A isn't a subtype. Because doubles have finite precision and
rationals don't, I don't think doubles are a subtype of the rationals,
even if you juggle Nan/Inf to make them a subset.

Then again, doubles aren't a group either because of this imprecision,
and I'm suggesting claiming they're a subclass of that, so maybe
there's room in a practical language to make them a subclass of the
rationals too.

-- 
Namasté,
Jeffrey Yasskin


More information about the Numpy-discussion mailing list