details: http://hg.sympy.org/sympy/rev/17b95f9f1d9d changeset: 1794:17b95f9f1d9d user: Mateusz Paprocki <[EMAIL PROTECTED]> date: Wed Oct 15 12:12:54 2008 +0200 description: Fixed issue #1123
The problem was in new roots() function - it was checking not enough trivial cases and used functional and square-free decomposition unnecessarily, making the results overcomplicated (so that simplify hanged on multivariate gcd computation). diffs (98 lines): diff -r 6bfb268ef808 -r 17b95f9f1d9d sympy/polys/rootfinding.py --- a/sympy/polys/rootfinding.py Mon Oct 13 22:45:28 2008 +0200 +++ b/sympy/polys/rootfinding.py Wed Oct 15 12:12:54 2008 +0200 @@ -238,43 +238,43 @@ else: return {} else: - if multiple: - return [S.Zero] * f.degree - else: - return { S.Zero : f.degree } + result = { S.Zero : f.degree } + else: + (k,), f = f.as_reduced() - (k,), f = f.as_reduced() + if k == 0: + result = {} + else: + result = { S.Zero : k } - if k == 0: - result = {} - else: - result = { S.Zero : k } + if f.degree == 1: + result[roots_linear(f)[0]] = 1 + else: + factors = poly_decompose(f) - factors = poly_decompose(f) + zeros, g = {}, factors[0] - zeros, g = {}, factors[0] - - for i, h in enumerate(poly_sqf(g)): - for zero in roots_trivial(h): - if zeros.has_key(zero): - zeros[zero] += i+1 - else: - zeros[zero] = i+1 - - for factor in factors[1:]: - previous, zeros = zeros.copy(), {} - - for zero, i in previous.iteritems(): - g = factor.sub_term(zero, (0,)) - - for j, h in enumerate(poly_sqf(g)): + for i, h in enumerate(poly_sqf(g)): for zero in roots_trivial(h): if zeros.has_key(zero): - zeros[zero] += i*(j+1) + zeros[zero] += i+1 else: - zeros[zero] = i*(j+1) + zeros[zero] = i+1 - result.update(zeros) + for factor in factors[1:]: + previous, zeros = zeros.copy(), {} + + for zero, i in previous.iteritems(): + g = factor.sub_term(zero, (0,)) + + for j, h in enumerate(poly_sqf(g)): + for zero in roots_trivial(h): + if zeros.has_key(zero): + zeros[zero] += i*(j+1) + else: + zeros[zero] = i*(j+1) + + result.update(zeros) domain = flags.get('domain', None) diff -r 6bfb268ef808 -r 17b95f9f1d9d sympy/polys/tests/test_polynomial.py --- a/sympy/polys/tests/test_polynomial.py Mon Oct 13 22:45:28 2008 +0200 +++ b/sympy/polys/tests/test_polynomial.py Wed Oct 15 12:12:54 2008 +0200 @@ -6,7 +6,7 @@ from sympy.polys.algorithms import * from sympy.polys.rootfinding import * -a,b,c,x,y,z,u,v,t = symbols('abcxyzuvt') +a,b,c,d,x,y,z,u,v,t = symbols('abcdxyzuvt') def test_monomial_cmp(): assert monomial_lex_cmp((3,2,1), (1,2,4)) == 1 @@ -997,6 +997,9 @@ S.One: 1, -S.One: 1, I: 1, -I: 1 } + assert roots((a+b+c)*x + a+b+c+d, x) == \ + { (-a-b-c-d) / (a+b+c) : 1 } + assert roots(x**3+x**2-x+1, x, cubics=False) == {} r1_2, r1_3, r1_9, r4_9, r19_27 = [ Rational(*r) \ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-commits" group. To post to this group, send email to sympy-commits@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-commits?hl=en -~----------~----~----~----~------~----~------~--~---