Karim Belabas on Sat, 20 Jul 2013 04:20:26 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Help with algebraic numbers


Bonjour Christelle,

* Christelle Vincent [2013-07-20 03:17]:
> I am having some trouble writing code dealing with algebraic numbers,
> basically because I can't anticipate if Pari will return a t_INT or a
> t_COL to describe the algebraic number. Is there an easy way to coerce
> one into the other mechanically, no matter which one comes out?
> Alternatively, is there a way to ensure that one of the two always
> comes out (whichever one, as long as I know which one in advance)?

nfalgtobasis(K, x) will coerce x into a t_COL (describing an
algebraic number in terms of K.zk)

> More precisely, I am looking at the output of rnfidealreltoabs. The
> relative matrix A which is the first component of the output might
> have entries that are either integers (if the element is rational) or
> a vector giving me the element in terms of the relative basis. I want
> to take an entry of the matrix, and have it as an algebraic number.

As a rule, you shouldn't have to care. All functions accepting an
algebraic number will be equally happy with a t_POL (implicitly modulo
K.pol), a t_POLMOD (modulo K.pol), a t_INT/t_FRAC (rational number), or
a t_COL.

Why do you need an explicit coercion ?

> If I get a vector I can do this by multiplying on the left by K.zk
> (where K is my field), and if I get an integer, I don't have to do
> that (and in fact multiplying by K.zk gives a vector which is not even
> the right number). Having to handle the two cases differently is a
> problem, because I want to be able to make the computation automatic.
> In other words, I need to be able to handle both occurrences in the
> same way. Is that possible?

( Yes. nfalgtobasis(K, x); also, matalgtobasis(K, M) will coerce all
elements of the matrix/vector M into t_COL form. )

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`