python - Sympy:用符号玻色子交换代替其数值

标签 python physics sympy mathematical-expressions commutativity

我想使用 sympy 简化涉及玻色子换向器的表达式。 问题在于,在 sympy 中使用 secondaryquant 时,玻色子换向器 [b_0,b^\dagger_0]=1 和 [b_0,b^\dagger_1]=0 的数值永远不会替换为符号表达式。 换句话说,我希望 SymPy 了解换向器身份。

以下代码

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)

给出

comm1= AnnihilateBoson(0)*CreateBoson(0) - CreateBoson(0)*AnnihilateBoson(0)
comm2= AnnihilateBoson(0)*CreateBoson(1) - CreateBoson(1)*AnnihilateBoson(0)

而不是预期值:

comm1= 1
comm2= 0

我已经尝试过这里提到的代码 How to use sympy.physics.quantum Commutator?

comm2=(Commutator(B(0),Bd(0))._eval_expand_commutator()).doit()
print('comm2=',comm2)

但这给出了与之前相同的表达式

comm2= AnnihilateBoson(0)*CreateBoson(0) - CreateBoson(0)*AnnihilateBoson(0)

此外,我发现了这个相关的未解答的问题: Does sympy give me wrong results for the second quantization commutators?

我在这里查看了第 1682 行: https://github.com/sympy/sympy/blob/master/sympy/physics/secondquant.py 据此,换向器应正确给出克罗内克增量。但是,我仍然得到上面报告的符号表达式。

最佳答案

问题的原因是

from sympy.physics.quantum import *

此代码给出了预期的行为

from sympy.physics.secondquant import *
from sympy import symbols
a, b = symbols('a,b')
c = Commutator(B(a),Bd(a))
print(c.doit())

关于python - Sympy:用符号玻色子交换代替其数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53269231/

相关文章:

python - 方法如何透明地查看函数属性

python - CANopen 设备更新太慢

ios - 将 Sprite Kit Physics Body 移动到用户触摸的位置而不通过

python - 使用 sympy.diffgeom 求黎曼曲率张量

python - 在 Sympy 中收集类似的表达式

python - os.walk() 的并行化

python - 为什么相关 HTTPResponse 关闭后 HttpConnection 仍可使用

python - 在 sympy 中分解多边形

java - "Rubber banding"会解决多人插值问题吗?

c++ - jacobi 迭代方法在 C++ 中有错误的答案