ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 20 Mar 2017 16:38:49 -0500Computing square free part of a multivariate polynomialhttps://ask.sagemath.org/question/36768/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)
IRad = I.radical().groebner_basis()
But I think this must be a very inefficient way to do it. Is there a better way? Thank you!Tue, 28 Feb 2017 14:49:14 -0600https://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/Comment by KittyL for <p>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, </p>
<pre><code>I = ideal(f)
IRad = I.radical().groebner_basis()
</code></pre>
<p>But I think this must be a very inefficient way to do it. Is there a better way? Thank you!</p>
https://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/?comment=36771#post-id-36771Do 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)`.Tue, 28 Feb 2017 16:53:33 -0600https://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/?comment=36771#post-id-36771Comment by tmonteil for <p>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, </p>
<pre><code>I = ideal(f)
IRad = I.radical().groebner_basis()
</code></pre>
<p>But I think this must be a very inefficient way to do it. Is there a better way? Thank you!</p>
https://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/?comment=36769#post-id-36769Could you provide a way to construct some interesting `f` ?Tue, 28 Feb 2017 15:49:47 -0600https://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/?comment=36769#post-id-36769Answer by dan_fulea for <p>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, </p>
<pre><code>I = ideal(f)
IRad = I.radical().groebner_basis()
</code></pre>
<p>But I think this must be a very inefficient way to do it. Is there a better way? Thank you!</p>
https://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/?answer=37010#post-id-37010Solution 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)
Mon, 20 Mar 2017 16:38:49 -0500https://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/?answer=37010#post-id-37010