Solution by example. Suppose we want to associate for the special polynomial $f$ from
R.<x,y,z> = QQ[]
f = (x+y+z)^3 * (x^2+y^3+z^4)^7
the polynomial g, which is the product of the two prime factors, taken each to the power one.
The one-liner does the job, we require a successful factorization:
g = prod( [ factor for (factor,power) in f.factor() ] )
Indeed:
sage: R.<x,y,z> = QQ[]
sage: f = (x+y+z)^3 * (x^2+y^3+z^4)^7
sage: g = prod( [ factor for (factor,power) in f.factor() ] )
sage: g
x*z^4 + y*z^4 + z^5 + x*y^3 + y^4 + y^3*z + x^3 + x^2*y + x^2*z
sage: g.factor()
(x + y + z) * (z^4 + y^3 + x^2)
Some more lines that play with the factorization instance:
sage: fi = f.factor()
sage: type( fi )
<class 'sage.structure.factorization.Factorization'>
sage: fi[0]
(x + y + z, 3)
sage: fi[1]
(z^4 + y^3 + x^2, 7)
sage: # fi[2] # -> error, so there should be something to get the full information.
sage: type( fi[0] )
<type 'tuple'>
sage: # how many factors there are?
sage: len( fi )
2
sage: # the above uses the iterator of fi,
sage: for factor, power in fi:
....: print factor, power
....:
x + y + z 3
z^4 + y^3 + x^2 7
sage: # alternatively:
sage: for factor in fi: print factor
(x + y + z, 3)
(z^4 + y^3 + x^2, 7)
Could you provide a way to construct some interesting
f
?Do you mean an example? For example, if
f
is inQ[x,y,z]
, thenf
could be(x-y)^2*(y-z)^2*(x+y+3)
. Then the square free part would be(x-y)*(y-z)*(x+y+3)
.