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.Sat, 19 Nov 2022 17:12:31 +0100Derivative in infinite polynomial ringhttps://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/ I am defining my ring as R.<x>=InfinitePolynomialRing(QQ), and this should give me ring with variables x[1],x[2],... etc. right? Now I want to differentiate a polynomial with respect to x[1] variable. So I defined f=x[1]^3 (for example). I am trying f.derivative(x[1]) but that does not work. It shows " 'typeerror': argument 'var' has incorrect type (expected sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular, got InfinitePolynomial_dense)."
Can someone please explain what is wrong and what I should do to fix it?
Sat, 05 Sep 2020 18:32:15 +0200https://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/Answer by Emmanuel Charpentier for <p>I am defining my ring as R.<x>=InfinitePolynomialRing(QQ), and this should give me ring with variables x[1],x[2],... etc. right? Now I want to differentiate a polynomial with respect to x[1] variable. So I defined f=x[1]^3 (for example). I am trying f.derivative(x[1]) but that does not work. It shows " 'typeerror': argument 'var' has incorrect type (expected sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular, got InfinitePolynomial_dense)."
Can someone please explain what is wrong and what I should do to fix it?</p>
https://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/?answer=53327#post-id-53327A nice one...
Consider
sage: R.<x>=InfinitePolynomialRing(QQ)
sage: f=R(x[1]^3)
Note that :
sage: [u.parent() for u in f.variables()]
[Multivariate Polynomial Ring in x_2, x_1, x_0 over Rational Field]
(yes, I played with `R` a bit...) contrasting with:
sage: x[1].parent()
Infinite polynomial ring in x over Rational Field
Hence the error you noticed. However :
sage: x[1] in f.variables()
True
It is there ; you just have to find it :
sage: f.variables().index(x[1])
0
Hence the (awkward) :
sage: f.derivative(f.variables()[f.variables().index(x[1])])
3*x_1^2
A better way would be to cast `x[1]` to the proper class. Finding which isn't intuitive...
Sat, 05 Sep 2020 20:53:08 +0200https://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/?answer=53327#post-id-53327Comment by Thrash for <p>A nice one...</p>
<p>Consider</p>
<pre><code>sage: R.<x>=InfinitePolynomialRing(QQ)
sage: f=R(x[1]^3)
</code></pre>
<p>Note that :</p>
<pre><code>sage: [u.parent() for u in f.variables()]
[Multivariate Polynomial Ring in x_2, x_1, x_0 over Rational Field]
</code></pre>
<p>(yes, I played with <code>R</code> a bit...) contrasting with:</p>
<pre><code>sage: x[1].parent()
Infinite polynomial ring in x over Rational Field
</code></pre>
<p>Hence the error you noticed. However :</p>
<pre><code>sage: x[1] in f.variables()
True
</code></pre>
<p>It is there ; you just have to find it :</p>
<pre><code>sage: f.variables().index(x[1])
0
</code></pre>
<p>Hence the (awkward) :</p>
<pre><code>sage: f.derivative(f.variables()[f.variables().index(x[1])])
3*x_1^2
</code></pre>
<p>A better way would be to cast <code>x[1]</code> to the proper class. Finding which isn't intuitive... </p>
https://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/?comment=64920#post-id-64920Can this nonconformity of "Multivariate Polynomial Ring" and "Infinite polynomial ring" be brought into conformity so that operations (for example the derivative) can be executed intuitively?Sat, 19 Nov 2022 17:12:31 +0100https://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/?comment=64920#post-id-64920Comment by mathstudent for <p>A nice one...</p>
<p>Consider</p>
<pre><code>sage: R.<x>=InfinitePolynomialRing(QQ)
sage: f=R(x[1]^3)
</code></pre>
<p>Note that :</p>
<pre><code>sage: [u.parent() for u in f.variables()]
[Multivariate Polynomial Ring in x_2, x_1, x_0 over Rational Field]
</code></pre>
<p>(yes, I played with <code>R</code> a bit...) contrasting with:</p>
<pre><code>sage: x[1].parent()
Infinite polynomial ring in x over Rational Field
</code></pre>
<p>Hence the error you noticed. However :</p>
<pre><code>sage: x[1] in f.variables()
True
</code></pre>
<p>It is there ; you just have to find it :</p>
<pre><code>sage: f.variables().index(x[1])
0
</code></pre>
<p>Hence the (awkward) :</p>
<pre><code>sage: f.derivative(f.variables()[f.variables().index(x[1])])
3*x_1^2
</code></pre>
<p>A better way would be to cast <code>x[1]</code> to the proper class. Finding which isn't intuitive... </p>
https://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/?comment=53334#post-id-53334Thanks a lot.Sun, 06 Sep 2020 10:42:42 +0200https://ask.sagemath.org/question/53319/derivative-in-infinite-polynomial-ring/?comment=53334#post-id-53334