# magma generators for unit group/ sage totally positive

Does anyone know how to find explicit generators for the unit group of a number field on magma?

For example, in sage one could do

K. = NumberField(x^3+x^2-2*x-1)

UnitGroup(K).gens()

and it gives you [-1, w^2 - 1, w + 1] which generate the unit group, but I can't figure out how to get this same data in magma.

Alternatively if anyone knows how to tell if something is totally positive in sage, that would work too.

• You can find information on how to compute groups of units of number fields in Magma in Section Unit Groups of Magma's handbook. – Stefan Kohl Apr 20 '16 at 19:30
• In gp you could do K=bnfinit(x^3+x^2-2*x-1); U=K.fu; S=bnfsignunit(K) to get a vector U of fundamental units and a matrix S of their real embeddings' signs. Then it just takes a bit of linear algebra mod 2 (possibly using matsolvemod) to construct a basis of totally positive units. – Noam D. Elkies Apr 20 '16 at 20:01
• (and anything that's in gp is automatically accessible by Sage even if there's no native Sage way to do it) – Noam D. Elkies Apr 20 '16 at 21:26

In Magma, the unit group is returned as an abstract group together with a map from that group into the field. So you would do something like the following:

> Zx<x> := PolynomialRing(Integers());
> K<w> := NumberField(x^3 + x^2 - 2*x - 1);
> G,phi := UnitGroup(K);
> G;
Abelian Group isomorphic to Z/2 + Z + Z
Defined on 3 generators
Relations:
2*G.1 = 0
> [ K!phi(G.i) : i in [1..Ngens(G)] ];
[
-1,
w,
w + 1
]


Note a couple of important points here. Firstly, for some reason calling Generators(G) would return a set rather than the more helpful sequence, hence the use of G.i and the loop over Ngens. Secondly, the concept of units is only useful with respect to an order, not the field, so the map phi is actually from G to the maximal order of K. That is why I have inserted the coercion into K, since that seems closer to what you want.