Comment #8 on issue 51 by mattpap: RootOf for polynomial equations
http://code.google.com/p/sympy/issues/detail?id=51

I made some progress with RootOf implementation. A few examples follow:

In [1]: f = cyclotomic_poly(20, x)

In [2]: RootOf(f, 0)
Out[2]:
  ⎛     2    4    6    8⎞
ζ₀⎝1 - x  + x  - x  + x ⎠

In [3]: for i in xrange(0, 8): RootOf(f, i).evalf()
   ...:
Out[3]: -0.951056516295154 + 0.309016994374947⋅ⅈ
Out[3]: -0.951056516295154 - 0.309016994374947⋅ⅈ
Out[3]: -0.587785252292473 + 0.809016994374947⋅ⅈ
Out[3]: -0.587785252292473 - 0.809016994374947⋅ⅈ
Out[3]: 0.951056516295154 + 0.309016994374947⋅ⅈ
Out[3]: 0.951056516295154 - 0.309016994374947⋅ⅈ
Out[3]: 0.587785252292473 + 0.809016994374947⋅ⅈ
Out[3]: 0.587785252292473 - 0.809016994374947⋅ⅈ

In [4]: f = expand((x-1)**2*(x**2 - 2)*(x**3 + 2)**2)

In [5]: for i in xrange(0, 10): RootOf(f, i)
   ...:
Out[5]:
  ⎛      2⎞
ζ₀⎝-2 + x ⎠
Out[5]:
  ⎛     3⎞
ζ₀⎝2 + x ⎠
Out[5]:
  ⎛     3⎞
ζ₀⎝2 + x ⎠
Out[5]: 1
Out[5]: 1
Out[5]:
  ⎛      2⎞
ζ₁⎝-2 + x ⎠
Out[5]:
  ⎛     3⎞
ζ₁⎝2 + x ⎠
Out[5]:
  ⎛     3⎞
ζ₁⎝2 + x ⎠
Out[5]:
  ⎛     3⎞
ζ₂⎝2 + x ⎠
Out[5]:
  ⎛     3⎞
ζ₂⎝2 + x ⎠

In [6]: for i in xrange(0, 10): RootOf(f, i).evalf()
   ...:
Out[6]: -1.41421356237310
Out[6]: -1.25992104989487
Out[6]: -1.25992104989487
Out[6]: 1.00000000000000
Out[6]: 1.00000000000000
Out[6]: 1.41421356237310
Out[6]: 0.629960524947437 + 1.09112363597172⋅ⅈ
Out[6]: 0.629960524947437 + 1.09112363597172⋅ⅈ
Out[6]: 0.629960524947437 - 1.09112363597172⋅ⅈ
Out[6]: 0.629960524947437 - 1.09112363597172⋅ⅈ

This is all quite slow as complex root isolation and refinement algorithms are slow at the moment. To improve speed I use caching, so that after univariate factoring over integers, unique (irreducible, primitive) polynomials are obtained and root isolation is done only once per polynomial and stored in cache. Each successive call to RootOf uses previously computed intervals. If new polynomials are encountered, then root isolation is performed only for those polynomials. If some of the real or complex intervals aren't disjoint, then they are refined until they are disjoint and new smaller intervals are stored in cache. evalf() uses mpmath's findroot() and root
refinement, if the current interval doesn't make findroot() successful.

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--
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