[sage list added]
"Travis E. Oliphant" firstname.lastname@example.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
and Section 2.2 gives a brief introduction to numbers:
The SAGE reference manual is at
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.