§
    OŠtjÉL  ã                   ó^  — d Z ddlmZ ddlmZ ddlmZ ddlmZ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dlmZ ddlmZ g d¢Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z  G d„ de¦  «        Z! G d„ de¦  «        Z" G d„ de¦  «        Z#dS )a  Quantum mechanical operators.

TODO:

* Fix early 0 in apply_operators.
* Debug and test apply_operators.
* Get cse working with classes in this file.
* Doctests and documentation of special methods for InnerProduct, Commutator,
  AntiCommutator, represent, apply_operators.
é    )ÚOptional)ÚAdd)ÚExpr)Ú
DerivativeÚexpand)ÚMul©Úoo©ÚS©Ú
prettyForm)ÚDagger)ÚOperatorKind)ÚQExprÚdispatch_method)Úeye)Úsympy_deprecation_warning)ÚOperatorÚHermitianOperatorÚUnitaryOperatorÚIdentityOperatorÚOuterProductÚDifferentialOperatorc                   ó¶   — e Zd ZU dZdZee         ed<   dZee         ed<   e	d„ ¦   «         Z
eZdZd„ ZeZd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZeZd„ ZdS )r   a
  Base class for non-commuting quantum operators.

    An operator maps between quantum states [1]_. In quantum mechanics,
    observables (including, but not limited to, measured physical values) are
    represented as Hermitian operators [2]_.

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the
        operator. For time-dependent operators, this will include the time.

    Examples
    ========

    Create an operator and examine its attributes::

        >>> from sympy.physics.quantum import Operator
        >>> from sympy import I
        >>> A = Operator('A')
        >>> A
        A
        >>> A.hilbert_space
        H
        >>> A.label
        (A,)
        >>> A.is_commutative
        False

    Create another operator and do some arithmetic operations::

        >>> B = Operator('B')
        >>> C = 2*A*A + I*B
        >>> C
        2*A**2 + I*B

    Operators do not commute::

        >>> A.is_commutative
        False
        >>> B.is_commutative
        False
        >>> A*B == B*A
        False

    Polymonials of operators respect the commutation properties::

        >>> e = (A+B)**3
        >>> e.expand()
        A*B*A + A*B**2 + A**2*B + A**3 + B*A*B + B*A**2 + B**2*A + B**3

    Operator inverses are handle symbolically::

        >>> A.inv()
        A**(-1)
        >>> A*A.inv()
        1

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Operator_%28physics%29
    .. [2] https://en.wikipedia.org/wiki/Observable
    NÚis_hermitianÚ
is_unitaryc                 ó   — dS )N)ÚO© ©Úselfs    ú\/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/physics/quantum/operator.pyÚdefault_argszOperator.default_argsn   s   € àˆvó    ú,c                 ó   — | j         j        S ©N)Ú	__class__Ú__name__©r"   ÚprinterÚargss      r#   Ú_print_operator_namezOperator._print_operator_namez   s   € ØŒ~Ô&Ð&r%   c                 ó4   — t          | j        j        ¦  «        S r(   )r   r)   r*   r+   s      r#   Ú_print_operator_name_prettyz$Operator._print_operator_name_pretty   s   € Ý˜$œ.Ô1Ñ2Ô2Ð2r%   c                 óŽ   — t          | j        ¦  «        dk    r | j        |g|¢R Ž S  | j        |g|¢R Ž ›d | j        |g|¢R Ž ›d�S )Né   ú(ú))ÚlenÚlabelÚ_print_labelr.   r+   s      r#   Ú_print_contentszOperator._print_contents‚   sx   € ÝˆtŒz‰?Œ?˜aÒÐØ$�4Ô$ WÐ4¨tÐ4Ð4Ð4Ð4ð *�Ô)¨'Ð9°DÐ9Ð9Ð9Ð9Ð9Ø!�Ô! 'Ð1¨DÐ1Ð1Ð1Ð1Ð1ðð r%   c                 óþ   — t          | j        ¦  «        dk    r | j        |g|¢R Ž S  | j        |g|¢R Ž } | j        |g|¢R Ž }t	          |                     dd¬¦  «        Ž }t	          |                     |¦  «        Ž }|S )Nr2   r3   r4   ©ÚleftÚright)r5   r6   Ú_print_label_prettyr0   r   Úparensr<   ©r"   r,   r-   ÚpformÚlabel_pforms        r#   Ú_print_contents_prettyzOperator._print_contents_pretty‹   s¡   € ÝˆtŒz‰?Œ?˜aÒÐØ+�4Ô+¨GÐ;°dÐ;Ð;Ð;Ð;à4�DÔ4°WÐD¸tÐDÐDÐDˆEØ2˜$Ô2°7ÐB¸TÐBÐBÐBˆKÝ$Ø×#Ò#¨°CÐ#Ñ8Ô8ðˆKõ  §¢¨KÑ 8Ô 8Ð9ˆEØˆLr%   c                 óŽ   — t          | j        ¦  «        dk    r | j        |g|¢R Ž S  | j        |g|¢R Ž ›d | j        |g|¢R Ž ›d�S )Nr2   z\left(z\right))r5   r6   Ú_print_label_latexÚ_print_operator_name_latexr+   s      r#   Ú_print_contents_latexzOperator._print_contents_latex—   sx   € ÝˆtŒz‰?Œ?˜aÒÐØ*�4Ô*¨7Ð:°TÐ:Ð:Ð:Ð:ð 0�Ô/°Ð?¸$Ð?Ð?Ð?Ð?Ð?Ø'�Ô'¨Ð7°$Ð7Ð7Ð7Ð7Ð7ðð r%   c                 ó    — t          | d|fi |¤ŽS )z:Evaluate [self, other] if known, return None if not known.Ú_eval_commutator©r   ©r"   ÚotherÚoptionss      r#   rH   zOperator._eval_commutator¤   s   € å˜tÐ%7¸ÐJÐJÀ'ÐJÐJÐJr%   c                 ó    — t          | d|fi |¤ŽS )z Evaluate [self, other] if known.Ú_eval_anticommutatorrI   rJ   s      r#   rN   zOperator._eval_anticommutator¨   s   € å˜tÐ%;¸UÐNÐNÀgÐNÐNÐNr%   c                 ó    — t          | d|fi |¤ŽS )NÚ_apply_operatorrI   ©r"   ÚketrL   s      r#   rP   zOperator._apply_operator°   s   € Ý˜tÐ%6¸ÐGÐG¸wÐGÐGÐGr%   c                 ó   — d S r(   r    ©r"   ÚbrarL   s      r#   Ú_apply_from_right_tozOperator._apply_from_right_to³   s   € Øˆtr%   c                 ó    — t          d¦  «        ‚)Nzmatrix_elements is not defined)ÚNotImplementedError)r"   r-   s     r#   Úmatrix_elementzOperator.matrix_element¶   s   € Ý!Ð"BÑCÔCÐCr%   c                 ó*   — |                       ¦   «         S r(   ©Ú_eval_inverser!   s    r#   ÚinversezOperator.inverse¹   ó   € Ø×!Ò!Ñ#Ô#Ð#r%   c                 ó   — | dz  S ©Néÿÿÿÿr    r!   s    r#   r\   zOperator._eval_inverse¾   s   € Ø�b‰zÐr%   )r*   Ú
__module__Ú__qualname__Ú__doc__r   r   ÚboolÚ__annotations__r   Úclassmethodr$   r   ÚkindÚ_label_separatorr.   rE   r0   r8   rB   rF   rH   rN   rP   rV   rY   r]   Úinvr\   r    r%   r#   r   r   *   sD  € € € € € € ð@ð @ðB $(€L�(˜4”.Ð'Ð'Ñ'Ø!%€J�˜”Ð%Ð%Ñ%Øðð ñ „[ðð €Dð Ðð'ð 'ð 'ð "6Ðð3ð 3ð 3ðð ð ð
ð 
ð 
ðð ð ðKð Kð KðOð Oð OðHð Hð Hðð ð ðDð Dð Dð$ð $ð $ð €Cðð ð ð ð r%   r   c                   ó"   — e Zd ZdZdZd„ Zd„ ZdS )r   a”  A Hermitian operator that satisfies H == Dagger(H).

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the
        operator. For time-dependent operators, this will include the time.

    Examples
    ========

    >>> from sympy.physics.quantum import Dagger, HermitianOperator
    >>> H = HermitianOperator('H')
    >>> Dagger(H)
    H
    Tc                 ód   — t          | t          ¦  «        r| S t                               | ¦  «        S r(   )Ú
isinstancer   r   r\   r!   s    r#   r\   zHermitianOperator._eval_inverse×   s-   € Ý�d�OÑ,Ô,ð 	0ØˆKå×)Ò)¨$Ñ/Ô/Ð/r%   c                 óœ   — t          | t          ¦  «        r|j        rddlm} |j        S |j        r| S t                               | |¦  «        S )Nr   r   )	rm   r   Úis_evenÚsympy.core.singletonr   ÚOneÚis_oddr   Ú_eval_power)r"   Úexpr   s      r#   rs   zHermitianOperator._eval_powerÝ   s\   € Ý�d�OÑ,Ô,ð 	àŒ{ð Ø2Ð2Ð2Ð2Ð2Ð2Ø”u�Ø”ð Ø�å×#Ò# D¨#Ñ.Ô.Ð.r%   N)r*   rb   rc   rd   r   r\   rs   r    r%   r#   r   r   Â   sC   € € € € € ðð ð$ €Lð0ð 0ð 0ð	/ð 	/ð 	/ð 	/ð 	/r%   r   c                   ó   — e Zd ZdZdZd„ ZdS )r   a’  A unitary operator that satisfies U*Dagger(U) == 1.

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the
        operator. For time-dependent operators, this will include the time.

    Examples
    ========

    >>> from sympy.physics.quantum import Dagger, UnitaryOperator
    >>> U = UnitaryOperator('U')
    >>> U*Dagger(U)
    1
    Tc                 ó*   — |                       ¦   «         S r(   r[   r!   s    r#   Ú_eval_adjointzUnitaryOperator._eval_adjointü   r^   r%   N)r*   rb   rc   rd   r   rw   r    r%   r#   r   r   é   s4   € € € € € ðð ð" €Jð$ð $ð $ð $ð $r%   r   c                   óŽ   — e Zd ZdZdZdZed„ ¦   «         Zed„ ¦   «         Z	d„ Z
d„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )r   a,  An identity operator I that satisfies op * I == I * op == op for any
    operator op.

    .. deprecated:: 1.14.
        Use the scalar S.One instead as the multiplicative identity for
        operators and states.

    Parameters
    ==========

    N : Integer
        Optional parameter that specifies the dimension of the Hilbert space
        of operator. This is used when generating a matrix representation.

    Examples
    ========

    >>> from sympy.physics.quantum import IdentityOperator
    >>> IdentityOperator() # doctest: +SKIP
    I
    Tc                 ó   — | j         S r(   )ÚNr!   s    r#   Ú	dimensionzIdentityOperator.dimension  s	   € àŒvˆr%   c                 ó   — t           fS r(   r	   r!   s    r#   r$   zIdentityOperator.default_args  s	   € åˆuˆr%   c                 óÎ   — t          ddd¬¦  «         t          |¦  «        dvrt          d|z  ¦  «        ‚t          |¦  «        dk    r|d         r|d         nt          | _        d S )	Nz�
            IdentityOperator has been deprecated. In the future, please use
            S.One as the identity for quantum operators and states.
            z1.14zdeprecated-operator-identity)Údeprecated_since_versionÚactive_deprecations_target)r   r2   z"0 or 1 parameters expected, got %sr2   r   )r   r5   Ú
ValueErrorr
   rz   )r"   r-   Úhintss      r#   Ú__init__zIdentityOperator.__init__   sv   € Ý!ðð &,Ø'Eð	
ñ 	
ô 	
ð 	
õ �4‰yŒy˜FÐ"Ð"ÝÐAÀDÑHÑIÔIÐIå  ™YœY¨!š^˜^°°Q´˜^��a”�½bˆŒˆˆr%   c                 ó   — t           j        S r(   )r   ÚZero©r"   rK   r�   s      r#   rH   z!IdentityOperator._eval_commutator.  s	   € ÝŒvˆr%   c                 ó   — d|z  S )Né   r    r…   s      r#   rN   z%IdentityOperator._eval_anticommutator1  s   € Ø�5‰yÐr%   c                 ó   — | S r(   r    r!   s    r#   r\   zIdentityOperator._eval_inverse4  ó   € Øˆr%   c                 ó   — | S r(   r    r!   s    r#   rw   zIdentityOperator._eval_adjoint7  r‰   r%   c                 ó   — |S r(   r    rQ   s      r#   rP   z IdentityOperator._apply_operator:  ó   € Øˆ
r%   c                 ó   — |S r(   r    rT   s      r#   rV   z%IdentityOperator._apply_from_right_to=  rŒ   r%   c                 ó   — | S r(   r    )r"   rt   s     r#   rs   zIdentityOperator._eval_power@  r‰   r%   c                 ó   — dS ©NÚIr    r+   s      r#   r8   z IdentityOperator._print_contentsC  s   € Øˆsr%   c                 ó    — t          d¦  «        S r�   r   r+   s      r#   rB   z'IdentityOperator._print_contents_prettyF  s   € Ý˜#‰ŒÐr%   c                 ó   — dS )Nz{\mathcal{I}}r    r+   s      r#   rF   z&IdentityOperator._print_contents_latexI  s   € ØÐr%   c                 óØ   — | j         r| j         t          k    rt          d¦  «        ‚|                     dd¦  «        }|dk    rt          dd|z  z   ¦  «        ‚t	          | j         ¦  «        S )NzCCannot represent infinite dimensional identity operator as a matrixÚformatÚsympyzRepresentation in format z%s not implemented.)rz   r
   rX   Úgetr   )r"   rL   r•   s      r#   Ú_represent_default_basisz)IdentityOperator._represent_default_basisL  sˆ   € ØŒvð 	H˜œ¥2š˜Ý%ð 'Gñ Hô Hð Hð —’˜X wÑ/Ô/ˆØ�WÒÐÝ%Ð&AØ&;¸fÑ&Dñ'Eñ Fô Fð Fõ �4”6‰{Œ{Ðr%   N)r*   rb   rc   rd   r   r   Úpropertyr{   rg   r$   r‚   rH   rN   r\   rw   rP   rV   rs   r8   rB   rF   r˜   r    r%   r#   r   r      s  € € € € € ðð ð* €LØ€JØðð ñ „Xðð ðð ñ „[ððAð Að Aðð ð ðð ð ðð ð ðð ð ðð ð ðð ð ðð ð ðð ð ðð ð ð ð  ð  ð
ð 
ð 
ð 
ð 
r%   r   c                   ór   — e Zd ZdZdZd„ Zed„ ¦   «         Zed„ ¦   «         Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zd„ ZdS )r   aß  An unevaluated outer product between a ket and bra.

    This constructs an outer product between any subclass of ``KetBase`` and
    ``BraBase`` as ``|a><b|``. An ``OuterProduct`` inherits from Operator as they act as
    operators in quantum expressions.  For reference see [1]_.

    Parameters
    ==========

    ket : KetBase
        The ket on the left side of the outer product.
    bar : BraBase
        The bra on the right side of the outer product.

    Examples
    ========

    Create a simple outer product by hand and take its dagger::

        >>> from sympy.physics.quantum import Ket, Bra, OuterProduct, Dagger

        >>> k = Ket('k')
        >>> b = Bra('b')
        >>> op = OuterProduct(k, b)
        >>> op
        |k><b|
        >>> op.hilbert_space
        H
        >>> op.ket
        |k>
        >>> op.bra
        <b|
        >>> Dagger(op)
        |b><k|

    In quantum expressions, outer products will be automatically
    identified and created::

        >>> k*b
        |k><b|

    However, the creation of inner products always has higher priority than that of
    outer products:

        >>> b*k*b
        <b|k>*<b|

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Outer_product
    Fc           	      óÂ  — ddl m}m} t          |¦  «        dk    rt	          dt          |¦  «        z  ¦  «        ‚t          |d         ¦  «        }t          |d         ¦  «        }t          ||t          f¦  «        �rbt          ||t          f¦  «        �rJ|                     ¦   «         \  }}|                     ¦   «         \  }	}
t          |¦  «        dk    st          |d         |¦  «        st          dt          |Ž z  ¦  «        ‚t          |
¦  «        dk    st          |
d         |¦  «        st          dt          |
Ž z  ¦  «        ‚|d          
                    ¦   «         |
d         j        k    s+t          d|d         j        ›d	|
d         j        ›�¦  «        ‚t          j        | g|d         |
d         f¢R i |¤Ž}|d         j        |_        t          ||	z   Ž |z  S g }t          |t          ¦  «        rKt          |t          ¦  «        r6|j        D ]-}|j        D ]#}|                     t%          ||fi |¤Ž¦  «         Œ$Œ.n—t          |t          ¦  «        r,|j        D ]#}|                     t%          ||fi |¤Ž¦  «         Œ$nVt          |t          ¦  «        r,|j        D ]#}|                     t%          ||fi |¤Ž¦  «         Œ$nt          d
|›d	|›�¦  «        ‚t          |Ž S )Nr   )ÚKetBaseÚBraBaser‡   z2 parameters expected, got %dr2   z"KetBase subclass expected, got: %rz"BraBase subclass expected, got: %rz"ket and bra are not dual classes: z, z&Expected ket and bra expression, got: )Úsympy.physics.quantum.staterœ   r�   r5   r€   r   rm   r   Úargs_cncÚ	TypeErrorÚ
dual_classr)   r   Ú__new__Úhilbert_spacer   r-   Úappendr   )Úclsr-   Úold_assumptionsrœ   r�   Úket_exprÚbra_exprÚket_cÚketsÚbra_cÚbrasÚobjÚop_termsÚket_termÚbra_terms                  r#   r¢   zOuterProduct.__new__�  s‘  € Ø@Ð@Ð@Ð@Ð@Ð@Ð@Ð@åˆt‰9Œ9˜Š>ˆ>ÝÐ<½sÀ4¹y¼yÑHÑIÔIÐIå˜$˜qœ'‘?”?ˆÝ˜$˜qœ'‘?”?ˆå�x '­3 Ñ0Ô0ñ 	/Ý˜8 g­s ^Ñ4Ô4ñ	/à"×+Ò+Ñ-Ô-‰KˆE�4Ø"×+Ò+Ñ-Ô-‰KˆE�4å�4‰yŒy˜AŠ~ˆ~¥Z°°Q´¸Ñ%AÔ%Aˆ~Ýð !,Ý.1°4¨jñ!9ñ :ô :ð :õ �4‰yŒy˜AŠ~ˆ~¥Z°°Q´¸Ñ%AÔ%Aˆ~Ýð !,Ý.1°4¨jñ!9ñ :ô :ð :ð ˜”7×%Ò%Ñ'Ô'¨4°¬7Ô+<Ò<Ð<Ý�ià˜!”WÔ&Ð&Ð&¨¨Q¬Ô(9Ð(9ð;ñô ð õ ”,˜sÐK d¨1¤g¨t°A¬wÐ%7ÐKÐKÐK¸?ÐKÐKˆCØ $ Q¤Ô 5ˆCÔÝ˜ ™Ð(¨3Ñ.Ð.àˆÝ�h¥Ñ$Ô$ð 	­°H½cÑ)BÔ)Bð 	Ø$œMð Eð E�Ø (¤ð Eð E�HØ—O’O¥L°¸8ð %Dð %DØ3Bð%Dð %Dñ Eô Eð Eð EðEðEõ ˜¥#Ñ&Ô&ð 	Ø$œMð Að A�Ø—’¥¨X°xð !@ð !@Ø/>ð!@ð !@ñ Aô Að Að AðAõ ˜¥#Ñ&Ô&ð 	Ø$œMð Að A�Ø—’¥¨X°xð !@ð !@Ø/>ð!@ð !@ñ Aô Að Að AðAõ �)à��˜8˜8ð%ñô ð õ
 �Hˆ~Ðr%   c                 ó   — | j         d         S )z5Return the ket on the left side of the outer product.r   ©r-   r!   s    r#   rR   zOuterProduct.ketÈ  ó   € ð Œy˜Œ|Ðr%   c                 ó   — | j         d         S )z6Return the bra on the right side of the outer product.r2   r²   r!   s    r#   rU   zOuterProduct.braÍ  r³   r%   c                 ój   — t          t          | j        ¦  «        t          | j        ¦  «        ¦  «        S r(   )r   r   rU   rR   r!   s    r#   rw   zOuterProduct._eval_adjointÒ  s&   € Ý�F 4¤8Ñ,Ô,­f°T´XÑ.>Ô.>Ñ?Ô?Ð?r%   c                 ól   — |                      | j        ¦  «        |                      | j        ¦  «        z   S r(   ©Ú_printrR   rU   r+   s      r#   Ú	_sympystrzOuterProduct._sympystrÕ  s)   € Ø�~Š~˜dœhÑ'Ô'¨'¯.ª.¸¼Ñ*BÔ*BÑBÐBr%   c                 óp   — | j         j        ›d |j        | j        g|¢R Ž ›d |j        | j        g|¢R Ž ›d�S )Nr3   r&   r4   )r)   r*   r¸   rR   rU   r+   s      r#   Ú
_sympyreprzOuterProduct._sympyreprØ  sY   € Ø"œnÔ5Ð5Ð5ØˆGŒN˜4œ8Ð+ dÐ+Ð+Ð+Ð+Ð+¨^¨W¬^¸D¼HÐ-LÀtÐ-LÐ-LÐ-LÐ-LÐ-LðNð 	Nr%   c                 ó‚   —  | j         j        |g|¢R Ž }t          |                      | j        j        |g|¢R Ž ¦  «        Ž S r(   )rR   Ú_prettyr   r<   rU   )r"   r,   r-   r@   s       r#   r½   zOuterProduct._prettyÜ  sM   € Ø �”Ô  Ð0¨4Ð0Ð0Ð0ˆÝ˜5Ÿ;š;Ð'7 t¤xÔ'7¸Ð'GÀ$Ð'GÐ'GÐ'GÑHÔHÐIÐIr%   c                 óX   —  |j         | j        g|¢R Ž } |j         | j        g|¢R Ž }||z   S r(   r·   )r"   r,   r-   ÚkÚbs        r#   Ú_latexzOuterProduct._latexà  sA   € ØˆGŒN˜4œ8Ð+ dÐ+Ð+Ð+ˆØˆGŒN˜4œ8Ð+ dÐ+Ð+Ð+ˆØ�1‰uˆr%   c                 óT   —  | j         j        di |¤Ž} | j        j        di |¤Ž}||z  S )Nr    )rR   Ú
_representrU   )r"   rL   r¿   rÀ   s       r#   rÃ   zOuterProduct._representå  s?   € ØˆDŒHÔÐ*Ð* 'Ð*Ð*ˆØˆDŒHÔÐ*Ð* 'Ð*Ð*ˆØ�‰sˆ
r%   c                 ó2   —  | j         j        | j        fi |¤ŽS r(   )rR   Ú_eval_tracerU   )r"   Úkwargss     r#   rÅ   zOuterProduct._eval_traceê  s#   € ð $ˆtŒxÔ# D¤HÐ7Ð7°Ð7Ð7Ð7r%   N)r*   rb   rc   rd   Úis_commutativer¢   r™   rR   rU   rw   r¹   r»   r½   rÁ   rÃ   rÅ   r    r%   r#   r   r   Y  sá   € € € € € ð3ð 3ðh €Nð6ð 6ð 6ðp ðð ñ „Xðð ðð ñ „Xðð@ð @ð @ðCð Cð CðNð Nð NðJð Jð Jðð ð ð
ð ð ð
8ð 8ð 8ð 8ð 8r%   r   c                   ó‚   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zd„ Z	d„ Z
d„ Zd	„ Zd
S )r   a+  An operator for representing the differential operator, i.e. d/dx

    It is initialized by passing two arguments. The first is an arbitrary
    expression that involves a function, such as ``Derivative(f(x), x)``. The
    second is the function (e.g. ``f(x)``) which we are to replace with the
    ``Wavefunction`` that this ``DifferentialOperator`` is applied to.

    Parameters
    ==========

    expr : Expr
           The arbitrary expression which the appropriate Wavefunction is to be
           substituted into

    func : Expr
           A function (e.g. f(x)) which is to be replaced with the appropriate
           Wavefunction when this DifferentialOperator is applied

    Examples
    ========

    You can define a completely arbitrary expression and specify where the
    Wavefunction is to be substituted

    >>> from sympy import Derivative, Function, Symbol
    >>> from sympy.physics.quantum.operator import DifferentialOperator
    >>> from sympy.physics.quantum.state import Wavefunction
    >>> from sympy.physics.quantum.qapply import qapply
    >>> f = Function('f')
    >>> x = Symbol('x')
    >>> d = DifferentialOperator(1/x*Derivative(f(x), x), f(x))
    >>> w = Wavefunction(x**2, x)
    >>> d.function
    f(x)
    >>> d.variables
    (x,)
    >>> qapply(d*w)
    Wavefunction(2, x)

    c                 ó&   — | j         d         j         S )a�  
        Returns the variables with which the function in the specified
        arbitrary expression is evaluated

        Examples
        ========

        >>> from sympy.physics.quantum.operator import DifferentialOperator
        >>> from sympy import Symbol, Function, Derivative
        >>> x = Symbol('x')
        >>> f = Function('f')
        >>> d = DifferentialOperator(1/x*Derivative(f(x), x), f(x))
        >>> d.variables
        (x,)
        >>> y = Symbol('y')
        >>> d = DifferentialOperator(Derivative(f(x, y), x) +
        ...                          Derivative(f(x, y), y), f(x, y))
        >>> d.variables
        (x, y)
        ra   r²   r!   s    r#   Ú	variableszDifferentialOperator.variables  s   € ð. Œy˜Œ}Ô!Ð!r%   c                 ó   — | j         d         S )ad  
        Returns the function which is to be replaced with the Wavefunction

        Examples
        ========

        >>> from sympy.physics.quantum.operator import DifferentialOperator
        >>> from sympy import Function, Symbol, Derivative
        >>> x = Symbol('x')
        >>> f = Function('f')
        >>> d = DifferentialOperator(Derivative(f(x), x), f(x))
        >>> d.function
        f(x)
        >>> y = Symbol('y')
        >>> d = DifferentialOperator(Derivative(f(x, y), x) +
        ...                          Derivative(f(x, y), y), f(x, y))
        >>> d.function
        f(x, y)
        ra   r²   r!   s    r#   ÚfunctionzDifferentialOperator.function4  s   € ð, Œy˜Œ}Ðr%   c                 ó   — | j         d         S )a¯  
        Returns the arbitrary expression which is to have the Wavefunction
        substituted into it

        Examples
        ========

        >>> from sympy.physics.quantum.operator import DifferentialOperator
        >>> from sympy import Function, Symbol, Derivative
        >>> x = Symbol('x')
        >>> f = Function('f')
        >>> d = DifferentialOperator(Derivative(f(x), x), f(x))
        >>> d.expr
        Derivative(f(x), x)
        >>> y = Symbol('y')
        >>> d = DifferentialOperator(Derivative(f(x, y), x) +
        ...                          Derivative(f(x, y), y), f(x, y))
        >>> d.expr
        Derivative(f(x, y), x) + Derivative(f(x, y), y)
        r   r²   r!   s    r#   ÚexprzDifferentialOperator.exprL  s   € ð. Œy˜Œ|Ðr%   c                 ó   — | j         j        S )z<
        Return the free symbols of the expression.
        )rÎ   Úfree_symbolsr!   s    r#   rÐ   z!DifferentialOperator.free_symbolse  s   € ð ŒyÔ%Ð%r%   c                 ó¾   — ddl m} | j        }|j        dd …         }| j        }| j                             | ||Ž ¦  «        }|                     ¦   «         } ||g|¢R Ž S )Nr   )ÚWavefunctionr2   )rž   rÒ   rÊ   r-   rÌ   rÎ   ÚsubsÚdoit)r"   ÚfuncrL   rÒ   ÚvarÚwf_varsÚfÚnew_exprs           r#   Ú_apply_operator_Wavefunctionz1DifferentialOperator._apply_operator_Wavefunctionm  sq   € Ø<Ð<Ð<Ð<Ð<Ð<ØŒnˆØ”)˜A˜B˜B”-ˆàŒMˆØ”9—>’> ! T T¨3 ZÑ0Ô0ˆØ—=’=‘?”?ˆàˆ|˜HÐ/ wÐ/Ð/Ð/Ð/r%   c                 ób   — t          | j        |¦  «        }t          || j        d         ¦  «        S r`   )r   rÎ   r   r-   )r"   ÚsymbolrÙ   s      r#   Ú_eval_derivativez%DifferentialOperator._eval_derivativex  s)   € Ý˜dœi¨Ñ0Ô0ˆÝ# H¨d¬i¸¬mÑ<Ô<Ð<r%   c                 óB   —  | j         |g|¢R Ž ›d | j        |g|¢R Ž ›d�S )Nr3   r4   )r.   r7   r+   s      r#   r¸   zDifferentialOperator._print€  sH   € à%ˆDÔ% gÐ5°Ð5Ð5Ð5Ð5Ð5ØˆDÔ˜gÐ-¨Ð-Ð-Ð-Ð-Ð-ð
ð 	
r%   c                 ó²   —  | j         |g|¢R Ž } | j        |g|¢R Ž }t          |                     dd¬¦  «        Ž }t          |                     |¦  «        Ž }|S )Nr3   r4   r:   )r0   r=   r   r>   r<   r?   s        r#   Ú_print_prettyz"DifferentialOperator._print_pretty†  ss   € Ø0�Ô0°Ð@¸4Ð@Ð@Ð@ˆØ.�dÔ.¨wÐ>¸Ð>Ð>Ð>ˆÝ Ø×Ò S°ÐÑ4Ô4ð
ˆõ ˜EŸKšK¨Ñ4Ô4Ð5ˆØˆr%   N)r*   rb   rc   rd   r™   rÊ   rÌ   rÎ   rÐ   rÚ   rÝ   r¸   rà   r    r%   r#   r   r   ñ  sÇ   € € € € € ð'ð 'ðR ð"ð "ñ „Xð"ð0 ðð ñ „Xðð. ðð ñ „Xðð0 ð&ð &ñ „Xð&ð	0ð 	0ð 	0ð=ð =ð =ð
ð 
ð 
ðð ð ð ð r%   r   N)$rd   Útypingr   Úsympy.core.addr   Úsympy.core.exprr   Úsympy.core.functionr   r   Úsympy.core.mulr   Úsympy.core.numbersr
   rp   r   Ú sympy.printing.pretty.stringpictr   Úsympy.physics.quantum.daggerr   Úsympy.physics.quantum.kindr   Úsympy.physics.quantum.qexprr   r   Úsympy.matricesr   Úsympy.utilities.exceptionsr   Ú__all__r   r   r   r   r   r   r    r%   r#   ú<module>rî      sD  ðð	ð 	ð Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø "Ð "Ð "Ð "Ð "Ð "Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø /Ð /Ð /Ð /Ð /Ð /Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø Ð Ð Ð Ð Ð Ø @Ð @Ð @Ð @Ð @Ð @ðð ð €ðUð Uð Uð Uð Uˆuñ Uô Uð Uðp$/ð $/ð $/ð $/ð $/˜ñ $/ô $/ð $/ðN$ð $ð $ð $ð $�hñ $ô $ð $ð.Vð Vð Vð Vð V�xñ Vô Vð VðrU8ð U8ð U8ð U8ð U8�8ñ U8ô U8ð U8ðp\ð \ð \ð \ð \˜8ñ \ô \ð \ð \ð \r%   