§
    OŠtjÐ  ã                   óØ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZmZ d
gZ G d„ d
e¦  «        Zej                             ee¦  «        d„ ¦   «         ZdS )z+The anti-commutator: ``{A,B} = A*B + B*A``.é    )ÚExpr)ÚKindDispatcher)ÚMul)ÚInteger)ÚS)Ú
prettyForm)ÚDagger)Ú_OperatorKindÚOperatorKindÚAntiCommutatorc                   ó†   — e Zd ZdZdZ edd¬¦  «        Zed„ ¦   «         Zd„ Z	e
d„ ¦   «         Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ ZdS )r   a  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                 ó8   — d„ | j         D ¦   «         } | j        |Ž S )Nc              3   ó$   K  — | ]}|j         V — Œd S ©N)Úkind)Ú.0Úas     úb/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/physics/quantum/anticommutator.pyú	<genexpr>z&AntiCommutator.kind.<locals>.<genexpr>X   s$   è è € Ð/Ð/ �Q”VÐ/Ð/Ð/Ð/Ð/Ð/ó    )ÚargsÚ_kind_dispatcher)ÚselfÚ	arg_kindss     r   r   zAntiCommutator.kindV   s'   € à/Ð/ T¤YÐ/Ñ/Ô/ˆ	Ø$ˆtÔ$ iÐ0Ð0r   c                 óf   — |                       ||¦  «        }|�|S t          j        | ||¦  «        }|S r   )Úevalr   Ú__new__)ÚclsÚAÚBÚrÚobjs        r   r   zAntiCommutator.__new__[   s5   € Ø�HŠH�Q˜‰NŒNˆØˆ=ØˆHÝŒl˜3  1Ñ%Ô%ˆØˆ
r   c           	      óà  — |r|st           j        S ||k    rt          d¦  «        |dz  z  S |j        s|j        rt          d¦  «        |z  |z  S |                     ¦   «         \  }}|                     ¦   «         \  }}||z   }|rEt          t          |Ž  | t          j        |¦  «        t          j        |¦  «        ¦  «        ¦  «        S |                     |¦  «        dk    r | ||¦  «        S d S )Né   é   )r   ÚZeror   Úis_commutativeÚargs_cncr   Ú
_from_argsÚcompare)r    r   ÚbÚcaÚncaÚcbÚncbÚc_parts           r   r   zAntiCommutator.evalb   s÷   € àð 	�að 	Ý”6ˆMØ�Š6ˆ6Ý˜1‘:”:˜a ™d‘?Ð"ØÔð 	"˜qÔ/ð 	"Ý˜1‘:”:˜a‘< ‘>Ð!ð —*’*‘,”,‰ˆˆCØ—*’*‘,”,‰ˆˆCØ�b‘ˆØð 	TÝ•s˜F�| S S­¬¸Ñ)<Ô)<½c¼nÈSÑ>QÔ>QÑ%RÔ%RÑSÔSÐSð �9Š9�Q‰<Œ<˜1ÒÐØ�3�q˜!‘9”9Ðð Ðr   c                 óP  — ddl m} | j        d         }| j        d         }t          ||¦  «        rat          ||¦  «        rQ	  |j        |fi |¤Ž}n2# t
          $ r% 	  |j        |fi |¤Ž}n# t
          $ r d}Y nw xY wY nw xY w|� |j        di |¤ŽS  ||z  ||z  z   j        di |¤ŽS )z Evaluate anticommutator r   )ÚOperatorr'   N© )Úsympy.physics.quantum.operatorr4   r   Ú
isinstanceÚ_eval_anticommutatorÚNotImplementedErrorÚdoit)r   Úhintsr4   r!   r"   Úcomms         r   r:   zAntiCommutator.doitw   s  € ð 	<Ð;Ð;Ð;Ð;Ð;ØŒI�aŒLˆØŒI�aŒLˆÝ�a˜Ñ"Ô"ð 		*¥z°!°XÑ'>Ô'>ð 		*ð Ø-�qÔ-¨aÐ9Ð9°5Ð9Ð9��øÝ&ð  ð  ð  ð Ø1˜1Ô1°!Ð=Ð=°uÐ=Ð=�D�DøÝ*ð  ð  ð  Ø�D�D�Dð øøøøøð øøøð
 ÐØ �t”yÐ)Ð) 5Ð)Ð)Ð)Ø��!‘�a˜‘c‘	ÔÐ(Ð( %Ð(Ð(Ð(s6   ÁA Á
B ÁA+Á*B Á+A:Á7B Á9A:Á:B Á?B c                 ó‚   — t          t          | j        d         ¦  «        t          | j        d         ¦  «        ¦  «        S )Nr   r'   )r   r	   r   )r   s    r   Ú_eval_adjointzAntiCommutator._eval_adjointŠ   s.   € Ý�f T¤Y¨q¤\Ñ2Ô2µF¸4¼9ÀQ¼<Ñ4HÔ4HÑIÔIÐIr   c                 ó¤   — | j         j        ›d|                     | j        d         ¦  «        ›d|                     | j        d         ¦  «        ›d�S )Nú(r   ú,r'   ú))Ú	__class__Ú__name__Ú_printr   ©r   Úprinterr   s      r   Ú
_sympyreprzAntiCommutator._sympyrepr�   sX   € àŒNÔ#Ð#Ð# W§^¢^Ø”	˜!”ñ&ô &ð &ð &Ø&Ÿ~š~¨d¬i¸¬lÑ;Ô;Ð;Ð;ð
ð 	
r   c                 óŒ   — d|                      | j        d         ¦  «        ›d|                      | j        d         ¦  «        ›d�S )NÚ{r   rA   r'   Ú})rE   r   rF   s      r   Ú	_sympystrzAntiCommutator._sympystr“   sE   € € à�NŠN˜4œ9 Qœ<Ñ(Ô(Ð(Ð(¨'¯.ª.¸¼À1¼Ñ*FÔ*FÐ*FÐ*FðHð 	Hr   c                 ó,  —  |j         | j        d         g|¢R Ž }t          |                     t          d¦  «        ¦  «        Ž }t          |                      |j         | j        d         g|¢R Ž ¦  «        Ž }t          |                     dd¬¦  «        Ž }|S )Nr   rA   r'   rJ   rK   )ÚleftÚright)rE   r   r   rO   Úparens)r   rG   r   Úpforms       r   Ú_prettyzAntiCommutator._pretty—   sŒ   € Ø�”˜tœy¨œ|Ð3¨dÐ3Ð3Ð3ˆÝ˜EŸKšK­
°3©¬Ñ8Ô8Ð9ˆÝ˜EŸKšK¨¨¬°t´yÀ´|Ð(KÀdÐ(KÐ(KÐ(KÑLÔLÐMˆÝ˜EŸLšL¨c¸˜LÑ=Ô=Ð>ˆØˆr   c                 óN   ‡‡— dt          ˆˆfd„| j        D ¦   «         ¦  «        z  S )Nz\left\{%s,%s\right\}c                 ó,   •— g | ]} ‰j         |g‰¢R Ž ‘ŒS r5   )rE   )r   Úargr   rG   s     €€r   ú
<listcomp>z)AntiCommutator._latex.<locals>.<listcomp>Ÿ   s:   ø€ ð 3=ð 3=ð 3=Ø+.ˆNˆGŒN˜3Ð& Ð&Ð&Ð&ð3=ð 3=ð 3=r   )Útupler   rF   s    ``r   Ú_latexzAntiCommutator._latexž   sJ   øø€ Ø)­Eð 3=ð 3=ð 3=ð 3=ð 3=Ø26´)ð3=ñ 3=ô 3=ñ ->ô ->ñ >ð 	>r   N)rD   Ú
__module__Ú__qualname__Ú__doc__r)   r   r   Úpropertyr   r   Úclassmethodr   r:   r>   rH   rL   rR   rX   r5   r   r   r   r      sà   € € € € € ð:ð :ðv €Nà%�~Ð&FÐTXÐYÑYÔYÐàð1ð 1ñ „Xð1ðð ð ð ðð ñ „[ðð()ð )ð )ð&Jð Jð Jð
ð 
ð 
ðHð Hð Hðð ð ð>ð >ð >ð >ð >r   c                 ó   — t           S )z8Find the kind of an anticommutator of two OperatorKinds.)r   )Úe1Úe2s     r   Úfind_op_kindra   £   s
   € õ Ðr   N)r[   Ú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   Úregisterra   r5   r   r   ú<module>rl      s  ðØ 1Ð 1à  Ð  Ð  Ð  Ð  Ð  Ø *Ð *Ð *Ð *Ð *Ð *Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ø "Ð "Ð "Ð "Ð "Ð "Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7à /Ð /Ð /Ð /Ð /Ð /Ø BÐ BÐ BÐ BÐ BÐ BÐ BÐ Bð ð€ðJ>ð J>ð J>ð J>ð J>�Tñ J>ô J>ð J>ðZ Ô ×)Ò)¨-¸ÑGÔGðð ñ HÔGðð ð r   