next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc > rings > factoring polynomials

factoring polynomials

Polynomials can be factored with factor. Factorization works in polynomial rings over prime finite fields, ZZ, or QQ.
i1 : R = ZZ/10007[a,b];
i2 : f = (2*a+3)^4 + 5

        4      3       2
o2 = 16a  + 96a  + 216a  + 216a + 86

o2 : R
i3 : g = (2*a+b+1)^3

       3      2        2    3      2             2
o3 = 8a  + 12a b + 6a*b  + b  + 12a  + 12a*b + 3b  + 6a + 3b + 1

o3 : R
i4 : S = factor f

                         2
o4 = (a - 402)(a + 405)(a  + 3a - 2301)(16)

o4 : Expression of class Product
i5 : T = factor g

                       3
o5 = (a - 5003b - 5003) (8)

o5 : Expression of class Product

The results have been packaged for easy viewing. The number of factors is obtained using

i6 : #T

o6 = 2
Each factor is represented as a power (exponents equal to 1 don't appear in the display.) The parts can be extracted with #.
i7 : T#0

                       3
o7 = (a - 5003b - 5003)

o7 : Expression of class Power
i8 : T#0#0

o8 = a - 5003b - 5003

o8 : R
i9 : T#0#1

o9 = 3