Ë
    7^(hÐ  ã                   óÌ   — 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(                  j+                  ee«      d„ «       Zy)z+The anti-commutator: ``{A,B} = A*B + B*A``.é    )ÚExpr)ÚKindDispatcher)ÚMul)ÚInteger)ÚS)Ú
prettyForm)ÚDagger)Ú_OperatorKindÚOperatorKindÚAntiCommutatorc                   ór   — 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y)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                 óF   — d„ | j                   D «       } | j                  |Ž S )Nc              3   ó4   K  — | ]  }|j                   –— Œ y ­w©N)Úkind)Ú.0Úas     úb/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/physics/quantum/anticommutator.pyú	<genexpr>z&AntiCommutator.kind.<locals>.<genexpr>X   s   è ø€ Ò/ �Q—V•VÑ/ùs   ‚)ÚargsÚ_kind_dispatcher)ÚselfÚ	arg_kindss     r   r   zAntiCommutator.kindV   s#   € á/ T§Y¡YÔ/ˆ	Ø$ˆt×$Ñ$ iÐ0Ð0ó    c                 ó`   — | j                  ||«      }|�|S t        j                  | ||«      }|S r   )Úevalr   Ú__new__)ÚclsÚAÚBÚrÚobjs        r   r   zAntiCommutator.__new__[   s2   € Ø�H‰H�Q˜‹NˆØˆ=ØˆHÜ�l‰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 |j	                  «       \  }}|j	                  «       \  }}||z   }|r?t        t        |Ž  | t        j                  |«      t        j                  |«      «      «      S |j                  |«      dk(  r	 | ||«      S y )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‘6ˆMØ�Š6Ü˜1“:˜a ™d‘?Ð"Ø×Ò˜q×/Ò/Ü˜1“:˜a‘< ‘>Ð!ð —*‘*“,‰ˆˆCØ—*‘*“,‰ˆˆCØ�b‘ˆÙÜ”s˜F�|¡S¬¯©¸Ó)<¼c¿n¹nÈSÓ>QÓ%RÓSÐSð �9‰9�Q‹<˜1ÒÙ�q˜!“9Ðð r   c                 ój  — ddl m} | j                  d   }| j                  d   }t        ||«      r4t        ||«      r(	  |j                  |fi |¤Ž}|� |j                  di |¤ŽS  ||z  ||z  z   j                  di |¤ŽS # t
        $ r) 	  |j                  |fi |¤Ž}n# t
        $ r d}Y nw xY wY Œ`w xY w)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‰I�a‰LˆØ�I‰I�a‰LˆÜ�a˜Ô"¤z°!°XÔ'>ð Ø-�q×-Ñ-¨aÑ9°5Ñ9�ð ÐØ �t—y‘yÑ) 5Ñ)Ð)Ø��!‘�a˜‘c‘	×ÑÑ( %Ñ(Ð(øô 'ò  ð Ø1˜1×1Ñ1°!Ñ=°uÑ=‘DøÜ*ò  Ø’Dð üð ús5   ¾B  Â 	B2Â
BÂB2ÂB,Â)B2Â+B,Â,B2Â1B2c                 ór   — 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¡Y¨q¡\Ó2´F¸4¿9¹9ÀQ¹<Ó4HÓIÐIr   c                 ó°   — | j                   j                  ›d|j                  | j                  d   «      ›d|j                  | j                  d   «      ›d�S )Nú(r   ú,r'   ú))Ú	__class__Ú__name__Ú_printr   ©r   Úprinterr   s      r   Ú
_sympyreprzAntiCommutator._sympyrepr�   sC   € à�N‰N×#Ó# W§^¡^Ø—	‘	˜!‘õ&Ø&Ÿ~™~¨d¯i©i¸©lÕ;ð
ð 	
r   c                 ó„   — d|j                  | j                  d   «      ›d|j                  | j                  d   «      ›d�S )Nú{r   rA   r'   ú})rE   r   rF   s      r   Ú	_sympystrzAntiCommutator._sympystr“   s5   � à�N‰N˜4Ÿ9™9 Q™<Õ(¨'¯.©.¸¿¹À1¹Õ*FðHð 	Hr   c                 ó"  —  |j                   | j                  d   g|¢­Ž }t        |j                  t        d«      «      Ž }t        |j                   |j                   | j                  d   g|¢­Ž «      Ž }t        |j	                  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™y¨™|Ð3¨dÒ3ˆÜ˜EŸK™K¬
°3«Ó8Ð9ˆÜ˜EŸK™K¨¨¯©°t·y±yÀ±|Ð(KÀdÒ(KÓLÐMˆÜ˜EŸL™L¨c¸˜LÓ=Ð>ˆØˆr   c           
      óz   — dt        | j                  D �cg c]  } |j                  |g|¢­Ž ‘Œ c}«      z  S c c}w )Nz\left\{%s,%s\right\})Útupler   rE   )r   rG   r   Úargs       r   Ú_latexzAntiCommutator._latexž   sB   € Ø)¬EØ26·)±)ö3=Ø+.ˆNˆG�N‰N˜3Ð& Ô&ò3=ó ->ñ >ð 	>ùò 3=s   •8
N)rD   Ú
__module__Ú__qualname__Ú__doc__r)   r   r   Úpropertyr   r   Úclassmethodr   r:   r>   rH   rL   rR   rV   r5   r   r   r   r      si   „ ñ:ðv €Ná%Ð&FÐTXÔYÐàñ1ó ð1òð ñó ðò()ò&Jò
òHòó>r   c                 ó   — t         S )z8Find the kind of an anticommutator of two OperatorKinds.)r   )Úe1Úe2s     r   Úfind_op_kindr_   £   s
   € ô Ðr   N)rY   Ú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   Úregisterr_   r5   r   r   ú<module>rj      sc   ðÙ 1å  Ý *Ý Ý &Ý "Ý 7å /ß Bð ð€ôJ>�Tô J>ðZ × Ñ ×)Ñ)¨-¸ÓGñó Hñr   