ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 28 Dec 2015 02:57:34 -0600Computations with complex algebraic numbers?http://ask.sagemath.org/question/31857/computations-with-complex-algebraic-numbers/I am trying to perform some Newton-type computations: `z-p(z)/p'(z)` where `p(z)` is a polynomial over the field of algebraic numbers.
For example, this shows the sort of thing I'm trying to do:
p = (z^2+1)*(z^2+4)
q = p/(z-I)
pd = diff(p,z)
qd = diff(q,z)
sol = solve(qd=0,solution_dict='true')
a0 = sol[0][z]
b0 = a0-p.subs(z=a0)/pd.subs(z=a0)
However, this doesn't work because the expression `z-I` is not recognized as a factor of `p`. So I might try defining
`p` as a polynomial over the field `QQbar`:
R.<z> = PolynomialRing(QQbar)
p = (z^2+1)*(z^2+4)
q = p.quo_rem(z-I)[0]
pd = p.differentiate(z)
qd = q.differentiate(z)
The trouble now is that I can only seem to solve `qd` over `CC`: that is, in numerical form. Both the commands
qd.roots()
qd.factor()
produce numerical roots; I can't use `solve` on `qd` to obtain closed-form expressions for the roots. I've also tried the first method above prefaced with `z=QQbar['z'].0` but to no avail.
Is there some way of doing this entire computation over `QQbar`, that is, with exact complex numbers instead of numerical approximations?Sun, 27 Dec 2015 02:33:06 -0600http://ask.sagemath.org/question/31857/computations-with-complex-algebraic-numbers/Answer by slelievre for <p>I am trying to perform some Newton-type computations: <code>z-p(z)/p'(z)</code> where <code>p(z)</code> is a polynomial over the field of algebraic numbers.</p>
<p>For example, this shows the sort of thing I'm trying to do:</p>
<pre><code>p = (z^2+1)*(z^2+4)
q = p/(z-I)
pd = diff(p,z)
qd = diff(q,z)
sol = solve(qd=0,solution_dict='true')
a0 = sol[0][z]
b0 = a0-p.subs(z=a0)/pd.subs(z=a0)
</code></pre>
<p>However, this doesn't work because the expression <code>z-I</code> is not recognized as a factor of <code>p</code>. So I might try defining
<code>p</code> as a polynomial over the field <code>QQbar</code>:</p>
<pre><code>R.<z> = PolynomialRing(QQbar)
p = (z^2+1)*(z^2+4)
q = p.quo_rem(z-I)[0]
pd = p.differentiate(z)
qd = q.differentiate(z)
</code></pre>
<p>The trouble now is that I can only seem to solve <code>qd</code> over <code>CC</code>: that is, in numerical form. Both the commands</p>
<pre><code>qd.roots()
qd.factor()
</code></pre>
<p>produce numerical roots; I can't use <code>solve</code> on <code>qd</code> to obtain closed-form expressions for the roots. I've also tried the first method above prefaced with <code>z=QQbar['z'].0</code> but to no avail.</p>
<p>Is there some way of doing this entire computation over <code>QQbar</code>, that is, with exact complex numbers instead of numerical approximations?</p>
http://ask.sagemath.org/question/31857/computations-with-complex-algebraic-numbers/?answer=31875#post-id-31875The impression that computations are numerical rather than in `QQbar` is mistaken.
Indeed, the trailing `?`s in the following indicate elements in `QQbar`:
sage: R.<z> = PolynomialRing(QQbar)
sage: p = (z^2+1)*(z^2+4)
sage: q = p.quo_rem(z-I)[0]
sage: pd = p.differentiate(z)
sage: qd = q.differentiate(z)
sage: qd.roots()
[(-1.535183758487997?*I, 1), (0.8685170918213298?*I, 1)]
sage: qd.factor()
(3) * (z - 0.8685170918213298?*I) * (z + 1.535183758487997?*I)
Thus, you are working in `QQbar` and the following works, for instance:
sage: a = qd.roots()[0][0]
sage: a
-1.535183758487997?*I
sage: a.parent()
Algebraic Field
sage: a.radical_expression()
-1/3*sqrt(-2*sqrt(13) - 14)
Mon, 28 Dec 2015 02:57:34 -0600http://ask.sagemath.org/question/31857/computations-with-complex-algebraic-numbers/?answer=31875#post-id-31875