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.Tue, 10 Apr 2012 15:42:46 +0200polynomials of derivative operatorhttps://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/Is there any way in Sage to evaluate expressions such as
p(x^2*d/dx + a + x - x^2*y) 1
where p() is a polynomial in one variable? The result would be a polynomial in a,x, and y.
Alternatively, can Sage evaluate
(1/f) p(d/dx) f
where f is a (non-polynomial) function of x and a and y?
Thanks very much.Wed, 04 Apr 2012 23:32:12 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/Comment by Daniel Friedan for <p>Is there any way in Sage to evaluate expressions such as
p(x^2<em>d/dx + a + x - x^2</em>y) 1
where p() is a polynomial in one variable? The result would be a polynomial in a,x, and y.</p>
<p>Alternatively, can Sage evaluate
(1/f) p(d/dx) f
where f is a (non-polynomial) function of x and a and y?</p>
<p>Thanks very much.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19971#post-id-19971Here's an example. Let p(y)=y^2. Then p(d/dx + x^2) = (d/dx)^2 + 2 x^2 d/dx + 2 x + x^4. Acting on 1, this operator gives 2 x + x^4.Fri, 06 Apr 2012 16:06:59 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19971#post-id-19971Comment by Daniel Friedan for <p>Is there any way in Sage to evaluate expressions such as
p(x^2<em>d/dx + a + x - x^2</em>y) 1
where p() is a polynomial in one variable? The result would be a polynomial in a,x, and y.</p>
<p>Alternatively, can Sage evaluate
(1/f) p(d/dx) f
where f is a (non-polynomial) function of x and a and y?</p>
<p>Thanks very much.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19973#post-id-19973Sorry I wasn't clear. Try a simpler example. p is a polynomial in 1 variable. p(d/dx + x^2) is a differential operator. p(d/dx + x^2) 1 is that operator acting on the constant function. The result is a polynomial in x. I'd like to calculate that polynomial in Sage. I have a workaround, using Fourier transforms, that Sage can do via Macsyma, but I suspect an algebraic method would scale better.Fri, 06 Apr 2012 15:56:47 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19973#post-id-19973Comment by jdc for <p>Is there any way in Sage to evaluate expressions such as
p(x^2<em>d/dx + a + x - x^2</em>y) 1
where p() is a polynomial in one variable? The result would be a polynomial in a,x, and y.</p>
<p>Alternatively, can Sage evaluate
(1/f) p(d/dx) f
where f is a (non-polynomial) function of x and a and y?</p>
<p>Thanks very much.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19982#post-id-19982I'm trying to understand exactly what you mean. Wouldn't your answer still (possibly) involve d/dx? For instance, wouldn't (d/dx + x^5)^2 = d^2/(d^2 x) + 5x^4 + x^5 d/dx + x^10? Or am I misunderstanding what you mean? Also, I don't understand the purpose of the "1" you put after p(x^2d/dx + a + x - x^2y). (Since you again put a 1 in a similar position in your comment to kcrisman's answer below, I assume it's not a typo.)Fri, 06 Apr 2012 10:21:58 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19982#post-id-19982Answer by kcrisman for <p>Is there any way in Sage to evaluate expressions such as
p(x^2<em>d/dx + a + x - x^2</em>y) 1
where p() is a polynomial in one variable? The result would be a polynomial in a,x, and y.</p>
<p>Alternatively, can Sage evaluate
(1/f) p(d/dx) f
where f is a (non-polynomial) function of x and a and y?</p>
<p>Thanks very much.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?answer=13427#post-id-13427 sage: var('a y')
(a, y)
sage: F = function('F',x)
sage: G = F.derivative(x)
sage: G
D[0](F)(x)
sage: exp = x^2*G + a + x - x^2*y
sage: p(h) = h^2-h+1
sage: p(exp)
x^2*y - x^2*D[0](F)(x) + (x^2*y - x^2*D[0](F)(x) - a - x)^2 - a - x + 1
sage: p(exp).expand()
x^4*y^2 - 2*x^4*y*D[0](F)(x) + x^4*D[0](F)(x)^2 - 2*a*x^2*y + 2*a*x^2*D[0](F)(x) - 2*x^3*y + 2*x^3*D[0](F)(x) + x^2*y - x^2*D[0](F)(x) + a^2 + 2*a*x + x^2 - a - x + 1
Downside: these aren't really differential *operators* or D-module thingies, just derivatives of a dummy function. There is [this functionality](http://www.sagemath.org/doc/reference/sage/tensor/differential_form_element.html), but:
sage: from sage.tensor.differential_form_element import d
sage: exp1 = x^2*d + a + x - x^2*y
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and '<type 'function'>'
so I don't think it's immediately usable. See also [this Trac ticket](http://trac.sagemath.org/sage_trac/ticket/10956) about implementing more general pseudo-differential operators.Thu, 05 Apr 2012 12:49:04 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?answer=13427#post-id-13427Comment by Daniel Friedan for <pre><code>sage: var('a y')
(a, y)
sage: F = function('F',x)
sage: G = F.derivative(x)
sage: G
D[0](F)(x)
sage: exp = x^2*G + a + x - x^2*y
sage: p(h) = h^2-h+1
sage: p(exp)
x^2*y - x^2*D[0](F)(x) + (x^2*y - x^2*D[0](F)(x) - a - x)^2 - a - x + 1
sage: p(exp).expand()
x^4*y^2 - 2*x^4*y*D[0](F)(x) + x^4*D[0](F)(x)^2 - 2*a*x^2*y + 2*a*x^2*D[0](F)(x) - 2*x^3*y + 2*x^3*D[0](F)(x) + x^2*y - x^2*D[0](F)(x) + a^2 + 2*a*x + x^2 - a - x + 1
</code></pre>
<p>Downside: these aren't really differential <em>operators</em> or D-module thingies, just derivatives of a dummy function. There is <a href="http://www.sagemath.org/doc/reference/sage/tensor/differential_form_element.html">this functionality</a>, but:</p>
<pre><code>sage: from sage.tensor.differential_form_element import d
sage: exp1 = x^2*d + a + x - x^2*y
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and '<type 'function'>'
</code></pre>
<p>so I don't think it's immediately usable. See also <a href="http://trac.sagemath.org/sage_trac/ticket/10956">this Trac ticket</a> about implementing more general pseudo-differential operators.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19972#post-id-19972please see my comment in response to jdc aboveFri, 06 Apr 2012 15:57:36 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19972#post-id-19972Comment by kcrisman for <pre><code>sage: var('a y')
(a, y)
sage: F = function('F',x)
sage: G = F.derivative(x)
sage: G
D[0](F)(x)
sage: exp = x^2*G + a + x - x^2*y
sage: p(h) = h^2-h+1
sage: p(exp)
x^2*y - x^2*D[0](F)(x) + (x^2*y - x^2*D[0](F)(x) - a - x)^2 - a - x + 1
sage: p(exp).expand()
x^4*y^2 - 2*x^4*y*D[0](F)(x) + x^4*D[0](F)(x)^2 - 2*a*x^2*y + 2*a*x^2*D[0](F)(x) - 2*x^3*y + 2*x^3*D[0](F)(x) + x^2*y - x^2*D[0](F)(x) + a^2 + 2*a*x + x^2 - a - x + 1
</code></pre>
<p>Downside: these aren't really differential <em>operators</em> or D-module thingies, just derivatives of a dummy function. There is <a href="http://www.sagemath.org/doc/reference/sage/tensor/differential_form_element.html">this functionality</a>, but:</p>
<pre><code>sage: from sage.tensor.differential_form_element import d
sage: exp1 = x^2*d + a + x - x^2*y
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and '<type 'function'>'
</code></pre>
<p>so I don't think it's immediately usable. See also <a href="http://trac.sagemath.org/sage_trac/ticket/10956">this Trac ticket</a> about implementing more general pseudo-differential operators.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19979#post-id-19979I guess I'm confused - what about this is not a polynomial in one variable? (Other than the dummy issue, of course.) I'm editing my answer with what you (perhaps?) mean...Fri, 06 Apr 2012 11:35:38 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19979#post-id-19979Comment by kcrisman for <pre><code>sage: var('a y')
(a, y)
sage: F = function('F',x)
sage: G = F.derivative(x)
sage: G
D[0](F)(x)
sage: exp = x^2*G + a + x - x^2*y
sage: p(h) = h^2-h+1
sage: p(exp)
x^2*y - x^2*D[0](F)(x) + (x^2*y - x^2*D[0](F)(x) - a - x)^2 - a - x + 1
sage: p(exp).expand()
x^4*y^2 - 2*x^4*y*D[0](F)(x) + x^4*D[0](F)(x)^2 - 2*a*x^2*y + 2*a*x^2*D[0](F)(x) - 2*x^3*y + 2*x^3*D[0](F)(x) + x^2*y - x^2*D[0](F)(x) + a^2 + 2*a*x + x^2 - a - x + 1
</code></pre>
<p>Downside: these aren't really differential <em>operators</em> or D-module thingies, just derivatives of a dummy function. There is <a href="http://www.sagemath.org/doc/reference/sage/tensor/differential_form_element.html">this functionality</a>, but:</p>
<pre><code>sage: from sage.tensor.differential_form_element import d
sage: exp1 = x^2*d + a + x - x^2*y
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and '<type 'function'>'
</code></pre>
<p>so I don't think it's immediately usable. See also <a href="http://trac.sagemath.org/sage_trac/ticket/10956">this Trac ticket</a> about implementing more general pseudo-differential operators.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19960#post-id-19960Okay, so what you really want are not just polynomials with a given dummy `Df`, but honest-to-goodness differential operators that take functions as input. Apparently even Maxima doesn't quite have this, though the `pdiff` package seems to be pretty close, which you can search their docs for (and then use within/in conjunction with Sage...)Tue, 10 Apr 2012 15:42:46 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19960#post-id-19960Comment by Daniel Friedan for <pre><code>sage: var('a y')
(a, y)
sage: F = function('F',x)
sage: G = F.derivative(x)
sage: G
D[0](F)(x)
sage: exp = x^2*G + a + x - x^2*y
sage: p(h) = h^2-h+1
sage: p(exp)
x^2*y - x^2*D[0](F)(x) + (x^2*y - x^2*D[0](F)(x) - a - x)^2 - a - x + 1
sage: p(exp).expand()
x^4*y^2 - 2*x^4*y*D[0](F)(x) + x^4*D[0](F)(x)^2 - 2*a*x^2*y + 2*a*x^2*D[0](F)(x) - 2*x^3*y + 2*x^3*D[0](F)(x) + x^2*y - x^2*D[0](F)(x) + a^2 + 2*a*x + x^2 - a - x + 1
</code></pre>
<p>Downside: these aren't really differential <em>operators</em> or D-module thingies, just derivatives of a dummy function. There is <a href="http://www.sagemath.org/doc/reference/sage/tensor/differential_form_element.html">this functionality</a>, but:</p>
<pre><code>sage: from sage.tensor.differential_form_element import d
sage: exp1 = x^2*d + a + x - x^2*y
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and '<type 'function'>'
</code></pre>
<p>so I don't think it's immediately usable. See also <a href="http://trac.sagemath.org/sage_trac/ticket/10956">this Trac ticket</a> about implementing more general pseudo-differential operators.</p>
https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19985#post-id-19985Thanks, but I don't think your proposed answer does what I asked. Here's a simpler version:
(d/dx + a x)^2 1 = a + a^2 x^2
Your code
sage: var('a y')
(a, y)
sage: F = function('F',x)
sage: G = F.derivative(x)
sage: G
D[0](F)(x)
sage: exp = G + a*x
sage: p(h) = h^2
sage: p(exp)
(a*x + D[0](F)(x))^2
Thu, 05 Apr 2012 13:27:24 +0200https://ask.sagemath.org/question/8855/polynomials-of-derivative-operator/?comment=19985#post-id-19985