图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

  1. from sympy.core.numbers import Integer
  2. from sympy.core.symbol import symbols
  3. from sympy.physics.quantum.dagger import Dagger
  4. from sympy.physics.quantum.anticommutator import AntiCommutator as AComm
  5. from sympy.physics.quantum.operator import Operator
  6. a, b, c = symbols('a,b,c')
  7. A, B, C, D = symbols('A,B,C,D', commutative=False)
  8. def test_anticommutator():
  9. ac = AComm(A, B)
  10. assert isinstance(ac, AComm)
  11. assert ac.is_commutative is False
  12. assert ac.subs(A, C) == AComm(C, B)
  13. def test_commutator_identities():
  14. assert AComm(a*A, b*B) == a*b*AComm(A, B)
  15. assert AComm(A, A) == 2*A**2
  16. assert AComm(A, B) == AComm(B, A)
  17. assert AComm(a, b) == 2*a*b
  18. assert AComm(A, B).doit() == A*B + B*A
  19. def test_anticommutator_dagger():
  20. assert Dagger(AComm(A, B)) == AComm(Dagger(A), Dagger(B))
  21. class Foo(Operator):
  22. def _eval_anticommutator_Bar(self, bar):
  23. return Integer(0)
  24. class Bar(Operator):
  25. pass
  26. class Tam(Operator):
  27. def _eval_anticommutator_Foo(self, foo):
  28. return Integer(1)
  29. def test_eval_commutator():
  30. F = Foo('F')
  31. B = Bar('B')
  32. T = Tam('T')
  33. assert AComm(F, B).doit() == 0
  34. assert AComm(B, F).doit() == 0
  35. assert AComm(F, T).doit() == 1
  36. assert AComm(T, F).doit() == 1
  37. assert AComm(B, T).doit() == B*T + T*B