id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,merged,author,reviewer,upstream,work_issues,branch,commit,dependencies,stopgaps
17895,Computing all roots is faster than computing a single one,Martin von Gagern,,"The following example comes from comment:27:ticket:16964 via comment:2:ticket:17886.
{{{
sage: x,y = polygens(QQ,""x,y"")
sage: p1 = x^5 + 6*x^4 - 42*x^3 - 142*x^2 + 467*x + 422
sage: p2 = p1(x=(x-1)^2)
sage: p3 = p2(x=x*y).resultant(p2,x).univariate_polynomial()
sage: p4, = [f[0] for f in p3.factor() if f[0].degree() == 80]
sage: ival = CIF((0.77, 0.78), (-0.08, -0.07))
sage: %time z1, = [r for r in p4.roots(QQbar, False) if r in ival]
CPU times: user 1.43 s, sys: 195 ms, total: 1.62 s
Wall time: 1.47 s
sage: %time z2 = QQbar.polynomial_root(p4, ival)
CPU times: user 1min 5s, sys: 212 ms, total: 1min 5s
Wall time: 1min 5s
}}}
The computation for `z1` works reasonably well and completes in under 2 seconds, but the one for `z2` takes over a minute. Which is definitely wrong, since computing all roots and then choosing the right one should be ''more'' work, not ''less'' than just computing a single one!
The reason for this is the time spent in the square-free decomposition (called from `sage/rings/polynomial/complex_roots.py`) which behave differently depending whether the polynomial is defined with coefficients in `QQ` or `AA`
{{{
sage: %time _ = p4.squarefree_decomposition()
CPU times: user 807 µs, sys: 0 ns, total: 807 µs
Wall time: 883 µs
sage: %time _ = p4.change_ring(AA).squarefree_decomposition()
CPU times: user 40.1 s, sys: 3.21 ms, total: 40.1 s
Wall time: 40.1 s
}}}",defect,new,major,sage-6.6,number fields,,qqbar polynomial_root roots performance,,,,,N/A,,,,,