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.Sun, 12 Nov 2017 13:38:43 -0600Complex argument of an algebraic numberhttp://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/This question is closely related to [that question here](http://ask.sagemath.org/question/1945/complex-argument-of-a-symbolic-expression). Basically I'd like to know whether there is a way to compute an *accurate symbolic expression* for the argument of an algebraic number.
That argument will in general not be an algebraic number itself, which seems to cause a lot of headache along the way. The following all fail, sometimes in rather spectacular backtracing ways:
sage: z = QQbar(3 + 2*I)
sage: z.arg()
AttributeError: 'AlgebraicNumber' object has no attribute 'arg'
sage: atan2(imag(z), real(z))
TypeError: Illegal initializer for algebraic number
sage: atan2(SR(imag(z)), SR(real(z)))
TypeError: Illegal initializer for algebraic number
sage: atan2(AA(imag(z)), AA(real(z)))
TypeError: Illegal initializer for algebraic number
I know a few cases which will work.
sage: atan2(QQ(imag(z)), QQ(real(z)))
arctan(2/3)
This however will break if the real or imaginary part were to contain any square roots.
sage: CC(z).arg()
0.588002603547568
This will give me a numeric approximation. I know I can get that approximation to arbitrary precision, but it's still not exact.
I have the impression that `atan2` attempts to turn its result into an algebraic number, which will fail horribly. I would expect that result to contain an unevaluated call to `atan2` instead, for the cases where the argument is not an algebraic number. Can this be done?Fri, 02 Nov 2012 06:42:21 -0500http://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/Comment by MvG for <p>This question is closely related to <a href="http://ask.sagemath.org/question/1945/complex-argument-of-a-symbolic-expression">that question here</a>. Basically I'd like to know whether there is a way to compute an <em>accurate symbolic expression</em> for the argument of an algebraic number.</p>
<p>That argument will in general not be an algebraic number itself, which seems to cause a lot of headache along the way. The following all fail, sometimes in rather spectacular backtracing ways:</p>
<pre><code>sage: z = QQbar(3 + 2*I)
sage: z.arg()
AttributeError: 'AlgebraicNumber' object has no attribute 'arg'
sage: atan2(imag(z), real(z))
TypeError: Illegal initializer for algebraic number
sage: atan2(SR(imag(z)), SR(real(z)))
TypeError: Illegal initializer for algebraic number
sage: atan2(AA(imag(z)), AA(real(z)))
TypeError: Illegal initializer for algebraic number
</code></pre>
<p>I know a few cases which will work.</p>
<pre><code>sage: atan2(QQ(imag(z)), QQ(real(z)))
arctan(2/3)
</code></pre>
<p>This however will break if the real or imaginary part were to contain any square roots.</p>
<pre><code>sage: CC(z).arg()
0.588002603547568
</code></pre>
<p>This will give me a numeric approximation. I know I can get that approximation to arbitrary precision, but it's still not exact.</p>
<p>I have the impression that <code>atan2</code> attempts to turn its result into an algebraic number, which will fail horribly. I would expect that result to contain an unevaluated call to <code>atan2</code> instead, for the cases where the argument is not an algebraic number. Can this be done?</p>
http://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/?comment=33561#post-id-33561I honestly don't remember what I had in mind when I posted this question. I guess I worked around it somehow, or tried a completely different approach.Thu, 26 May 2016 18:25:45 -0500http://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/?comment=33561#post-id-33561Comment by vdelecroix for <p>This question is closely related to <a href="http://ask.sagemath.org/question/1945/complex-argument-of-a-symbolic-expression">that question here</a>. Basically I'd like to know whether there is a way to compute an <em>accurate symbolic expression</em> for the argument of an algebraic number.</p>
<p>That argument will in general not be an algebraic number itself, which seems to cause a lot of headache along the way. The following all fail, sometimes in rather spectacular backtracing ways:</p>
<pre><code>sage: z = QQbar(3 + 2*I)
sage: z.arg()
AttributeError: 'AlgebraicNumber' object has no attribute 'arg'
sage: atan2(imag(z), real(z))
TypeError: Illegal initializer for algebraic number
sage: atan2(SR(imag(z)), SR(real(z)))
TypeError: Illegal initializer for algebraic number
sage: atan2(AA(imag(z)), AA(real(z)))
TypeError: Illegal initializer for algebraic number
</code></pre>
<p>I know a few cases which will work.</p>
<pre><code>sage: atan2(QQ(imag(z)), QQ(real(z)))
arctan(2/3)
</code></pre>
<p>This however will break if the real or imaginary part were to contain any square roots.</p>
<pre><code>sage: CC(z).arg()
0.588002603547568
</code></pre>
<p>This will give me a numeric approximation. I know I can get that approximation to arbitrary precision, but it's still not exact.</p>
<p>I have the impression that <code>atan2</code> attempts to turn its result into an algebraic number, which will fail horribly. I would expect that result to contain an unevaluated call to <code>atan2</code> instead, for the cases where the argument is not an algebraic number. Can this be done?</p>
http://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/?comment=32072#post-id-32072What do you want to do with these numbers?Mon, 04 Jan 2016 20:05:49 -0600http://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/?comment=32072#post-id-32072Answer by Emmanuel Charpentier for <p>This question is closely related to <a href="http://ask.sagemath.org/question/1945/complex-argument-of-a-symbolic-expression">that question here</a>. Basically I'd like to know whether there is a way to compute an <em>accurate symbolic expression</em> for the argument of an algebraic number.</p>
<p>That argument will in general not be an algebraic number itself, which seems to cause a lot of headache along the way. The following all fail, sometimes in rather spectacular backtracing ways:</p>
<pre><code>sage: z = QQbar(3 + 2*I)
sage: z.arg()
AttributeError: 'AlgebraicNumber' object has no attribute 'arg'
sage: atan2(imag(z), real(z))
TypeError: Illegal initializer for algebraic number
sage: atan2(SR(imag(z)), SR(real(z)))
TypeError: Illegal initializer for algebraic number
sage: atan2(AA(imag(z)), AA(real(z)))
TypeError: Illegal initializer for algebraic number
</code></pre>
<p>I know a few cases which will work.</p>
<pre><code>sage: atan2(QQ(imag(z)), QQ(real(z)))
arctan(2/3)
</code></pre>
<p>This however will break if the real or imaginary part were to contain any square roots.</p>
<pre><code>sage: CC(z).arg()
0.588002603547568
</code></pre>
<p>This will give me a numeric approximation. I know I can get that approximation to arbitrary precision, but it's still not exact.</p>
<p>I have the impression that <code>atan2</code> attempts to turn its result into an algebraic number, which will fail horribly. I would expect that result to contain an unevaluated call to <code>atan2</code> instead, for the cases where the argument is not an algebraic number. Can this be done?</p>
http://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/?answer=39508#post-id-39508Well...
sage: z=QQbar(3+2*i);z
2*I + 3
sage: arg(z)
arctan(0.6666666666666667?)
Note the "?" printed at the end of the decimal approximation. That means that this number is "exact", in the sense that this "quantity" represents an algorithm able to approximate the underlying complex to any precision. At least, that's what Sage says :
sage: arg(z).is_exact()
True
Note that, while there exists a radical expression for z (the original `3+2*i`), there cannot be one for arctan(z)`, unless this one happens to be _known_ to be rational, in which case it can be coerced to be rational and a radical expression can be searched. As far as Sage can say, this is not the case...
Sun, 12 Nov 2017 13:38:43 -0600http://ask.sagemath.org/question/9497/complex-argument-of-an-algebraic-number/?answer=39508#post-id-39508