[sage list added]

"Travis E. Oliphant" oliphant.travis@ieee.org writes:

The SAGE people may be interested in this, but I doubt there will more than a handful of users of these algebraic base classes.

SAGE has quite a sophisticated type hierarchy, and a sophisticated set of coercion methods. What is done in SAGE should definitely be consulted, since it is probably the most complex set of mathematical types yet written in python. The SAGE tutorial is at

http://www.sagemath.org/doc/html/tut/tut.html

and Section 2.2 gives a brief introduction to numbers:

http://www.sagemath.org/doc/html/tut/node9.html

The SAGE reference manual is at

http://www.sagemath.org/doc/html/ref/index.html

Chapter 20:

http://www.sagemath.org/doc/html/ref/node198.html

and nearby chapters are quite relevant for this discussion.

For general purpose Python, I would do something like

Complex Rational_Complex Integer_Complex Floating_Complex # uses hardware float Decimal_Complex Real Rational Integer Floating # uses hardware float Decimal

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.

I believe that in SAGE these relationships aren't expressed using subclassing.

Dan