K idZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZmZd gZGd d eZej(j+eed Zy )z+The anti-commutator: ``{A,B} = A*B + B*A``.)Expr)KindDispatcher)Mul)Integer)S) prettyForm)Dagger) _OperatorKind OperatorKindAntiCommutatorcreZdZdZdZeddZedZdZ e dZ d Z d Z d Zd Zd ZdZy)r aThe standard anticommutator, in an unevaluated state. Explanation =========== Evaluating an anticommutator is defined [1]_ as: ``{A, B} = A*B + B*A``. This class returns the anticommutator in an unevaluated form. To evaluate the anticommutator, use the ``.doit()`` method. Canonical ordering of an anticommutator is ``{A, B}`` for ``A < B``. The arguments of the anticommutator are put into canonical order using ``__cmp__``. If ``B < A``, then ``{A, B}`` is returned as ``{B, A}``. Parameters ========== A : Expr The first argument of the anticommutator {A,B}. B : Expr The second argument of the anticommutator {A,B}. Examples ======== >>> from sympy import symbols >>> from sympy.physics.quantum import AntiCommutator >>> from sympy.physics.quantum import Operator, Dagger >>> x, y = symbols('x,y') >>> A = Operator('A') >>> B = Operator('B') Create an anticommutator and use ``doit()`` to multiply them out. >>> ac = AntiCommutator(A,B); ac {A,B} >>> ac.doit() A*B + B*A The commutator orders it arguments in canonical order: >>> ac = AntiCommutator(B,A); ac {A,B} Commutative constants are factored out: >>> AntiCommutator(3*x*A,x*y*B) 3*x**2*y*{A,B} Adjoint operations applied to the anticommutator are properly applied to the arguments: >>> Dagger(AntiCommutator(A,B)) {Dagger(A),Dagger(B)} References ========== .. [1] https://en.wikipedia.org/wiki/Commutator FAntiCommutator_kind_dispatcherT) commutativecFd|jD}|j|S)Nc34K|]}|jywN)kind).0as j/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/quantum/anticommutator.py z&AntiCommutator.kind..Xs/QVV/s)args_kind_dispatcher)self arg_kindss rrzAntiCommutator.kindVs#/TYY/ $t$$i00c`|j||}||Stj|||}|Sr)evalr__new__)clsABrobjs rrzAntiCommutator.__new__[s2 HHQN =Hll31% rc |r|stjS||k(rtd|dzzS|js |jrtd|z|zS|j \}}|j \}}||z}|r?t t ||t j |t j |S|j|dk(r |||Sy)N)rZeroris_commutativeargs_cncr _from_argscompare)r rbcancacbncbc_parts rrzAntiCommutator.evalbsa66M 61:ad? "  q//1:a<> !**,C**,Cb sF|S)Q%RS S 99Q<1 q!9  rc jddlm}|jd}|jd}t||r4t||r( |j|fi|}||j di|S||z||zzj di|S#t $r) |j|fi|}n#t $rd}YnwxYwY`wxYw)z Evaluate anticommutator r)Operatorr'N)sympy.physics.quantum.operatorr4r isinstance_eval_anticommutatorNotImplementedErrordoit)rhintsr4r!r"comms rr:zAntiCommutator.doitws < IIaL IIaL a "z!X'> -q--a959  tyy)5))!ac (%(('  1111!=u=D* D  s5B B2 BB2 B,)B2+B,,B21B2crtt|jdt|jdS)Nrr')r r r)rs r _eval_adjointzAntiCommutator._eval_adjoints)fTYYq\2F499Q<4HIIrc|jjd|j|jdd|j|jddS)N(r,r')) __class____name___printrrprinterrs r _sympyreprzAntiCommutator._sympyreprsC NN # #W^^ ! &&~~diil;  rcd|j|jdd|j|jddS)N{rrAr'})rErrFs r _sympystrzAntiCommutator._sympystrs5 NN499Q< ('..1*FH Hrc"|j|jdg|}t|jtd}t|j|j|jdg|}t|j dd}|S)NrrAr'rJrK)leftright)rErrrOparens)rrGrpforms r_prettyzAntiCommutator._prettys}tyy|3d3EKK 389EKKtyy|(Kd(KLMELLcL=> rc zdt|jDcgc]}|j|g|c}zScc}w)Nz\left\{%s,%s\right\})tuplerrE)rrGrargs r_latexzAntiCommutator._latexsB)E26))3=+.NGNN3 & &3=->> >3=s8 N)rD __module__ __qualname____doc__r)rrpropertyrr classmethodrr:r>rHrLrRrVr5rrr r si:vN%&FTXY 11()&J H>rctS)z8Find the kind of an anticommutator of two OperatorKinds.)r )e1e2s r find_op_kindr_s  rN)rYsympy.core.exprrsympy.core.kindrsympy.core.mulrsympy.core.numbersrsympy.core.singletonr sympy.printing.pretty.stringpictrsympy.physics.quantum.daggerr sympy.physics.quantum.kindr r __all__r rregisterr_r5rrrjsc1 *&"7/B J>TJ>Z  ))-GHr