How to use sympy.physics.quantum Commutator?

安稳与你 提交于 2019-12-07 17:31:13

问题


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.


回答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



来源:https://stackoverflow.com/questions/36095622/how-to-use-sympy-physics-quantum-commutator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!