+
    iL                     :   R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHtHt ^ RIHt ^ RIHt . ROt ! R R]4      t ! R R]4      t ! R R]4      t  ! R R]4      t! ! R R]4      t" ! R R]4      t#R# )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                      a  ] tR t^*t o RtRtRt]R 4       t]	t
RtR t]tR tR tR tR	 tR
 tR tR tR tR tR t]tR tV 3R ltRtV tR# )r   aJ  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
Nc                    R# )O)r    selfs   &\/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/physics/quantum/operator.pydefault_argsOperator.default_argsn   s        ,c                .    V P                   P                  # N)	__class____name__r   printerargss   &&*r    _print_operator_nameOperator._print_operator_namez   s    ~~&&&r#   c                @    \        V P                  P                  4      # r&   )r   r'   r(   r)   s   &&*r    _print_operator_name_pretty$Operator._print_operator_name_pretty   s    $..1122r#   c                    \        V P                  4      ^8X  d   V P                  ! V.VO5!  # V P                  ! V.VO5!  : RV P                  ! V.VO5!  : R2# )   ())lenlabel_print_labelr,   r)   s   &&*r    _print_contentsOperator._print_contents   sZ    tzz?a$$W4t44 ))'9D9!!'1D1 r#   c                   \        V P                  4      ^8X  d   V P                  ! V.VO5!  # V P                  ! V.VO5!  pV P                  ! V.VO5!  p\	        VP                  RRR7      !  p\	        VP                  V4      !  pV# )r2   r3   r4   leftright)r5   r6   _print_label_prettyr/   r   parensr=   r   r*   r+   pformlabel_pforms   &&*  r    _print_contents_prettyOperator._print_contents_pretty   s    tzz?a++G;d;;44WDtDE227BTBK$##C#8K K 89ELr#   c                    \        V P                  4      ^8X  d   V P                  ! V.VO5!  # V P                  ! V.VO5!  : RV P                  ! V.VO5!  : R2# )r2   z\left(z\right))r5   r6   _print_label_latex_print_operator_name_latexr)   s   &&*r    _print_contents_latexOperator._print_contents_latex   sZ    tzz?a**7:T:: //?$?''7$7 r#   c                    \        V RV3/ VB # )z:Evaluate [self, other] if known, return None if not known._eval_commutatorr   r   otheroptionss   &&,r    rK   Operator._eval_commutator   s    t%7J'JJr#   c                    \        V RV3/ VB # )z Evaluate [self, other] if known._eval_anticommutatorrL   rM   s   &&,r    rR   Operator._eval_anticommutator   s    t%;UNgNNr#   c                    \        V R V3/ VB # )_apply_operatorrL   r   ketrO   s   &&,r    rU   Operator._apply_operator   s    t%6GwGGr#   c                    R # r&   r   r   brarO   s   &&,r    _apply_from_right_toOperator._apply_from_right_to   s    r#   c                    \        R 4      h)zmatrix_elements is not defined)NotImplementedError)r   r+   s   &*r    matrix_elementOperator.matrix_element   s    !"BCCr#   c                "    V P                  4       # r&   _eval_inverser   s   &r    inverseOperator.inverse       !!##r#   c                    V R,          # r2   r   r   s   &r    rd   Operator._eval_inverse   s    bzr#   c                R   < V ^8  d   Qh/ S[ S[,          ;R&   S[ S[,          ;R&   # )   is_hermitian
is_unitary)r   bool)format__classdict__s   "r    __annotate__Operator.__annotate__*   s+     D 4.'E F %G r#   r   )r(   
__module____qualname____firstlineno____doc__rn   ro   classmethodr!   r   kind_label_separatorr,   rG   r/   r8   rC   rH   rK   rR   rU   r\   r`   re   invrd   __annotate_func____static_attributes____classdictcell__rr   s   @r    r   r   *   s     @B $(L!%J  D ' "63
KOHD$ Ci  r#   c                   4   a  ] tR t^t o RtRtR tR tRtV t	R# )r   ad  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                \    \        V \        4      '       d   V # \        P                  V 4      # r&   )
isinstancer   r   rd   r   s   &r    rd   HermitianOperator._eval_inverse   s%    dO,,K))$//r#   c                    \        V \        4      '       d9   VP                  '       d   ^ RIHp VP
                  # VP                  '       d   V # \        P                  W4      # )    r
   )	r   r   is_evensympy.core.singletonr   Oneis_oddr   _eval_power)r   expr   s   && r    r   HermitianOperator._eval_power   sC    dO,,{{{2uu##D..r#   r   N)
r(   ru   rv   rw   rx   rn   rd   r   r~   r   r   s   @r    r   r      s      $ L0	/ 	/r#   c                   .   a  ] tR t^t o RtRtR tRtV tR# )r   ab  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                "    V P                  4       # r&   rc   r   s   &r    _eval_adjointUnitaryOperator._eval_adjoint   rg   r#   r   N)	r(   ru   rv   rw   rx   ro   r   r~   r   r   s   @r    r   r      s     " J$ $r#   c                      a  ] tR tRt o RtRtRt]R 4       t]	R 4       t
R tR tR tR	 tR
 tR tR tR tR tR tR tR tRtV tR# )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                    V P                   # r&   Nr   s   &r    	dimensionIdentityOperator.dimension  s    vvr#   c                    \         3# r&   r   r   s   &r    r!   IdentityOperator.default_args  s	    ur#   c                    \        R RRR7       \        V4      R9   g   \        RV,          4      h\        V4      ^8X  d    V^ ,          '       d   V^ ,          V n        R# \        V n        R# )z
            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_targetz"0 or 1 parameters expected, got %sN)r   r2   )r   r5   
ValueErrorr	   r   )r   r+   hintss   &*,r    __init__IdentityOperator.__init__   sY    ! &,'E	
 4yF"ADHII Y!^Qabr#   c                "    \         P                  # r&   )r   Zeror   rN   r   s   &&,r    rK   !IdentityOperator._eval_commutator.  s    vvr#   c                    ^V,          # )rm   r   r   s   &&,r    rR   %IdentityOperator._eval_anticommutator1  s    5yr#   c                    V # r&   r   r   s   &r    rd   IdentityOperator._eval_inverse4      r#   c                    V # r&   r   r   s   &r    r   IdentityOperator._eval_adjoint7  r   r#   c                    V# r&   r   rV   s   &&,r    rU    IdentityOperator._apply_operator:      
r#   c                    V# r&   r   rZ   s   &&,r    r\   %IdentityOperator._apply_from_right_to=  r   r#   c                    V # r&   r   )r   r   s   &&r    r   IdentityOperator._eval_power@  r   r#   c                    R # Ir   r)   s   &&*r    r8    IdentityOperator._print_contentsC  s    r#   c                    \        R 4      # r   r   r)   s   &&*r    rC   'IdentityOperator._print_contents_prettyF  s    #r#   c                    R # )z{\mathcal{I}}r   r)   s   &&*r    rH   &IdentityOperator._print_contents_latexI  s    r#   c                    V P                   '       d   V P                   \        8X  d   \        R4      hVP                  RR4      pVR8w  d   \        RRV,          ,           4      h\	        V P                   4      # )z%Cannot represent infinite dimensionalrq   sympyzRepresentation in format z%s not implemented.zCCannot represent infinite dimensional identity operator as a matrix)r   r	   r_   getr   )r   rO   rq   s   &, r    _represent_default_basis)IdentityOperator._represent_default_basisL  st    vvv2% 'G H H Xw/W%&A&;f&D'E F F 466{r#   r   N)r(   ru   rv   rw   rx   rn   ro   propertyr   ry   r!   r   rK   rR   rd   r   rU   r\   r   r8   rC   rH   r   r~   r   r   s   @r    r   r      s~     * LJ   A 
 
r#   c                   x   a  ] tR tRt o RtRtR t]R 4       t]R 4       t	R t
R tR	 tR
 tR tR tR tRtV tR# )r   iY  aG  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           	         ^ RI HpHp \        V4      ^8w  d   \	        R\        V4      ,          4      h\        V^ ,          4      p\        V^,          4      p\        WS\        34      '       Ed{   \        Wd\        34      '       Edc   VP                  4       w  rxVP                  4       w  r\        V4      ^8w  g   \        V^ ,          V4      '       g   \        R\        V!  ,          4      h\        V
4      ^8w  g   \        V
^ ,          V4      '       g   \        R\        V
!  ,          4      hV^ ,          P                  4       V
^ ,          P                  8X  g6   \        RV^ ,          P                  : RV
^ ,          P                  : 24      h\        P                  ! V .V^ ,          V
^ ,          3O5/ VB pV^ ,          P                  Vn        \        Wy,           !  V,          # . p\        V\        4      '       dY   \        V\        4      '       dC   VP                    F1  pVP                    F  pVP#                  \%        W3/ VB 4       K   	  K3  	  M\        V\        4      '       d0   VP                    F  pVP#                  \%        W3/ VB 4       K   	  MX\        V\        4      '       d0   VP                    F  pVP#                  \%        W^3/ VB 4       K   	  M\        RV: RV: 24      h\        V!  # )r   )KetBaseBraBasez2 parameters expected, got %dz"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   r   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   OuterProduct.__new__  s   @t9><s4yHII$q'?$q'?x3008s^44"++-KE"++-KE4yA~ZQ%A%A !,.14j!9 : : 4yA~ZQ%A%A !,.14j!9 : : 7%%'47+<+<<!W&&Q(9(9;  ,,sKd1gtAw%7K?KC $Q 5 5C(3..h$$Hc)B)B$MM (HOOL %D3B%D E !. * #&&$MMX !@/>!@ A * #&&$MMX !@/>!@ A * 8% 
 H~r#   c                (    V P                   ^ ,          # )z5Return the ket on the left side of the outer product.r+   r   s   &r    rW   OuterProduct.ket       yy|r#   c                (    V P                   ^,          # )z6Return the bra on the right side of the outer product.r   r   s   &r    r[   OuterProduct.bra  r   r#   c                f    \        \        V P                  4      \        V P                  4      4      # r&   )r   r   r[   rW   r   s   &r    r   OuterProduct._eval_adjoint  s!    F488,fTXX.>??r#   c                x    VP                  V P                  4      VP                  V P                  4      ,           # r&   _printrW   r[   r)   s   &&*r    	_sympystrOuterProduct._sympystr  s'    ~~dhh''..*BBBr#   c                    V P                   P                  : R VP                  ! V P                  .VO5!  : RVP                  ! V P                  .VO5!  : R2# )r3   r$   r4   )r'   r(   r   rW   r[   r)   s   &&*r    
_sympyreprOuterProduct._sympyrepr  sD    "nn55NN488+d+W^^DHH-Lt-LN 	Nr#   c                    V P                   P                  ! V.VO5!  p\        VP                  V P                  P                  ! V.VO5!  4      !  # r&   )rW   _prettyr   r=   r[   )r   r*   r+   rA   s   &&* r    r   OuterProduct._pretty  sC      0405;;txx'7'7'G$'GHIIr#   c                    VP                   ! V P                  .VO5!  pVP                   ! V P                  .VO5!  pW4,           # r&   r   )r   r*   r+   kbs   &&*  r    _latexOuterProduct._latex  s7    NN488+d+NN488+d+ur#   c                    V P                   P                  ! R/ VB pV P                  P                  ! R/ VB pW#,          # )Nr   )rW   
_representr[   )r   rO   r   r   s   &,  r    r   OuterProduct._represent  s7    HH*'*HH*'*s
r#   c                P    V P                   P                  ! V P                  3/ VB # r&   )rW   _eval_tracer[   )r   kwargss   &,r    r   OuterProduct._eval_trace  s"     xx##DHH777r#   r   N)r(   ru   rv   rw   rx   is_commutativer   r   rW   r[   r   r   r   r   r   r   r   r~   r   r   s   @r    r   r   Y  sl     3h N6p    @CNJ

8 8r#   c                   |   a  ] tR tRt o Rt]R 4       t]R 4       t]R 4       t]R 4       t	R t
R tR	 tR
 tRtV tR# )r   i  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                <    V P                   R,          P                   # )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)
rj   r   r   s   &r    	variablesDifferentialOperator.variables  s    . yy}!!!r#   c                (    V P                   R,          # )a  
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)
rj   r   r   s   &r    functionDifferentialOperator.function4  s    , yy}r#   c                (    V P                   ^ ,          # )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   s   &r    exprDifferentialOperator.exprL  s    . yy|r#   c                .    V P                   P                  # )z,
Return the free symbols of the expression.
)r  free_symbolsr   s   &r    r  !DifferentialOperator.free_symbolse  s     yy%%%r#   c                    ^ RI Hp V P                  pVP                  R,          pV P                  pV P
                  P                  Wa! V!  4      pVP                  4       pV! V.VO5!  # )r   )Wavefunction:r2   NN)r   r  r   r+   r   r  subsdoit)r   funcrO   r  varwf_varsfnew_exprs   &&,     r    _apply_operator_Wavefunction1DifferentialOperator._apply_operator_Wavefunctionm  sW    <nn))B-MM99>>!T3Z0==?H/w//r#   c                f    \        V P                  V4      p\        W P                  R,          4      # ri   )r   r  r   r+   )r   symbolr  s   && r    _eval_derivative%DifferentialOperator._eval_derivativex  s%    dii0#Hiim<<r#   c                ^    V P                   ! V.VO5!  : R V P                  ! V.VO5!  : R2# )r3   r4   )r,   r7   r)   s   &&*r    r   DifferentialOperator._print  s2    %%g55g--
 	
r#   c                    V P                   ! V.VO5!  pV P                  ! V.VO5!  p\        VP                  R RR7      !  p\        VP	                  V4      !  pV# )r3   r4   r;   )r/   r>   r   r?   r=   r@   s   &&*  r    _print_pretty"DifferentialOperator._print_pretty  sc    00@4@..w>> S4
 EKK45r#   r   N)r(   ru   rv   rw   rx   r   r   r   r  r  r  r  r   r  r~   r   r   s   @r    r   r     st     'R " "0  .  0 & &	0=
 r#   N)r   r   r   r   r   r   )$rx   typingr   sympy.core.addr   sympy.core.exprr   sympy.core.functionr   r   sympy.core.mulr   sympy.core.numbersr	   r   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(     s   	     4  ! " 7 / 3 >  @Uu Up$/ $/N$h $.Vx VrU88 U8p\8 \r#   