§
    ^²ÅjdL  ã                   óF  — 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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)ÚQExprÚdispatch_method)Úeye)Ú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
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„ 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    úOC:\Projects\Historical\venv\Lib\site-packages\sympy/physics/quantum/operator.pyÚdefault_argszOperator.default_argsj   s   € àˆvó    ú,c                 ó   — | j         j        S ©N)Ú	__class__Ú__name__©r    ÚprinterÚargss      r!   Ú_print_operator_namezOperator._print_operator_namet   s   € ØŒ~Ô&Ð&r#   c                 ó4   — t          | j        j        ¦  «        S r&   )r   r'   r(   r)   s      r!   Ú_print_operator_name_prettyz$Operator._print_operator_name_prettyy   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 )Nr0   r1   r2   ©ÚleftÚright)r3   r4   Ú_print_label_prettyr.   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 )Nr0   z\left(z\right))r3   r4   Ú_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!   rF   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_anticommutatorrG   rH   s      r!   rL   zOperator._eval_anticommutator¢   s   € å˜tÐ%;¸UÐNÐNÀgÐNÐNÐNr#   c                 ó    — t          | d|fi |¤ŽS )NÚ_apply_operatorrG   ©r    ÚketrJ   s      r!   rN   zOperator._apply_operatorª   s   € Ý˜tÐ%6¸ÐGÐG¸wÐGÐGÐGr#   c                 ó   — d S r&   r   ©r    ÚbrarJ   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!   rZ   zOperator._eval_inverse¸   s   € Ø�b‰zÐr#   c                 óP   — t          |t          ¦  «        r| S t          | |¦  «        S r&   )Ú
isinstancer   r   ©r    rI   s     r!   Ú__mul__zOperator.__mul__»   s*   € å�eÕ-Ñ.Ô.ð 	ØˆKå�4˜ÑÔÐr#   )r(   Ú
__module__Ú__qualname__Ú__doc__r   r   ÚboolÚ__annotations__r   Úclassmethodr"   Ú_label_separatorr,   rC   r.   r6   r@   rD   rF   rL   rN   rT   rW   r[   ÚinvrZ   rc   r   r#   r!   r   r   &   sL  € € € € € € ð@ð @ðB $(€L�(˜4”.Ð'Ð'Ñ'Ø!%€J�˜”Ð%Ð%Ñ%Øðð ñ „[ðð Ðð'ð 'ð 'ð "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&   )ra   r   r   rZ   r   s    r!   rZ   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   )	ra   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(   rd   re   rf   r   rZ   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&   rY   r   s    r!   Ú_eval_adjointzUnitaryOperator._eval_adjointý   r\   r#   N)r(   rd   re   rf   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„ ZdS )r   aš  An identity operator I that satisfies op * I == I * op == op for any
    operator op.

    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()
    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vrt          d|z  ¦  «        ‚t          |¦  «        dk    r|d         r|d         nt          | _        d S )N)r   r0   z"0 or 1 parameters expected, got %sr0   r   )r3   Ú
ValueErrorr
   rz   )r    r+   Úhintss      r!   Ú__init__zIdentityOperator.__init__  sP   € Ý�4‰yŒy˜FÐ"Ð"ÝÐAÀDÑHÑIÔIÐIå  ™YœY¨!š^˜^°°Q´˜^��a”�½bˆŒˆˆr#   c                 ó   — t           j        S r&   )r   ÚZero©r    rI   r   s      r!   rF   z!IdentityOperator._eval_commutator#  s	   € ÝŒvˆr#   c                 ó   — d|z  S )Né   r   rƒ   s      r!   rL   z%IdentityOperator._eval_anticommutator&  s   € Ø�5‰yÐr#   c                 ó   — | S r&   r   r   s    r!   rZ   zIdentityOperator._eval_inverse)  ó   € Øˆr#   c                 ó   — | S r&   r   r   s    r!   rw   zIdentityOperator._eval_adjoint,  r‡   r#   c                 ó   — |S r&   r   rO   s      r!   rN   z IdentityOperator._apply_operator/  ó   € Øˆ
r#   c                 ó   — |S r&   r   rR   s      r!   rT   z%IdentityOperator._apply_from_right_to2  rŠ   r#   c                 ó   — | S r&   r   )r    rt   s     r!   rs   zIdentityOperator._eval_power5  r‡   r#   c                 ó   — dS ©NÚIr   r)   s      r!   r6   z IdentityOperator._print_contents8  s   € Øˆsr#   c                 ó    — t          d¦  «        S rŽ   r   r)   s      r!   r@   z'IdentityOperator._print_contents_pretty;  s   € Ý˜#‰ŒÐr#   c                 ó   — dS )Nz{\mathcal{I}}r   r)   s      r!   rD   z&IdentityOperator._print_contents_latex>  s   € ØÐr#   c                 ó^   — t          |t          t          f¦  «        r|S t          | |¦  «        S r&   )ra   r   r   r   rb   s     r!   rc   zIdentityOperator.__mul__A  s.   € å�e�h­Ð/Ñ0Ô0ð 	ØˆLå�4˜ÑÔÐ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
   rV   Úgetr   )r    rJ   r”   s      r!   Ú_represent_default_basisz)IdentityOperator._represent_default_basisH  sˆ   € ØŒvð 	H˜œ¥2š˜Ý%ð 'Gñ Hô Hð Hð —’˜X wÑ/Ô/ˆØ�WÒÐÝ%Ð&AØ&;¸fÑ&Dñ'Eñ Fô Fð Fõ �4”6‰{Œ{Ðr#   N)r(   rd   re   rf   r   r   Úpropertyr{   ri   r"   r€   rF   rL   rZ   rw   rN   rT   rs   r6   r@   rD   rc   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
        >>> from sympy.physics.quantum import Operator

        >>> 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 simple products of kets and bras outer products will be automatically
    identified and created::

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

    But in more complex expressions, outer products are not automatically
    created::

        >>> A = Operator('A')
        >>> A*k*b
        A*|k>*<b|

    A user can force the creation of an outer product in a complex expression
    by using parentheses to group the ket and bra::

        >>> A*(k*b)
        A*|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 %dr0   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œ   r3   r~   r   ra   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!   rP   zOuterProduct.ketÌ  ó   € ð Œy˜Œ|Ðr#   c                 ó   — | j         d         S )z6Return the bra on the right side of the outer product.r0   r±   r   s    r!   rS   zOuterProduct.braÑ  r²   r#   c                 ój   — t          t          | j        ¦  «        t          | j        ¦  «        ¦  «        S r&   )r   r   rS   rP   r   s    r!   rw   zOuterProduct._eval_adjointÖ  s&   € Ý�F 4¤8Ñ,Ô,­f°T´XÑ.>Ô.>Ñ?Ô?Ð?r#   c                 ól   — |                      | j        ¦  «        |                      | j        ¦  «        z   S r&   ©Ú_printrP   rS   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 )Nr1   r$   r2   )r'   r(   r·   rP   rS   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&   )rP   Ú_prettyr   r:   rS   )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   )rP   Ú
_representrS   )r    rJ   r¾   r¿   s       r!   rÂ   zOuterProduct._representé  s?   € ØˆDŒHÔÐ*Ð* 'Ð*Ð*ˆØˆDŒHÔÐ*Ð* 'Ð*Ð*ˆØ�‰sˆ
r#   c                 ó2   —  | j         j        | j        fi |¤ŽS r&   )rP   Ú_eval_tracerS   )r    Úkwargss     r!   rÄ   zOuterProduct._eval_traceî  s#   € ð $ˆtŒxÔ# D¤HÐ7Ð7°Ð7Ð7Ð7r#   N)r(   rd   re   rf   Úis_commutativer¡   r˜   rP   rS   rw   r¸   rº   r¼   rÀ   rÂ   rÄ   r   r#   r!   r   r   U  sá   € € € € € ð;ð ;ðx €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)
        r_   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)
        r_   r±   r   s    r!   ÚfunctionzDifferentialOperator.function8  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.exprP  s   € ð. Œy˜Œ|Ðr#   c                 ó   — | j         j        S )z<
        Return the free symbols of the expression.
        )rÍ   Úfree_symbolsr   s    r!   rÏ   z!DifferentialOperator.free_symbolsi  s   € ð ŒyÔ%Ð%r#   c                 ó¾   — ddl m} | j        }|j        dd …         }| j        }| j                             | ||Ž ¦  «        }|                     ¦   «         } ||g|¢R Ž S )Nr   )ÚWavefunctionr0   )r�   rÑ   rÉ   r+   rË   rÍ   ÚsubsÚdoit)r    ÚfuncrJ   rÑ   ÚvarÚwf_varsÚfÚnew_exprs           r!   Ú_apply_operator_Wavefunctionz1DifferentialOperator._apply_operator_Wavefunctionq  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_derivative|  s)   € Ý˜dœi¨Ñ0Ô0ˆÝ# H¨d¬i¸¬mÑ<Ô<Ð<r#   c                 óB   —  | j         |g|¢R Ž ›d | j        |g|¢R Ž ›d�S )Nr1   r2   )r,   r5   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 )Nr1   r2   r8   )r.   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(   rd   re   rf   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) rf   Ú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.qexprr   r   Úsympy.matricesr   Ú__all__r   r   r   r   r   r   r   r#   r!   ú<module>rë      s   ðð	ð 	ð Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø "Ð "Ð "Ð "Ð "Ð "Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø /Ð /Ð /Ð /Ð /Ð /Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø Ð Ð Ð Ð Ð ðð ð €ðZ ð Z ð Z ð Z ð Z ˆuñ Z ô Z ð Z ðz$/ð $/ð $/ð $/ð $/˜ñ $/ô $/ð $/ðN$ð $ð $ð $ð $�hñ $ô $ð $ð.Qð Qð Qð Qð Q�xñ Qô Qð Qðh]8ð ]8ð ]8ð ]8ð ]8�8ñ ]8ô ]8ð ]8ð@\ð \ð \ð \ð \˜8ñ \ô \ð \ð \ð \r#   