I would like to simplify expressions involving boson commutators using sympy. The problem is that, using secondquant in sympy, the numerical values of the bosonic commutator [b_0,b^\dagger_0]=1 and [b_0,b^\dagger_1]=0 is never substituted to the symbolic expression. In other words, I would like SymPy to know about the commutator identity.
The following code
from sympy import simplify
from sympy.physics.secondquant import Bd, B
from sympy.physics.quantum import *
comm1=simplify(Commutator(B(0),Bd(0)).doit())
print(comm1)
comm2=simplify(Commutator(B(0),Bd(1)).doit())
print(comm2)
gives
comm1= AnnihilateBoson(0)*CreateBoson(0) - CreateBoson(0)*AnnihilateBoson(0)
comm2= AnnihilateBoson(0)*CreateBoson(1) - CreateBoson(1)*AnnihilateBoson(0)
instead of the expected values:
comm1= 1
comm2= 0
I have tried the code mentioned here How to use sympy.physics.quantum Commutator?
comm2=(Commutator(B(0),Bd(0))._eval_expand_commutator()).doit()
print('comm2=',comm2)
but this gives the same expression as before
comm2= AnnihilateBoson(0)*CreateBoson(0) - CreateBoson(0)*AnnihilateBoson(0)
Moreover I have found this related unanswered question: Does sympy give me wrong results for the second quantization commutators?
I had a look around line 1682 here: https://github.com/sympy/sympy/blob/master/sympy/physics/secondquant.py and according to this the commutator should correctly give a Kronecker delta. However, I still get the symbolic expression reported above.
The problem is caused by
from sympy.physics.quantum import *
This code gives the expected behaviour
from sympy.physics.secondquant import *
from sympy import symbols
a, b = symbols('a,b')
c = Commutator(B(a),Bd(a))
print(c.doit())