# Derivative in infinite polynomial ring

I am defining my ring as R.<x>=InfinitePolynomialRing(QQ), and this should give me ring with variables x,x,... etc. right? Now I want to differentiate a polynomial with respect to x variable. So I defined f=x^3 (for example). I am trying f.derivative(x) 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?

edit retag close merge delete

Sort by » oldest newest most voted

A nice one...

Consider

sage: R.<x>=InfinitePolynomialRing(QQ)
sage: f=R(x^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.parent()
Infinite polynomial ring in x over Rational Field


Hence the error you noticed. However :

sage: x in f.variables()
True


It is there ; you just have to find it :

sage: f.variables().index(x)
0


Hence the (awkward) :

sage: f.derivative(f.variables()[f.variables().index(x)])
3*x_1^2


A better way would be to cast x to the proper class. Finding which isn't intuitive...

more