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.Mon, 14 Mar 2022 20:39:15 +0100Multivariate polynomial ring with total degree no larger than nhttps://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/Hello everyone,
I need to compute the product: $f(x_1) f(x_2) ... f(x_n)$, where $f$ is a polynomial
of degree $n$, and I do not need the part with total degree larger than $n$.
To reduce the computation complexity, I think it would be helpful to construct
an $n$-variable multivariate polynomial ring, with terms total degree no larger
than $n$. I found the following two possible ways to do this, however, I could not
make either of them work for my settings.
1. Create a multivariate polynomial ring then quotient out every monomial
with total degree larger than $n$. However I do not know how to express
this ideal.
Q = PolynomialRing(QQ, n, 'x')
x = Q.gens()
2. I found a suggestion to use a function `max_degree` for polynomial rings at
- [Ask Sage question 55842: Set of polynomials under a certain degree](https://ask.sagemath.org/question/55842)
However, it seems there is no `max_total_degree` function for the multivariate case.
I am new to Python, Sage, and this community, so thank you in advance
for your helpful suggestions and comments!Fri, 11 Mar 2022 17:38:44 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/Comment by timaeus for <p>Hello everyone,</p>
<p>I need to compute the product: $f(x_1) f(x_2) ... f(x_n)$, where $f$ is a polynomial
of degree $n$, and I do not need the part with total degree larger than $n$.
To reduce the computation complexity, I think it would be helpful to construct
an $n$-variable multivariate polynomial ring, with terms total degree no larger
than $n$. I found the following two possible ways to do this, however, I could not
make either of them work for my settings. </p>
<ol>
<li><p>Create a multivariate polynomial ring then quotient out every monomial
with total degree larger than $n$. However I do not know how to express
this ideal.</p>
<pre><code>Q = PolynomialRing(QQ, n, 'x')
x = Q.gens()
</code></pre></li>
<li><p>I found a suggestion to use a function <code>max_degree</code> for polynomial rings at</p>
<ul>
<li><a href="https://ask.sagemath.org/question/55842">Ask Sage question 55842: Set of polynomials under a certain degree</a></li>
</ul>
<p>However, it seems there is no <code>max_total_degree</code> function for the multivariate case. </p></li>
</ol>
<p>I am new to Python, Sage, and this community, so thank you in advance
for your helpful suggestions and comments!</p>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61485#post-id-61485Thank you very much for fixing my link and your comment!Sun, 13 Mar 2022 01:52:44 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61485#post-id-61485Comment by slelievre for <p>Hello everyone,</p>
<p>I need to compute the product: $f(x_1) f(x_2) ... f(x_n)$, where $f$ is a polynomial
of degree $n$, and I do not need the part with total degree larger than $n$.
To reduce the computation complexity, I think it would be helpful to construct
an $n$-variable multivariate polynomial ring, with terms total degree no larger
than $n$. I found the following two possible ways to do this, however, I could not
make either of them work for my settings. </p>
<ol>
<li><p>Create a multivariate polynomial ring then quotient out every monomial
with total degree larger than $n$. However I do not know how to express
this ideal.</p>
<pre><code>Q = PolynomialRing(QQ, n, 'x')
x = Q.gens()
</code></pre></li>
<li><p>I found a suggestion to use a function <code>max_degree</code> for polynomial rings at</p>
<ul>
<li><a href="https://ask.sagemath.org/question/55842">Ask Sage question 55842: Set of polynomials under a certain degree</a></li>
</ul>
<p>However, it seems there is no <code>max_total_degree</code> function for the multivariate case. </p></li>
</ol>
<p>I am new to Python, Sage, and this community, so thank you in advance
for your helpful suggestions and comments!</p>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61482#post-id-61482To post links as a new user, insert spaces in them. Someone can then fix them.
Example: https ://doc .sagemath .orgSat, 12 Mar 2022 18:10:33 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61482#post-id-61482Comment by slelievre for <p>Hello everyone,</p>
<p>I need to compute the product: $f(x_1) f(x_2) ... f(x_n)$, where $f$ is a polynomial
of degree $n$, and I do not need the part with total degree larger than $n$.
To reduce the computation complexity, I think it would be helpful to construct
an $n$-variable multivariate polynomial ring, with terms total degree no larger
than $n$. I found the following two possible ways to do this, however, I could not
make either of them work for my settings. </p>
<ol>
<li><p>Create a multivariate polynomial ring then quotient out every monomial
with total degree larger than $n$. However I do not know how to express
this ideal.</p>
<pre><code>Q = PolynomialRing(QQ, n, 'x')
x = Q.gens()
</code></pre></li>
<li><p>I found a suggestion to use a function <code>max_degree</code> for polynomial rings at</p>
<ul>
<li><a href="https://ask.sagemath.org/question/55842">Ask Sage question 55842: Set of polynomials under a certain degree</a></li>
</ul>
<p>However, it seems there is no <code>max_total_degree</code> function for the multivariate case. </p></li>
</ol>
<p>I am new to Python, Sage, and this community, so thank you in advance
for your helpful suggestions and comments!</p>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61481#post-id-61481Welcome to Ask Sage! Thank you for your question.Sat, 12 Mar 2022 18:09:31 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61481#post-id-61481Answer by Max Alekseyev for <p>Hello everyone,</p>
<p>I need to compute the product: $f(x_1) f(x_2) ... f(x_n)$, where $f$ is a polynomial
of degree $n$, and I do not need the part with total degree larger than $n$.
To reduce the computation complexity, I think it would be helpful to construct
an $n$-variable multivariate polynomial ring, with terms total degree no larger
than $n$. I found the following two possible ways to do this, however, I could not
make either of them work for my settings. </p>
<ol>
<li><p>Create a multivariate polynomial ring then quotient out every monomial
with total degree larger than $n$. However I do not know how to express
this ideal.</p>
<pre><code>Q = PolynomialRing(QQ, n, 'x')
x = Q.gens()
</code></pre></li>
<li><p>I found a suggestion to use a function <code>max_degree</code> for polynomial rings at</p>
<ul>
<li><a href="https://ask.sagemath.org/question/55842">Ask Sage question 55842: Set of polynomials under a certain degree</a></li>
</ul>
<p>However, it seems there is no <code>max_total_degree</code> function for the multivariate case. </p></li>
</ol>
<p>I am new to Python, Sage, and this community, so thank you in advance
for your helpful suggestions and comments!</p>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?answer=61484#post-id-61484Ignoring parts with total degree $\geq d$ suggests that power series with precision $d$ are more suitable in this setting:
d = 3
Q = PowerSeriesRing(QQ, 3, 'x', default_prec=d)
x = [g.add_bigoh(d) for g in Q.gens()]
f = x[0]^4
print( f.add_bigoh(d).polynomial() )Sat, 12 Mar 2022 22:00:33 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?answer=61484#post-id-61484Comment by Max Alekseyev for <p>Ignoring parts with total degree $\geq d$ suggests that power series with precision $d$ are more suitable in this setting:</p>
<pre><code>d = 3
Q = PowerSeriesRing(QQ, 3, 'x', default_prec=d)
x = [g.add_bigoh(d) for g in Q.gens()]
f = x[0]^4
print( f.add_bigoh(d).polynomial() )
</code></pre>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61503#post-id-61503Define `g` in Python way:
def g(y):
return y^2Mon, 14 Mar 2022 20:39:15 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61503#post-id-61503Comment by timaeus for <p>Ignoring parts with total degree $\geq d$ suggests that power series with precision $d$ are more suitable in this setting:</p>
<pre><code>d = 3
Q = PowerSeriesRing(QQ, 3, 'x', default_prec=d)
x = [g.add_bigoh(d) for g in Q.gens()]
f = x[0]^4
print( f.add_bigoh(d).polynomial() )
</code></pre>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61498#post-id-61498Thank you very much for your answer! It works fine now. By the way, do you know how to fix this problem under your settings?
g(y) = y^2; g(x[0])
This code used to work when Q is a polynomial ring, but it seems get some trouble when Q is a power series ring.Mon, 14 Mar 2022 16:50:24 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61498#post-id-61498Comment by Max Alekseyev for <p>Ignoring parts with total degree $\geq d$ suggests that power series with precision $d$ are more suitable in this setting:</p>
<pre><code>d = 3
Q = PowerSeriesRing(QQ, 3, 'x', default_prec=d)
x = [g.add_bigoh(d) for g in Q.gens()]
f = x[0]^4
print( f.add_bigoh(d).polynomial() )
</code></pre>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61492#post-id-61492The reason is that Sage tries to keep precision as large as possible, and for the 4th power the precision becomes 6. It can be always decreased by `.add_bigoh()` and the resulting series can be converted into a polynomial via `.polynomial()` method. I've updated an example in my answer accordingly.Sun, 13 Mar 2022 15:58:06 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61492#post-id-61492Comment by timaeus for <p>Ignoring parts with total degree $\geq d$ suggests that power series with precision $d$ are more suitable in this setting:</p>
<pre><code>d = 3
Q = PowerSeriesRing(QQ, 3, 'x', default_prec=d)
x = [g.add_bigoh(d) for g in Q.gens()]
f = x[0]^4
print( f.add_bigoh(d).polynomial() )
</code></pre>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61488#post-id-61488P = PowerSeriesRing(QQ, 3, 'x', default_prec = 3); x = [g.add_bigoh(3) for g in P.gens()]; f=P(x[0]^4); f
The above code still yields x0^4 + O(x0, x1, x2)^6 instead of 0. Also, since I need to convert the product into symmetric polynomials afterwards, the introducing of the big O seems cause more trouble...Sun, 13 Mar 2022 08:20:20 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61488#post-id-61488Comment by Max Alekseyev for <p>Ignoring parts with total degree $\geq d$ suggests that power series with precision $d$ are more suitable in this setting:</p>
<pre><code>d = 3
Q = PowerSeriesRing(QQ, 3, 'x', default_prec=d)
x = [g.add_bigoh(d) for g in Q.gens()]
f = x[0]^4
print( f.add_bigoh(d).polynomial() )
</code></pre>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61487#post-id-61487It turns out generators do not inherit default precision, so it needs to be added explicitly. In your example, it would be `x = [g.add_bigoh(3) for g in Q.gens()]`.Sun, 13 Mar 2022 03:17:18 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61487#post-id-61487Comment by timaeus for <p>Ignoring parts with total degree $\geq d$ suggests that power series with precision $d$ are more suitable in this setting:</p>
<pre><code>d = 3
Q = PowerSeriesRing(QQ, 3, 'x', default_prec=d)
x = [g.add_bigoh(d) for g in Q.gens()]
f = x[0]^4
print( f.add_bigoh(d).polynomial() )
</code></pre>
https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61486#post-id-61486Thank you for your answer! I tried the following code:
`Q = PowerSeriesRing(QQ, 3, 'x', default_prec = 3); x = Q.gens(); f = x[0]^2; print(f^3)`
However I still get x0^6 here instead of an expected 0.Sun, 13 Mar 2022 02:00:57 +0100https://ask.sagemath.org/question/61470/multivariate-polynomial-ring-with-total-degree-no-larger-than-n/?comment=61486#post-id-61486