§
    ^²Åj^  ã                   ó€   — 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	gZ G d
„ d	e¦  «        ZdS )z+The anti-commutator: ``{A,B} = A*B + B*A``.é    )ÚExpr)ÚMul)ÚInteger)ÚS)Ú
prettyForm)ÚOperator)ÚDaggerÚAntiCommutatorc                   óV   — e Zd ZdZ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
    Fc                 óf   — |                       ||¦  «        }|�|S t          j        | ||¦  «        }|S )N)Úevalr   Ú__new__)ÚclsÚAÚBÚrÚobjs        úUC:\Projects\Historical\venv\Lib\site-packages\sympy/physics/quantum/anticommutator.pyr   zAntiCommutator.__new__S   s5   € Ø�HŠH�Q˜‰NŒNˆØˆ=ØˆHÝŒl˜3  1Ñ%Ô%ˆØˆ
ó    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   ÚaÚbÚcaÚncaÚcbÚncbÚc_parts           r   r   zAntiCommutator.evalZ   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                 óX  — | j         d         }| j         d         }t          |t          ¦  «        rft          |t          ¦  «        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   r   N© )ÚargsÚ
isinstancer   Ú_eval_anticommutatorÚNotImplementedErrorÚdoit)ÚselfÚhintsr   r   Úcomms        r   r+   zAntiCommutator.doito   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>Á;BÁ=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   r3   r   Ú})r7   r'   r8   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   r3   r   r<   r=   )ÚleftÚright)r7   r'   r   rA   Úparens)r,   r9   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 r&   )r7   )Ú.0Úargr'   r9   s     €€r   ú
<listcomp>z)AntiCommutator._latex.<locals>.<listcomp>”   s:   ø€ ð 3=ð 3=ð 3=Ø+.ˆNˆGŒN˜3Ð& Ð&Ð&Ð&ð3=ð 3=ð 3=r   )Útupler'   r8   s    ``r   Ú_latexzAntiCommutator._latex“   sJ   øø€ Ø)­Eð 3=ð 3=ð 3=ð 3=ð 3=Ø26´)ð3=ñ 3=ô 3=ñ ->ô ->ñ >ð 	>r   N)r6   Ú
__module__Ú__qualname__Ú__doc__r   r   Úclassmethodr   r+   r0   r:   r>   rD   rK   r&   r   r   r
   r
      s°   € € € € € ð:ð :ðv €Nðð ð ð ðð ñ „[ðð()ð )ð )ð Jð Jð Jð
ð 
ð 
ðHð Hð Hðð ð ð>ð >ð >ð >ð >r   N)rN   Ú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>rX      sÓ   ðØ 1Ð 1à  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ø "Ð "Ð "Ð "Ð "Ð "Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7à 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø /Ð /Ð /Ð /Ð /Ð /ð ð€ð@>ð @>ð @>ð @>ð @>�Tñ @>ô @>ð @>ð @>ð @>r   