Representing operators within commutators and expanding on some arbitrary func f.

91 views
Skip to first unread message

Guru Devanla

unread,
Aug 18, 2012, 6:10:42 PM8/18/12
to sy...@googlegroups.com
I am doing some exercises, and wanted to see how I could represent this expression using Sympy.

Say  A = d/dx and B = x.

I need to evaluate [A,B].  

Manually, this is what I do: say, I have some function f, this commutator acts on, then I have

[A,B] f =  (AB - BA)(f) =   (d/dx)(x)(f) - x(d/dx)(f) 
           =  x * (df/dx) + f - x * (df/dx) =  f.

How can I represent such an expression in Sympy, and also get f as the answer if I use .doit() to expand the expression.

I am documenting some of the use cases I have been playing with, so that I can consolidate and publish these exercises as a notebook document.

Thanks
-Guru   

Aaron Meurer

unread,
Aug 18, 2012, 6:36:57 PM8/18/12
to sy...@googlegroups.com
SymPy does not yet have a derivative operator object (see http://code.google.com/p/sympy/issues/detail?id=1620) and classes like Lambda only work on arguments of functions, not functions (i.e., something like Lambda(f(x), f) does not work). 

So I think the only way to do this right now is to create the expression with a dummy function (and unfortunately, we don't even have a DummyFunction class!) and the replace it with subs.  

We definitely need more support for operators in the core of SymPy. I can point you to some issues and discussions if you are interested in improving the situation. 

Aaron Meurer
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/02WXqQX7VCkJ.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

krastano...@gmail.com

unread,
Aug 18, 2012, 7:15:22 PM8/18/12
to sy...@googlegroups.com
You can emulate this behavior with the diffgeom module on which I am
working (the version in master is out of date, you can check out the
pull request)

Vector fields are differential operators:

from sympy.diffgeom.Rn import R2 # the R^2 manifold
derivative_wrt_x = R2.e_x # the base vector along the x axis
more_complicated_derivative_op = (stuff*derivative_wrt_x)
some_expression = (cos(R2.x) + R2.y)
more_complicated_derivative_op(some_expression) == -stuff*sin(R2.x)

You even have a somewhat intelligent Commutator class inside the module.

krastano...@gmail.com

unread,
Aug 18, 2012, 7:21:15 PM8/18/12
to sy...@googlegroups.com
However the commutator in the diffgeom module is between differential
operators. It is not exactly what you ask for. Actually I do not
understand how "x" acts on anything in your example as it is not a
differential operator (it can be regarded as a hermitian operator as
in quantum mechanics "acting" simply by multiplication, however this
requires to much magic for the moment)

Sean Vig

unread,
Aug 18, 2012, 7:45:13 PM8/18/12
to sy...@googlegroups.com
Guru,

There is a DifferentialOperator class in physics/quantum/operator that you could probably use. There is still a pull open from last year's GSOC that finishes off the continuous basis stuff that implemented that operator [1]. That along with XOp in quantum/cartesian might do what you need.

Sean

--
You received this message because you are subscribed to the Google Groups "sympy" group.

Aaron Meurer

unread,
Aug 18, 2012, 10:50:01 PM8/18/12
to sy...@googlegroups.com
I created http://code.google.com/p/sympy/issues/detail?id=3366 for the
DummyFunction. I guess what you want perhaps is doable, but even the
physics or diff geom stuff will either be hacks, or limited. We
really should have support for arbitrary operators on functions in the
core of SymPy.

Also, users shouldn't have to know physics or differential geometry to use it.
IMHO, this should be represented as x*Id, even with core operator
support. Ambiguous notation is nice for hand written stuff, but it's
better to use completely unambiguous notation when using a computer
algebra system.

Aaron Meurer

Guru Devanla

unread,
Aug 19, 2012, 8:14:51 PM8/19/12
to sy...@googlegroups.com
OK, thanks for all the suggestions. I think for now in the interest of time I plan to look at what Sean had suggested. Will post back an update on this sometime soon.

-Guru
Reply all
Reply to author
Forward
0 new messages