File size: 1,304 Bytes
ac2f8e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
from sympy.core.numbers import Integer
from sympy.core.symbol import symbols
from sympy.physics.quantum.dagger import Dagger
from sympy.physics.quantum.anticommutator import AntiCommutator as AComm
from sympy.physics.quantum.operator import Operator
a, b, c = symbols('a,b,c')
A, B, C, D = symbols('A,B,C,D', commutative=False)
def test_anticommutator():
ac = AComm(A, B)
assert isinstance(ac, AComm)
assert ac.is_commutative is False
assert ac.subs(A, C) == AComm(C, B)
def test_commutator_identities():
assert AComm(a*A, b*B) == a*b*AComm(A, B)
assert AComm(A, A) == 2*A**2
assert AComm(A, B) == AComm(B, A)
assert AComm(a, b) == 2*a*b
assert AComm(A, B).doit() == A*B + B*A
def test_anticommutator_dagger():
assert Dagger(AComm(A, B)) == AComm(Dagger(A), Dagger(B))
class Foo(Operator):
def _eval_anticommutator_Bar(self, bar):
return Integer(0)
class Bar(Operator):
pass
class Tam(Operator):
def _eval_anticommutator_Foo(self, foo):
return Integer(1)
def test_eval_commutator():
F = Foo('F')
B = Bar('B')
T = Tam('T')
assert AComm(F, B).doit() == 0
assert AComm(B, F).doit() == 0
assert AComm(F, T).doit() == 1
assert AComm(T, F).doit() == 1
assert AComm(B, T).doit() == B*T + T*B
|