2
$\begingroup$

Given a number field $K$, I would like to compute (in Sage) generators for the group of totally positive units of $K$.

Update: I've tried some code (details below), which I've received some help on in the comments. To clarify, my ideal would be to write up my own algorithm (rather than use code I found, as I discuss below).

I see reference to a strategy in the comments of the related question magma generators for unit group/ sage totally positive. The comment says that "it takes a bit of linear algebra mod 2 to construct a basis of totally positive units" from an existing set of fundamental units. I see some matrix algebra modulo 2 in the Pari code I found, but I don't know Pari well.

Question: Can anyone clarify the linear algebra to be done modulo 2, because then I could just go ahead and implement it in Sage myself?

What I had previously tried:

Option 1: (existing Sage functions) The Sage function

K.S_units(S = [])

computes a set of (not necessarily positive) generators. For $K$ of degree 3 or 4, I have successfully used this to get to a system of totally positive units. But I want an algorithm I can write for general degrees. I searched for other Sage functions that might help, without success. (Maybe I missed something?)

Option 2: (existing GP/Pari functions) I'm aware that I can use Pari in Sage. I've tried to adapt code on page 103 of the "User's Guide to PARI", link at https://math.mit.edu/~brubaker/PARI/PARIusers.pdf to arrive at the following (where I use %%gp to tell Sage to use GP for the cell):

%%gp 

bnf = bnfinit(x^3 + x^2 - 1)

S = bnfsignunit(bnf)
d = matsize(S)
S = matrix(d[1],d[2], i,j, if (S[i,j] < 0, 1,0))
S = concat(S, vectorv(d[1],i,1))
K = lift(matker(S * Mod(1,2)))

if(K, ex = mathnfmodid(K, 2), ex = 2*matid(d[1]))
units = concat(bnf.tu[2], bnf.fu)
result = vector(length(ex)-1, i, factorback([units, ex[,i+1]]))

print(result)

The code runs without errors. But I'm not getting expected results. For example, the shown polynomial of $x^3 + x^2 - 1$ gives me a result of $2x$ -- I note that this is just 2 times the unit returned by bnf.fu (which happens to already be totally positive). Meanwhile, I tried it on $x^4 + x - 1$ with result $(-2x, -x^3 - 1)$, neither of which is totally positive.

$\endgroup$
7
  • 2
    $\begingroup$ I do not know where you got that Pari code, but it is very old (for instance one now uses my() instead of local()). In particular, bnf.tufu does not exist. To make it work, simply replace bnf.tufu by concat(bnf.tu[2],bnf.fu). It should not give any more errors. $\endgroup$ Commented Nov 25 at 11:38
  • $\begingroup$ Thank you for your response/suggestion. I've edited my question with updates/clarification. Getting rid of tufu (and removing the calls to local() by not using function declarations) has produced code that doesn't raise errors. But I still don't get a basis of totally positive units, so something remains incorrect. I appreciate any insight or clarification on what is happening so that I can either (a) correct the above code, or (b) understand the algorithm itself so that I can code it in Sage myself. $\endgroup$
    – xion3582
    Commented Nov 25 at 17:44
  • 2
    $\begingroup$ Since you'r getting results like $2x$ and $-2x$ which are not units at all, while $x^2$ and $x^{-2}$ are positive units, you might be somehow computing $\sum_i c_i u_i$ instead of $\prod_i u_i^{c_i}$ (where $u_i$ are generators of the unit group). $\endgroup$ Commented Nov 25 at 17:53
  • 2
    $\begingroup$ Might be also useful to ask at: ask.sagemath.org/questions/scope:all/sort:activity-desc/page:1 $\endgroup$ Commented Nov 25 at 17:59
  • 4
    $\begingroup$ your factorback should not have [ ]: write factorback(units,ex[,i+1]). In any case, MO is not the forum to debug code, please write to the Sage or Pari maintainers instead. The result [Mod(x,x^3+x^2-1)] is correct in this example. $\endgroup$ Commented Nov 25 at 19:10

0

You must log in to answer this question.