3

I want to work out some commutator manipulations and found this tool in sympy. It appears to work as expected (but the documentation is virtually non-existent or at least I found little, but see the comment by Dalton Bentley below), but I ran into the following problem.

from sympy.physics.quantum import Commutator as Comm
from sympy.physics.quantum import Operator
A = Operator('A')
B = Operator('B')
C = Comm(Comm(Comm(A,B),A),B)
D = Comm(Comm(Comm(A,B),B),A)
E = (C-D).expand(commutator=true)
E
>>> [[[A,B],A],B] - [[[A,B],B],A]

instead of the expected simpler result 0 (since [[[A,B],A],B] = [[[A,B],B],A]). So how can I force the simpler result without evaluating the commutators (i.e. w/o calling the doit() function)? Note that

simplify(E.doit())
>>> 0

gives the desired result.

Walter
  • 44,150
  • 20
  • 113
  • 196
  • 1
    Why is calling `doit()` an issue? Generally SymPy is conservative with automatically simplifying things since simplification can be very costly (and cost is usually hard to predict a priori). EDIT: Or do you want to teach SymPy about the commutator identity? – Bjoern Dahlgren Mar 20 '16 at 12:15
  • @BjoernDahlgren I want to know the answer in the unevaluated context, i.e. I want an commutator expression. Simplification in the unevaluated context should obtain zero for above result. – Walter Mar 21 '16 at 18:32
  • 2
    I see, from what I can tell [it is not implemented](https://github.com/sympy/sympy/blob/112d6abaf2c777a844d4290db9ecd952053a4a55/sympy/physics/quantum/commutator.py#L121). You may want to open an issue for it. – Bjoern Dahlgren Mar 21 '16 at 21:32
  • @BjoernDahlgren thanks. I would accept that as an answer. I'm not sure I want to raise an issue -- the package seems to have insufficient commutator support for my needs. I want to do some serious nested commutator manipulations using the Campbell-Baker-Hausdorff formula and all I've tried so far with this package was disappointing. – Walter Mar 23 '16 at 09:30
  • I have converted the comment to an answer. You are also welcome to add your comments to the issue on github, even if it is just a "wishlist". – Bjoern Dahlgren Mar 23 '16 at 14:11
  • 2
    It appears that the specific question was answered but I arrived here looking for documentation on the Sympy QM module and thought I would share two sources I found (since there is almost no documentation for it). JR Johansson has some pages at http://nbviewer.jupyter.org/github/jrjohansson/sympsi-notebooks/tree/master/ with a lot of examples and lectures. Cal Poly has a 2011 paper on doing QM with Sympy at http://digitalcommons.calpoly.edu/cgi/viewcontent.cgi?article=1038&context=physsp I hope this helps others. – Dalton Bentley Sep 26 '17 at 17:13

1 Answers1

1

Currently in SymPy, Commutator._eval_expand_commutator, does not know about this identity so it has to expand the commutators (in the .doit method as you have identified) in order to be able to simplify the expression.

What would be needed for this to work, would be to add special case(s) to the Commutator._eval_expand_commutator method for when the arguments of a commutator contains commutators, and then check for known identities.

I have opened an issue for this here: https://github.com/sympy/sympy/issues/10892

Bjoern Dahlgren
  • 931
  • 8
  • 18