
    Цi^                     x    S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  S	/r " S
 S	\5      rg)z+The anti-commutator: ``{A,B} = A*B + B*A``.    )Expr)Mul)Integer)S)
prettyForm)Operator)DaggerAntiCommutatorc                   V    \ rS rSrSrSrS r\S 5       rS r	S r
S rS	 rS
 rS rSrg)r
      ar  The 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
Fc                 `    U R                  X5      nUb  U$ [        R                  " XU5      nU$ )N)evalr   __new__)clsABrobjs        c/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/sympy/physics/quantum/anticommutator.pyr   AntiCommutator.__new__S   s.    HHQN=Hll31%
    c           	         U(       a  U(       d  [         R                  $ X:X  a  [        S5      US-  -  $ UR                  (       d  UR                  (       a  [        S5      U-  U-  $ UR	                  5       u  p4UR	                  5       u  pVX5-   nU(       aA  [        [        U6 U " [
        R                  " U5      [
        R                  " U5      5      5      $ UR                  U5      S:X  a  U " X!5      $ g )N      )r   Zeror   is_commutativeargs_cncr   
_from_argscompare)r   abcancacbncbc_parts           r   r   AntiCommutator.evalZ   s    a66M61:ad?"q//1:a<>! **,**,sF|S)<cnnS>Q%RSS 99Q<1q9 r   c                    U R                   S   nU R                   S   n[        U[        5      (       a>  [        U[        5      (       a)   UR                  " U40 UD6nUb  UR
                  " S0 UD6$ X#-  X2-  -   R
                  " S0 UD6$ ! [         a*     UR                  " U40 UD6n NN! [         a    Sn  N]f = ff = f)zEvaluate anticommutator r   r   N )args
isinstancer   _eval_anticommutatorNotImplementedErrordoit)selfhintsr   r   comms        r   r.   AntiCommutator.doito   s    IIaLIIaLa""z!X'>'> --a959 yy)5))ac	(%(( '   11!=u=D*  D  s*   
B 
B?B++B;7B?:B;;B?c                 r    [        [        U R                  S   5      [        U R                  S   5      5      $ )Nr   r   )r
   r	   r*   )r/   s    r   _eval_adjointAntiCommutator._eval_adjoint   s)    fTYYq\2F499Q<4HIIr   c                     U R                   R                  < SUR                  U R                  S   5      < SUR                  U R                  S   5      < S3$ )N(r   ,r   ))	__class____name___printr*   r/   printerr*   s      r   
_sympyreprAntiCommutator._sympyrepr   sC    NN##W^^		!&&~~diil;
 	
r   c                     SUR                  U R                  S   5      < SUR                  U R                  S   5      < S3$ )N{r   r8   r   })r<   r*   r=   s      r   	_sympystrAntiCommutator._sympystr   s5    NN499Q<('..1*FH 	Hr   c                    UR                   " U R                  S   /UQ76 n[        UR                  [        S5      5      6 n[        UR                  UR                   " U R                  S   /UQ76 5      6 n[        UR	                  SSS96 nU$ )Nr   r8   r   rB   rC   )leftright)r<   r*   r   rH   parens)r/   r>   r*   pforms       r   _prettyAntiCommutator._pretty   sy    tyy|3d3EKK
389EKKtyy|(Kd(KLMELLcL=>r   c           
      ~    S[        U R                   Vs/ s H  o1R                  " U/UQ76 PM     sn5      -  $ s  snf )Nz\left\{%s,%s\right\})tupler*   r<   )r/   r>   r*   args       r   _latexAntiCommutator._latex   sB    )E26))3=2;3NN3&&)3= -> > 	> 3=s   :
r)   N)r;   
__module____qualname____firstlineno____doc__r   r   classmethodr   r.   r4   r?   rD   rK   rP   __static_attributes__r)   r   r   r
   r
      sH    :v N  () J
H>r   N)rU   sympy.core.exprr   sympy.core.mulr   sympy.core.numbersr   sympy.core.singletonr    sympy.printing.pretty.stringpictr   sympy.physics.quantum.operatorr   sympy.physics.quantum.daggerr	   __all__r
   r)   r   r   <module>r`      s7    1    & " 7 3 / @>T @>r   