Comment #43 on issue 2607 by smi...@gmail.com: as_numer_denom() is too slow http://code.google.com/p/sympy/issues/detail?id=2607
I'm finding that there are too many special things to watch out for. The approach is sound, I think, but what is going to happen is that I am just going to end up re-writing Mul's flatten machinery. What we need is a way to keep all the flatten info and then just update that info as terms are removed. Here's the basic approach I am taking; calc num, den of all terms if all dens are the same, return Add(*nums), den[0] find lcm of den coeffs multiply num_i by lcm/den_i's coeff and remove den_i's coeff [so all dens become coeff free] collect common dens and update nums, e.g. num, den = [1, 3*y], [x, x] -> [1 + 3*y], [x] if all dens are the same, return Add(*nums), den[0] numden = Mul(*(num+den)) terms = [] for i in range(len(num)): term = divide(numden, num[i]) for j in range(len(num)): if j == i: continue term = divide(term, den[j]) terms.append(term) for j in range(len(num)): numden = divide(numden, den[j]) return Add(*terms), numden All the details are in the divide routine (which doesn't exist separate from my asnd routine). That's what we need to do the efficient processing because all the terms are present, so we are either going to be totally removing a term (divide(x*y, x)) or updating a term (divide(x**2*y, x)). The order of the terms isn't going to change so we can just rebuild the mul with new_rawargs. The problem right now are the 'orphans', things that changed appearance when multiplied together, e.g. 2**x*2**x -> 4**x so when you try divide by 2**x, that term isn't found. The same for things like I and radicals. btw, something interesting I noticed is that in testing 4b, `den*n/d` was faster than `den/d*n` and I'm not sure why. -- 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.