Search code examples
polynomialsparipari-gp

Returning the factors of a polynomial as a vector in Pari/GP


When using factor, Pari prints the factors of a polynomial and their multiplicities. When using, say, polcyclofactors, however, the cyclotomic factors of the polynomial are listed as a vector, without multiplicity.

Is there are way to mimic polcyclofactors when just simply factoring polynomials? So, to just display the factors of the polynomial as a vector, without worrying about multiplicities?


Solution

  • Yes. The function factor returns a two column matrix. If you are only interested in the primes, not the multiplicities you can select just the first column:

    For example:

    factor(120)[,1]
    

    If you were only interested in the multiplicities you would do [,2]. If you need the result as a vector rather than a column vector (the two types are mostly interchangeable), then you also need to add a conversion:

    Vec(factor(120)[,1])
    

    Although, I have done my examples with an integer, it also works with polynomials.

    Vec(factor((1+x)^7*(1+x^2)^3)[,1])