test_operatorordering.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from sympy.physics.quantum import Dagger
  2. from sympy.physics.quantum.boson import BosonOp
  3. from sympy.physics.quantum.fermion import FermionOp
  4. from sympy.physics.quantum.operatorordering import (normal_order,
  5. normal_ordered_form)
  6. def test_normal_order():
  7. a = BosonOp('a')
  8. c = FermionOp('c')
  9. assert normal_order(a * Dagger(a)) == Dagger(a) * a
  10. assert normal_order(Dagger(a) * a) == Dagger(a) * a
  11. assert normal_order(a * Dagger(a) ** 2) == Dagger(a) ** 2 * a
  12. assert normal_order(c * Dagger(c)) == - Dagger(c) * c
  13. assert normal_order(Dagger(c) * c) == Dagger(c) * c
  14. assert normal_order(c * Dagger(c) ** 2) == Dagger(c) ** 2 * c
  15. def test_normal_ordered_form():
  16. a = BosonOp('a')
  17. c = FermionOp('c')
  18. assert normal_ordered_form(Dagger(a) * a) == Dagger(a) * a
  19. assert normal_ordered_form(a * Dagger(a)) == 1 + Dagger(a) * a
  20. assert normal_ordered_form(a ** 2 * Dagger(a)) == \
  21. 2 * a + Dagger(a) * a ** 2
  22. assert normal_ordered_form(a ** 3 * Dagger(a)) == \
  23. 3 * a ** 2 + Dagger(a) * a ** 3
  24. assert normal_ordered_form(Dagger(c) * c) == Dagger(c) * c
  25. assert normal_ordered_form(c * Dagger(c)) == 1 - Dagger(c) * c
  26. assert normal_ordered_form(c ** 2 * Dagger(c)) == Dagger(c) * c ** 2
  27. assert normal_ordered_form(c ** 3 * Dagger(c)) == \
  28. c ** 2 - Dagger(c) * c ** 3