ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 04 Jul 2012 14:49:48 +0200Polynomial: find the common factorhttps://ask.sagemath.org/question/9132/polynomial-find-the-common-factor/Hello, assuming I have a polynomial like this:
sage: var('y, x')
(y, x)
sage: y = x^2 + 6*x^3 + 3*x^4
When I use collect_common_factors(), I get:
(3*x^2 + 6*x + 1)*x^2
Now, is there a way to know which are the common_factors collected?
In this case, I'm expecting this output:
x^2
Thank you everyone!Wed, 04 Jul 2012 10:25:29 +0200https://ask.sagemath.org/question/9132/polynomial-find-the-common-factor/Answer by Volker Braun for <p>Hello, assuming I have a polynomial like this:</p>
<pre><code>sage: var('y, x')
(y, x)
sage: y = x^2 + 6*x^3 + 3*x^4
</code></pre>
<p>When I use collect_common_factors(), I get:</p>
<pre><code>(3*x^2 + 6*x + 1)*x^2
</code></pre>
<p>Now, is there a way to know which are the common_factors collected?</p>
<p>In this case, I'm expecting this output:</p>
<pre><code>x^2
</code></pre>
<p>Thank you everyone!</p>
https://ask.sagemath.org/question/9132/polynomial-find-the-common-factor/?answer=13796#post-id-13796If are dealing with polynomials only you should look into using polynomial rings.
sage: R.<x> = QQ[]
sage: y = x^2 + 6*x^3 + 3*x^4
sage: y.factor()
(3) * x^2 * (x^2 + 2*x + 1/3)
sage: list(_)
[(x, 2), (x^2 + 2*x + 1/3, 1)]
Wed, 04 Jul 2012 14:49:48 +0200https://ask.sagemath.org/question/9132/polynomial-find-the-common-factor/?answer=13796#post-id-13796Answer by calc314 for <p>Hello, assuming I have a polynomial like this:</p>
<pre><code>sage: var('y, x')
(y, x)
sage: y = x^2 + 6*x^3 + 3*x^4
</code></pre>
<p>When I use collect_common_factors(), I get:</p>
<pre><code>(3*x^2 + 6*x + 1)*x^2
</code></pre>
<p>Now, is there a way to know which are the common_factors collected?</p>
<p>In this case, I'm expecting this output:</p>
<pre><code>x^2
</code></pre>
<p>Thank you everyone!</p>
https://ask.sagemath.org/question/9132/polynomial-find-the-common-factor/?answer=13795#post-id-13795I can't find a specific function to get the terms out of a polynomial, but here is some code that should do the job for a function just of x.
var('x,y')
y = 2*x^2 + x^3 + 10*x^4
info=y.coeffs()
terms=[a[0]*x^a[1] for a in info]
gcd(terms)Wed, 04 Jul 2012 14:14:24 +0200https://ask.sagemath.org/question/9132/polynomial-find-the-common-factor/?answer=13795#post-id-13795