Comment #39 on issue 2607 by [email protected]: as_numer_denom() is too slow
http://code.google.com/p/sympy/issues/detail?id=2607

By keeping track of the terms internally rather than feeding it back to Mul, some significant improvements can be made:

    >>> from timeit import timeit as T
>>> T('Add(*[1/Dummy() for i in xrange(500)]).as_numer_denom6()','from sympy imp
    ort Dummy, Add', number=1)
    1.4353856028742573
>>> T('Add(*[1/Dummy() for i in xrange(500)]).as_numer_denom4()','from sympy imp
    ort Dummy, Add', number=1)
    21.225003537452913
>>> T('Add(*[Dummy() for i in xrange(1000)]).as_numer_denom6()','from sympy impo
    rt Dummy, Add', number=1)
    0.016849042016737314
>>> T('Add(*[Dummy()/i for i in xrange(1,1000)]).as_numer_denom6()','from sympy
    import Dummy, Add', number=1)
    0.9006821644700267

This handles the constant, too:

    >>> (x/y+x/2+3/x).as_numer_denom6()
    (x**2*y + 2*x**2 + 6*y, 2*x*y)
    >>> (x/y+x/2+3/x).as_numer_denom()
    (x**2*y + 2*x**2 + 6*y, 2*x*y)
    >>> (x/1+y/2+z/3).as_numer_denom6()
    (6*x + 3*y + 2*z, 6)
    >>> (x/1+y/2+z/3).as_numer_denom()
    (6*x + 3*y + 2*z, 6)
    >>> (x/2 + 1/(5*(x + 1))).as_numer_denom6()
    (x*(5*x + 5) + 2, 10*x + 10)
    >>> (x/2 + 1/(5*(x + 1))).as_numer_denom()
    (x*(5*x + 5) + 2, 10*x + 10)


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" 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-issues?hl=en.

Reply via email to