For integer and rational support, gmpy2 is stable. gmpy2 also wraps
the MPFR and MPC libraries but the API may change. Since sympy uses
mpmath for real and complex arithmetic, I don't sympy needs gmpy2's
new features. I'm confident I can make any version >= 1.13 work.
Here is an update on my progress.
I found gmpy imported twice in sympy code and either gmpy2 or gmpy
imported in mpmath. As an experiment, I imported gmpy2 or gmpy in
sympy.core.compatibility and then tweaked the other import locations.
This did work, but I think I'll follow a different approach (see
below).
The majority of the remaining changes were (1) replacing mpq.numer() &
mpq.denom() with mpq.numerator and mpq.denominator and (2) replacing
changing the qdiv() method calls to gmpy.qdiv() function calls. (gmpy
duplicated almost all function calls with method calls; gmpy2 removes
most of duplicate method calls).
There are still a few subtle issues. 'bitcount' is directly imported
from mpmath. The pure Python version of bitcount works with a sympy
Integer, but the gmpy version does not. I created a simple wrapper
function that returns mpmath_bitcount(int(a)). Is that the recommended
way to force an Integer to an int or is there a different strategy I
should follow?
I've also found code in scaled_zero that does "type(mag) is int". This
fails when gmpy is used since the type is actually an mpz. This could
also fail if mag is a long on Python 2.x. mpmath uses a tuple call
int_types that contains all the low-level integer types - the
appropriate combination of int, long, and mpz. I just imported
int_types from mpmath and changed the code to "type(mag) in int_types"
in the various places I found an "is int:" fragment. I made this
change aggressively and didn't check that is caused an issue with gmpy
since it could also trigger a bug with Python 2.x.
core/numbers.py also uses isinstance(n, (int, long, Rational)) which I changed.
I'm down to one failed test to resolve.
Given the dependencies on mpmath's int_types, I think I'll change my
approach to use mpmath's version of gmpy throughout. This will require
that (1) mpmath gets imported before anything else that uses gmpy (I
think that is true) and (2) the minimum version check in mpmath needs
to be changed.
Regards,
casevh