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

Jeffrey Yasskin jyasskin at gmail.com
Wed Apr 25 16:04:18 EDT 2007


On 4/25/07, Guido van Rossum <guido at python.org> wrote:
> Jeffrey, is there any way you can drop the top of the tree and going
> straight from Number to Complex -> Real -> Rational -> Integer? These
> are the things that everyone with high school math will know.

I think yes, if you can confirm that the
    import numbers
    class Ring(AdditiveGroup): ...
    numbers.Complex.__bases__ = (Ring,) + numbers.Complex.__bases__
hack I mention under IntegralDomain will make isinstance(int, Ring) return True.

Do you want "Number" to be equivalent to Ring+Hashable (or a
Haskell-like Ring+Hashable+__abs__+__str__)? I don't think a "Number"
class is strictly necessary since people can check for Complex or Real
directly, and one of those two is probably what they'll expect after
knowing that something's a number.

Also, I don't see much point in putting Rational between Real and
Integer. The current hierarchy is Real (int, float, Decimal, rational)
:> Integer (int) and Real :> FractionalReal (float, Decimal,
rational), but Integer and FractionalReal are just siblings.


I'm wondering how many people are writing new numeric types who don't
know the abstract algebra. I think we should be able to insulate
people who are just using the types from the complexities underneath,
and the people writing new types will benefit. Or will seeing "Ring"
in a list of superclasses be enough to confuse people?

-- 
Namasté,
Jeffrey Yasskin


More information about the NumPy-Discussion mailing list