# Computing square free part of a multivariate polynomial

In one of the algorithms I am working on, there is a part asking for the square-free part of a multivariate polynomial. I can find it using a complicated way, namely,

I = ideal(f)


But I think this must be a very inefficient way to do it. Is there a better way? Thank you!

edit retag close merge delete

Could you provide a way to construct some interesting f ?

Do you mean an example? For example, if f is in Q[x,y,z], then f 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).

Sort by » oldest newest most voted

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
(x + y + z, 3)
sage: fi
(z^4 + y^3 + x^2, 7)
sage: # fi    # -> error, so there should be something to get the full information.

sage: type( fi )
<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)

more