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.Thu, 09 Sep 2021 15:56:09 +0200Sturm polynomials with polynomial coefficients. How?https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/We are stuck with the following problem: we want Sage to compute Sturm polynomials for a polynomial with coefficients in a field of rational functions. As long as the coefficients are actually functions, no problem:
R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1)/(k-1) *a + 1)
=> [((2*k + 1)/(k - 1))*a + 1, (2*k + 1)/(k - 1)]
The problem is that unless the coeffients are actual functions, Sage refuses to do it:
R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1) *a + 1)
=> [...
~/Applications/SageMath/local/lib/python3.9/site-packages/sage/rings/polynomial/polynomial_element.pyx in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense.quo_rem (build/cythonized/sage/rings/polynomial/polynomial_element.c:94403)()
11434 q = R(q)
11435 except TypeError:
> 11436 raise ArithmeticError("division non exact (consider coercing to polynomials over the fraction field)")
11437 for j from n+k-2 >= j >= k:
11438 x[j] -= q * y[j-k]
ArithmeticError: division non exact (consider coercing to polynomials over the fraction field)
We tried several way to coerce, with no success. Suggestions welcome!
Wed, 08 Sep 2021 08:51:15 +0200https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/Comment by Max Alekseyev for <p>We are stuck with the following problem: we want Sage to compute Sturm polynomials for a polynomial with coefficients in a field of rational functions. As long as the coefficients are actually functions, no problem:</p>
<pre><code>R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1)/(k-1) *a + 1)
=> [((2*k + 1)/(k - 1))*a + 1, (2*k + 1)/(k - 1)]
</code></pre>
<p>The problem is that unless the coeffients are actual functions, Sage refuses to do it:</p>
<pre><code>R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1) *a + 1)
=> [...
~/Applications/SageMath/local/lib/python3.9/site-packages/sage/rings/polynomial/polynomial_element.pyx in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense.quo_rem (build/cythonized/sage/rings/polynomial/polynomial_element.c:94403)()
11434 q = R(q)
11435 except TypeError:
> 11436 raise ArithmeticError("division non exact (consider coercing to polynomials over the fraction field)")
11437 for j from n+k-2 >= j >= k:
11438 x[j] -= q * y[j-k]
ArithmeticError: division non exact (consider coercing to polynomials over the fraction field)
</code></pre>
<p>We tried several way to coerce, with no success. Suggestions welcome!</p>
https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/?comment=58924#post-id-58924The coefficient `(2*k+1)/(k-1)` is not a polynomial but a rational function in `k`. So, "polynomial coefficients" are irrelevant here and the base ring should be a fraction field (not a polynomial ring) as FrédéricC suggested above.Thu, 09 Sep 2021 15:56:09 +0200https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/?comment=58924#post-id-58924Comment by FrédéricC for <p>We are stuck with the following problem: we want Sage to compute Sturm polynomials for a polynomial with coefficients in a field of rational functions. As long as the coefficients are actually functions, no problem:</p>
<pre><code>R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1)/(k-1) *a + 1)
=> [((2*k + 1)/(k - 1))*a + 1, (2*k + 1)/(k - 1)]
</code></pre>
<p>The problem is that unless the coeffients are actual functions, Sage refuses to do it:</p>
<pre><code>R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1) *a + 1)
=> [...
~/Applications/SageMath/local/lib/python3.9/site-packages/sage/rings/polynomial/polynomial_element.pyx in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense.quo_rem (build/cythonized/sage/rings/polynomial/polynomial_element.c:94403)()
11434 q = R(q)
11435 except TypeError:
> 11436 raise ArithmeticError("division non exact (consider coercing to polynomials over the fraction field)")
11437 for j from n+k-2 >= j >= k:
11438 x[j] -= q * y[j-k]
ArithmeticError: division non exact (consider coercing to polynomials over the fraction field)
</code></pre>
<p>We tried several way to coerce, with no success. Suggestions welcome!</p>
https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/?comment=58898#post-id-58898What about using `S.<a> = PolynomialRing(R.fraction_field())` ?Wed, 08 Sep 2021 13:20:07 +0200https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/?comment=58898#post-id-58898Answer by vigna for <p>We are stuck with the following problem: we want Sage to compute Sturm polynomials for a polynomial with coefficients in a field of rational functions. As long as the coefficients are actually functions, no problem:</p>
<pre><code>R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1)/(k-1) *a + 1)
=> [((2*k + 1)/(k - 1))*a + 1, (2*k + 1)/(k - 1)]
</code></pre>
<p>The problem is that unless the coeffients are actual functions, Sage refuses to do it:</p>
<pre><code>R.<k> = PolynomialRing(QQ)
S.<a> = PolynomialRing(R)
sturm((2*k+1) *a + 1)
=> [...
~/Applications/SageMath/local/lib/python3.9/site-packages/sage/rings/polynomial/polynomial_element.pyx in sage.rings.polynomial.polynomial_element.Polynomial_generic_dense.quo_rem (build/cythonized/sage/rings/polynomial/polynomial_element.c:94403)()
11434 q = R(q)
11435 except TypeError:
> 11436 raise ArithmeticError("division non exact (consider coercing to polynomials over the fraction field)")
11437 for j from n+k-2 >= j >= k:
11438 x[j] -= q * y[j-k]
ArithmeticError: division non exact (consider coercing to polynomials over the fraction field)
</code></pre>
<p>We tried several way to coerce, with no success. Suggestions welcome!</p>
https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/?answer=58894#post-id-58894We tried a bit more and it turns out that dividing by a small irreducible polynomial will actually work:
sturm(((2*k+1) *a + 1)/(k^2+1))
=> [((2*k + 1)/(k^2 + 1))*a + 1/(k^2 + 1), (2*k + 1)/(k^2 + 1)]
The spurious factor cannot change the number of sign changes, so that's a workaround.
Wed, 08 Sep 2021 09:31:55 +0200https://ask.sagemath.org/question/58893/sturm-polynomials-with-polynomial-coefficients-how/?answer=58894#post-id-58894