# How to differentiate in the Laurent polynomial ring? R.<x> = LaurentPolynomialRing(ZZ,1); R
f = x^2 - 2*x^-2
diff(f,x)


Expected: 2*x+4/x^3

TypeError: no canonical coercion from Univariate Laurent Polynomial Ring in x over Integer Ring to Symbolic Ring.

edit retag close merge delete

Sort by » oldest newest most voted

I don't think this is implemented yet. You can make a feature request for it on the bug tracking system http://trac.sagemath.org.

more

Hm, would this be worthwhile and have a chance to be done? What do longtime contributors think?

Doesn't look very hard to implement. I'd say it has a fair chance of being done rapidly. I personally wouldn't mind adding the method as soon as I have a spare hour.

The antiderivative is more problematic: what would the parent of integral(1/x) be? If you need this, you're better off with the symbolic ring.

Hey I don't understand.. But it is perhaps the answer.

sage: R.<x> = LaurentPolynomialRing(ZZ,1); R
Univariate Laurent Polynomial Ring in x over Integer Ring
sage: f(x) = x^2 - 2*x^-2
sage: f.diff(x)
x |--> 2*x + 4/x^3


I hope it helps.

sage: R.<x> = LaurentPolynomialRing(ZZ,1); R
Univariate Laurent Polynomial Ring in x over Integer Ring
sage: f = x^2 - 2*x^-2
sage: ff = f; ff
x^2 - 2*x^-2
sage: f(x) = x^2 - 2*x^-2
sage: f
x |--> x^2 - 2/x^2
sage: diff(ff,x)
0
sage: ff
x^2 - 2*x^-2
sage: f.diff(x)
x |--> 2*x + 4/x^3
sage: diff?
sage: diff(ff)
0


The way of defining the "ff" is not good. Do we have to define a polynomial like this, in order to compute its derivative conveniently?

p(x) = x**2 + a1*x + a2


more

Your answer uses symbolic variables, rather than Laurent polynomials. It is a good workaround, given that Laurent polynomials do not have a derivative method. Note that with ordinary polynomials you do not have to use symbolics to differentiate: sage: R = PolynomialRing(QQ, 'x') sage: x = R.gen() sage: diff(x^2) 2*x sage: (x^2).derivative() 2*x

Comment the line "R.<x> = LaurentPolynomialRing(ZZ,1)" and you get the same result. Thus you do not work with the LaurentPolynomialRing.