homocomputeris
homocomputeris

Reputation: 509

How can I apply SymPy's DifferentialOperator to another Operator?

Suppose I have something like this:

from sympy.physics.quantum import *
from sympy import symbols, Function, Derivative, var
m = symbols('mu', positive=True)
var('x')
var('t')
f = Function('psi')
T = DifferentialOperator(-1 / (2 * m) * Derivative('psi(x,t)', x, x))
V = Operator('V(x)')
K = Operator('K(x)')

How can I get the expression for [T,K]u(x,t) = T(K(u)) - K(T(u))? Here, u is a wave function, and T should apply the chain rule to the K(u) product.

Upvotes: 1

Views: 84

Answers (1)

homocomputeris
homocomputeris

Reputation: 509

Well, a workaround:

from sympy import symbols, Function, Derivative, var, init_printing

def T(y):
    var('mu')
    return -1 / (2 * mu) * Derivative(y, x, x)

def V(y):
    var('x')
    V = Function('V', commutative=True)(x)
    return V * y

def comm(A, B):
    def comm(y):
        return A(B(y)) - B(A(y))
    return comm

var('x')
var('t')
f = Function('psi', commutative=False)
comm(T, V)(f)

Upvotes: 1

Related Questions