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.Sun, 31 Oct 2021 03:17:27 +0100gcd on polynomials over ZZhttps://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/In Sage 9.4, in the following code:
P.<x> = QQ[]
pol = 2*x^2 + 4*x + 6
print( gcd(pol) )
print( gcd(pol.change_ring(ZZ)) )
The first `gcd` works fine, while the second `gcd` results in
`TypeError: object of type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' has no len()`
There is a workaround by using `gcd(pol.coefficients())`, but I wonder if above error is a bug.
PS. This gcd is essentially what is called the *content* of a polynomial. Surprisingly, `.content()` is defined for multivariate polynomials but not for univariate ones.Fri, 29 Oct 2021 23:45:23 +0200https://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/Comment by Max Alekseyev for <p>In Sage 9.4, in the following code:</p>
<pre><code>P.<x> = QQ[]
pol = 2*x^2 + 4*x + 6
print( gcd(pol) )
print( gcd(pol.change_ring(ZZ)) )
</code></pre>
<p>The first <code>gcd</code> works fine, while the second <code>gcd</code> results in </p>
<p><code>TypeError: object of type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' has no len()</code></p>
<p>There is a workaround by using <code>gcd(pol.coefficients())</code>, but I wonder if above error is a bug.</p>
<p>PS. This gcd is essentially what is called the <em>content</em> of a polynomial. Surprisingly, <code>.content()</code> is defined for multivariate polynomials but not for univariate ones.</p>
https://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/?comment=59550#post-id-59550That is good to know. Does 9.5 have `.content()` defined for univariate polynomials by any chance?Sun, 31 Oct 2021 03:17:27 +0100https://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/?comment=59550#post-id-59550Comment by tmonteil for <p>In Sage 9.4, in the following code:</p>
<pre><code>P.<x> = QQ[]
pol = 2*x^2 + 4*x + 6
print( gcd(pol) )
print( gcd(pol.change_ring(ZZ)) )
</code></pre>
<p>The first <code>gcd</code> works fine, while the second <code>gcd</code> results in </p>
<p><code>TypeError: object of type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' has no len()</code></p>
<p>There is a workaround by using <code>gcd(pol.coefficients())</code>, but I wonder if above error is a bug.</p>
<p>PS. This gcd is essentially what is called the <em>content</em> of a polynomial. Surprisingly, <code>.content()</code> is defined for multivariate polynomials but not for univariate ones.</p>
https://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/?comment=59543#post-id-59543It works for me on 9.5.beta4:
sage: P.<x> = QQ[]
....: pol = 2*x^2 + 4*x + 6
....: print( gcd(pol) )
....: print( gcd(pol.change_ring(ZZ)) )
2
2Sat, 30 Oct 2021 12:12:16 +0200https://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/?comment=59543#post-id-59543Comment by Emmanuel Charpentier for <p>In Sage 9.4, in the following code:</p>
<pre><code>P.<x> = QQ[]
pol = 2*x^2 + 4*x + 6
print( gcd(pol) )
print( gcd(pol.change_ring(ZZ)) )
</code></pre>
<p>The first <code>gcd</code> works fine, while the second <code>gcd</code> results in </p>
<p><code>TypeError: object of type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint' has no len()</code></p>
<p>There is a workaround by using <code>gcd(pol.coefficients())</code>, but I wonder if above error is a bug.</p>
<p>PS. This gcd is essentially what is called the <em>content</em> of a polynomial. Surprisingly, <code>.content()</code> is defined for multivariate polynomials but not for univariate ones.</p>
https://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/?comment=59542#post-id-59542This smells of an implementation oversight which, IMHO, should be filed as a bug...Sat, 30 Oct 2021 10:53:15 +0200https://ask.sagemath.org/question/59541/gcd-on-polynomials-over-zz/?comment=59542#post-id-59542