![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/lib/python3.6/dist-packages/sympy/physics/quantum/tests/ |
Upload File : |
from sympy import symbols, Integer 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