
    \h                         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S	KJrJr  S
/r " S S
\5      r\R(                  R+                  \\5      S 5       rg)z+The anti-commutator: ``{A,B} = A*B + B*A``.    )Expr)KindDispatcher)Mul)Integer)S)
prettyForm)Dagger)_OperatorKindOperatorKindAntiCommutatorc                   t    \ rS rSrSrSr\" SSS9r\S 5       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
FAntiCommutator_kind_dispatcherT)commutativec                 F    S U R                    5       nU R                  " U6 $ )Nc              3   8   #    U  H  oR                   v   M     g 7fN)kind).0as     \/var/www/auris/envauris/lib/python3.13/site-packages/sympy/physics/quantum/anticommutator.py	<genexpr>&AntiCommutator.kind.<locals>.<genexpr>X   s     /YVVYs   )args_kind_dispatcher)self	arg_kindss     r   r   AntiCommutator.kindV   s!    /TYY/	$$i00    c                 `    U R                  X5      nUb  U$ [        R                  " XU5      nU$ r   )evalr   __new__)clsABrobjs        r   r"   AntiCommutator.__new__[   s.    HHQN=Hll31%
r   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#   r   bcancacbncbc_parts           r   r!   AntiCommutator.evalb   s    a66M61:ad?"q//1:a<>! **,**,sF|S)<cnnS>Q%RSS 99Q<1q9 r   c                 |   SSK Jn  U R                  S   nU R                  S   n[        X25      (       a9  [        XB5      (       a)   UR                  " U40 UD6nUb  UR                  " S0 UD6$ X4-  XC-  -   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   )Operatorr+   N )sympy.physics.quantum.operatorr9   r   
isinstance_eval_anticommutatorNotImplementedErrordoit)r   hintsr9   r$   r%   comms         r   r?   AntiCommutator.doitw   s     	<IIaLIIaLa""z!'>'> --a959 yy)5))ac	(%(( '   11!=u=D*  D  s*   B 
B;B''B73B;6B77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   rH   r+   })rL   r   rM   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   rH   r+   rR   rS   )leftright)rL   r   r   rX   parens)r   rN   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   rL   )r   rN   r   args       r   _latexAntiCommutator._latex   sB    )E26))3=2;3NN3&&)3= -> > 	> 3=s   :
r:   N)rK   
__module____qualname____firstlineno____doc__r-   r   r   propertyr   r"   classmethodr!   r?   rD   rO   rT   r[   r`   __static_attributes__r:   r   r   r   r      si    :v N%&FTXY1 1  ()&J
H>r   c                     [         $ )z8Find the kind of an anticommutator of two OperatorKinds.)r   )e1e2s     r   find_op_kindrl      s
     r   N)re   sympy.core.exprr   sympy.core.kindr   sympy.core.mulr   sympy.core.numbersr   sympy.core.singletonr    sympy.printing.pretty.stringpictr   sympy.physics.quantum.daggerr	   sympy.physics.quantum.kindr
   r   __all__r   r   registerrl   r:   r   r   <module>rw      sc    1   *  & " 7 / B J>T J>Z   ))-G Hr   