Comment #19 on issue 2607 by asmeurer: as_numer_denom() is too slow
http://code.google.com/p/sympy/issues/detail?id=2607

Sorry, that's as_numer_denom4().  And here are some timings:

In [12]: numers, denoms = zip(*((Symbol('n%d'%i),Symbol('d%d'%i)) for i in xrange(1000)))

In [13]: a = Add(*(n/d for n, d in zip(numers, denoms)))

In [14]: %timeit a.as_numer_denom4()
1 loops, best of 3: 134 ms per loop

Compare the above to timings 18-21 in comment 15. And for all denoms == to 1:

In [1]: a = Add(*(x**i for i in xrange(1000)))

In [2]: %timeit a.as_numer_denom()
1 loops, best of 3: 7.21 s per loop

In [3]: %timeit a.as_numer_denom1()
1 loops, best of 3: 17.2 s per loop

In [4]: %timeit a.as_numer_denom2()
1 loops, best of 3: 8.42 s per loop

In [5]: %timeit a.as_numer_denom3()
1 loops, best of 3: 135 ms per loop

In [6]: %timeit a.as_numer_denom4()
1 loops, best of 3: 124 ms per loop

Based on what I've tried so far, we must reject as_numer_denom0-3 (I'll leave them around for reference). If you can break 4, then we will have to try harder, but so far, it seems to work and work fast. My main concern with it is not speed that but that canceling won't work correctly (see the above comments).

Thanks for trying sifting. I figured that no matter what optimization we do, that will only make it fast, so I wan't going to implement it until the end.

Other kinds of expressions to try:

- Add(random_poly/random_poly)
- Add(exp(i*x) for i in xrange(whatever))
- Add(n/d for n in [n1, n2] for d in [d1, d2, ..., dn]) # Many denoms with some common denoms - Add(n/d for n in [n1, n2, ...., nn] for d in [d1, d2]) # Few denoms with many common denoms - See if you can get automatic distribution of numbers through Adds to mess up the cancelation from as_numer_denom4().

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to