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.Wed, 25 Apr 2018 17:56:48 +0200Number field basis containing 1https://ask.sagemath.org/question/42150/number-field-basis-containing-1/ In Sage, the default basis for a maximal order $O_K$ often does not contain the element $1$:
sage: QuadraticField(-3).ring_of_integers().basis()
[1/2*a + 1/2, a]
However, $1$ is always a primitive lattice vector in $O_K$. Is there an elegant way to produce a basis containing $1$?Tue, 24 Apr 2018 21:21:01 +0200https://ask.sagemath.org/question/42150/number-field-basis-containing-1/Answer by eodorney for <p>In Sage, the default basis for a maximal order $O_K$ often does not contain the element $1$:</p>
<pre><code>sage: QuadraticField(-3).ring_of_integers().basis()
[1/2*a + 1/2, a]
</code></pre>
<p>However, $1$ is always a primitive lattice vector in $O_K$. Is there an elegant way to produce a basis containing $1$?</p>
https://ask.sagemath.org/question/42150/number-field-basis-containing-1/?answer=42153#post-id-42153Found the answer! Basically the method is to reverse the coordinates on $O_K$ and re-echelonize the basis.
def basis_with_1(L):
assert L.is_field();
n = L.degree();
R = matrix([[1 if i+j==n+1 else 0 for j in [1..n]] for i in [1..n]]);
A = L.maximal_order().module().matrix();
A = A*R;
M = (ZZ^n).span_of_basis([vector(v) for v in A])
A = matrix(M.echelonized_basis());
A = R*A*R;
return [L(v) for v in A];
sage: L = QuadraticField(-3)
sage: basis_with_1(L)
[1, 1/2*a + 1/2]Wed, 25 Apr 2018 03:44:22 +0200https://ask.sagemath.org/question/42150/number-field-basis-containing-1/?answer=42153#post-id-42153Comment by slelievre for <p>Found the answer! Basically the method is to reverse the coordinates on $O_K$ and re-echelonize the basis.</p>
<pre><code>def basis_with_1(L):
assert L.is_field();
n = L.degree();
R = matrix([[1 if i+j==n+1 else 0 for j in [1..n]] for i in [1..n]]);
A = L.maximal_order().module().matrix();
A = A*R;
M = (ZZ^n).span_of_basis([vector(v) for v in A])
A = matrix(M.echelonized_basis());
A = R*A*R;
return [L(v) for v in A];
sage: L = QuadraticField(-3)
sage: basis_with_1(L)
[1, 1/2*a + 1/2]
</code></pre>
https://ask.sagemath.org/question/42150/number-field-basis-containing-1/?comment=42163#post-id-42163Congratulations; you can accept your own answer to mark your question as solved.Wed, 25 Apr 2018 17:56:48 +0200https://ask.sagemath.org/question/42150/number-field-basis-containing-1/?comment=42163#post-id-42163