So the state of this depends on what version of SymPy you are using. If you use 0.6.7 (the latest release) there is no new polys yet, so everything is slower, and uses SymPy's rational type.
In master, as well as in the development polys12, the new polys use gmpy ground types by default if gmpy is installed. If it isn't, in master, it falls back to Python's Fraction for Python 2.6 and up and SymPy's Rational otherwise. In polys12, it falls back to a reimplementation of Python's Fraction (because Fraction was introduced in Python 2.6, also, Mateusz claims that this is faster than Fraction). In polys12, the SymPy ground types are not used and exist only for experimentation purposes. If you use iSymPy, it will tell you what ground type is being used at the top: IPython console for SymPy 0.6.7-git (Python 2.7.1) (ground types: gmpy) and you can set it manually by setting the SYMPY_GROUND_TYPES environment variable (set it to 'gmpy', 'python', or 'sympy'). You can also tell what ground types you have by looking at, for example, ZZ.dtype. It will look like this with gmpy ground types (Python is similar): In [1]: ZZ.dtype Out[1]: <built-in function mpz> I hope that clarifies everything. Aaron Meurer On Apr 19, 2011, at 11:52 AM, mario wrote: > >> The most recent branch is p12. The pull request: >> >> https://github.com/sympy/sympy/pull/120 >> >> The branch: >> >> https://github.com/smichr/sympy/tree/p12 >> >> Vinzent > > Thank you. > > I realized just now that sympy and rmpoly seem to go together well; > in rmpoly one must specify the factory of the ring or free algebra; > it seems one can use sympify as factory, at least the following > example gives > a correct answer > >>>> from rmpoly import * >>>> from sympy import * >>>> rp, x = mrgens('x',8,sympify) >>>> h=10;p=(x*sqrt(2) + x**2*sqrt(3)).cos('x',h).pow_trunc(-1,'x',h);p > +(2*2**(1/2)*(-17*3**(1/2)/144 + 47*2*3**(1/2)/240) + 3309*6**(1/2)/ > 280)*x^9 +(2227/126)*x^8 +(68*6**(1/2)/15)*x^7 +(368/45)*x^6 > +(5*6**(1/2)/3)*x^5 +(7/3)*x^4 +(6**(1/2))*x^3 +(1)*x^2 +(1) > > although it does not simplify the coefficient of x**9 to > 779/63*sqrt(6) > > The speed is not so bad >>>> from time import time >>>> h=100 >>>> t0=time();p=(x*sqrt(2)).cos('x',h).pow_trunc(-1,'x',h);'%.2f'%(time()-t0) > '1.29' > > Does sympy use gmpy mpq to implement rationals? if it does but not by > default, > the above timing would improved choosing the mpq backend. > > In fact, if sympy uses Fraction by default as backend for rationals, I > must correct > the comparison between rmpoly and sympy: > it is 47x slower, not 3 orders of magnitude as claimed before. > If so, I apologize for the mistake; I am not much familiar with sympy. > >>>> from rmpoly import * >>>> from fractions import Fraction >>>> rp,x = rgens('x',10,Fraction) >>>> h=100 >>>> from time import time >>>> t0=time();p = x.cos('x',h).pow_trunc(-1,'x',h); '%.2f'%(time()-t0) > '1.04' > >>>> from sympy import * >>>> from time import time >>>> x = Symbol('x') >>>> t0=time();p = series(1/cos(x),x,0,100); '%.2f'%(time()-t0) > '48.97' > > > Mario > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
