ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 23 Sep 2018 05:24:34 -0500Enumerating points in 0-dimensional ideals over Qbarhttp://ask.sagemath.org/question/43728/enumerating-points-in-0-dimensional-ideals-over-qbar/I would like to find the points of a 0-dimensional ideal over Qbar. That is I do not want just the rational points,
The problem is that I found multiple problem while doing that.
1) While the code
R.<t1,t2,t3,e1,e2,e3> = PolynomialRing(QQbar,6, order="degrevlex(3),lex(3)")
is legal, the code
R.<t1,t2,t3> = PolynomialRing(QQbar,6, order="degrevlex(3)")
is not for reasons that esapes me.
2) The code
R.<t1,t2,t3,e1,e2,e3> = PolynomialRing(QQbar,6, order="degrevlex(3),lex(3)")
tvars = [t1,t2,t3]
eltsyms = [R((SymmetricFunctions(QQbar).elementary())[i].expand(3,alphabet=tvars)) for i in range(4)]
is not legal, it is if we replace QQbar by QQ. Why?Mathieu Dutour SikiricSun, 23 Sep 2018 05:24:34 -0500http://ask.sagemath.org/question/43728/Simultaneously diagonalizing matrices exactlyhttp://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/I have a bunch of matrices with integer coefficients that simultaneously commute. I know that there is a basis that simultaneously diagonalizes all of them, and I want to find it exactly so that I can recover all the corresponding eigenvalues as algebraic numbers.
I've tried casting to QQbar and using eigenvectors, but this occasionally tries to divide by zero for no reason I can discern. Any ideas?watson_laddMon, 22 Jan 2018 11:43:40 -0600http://ask.sagemath.org/question/40737/Complex 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?MvGFri, 02 Nov 2012 06:42:21 -0500http://ask.sagemath.org/question/9497/why cloud.sage so many Undefined control sequences?http://ask.sagemath.org/question/24620/why-cloudsage-so-many-undefined-control-sequences/ old sagenb can do show(Qp(5)),show(QQbar()) and ,it is very beautil,but cloud.sage cannot
https://cloud.sagemath.com/projects/faaa84be-e0d1-451f-9517-cf6d911a9bde/files/2014-10-24-145338.sagewscjshFri, 24 Oct 2014 06:08:40 -0500http://ask.sagemath.org/question/24620/radical expression for algebraic numberhttp://ask.sagemath.org/question/9762/radical-expression-for-algebraic-number/What is the easiest way to turn an algebraic number (i.e. an element of `QQbar`) into a symbolic expression involving radicals? I know that this is only possible if the degree of the minimal polynomial does not exceed 4, but for those cases I'd have hoped to find an easy solution, but haven't found one yet.
Example of where this would be useful:
sage: M = Matrix([[1,2],[3,4]])
sage: M.parent()
Full MatrixSpace of 2 by 2 dense matrices over Integer Ring
Simply applying `gram_schmidt` over `ZZ` will fail:
sage: M.gram_schmidt(True)[0]
TypeError: QR decomposition unable to compute square roots in Rational Field
Changing to the symbolic ring won't help either:
sage: M.change_ring(SR).gram_schmidt(True)[0]
NotImplementedError: Gram-Scmidt orthogonalization not implemented
for matrices over inexact rings, except for RDF and CDF
Changing to the algebraic numbers lets me compute the matrix, but reading the result is kind of hard.
sage: N = M.change_ring(QQbar).gram_schmidt(True)[0]
sage: N
[ 0.4472135954999580? 0.8944271909999159?]
[ 0.8944271909999159? -0.4472135954999580?]
But all the numbers in there are actually simple square roots, as the minimal polynomials will show.
sage: N.apply_map(lambda x: x.minpoly())
[x^2 - 1/5 x^2 - 4/5]
[x^2 - 4/5 x^2 - 1/5]
So I wrote my own function to convert real algebraic numbers of degree two to symbolic expressions.
sage: def AA2SR(x):
....: x = AA(x)
....: p = x.minpoly()
....: if p.degree() < 2:
....: return SR(QQ(x))
....: if p.degree() > 2:
....: raise TypeError("Cannot handle degrees > 2")
....: c, b, a = p.coeffs()
....: y = (-b+sqrt(b*b-4*a*c))/(2*a)
....: if x == AA(y):
....: return y
....: y = (-b-sqrt(b*b-4*a*c))/(2*a)
....: assert x == AA(y)
....: return y
....:
sage: M.change_ring(QQbar).gram_schmidt(True)[0].apply_map(AA2SR)
[ sqrt(1/5) 2*sqrt(1/5)]
[2*sqrt(1/5) -sqrt(1/5)]
But pasting that code into every sage session where I might need it feels rather ugly. I would have hoped that there is some easier way to achieve what I'm doing here. Is there?MvGFri, 01 Feb 2013 08:02:24 -0600http://ask.sagemath.org/question/9762/