Karim Belabas on Tue, 04 Sep 2007 11:19:04 +0200


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

Re: polynomial factoring question


* McLaughlin, James [2007-09-04 05:24]:
> What is the best way to get the irreducible factors (over Z) of a polynomial as a list?
>  
> For example, for x^16-2^16, I would like the output to be 
> [x - 2, x + 2, x^2 + 4, x^4 + 16, x^8 + 256]
>  
> facs=factor(x^16-2^16)  gives
> [x - 2 1]
> [x + 2 1]
> [x^2 + 4 1]
> [x^4 + 16 1]
> [x^8 + 256 1]

facts[,1] returns the first column of the above 5 x 2 matrix.

> ls=[ ]; for(j=1, length(facs), ls=concat(ls, facs[j,1]););  
> does not work since length(facs)=2 
> (this seems strange to me - I would have thought length(facs) = 5?)

#facs [ = length(facs) ] is the number of columns, here 2.


matsize(facs)[1] would be the number of lines.

You may then easily adapt the above code, but

  vector( j, matsize(facs)[1], facs[j,1] )

would be a little more efficient (linear vs quadratic). 

> Maybe there is some simple command in the ? lists that I am missing,
> but I could not find it.

?? factor     would tell you the result is a matrix

?? component  would tell how to handle matrix / vector components.

Cheers,

    K.B.
--
Karim Belabas                  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-bordeaux.fr/~belabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`