Ë
    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 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 commutator: [A,B] = A*B - B*A.é    )ÚAdd)ÚExpr)ÚKindDispatcher)ÚMul)ÚPow)ÚS)Ú
prettyForm)ÚDagger)Ú_OperatorKindÚOperatorKindÚ
Commutatorc                   ó~   — 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„ Zd„ Zy)r   a?  The standard commutator, in an unevaluated state.

    Explanation
    ===========

    Evaluating a commutator is defined [1]_ as: ``[A, B] = A*B - B*A``. This
    class returns the commutator in an unevaluated form. To evaluate the
    commutator, use the ``.doit()`` method.

    Canonical ordering of a commutator is ``[A, B]`` for ``A < B``. The
    arguments of the commutator are put into canonical order using ``__cmp__``.
    If ``B < A``, then ``[B, A]`` is returned as ``-[A, B]``.

    Parameters
    ==========

    A : Expr
        The first argument of the commutator [A,B].
    B : Expr
        The second argument of the commutator [A,B].

    Examples
    ========

    >>> from sympy.physics.quantum import Commutator, Dagger, Operator
    >>> from sympy.abc import x, y
    >>> A = Operator('A')
    >>> B = Operator('B')
    >>> C = Operator('C')

    Create a commutator and use ``.doit()`` to evaluate it:

    >>> comm = Commutator(A, B)
    >>> comm
    [A,B]
    >>> comm.doit()
    A*B - B*A

    The commutator orders it arguments in canonical order:

    >>> comm = Commutator(B, A); comm
    -[A,B]

    Commutative constants are factored out:

    >>> Commutator(3*x*A, x*y*B)
    3*x**2*y*[A,B]

    Using ``.expand(commutator=True)``, the standard commutator expansion rules
    can be applied:

    >>> Commutator(A+B, C).expand(commutator=True)
    [A,C] + [B,C]
    >>> Commutator(A, B+C).expand(commutator=True)
    [A,B] + [A,C]
    >>> Commutator(A*B, C).expand(commutator=True)
    [A,C]*B + A*[B,C]
    >>> Commutator(A, B*C).expand(commutator=True)
    [A,B]*C + B*[A,C]

    Adjoint operations applied to the commutator are properly applied to the
    arguments:

    >>> Dagger(Commutator(A, B))
    -[Dagger(A),Dagger(B)]

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Commutator
    FÚCommutator_kind_dispatcherT)Úcommutativec                 óF   — d„ | j                   D «       } | j                  |Ž S )Nc              3   ó4   K  — | ]  }|j                   –— Œ y ­w©N)Úkind)Ú.0Úas     ú^/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/physics/quantum/commutator.pyú	<genexpr>z"Commutator.kind.<locals>.<genexpr>f   s   è ø€ Ò/ �Q—V•VÑ/ùs   ‚)ÚargsÚ_kind_dispatcher)ÚselfÚ	arg_kindss     r   r   zCommutator.kindd   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Commutator.__new__i   s2   € Ø�H‰H�Q˜‹NˆØˆ=ØˆHÜ�l‰l˜3  1Ó%ˆØˆ
r   c           	      óÚ  — |r|st         j                  S ||k(  rt         j                  S |j                  s|j                  rt         j                  S |j                  «       \  }}|j                  «       \  }}||z   }|r?t	        t	        |Ž  | t	        j
                  |«      t	        j
                  |«      «      «      S |j                  |«      dk(  rt         j                   | ||«      z  S y )Né   )r   ÚZeroÚis_commutativeÚargs_cncr   Ú
_from_argsÚcompareÚNegativeOne)r!   r   ÚbÚcaÚncaÚcbÚncbÚc_parts           r   r   zCommutator.evalp   s¼   € á‘aÜ—6‘6ˆMØ�Š6Ü—6‘6ˆMØ×Ò˜q×/Ò/Ü—6‘6ˆMð —*‘*“,‰ˆˆCØ—*‘*“,‰ˆˆCØ�b‘ˆÙÜ”s˜F�|¡S¬¯©¸Ó)<¼c¿n¹nÈSÓ>QÓ%RÓSÐSð �9‰9�Q‹<˜1ÒÜ—=‘=¡ Q¨£Ñ*Ð*ð r   c                 óŠ  — |j                   }|j                  r|j                  «       rt        |«      dk  r| S |j                  }|j
                  r|j                  dz  }| }t        ||«      j                  d¬«      }||dz
  z  |z  }t        d|«      D ]  }|||dz
  |z
  z  |z  ||z  z  z  }Œ ||j                  «       z  S )Nr'   éÿÿÿÿT)Ú
commutator)	ÚexpÚ
is_integerÚis_constantÚabsÚbaseÚis_negativer   ÚexpandÚrange)	r   r"   r#   Úsignr7   r;   ÚcommÚresultÚis	            r   Ú_expand_powzCommutator._expand_pow…   sÅ   € Ø�e‰eˆØ�~Š~ S§_¡_Ô%6¼#¸c»(Àaº-àˆKØ�v‰vˆØ�?Š?Ø—6‘6˜2‘:ˆDØ�$ˆCÜ˜$ Ó"×)Ñ)°TÐ)Ó:ˆà˜˜a™‘ 4Ñ'ˆÜ�q˜#“ò 	;ˆAØ�d˜S 1™W q™[Ñ)¨DÑ0°4¸±7Ñ:Ñ:‰Fð	;à�F—M‘M“OÑ#Ð#r   c                 ó6  — | j                   d   }| j                   d   }t        |t        «      rXg }|j                   D ]?  }t        ||«      }t        |t        «      r|j	                  «       }|j                  |«       ŒA t        |Ž S t        |t        «      rXg }|j                   D ]?  }t        ||«      }t        |t        «      r|j	                  «       }|j                  |«       ŒA t        |Ž S t        |t        «      r¢|j                   d   }t        |j                   dd  Ž }|}	t        ||	«      }
t        ||	«      }t        |
t        «      r|
j	                  «       }
t        |t        «      r|j	                  «       }t        ||
«      }t        ||«      }t        ||«      S t        |t        «      r¢|}|j                   d   }t        |j                   dd  Ž }	t        ||«      }
t        ||	«      }t        |
t        «      r|
j	                  «       }
t        |t        «      r|j	                  «       }t        |
|	«      }t        ||«      }t        ||«      S t        |t        «      r| j                  ||d«      S t        |t        «      r| j                  ||d«      S | S )Nr   r'   r5   )	r   Ú
isinstancer   r   Ú_eval_expand_commutatorÚappendr   r   rC   )r   Úhintsr"   r#   ÚsargsÚtermr@   r   r.   ÚcÚcomm1Úcomm2ÚfirstÚseconds                 r   rF   z"Commutator._eval_expand_commutator•   sS  € Ø�I‰I�a‰LˆØ�I‰I�a‰Lˆä�aœÔàˆEØŸ™ò #�Ü! $¨Ó*�Ü˜d¤JÔ/Ø×7Ñ7Ó9�DØ—‘˜TÕ"ð	#ô
 ˜�;ÐÜ˜œ3ÔàˆEØŸ™ò #�Ü! ! TÓ*�Ü˜d¤JÔ/Ø×7Ñ7Ó9�DØ—‘˜TÕ"ð	#ô
 ˜�;ÐÜ˜œ3Ôà—‘�q‘	ˆAÜ�Q—V‘V˜A˜B�ZÐ ˆAØˆAÜ˜q !Ó$ˆEÜ˜q !Ó$ˆEÜ˜%¤Ô,Ø×5Ñ5Ó7�Ü˜%¤Ô,Ø×5Ñ5Ó7�Ü˜˜5“MˆEÜ˜ “]ˆFÜ�u˜fÓ%Ð%Ü˜œ3ÔàˆAØ—‘�q‘	ˆAÜ�Q—V‘V˜A˜B�ZÐ ˆAÜ˜q !Ó$ˆEÜ˜q !Ó$ˆEÜ˜%¤Ô,Ø×5Ñ5Ó7�Ü˜%¤Ô,Ø×5Ñ5Ó7�Ü˜˜q“MˆEÜ˜˜E“]ˆFÜ�u˜fÓ%Ð%Ü˜œ3Ôà×#Ñ# A q¨!Ó,Ð,Ü˜œ3Ôà×#Ñ# A q¨"Ó-Ð-ð ˆr   c                 óp  — 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, 	 d |j                  |fi |¤Žz  }n# t
        $ r d}Y nw xY wY Œcw xY w)z Evaluate commutator r   )ÚOperatorr'   r5   N© )Úsympy.physics.quantum.operatorrQ   r   rE   Ú_eval_commutatorÚNotImplementedErrorÚdoit)r   rH   rQ   r"   r#   r@   s         r   rV   zCommutator.doitÑ   sÕ   € õ 	<Ø�I‰I�a‰LˆØ�I‰I�a‰LˆÜ�a˜Ô"¤z°!°XÔ'>ð Ø)�q×)Ñ)¨!Ñ5¨uÑ5�ð ÐØ �t—y‘yÑ) 5Ñ)Ð)Ø��!‘�a˜‘c‘	×ÑÑ( %Ñ(Ð(øô 'ò  ð ØÐ0˜a×0Ñ0°Ñ<°eÑ<Ñ<‘DøÜ*ò  Ø’Dð üð ús5   ¾B  Â 	B5Â
B!Â B5Â!B/Â,B5Â.B/Â/B5Â4B5c                 ór   — t        t        | j                  d   «      t        | j                  d   «      «      S )Nr'   r   )r   r
   r   )r   s    r   Ú_eval_adjointzCommutator._eval_adjointä   s)   € Üœ& §¡¨1¡Ó.´°t·y±yÀ±|Ó0DÓEÐEr   c                 ó°   — | j                   j                  ›d|j                  | j                  d   «      ›d|j                  | j                  d   «      ›d�S )Nú(r   ú,r'   ú))Ú	__class__Ú__name__Ú_printr   ©r   Úprinterr   s      r   Ú
_sympyreprzCommutator._sympyreprç   sC   € à�N‰N×#Ó# W§^¡^Ø—	‘	˜!‘õ&Ø&Ÿ~™~¨d¯i©i¸©lÕ;ð
ð 	
r   c                 ó„   — d|j                  | j                  d   «      ›d|j                  | j                  d   «      ›d�S )Nú[r   r[   r'   ú])r_   r   r`   s      r   Ú	_sympystrzCommutator._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   r[   r'   rd   re   )ÚleftÚright)r_   r   r	   ri   Úparens)r   ra   r   Úpforms       r   Ú_prettyzCommutator._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   r_   )r   ra   r   Úargs       r   Ú_latexzCommutator._latexø   sB   € Ø%¬Ø26·)±)ö/=Ø+.ˆNˆG�N‰N˜3Ð& Ô&ò/=ó )>ñ >ð 	>ùò /=s   •8
N)r^   Ú
__module__Ú__qualname__Ú__doc__r)   r   r   Úpropertyr   r    Úclassmethodr   rC   rF   rV   rX   rb   rf   rl   rp   rR   r   r   r   r      su   „ ñFðN €Ná%Ð&BÐPTÔUÐàñ1ó ð1òð ñ+ó ð+ò($ò :òx)ò&Fò
òHòó>r   c                 ó   — t         S )z8Find the kind of an anticommutator of two OperatorKinds.)r   )Úe1Úe2s     r   Úfind_op_kindry   ý   s
   € ô Ðr   N)rs   Úsympy.core.addr   Úsympy.core.exprr   Úsympy.core.kindr   Úsympy.core.mulr   Úsympy.core.powerr   Úsympy.core.singletonr   Ú sympy.printing.pretty.stringpictr	   Úsympy.physics.quantum.daggerr
   Úsympy.physics.quantum.kindr   r   Ú__all__r   r   Úregisterry   rR   r   r   ú<module>r…      sf   ðÙ (å Ý  Ý *Ý Ý  Ý "Ý 7å /ß Bð ð€ôb>�ô b>ðJ ×Ñ×%Ñ% m°]ÓCñó Dñr   