ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 04 Feb 2019 22:29:35 +0100basis of subspace of complex fieldhttps://ask.sagemath.org/question/45317/basis-of-subspace-of-complex-field/ Hi -
Given a set of elements of `CC`, or perhaps `QQbar`, I want to compute a basis for a subspace over `QQ` that contains those elements.
For example, given $3$, $1+\sqrt{5}$, $i$, and $i-1$, I'd expect my output to be $\\{1, \sqrt{5}, i\\}$, since my original four elements can be written as $(3,0,0)$, $(1,1,0)$, $(0,0,1)$, and $(-1,0,1)$ with respect to that basis.
Obviously, the basis won't be unique.
Can anybody suggest what tools in Sage might be useful for this calculation?Mon, 04 Feb 2019 21:59:43 +0100https://ask.sagemath.org/question/45317/basis-of-subspace-of-complex-field/Answer by rburing for <p>Hi -</p>
<p>Given a set of elements of <code>CC</code>, or perhaps <code>QQbar</code>, I want to compute a basis for a subspace over <code>QQ</code> that contains those elements.</p>
<p>For example, given $3$, $1+\sqrt{5}$, $i$, and $i-1$, I'd expect my output to be $\{1, \sqrt{5}, i\}$, since my original four elements can be written as $(3,0,0)$, $(1,1,0)$, $(0,0,1)$, and $(-1,0,1)$ with respect to that basis.</p>
<p>Obviously, the basis won't be unique.</p>
<p>Can anybody suggest what tools in Sage might be useful for this calculation?</p>
https://ask.sagemath.org/question/45317/basis-of-subspace-of-complex-field/?answer=45318#post-id-45318Here is one way:
sage: K, elts, hom = number_field_elements_from_algebraics([3, 1+sqrt(5), I, I-1], minimal=True)
sage: K.defining_polynomial()
y^4 + 3*y^2 + 1
sage: K.power_basis()
[1, a, a^2, a^3]
sage: map(vector, elts)
[(3, 0, 0, 0), (4, 0, 2, 0), (0, -2, 0, -1), (-1, -2, 0, -1)]
sage: A = matrix(QQ, map(vector, elts))
sage: A.image().basis()
[
(1, 0, 0, 0),
(0, 1, 0, 1/2),
(0, 0, 1, 0)
]
sage: mybasis = map(K, A.image().basis()); mybasis
[1, 1/2*a^3 + a, a^2]
sage: map(lambda z: hom(z).radical_expression(), mybasis)
[1, -1/2*I, 1/2*sqrt(5) - 3/2]Mon, 04 Feb 2019 22:29:35 +0100https://ask.sagemath.org/question/45317/basis-of-subspace-of-complex-field/?answer=45318#post-id-45318