图片解析应用
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.

49 lines
1.6 KiB

  1. from sympy.core.mul import prod
  2. from sympy.core.numbers import Rational
  3. from sympy.functions.elementary.exponential import exp
  4. from sympy.functions.elementary.miscellaneous import sqrt
  5. from sympy.physics.quantum import Dagger, Commutator, qapply
  6. from sympy.physics.quantum.boson import BosonOp
  7. from sympy.physics.quantum.boson import (
  8. BosonFockKet, BosonFockBra, BosonCoherentKet, BosonCoherentBra)
  9. def test_bosonoperator():
  10. a = BosonOp('a')
  11. b = BosonOp('b')
  12. assert isinstance(a, BosonOp)
  13. assert isinstance(Dagger(a), BosonOp)
  14. assert a.is_annihilation
  15. assert not Dagger(a).is_annihilation
  16. assert BosonOp("a") == BosonOp("a", True)
  17. assert BosonOp("a") != BosonOp("c")
  18. assert BosonOp("a", True) != BosonOp("a", False)
  19. assert Commutator(a, Dagger(a)).doit() == 1
  20. assert Commutator(a, Dagger(b)).doit() == a * Dagger(b) - Dagger(b) * a
  21. assert Dagger(exp(a)) == exp(Dagger(a))
  22. def test_boson_states():
  23. a = BosonOp("a")
  24. # Fock states
  25. n = 3
  26. assert (BosonFockBra(0) * BosonFockKet(1)).doit() == 0
  27. assert (BosonFockBra(1) * BosonFockKet(1)).doit() == 1
  28. assert qapply(BosonFockBra(n) * Dagger(a)**n * BosonFockKet(0)) \
  29. == sqrt(prod(range(1, n+1)))
  30. # Coherent states
  31. alpha1, alpha2 = 1.2, 4.3
  32. assert (BosonCoherentBra(alpha1) * BosonCoherentKet(alpha1)).doit() == 1
  33. assert (BosonCoherentBra(alpha2) * BosonCoherentKet(alpha2)).doit() == 1
  34. assert abs((BosonCoherentBra(alpha1) * BosonCoherentKet(alpha2)).doit() -
  35. exp((alpha1 - alpha2) ** 2 * Rational(-1, 2))) < 1e-12
  36. assert qapply(a * BosonCoherentKet(alpha1)) == \
  37. alpha1 * BosonCoherentKet(alpha1)