o
    jgBy                     @   s  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
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 g dZdZdZdZdZdZdZG dd deZ G dd de Z!G dd de Z"G dd de Z#G dd de#e!Z$G dd de#e"Z%G d d! d!e Z&G d"d# d#e&e!Z'G d$d% d%e&e"Z(G d&d' d'e#e Z)G d(d) d)e)e!Z*G d*d+ d+e)e"Z+G d,d- d-eZ,d.S )/zDirac notation for states.    )cacheit)Tuple)Expr)Function)ooequal_valued)S)	conjugate)sqrt)	integrate)
stringPict)QExprdispatch_method)KetBaseBraBase	StateBaseStateKetBraTimeDepState
TimeDepBra
TimeDepKetOrthogonalKetOrthogonalBraOrthogonalStateWavefunction<>|u   ⟨u   ⟩u   ❘c                   @   s   e Zd ZdZedd Zdd Zedd Zdd	 Z	d
d Z
dd Zedd Zedd Zdd ZdddZdd Zdd Zdd ZdS )r   a_  Abstract base class for general abstract states in quantum mechanics.

    All other state classes defined will need to inherit from this class. It
    carries the basic structure for all other states such as dual, _eval_adjoint
    and label.

    This is an abstract base class and you should not instantiate it directly,
    instead use State.
    c                 K      t d)ad   Returns the eigenstate instance for the passed operators.

        This method should be overridden in subclasses. It will handle being
        passed either an Operator instance or set of Operator instances. It
        should return the corresponding state INSTANCE or simply raise a
        NotImplementedError. See cartesian.py for an example.
        zECannot map operators to states in this class. Method not implemented!NotImplementedError)selfopsoptions r%   S/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/physics/quantum/state.py_operators_to_stateJ   s   
zStateBase._operators_to_statec                 K   r   )a   Returns the operators which this state instance is an eigenstate
        of.

        This method should be overridden in subclasses. It will be called on
        state instances and be passed the operator classes that we wish to make
        into instances. The state instance will then transform the classes
        appropriately, or raise a NotImplementedError if it cannot return
        operator instances. See cartesian.py for examples,
        z;Cannot map this state to operators. Method not implemented!r    r"   
op_classesr$   r%   r%   r&   _state_to_operatorsV   s   zStateBase._state_to_operatorsc                 C   s   ddl m} || S )z:Return the operator(s) that this state is an eigenstate of   )state_to_operators)operatorsetr,   )r"   r,   r%   r%   r&   	operatorsd   s   zStateBase.operatorsc                 K   r   )NzCannot enumerate this state!r    )r"   
num_statesr$   r%   r%   r&   _enumerate_statej   s   zStateBase._enumerate_statec                 K   s   | j | jdS )N)basis)
_representr.   )r"   r$   r%   r%   r&   _represent_default_basism   s   z"StateBase._represent_default_basisc                 K      d S Nr%   r"   opr$   r%   r%   r&   _apply_operatorp      zStateBase._apply_operatorc                 C   s   |   j| jg| jR  S )z"Return the dual state of this one.)
dual_class_new_rawargshilbert_spaceargsr"   r%   r%   r&   dualw   s   zStateBase.dualc                 C   r   )z,Return the class used to construct the dual.z,dual_class must be implemented in a subclassr    r>   r%   r%   r&   r:   |   s   zStateBase.dual_classc                 C   s   | j S )z0Compute the dagger of this state using the dual.r?   r>   r%   r%   r&   _eval_adjoint   s   zStateBase._eval_adjointTc           	         sX  |rt | ddt | dd}}d\ }nt | ddt | dd}}d\ }dkr3t|t|fS d	 7 g }||fD ]j}|tthv rffd
dtd	 D }| fddtd	 D  n5|tthv r fddtd	 D }|fddtd	 D  n|tt	hv r|g }nt
||td|d	 d q?|S )Nlbracket_ucode rbracket_ucode)u   ╱u   ╲u   │lbracketrbracket)/\r   r+      c                    $   g | ]}d  d | d   qS  rI   r+   r%   .0iheightslashr%   r&   
<listcomp>   s
    z.StateBase._pretty_brackets.<locals>.<listcomp>c                       g | ]}d |   qS rL   r%   rM   bslashr%   r&   rS          c                    rT   rU   r%   rM   rV   r%   r&   rS      rX   c                    rJ   rK   r%   rM   rP   r%   r&   rS      s    
)baseline)getattrr   	_lbracket_lbracket_ucoderangeextend	_rbracket_rbracket_ucode_straight_bracket_straight_bracket_ucode
ValueErrorappendjoin)	r"   rQ   use_unicoderE   rF   vertbracketsbracketbracket_argsr%   )rW   rQ   rR   r&   _pretty_brackets   s:   



zStateBase._pretty_bracketsc                 G   0   | j |g|R  }dt| dd|t| ddf S )Nz%s%s%srE   rC   rF   )_print_contentsr[   r"   printerr=   contentsr%   r%   r&   	_sympystr   s   zStateBase._sympystrc                 G   sT   ddl m} | j|g|R  }| | |j\}}||| }||| }|S )Nr   )
prettyForm) sympy.printing.pretty.stringpictrs   _print_contents_prettyrl   rQ   _use_unicodeleftright)r"   rp   r=   rs   pformrE   rF   r%   r%   r&   _pretty   s   
zStateBase._prettyc                 G   rm   )Nz{%s%s%s}lbracket_latexrC   rbracket_latex)_print_contents_latexr[   ro   r%   r%   r&   _latex   s   zStateBase._latexN)T)__name__
__module____qualname____doc__classmethodr'   r*   propertyr.   r0   r3   r8   r?   r:   rA   rl   rr   rz   r~   r%   r%   r%   r&   r   ?   s&    





*r   c                   @   s`   e Zd ZdZeZeZeZ	e
ZdZdZedd Zedd Zdd	 Zd
d Zdd Zdd ZdS )r   zBase class for Kets.

    This class defines the dual property and the brackets for printing. This is
    an abstract base class and you should not instantiate it directly, instead
    use Ket.
    z\left|z\right\rangle c                 C      dS )N)psir%   r>   r%   r%   r&   default_args      zKetBase.default_argsc                 C      t S r5   )r   r>   r%   r%   r&   r:      r   zKetBase.dual_classc                 C   ,   ddl m} t|tr|| |S t| |S )zKetBase*otherr   OuterProduct)sympy.physics.quantum.operatorr   
isinstancer   r   __mul__r"   otherr   r%   r%   r&   r         

zKetBase.__mul__c                 C   ,   ddl m} t|tr||| S t| |S )zother*KetBaser   InnerProduct)"sympy.physics.quantum.innerproductr   r   r   r   __rmul__r"   r   r   r%   r%   r&   r      r   zKetBase.__rmul__c                 K      t | d|fi |S )a  Evaluate the inner product between this ket and a bra.

        This is called to compute <bra|ket>, where the ket is ``self``.

        This method will dispatch to sub-methods having the format::

            ``def _eval_innerproduct_BraClass(self, **hints):``

        Subclasses should define these methods (one for each BraClass) to
        teach the ket how to take inner products with bras.
        _eval_innerproductr   )r"   brahintsr%   r%   r&   r      s   zKetBase._eval_innerproductc                 K   r   )a?  Apply an Operator to this Ket as Operator*Ket

        This method will dispatch to methods having the format::

            ``def _apply_from_right_to_OperatorName(op, **options):``

        Subclasses should define these methods (one for each OperatorName) to
        teach the Ket how to implement OperatorName*Ket

        Parameters
        ==========

        op : Operator
            The Operator that is acting on the Ket as op*Ket
        options : dict
            A dict of key/value pairs that control how the operator is applied
            to the Ket.
        _apply_from_right_tor   r6   r%   r%   r&   r     s   zKetBase._apply_from_right_toN)r   r   r   r   rb   rE   r`   rF   rc   rB   ra   rD   r{   r|   r   r   r:   r   r   r   r   r%   r%   r%   r&   r      s     

r   c                   @   st   e Zd ZdZeZeZeZ	e
ZdZdZedd Zdd Zdd	 Zed
d Zedd Zdd Zdd Zdd ZdS )r   zBase class for Bras.

    This class defines the dual property and the brackets for printing. This
    is an abstract base class and you should not instantiate it directly,
    instead use Bra.
    z\left\langle z\right|c                 K   s   |   j|fi |}|jS r5   )r:   r'   r?   )r"   r#   r$   stater%   r%   r&   r'   )  s   zBraBase._operators_to_statec                 K   s   | j j|fi |S r5   )r?   r*   r(   r%   r%   r&   r*   .     zBraBase._state_to_operatorsc                 K   s"   | j j|fi |}dd |D S )Nc                 S   s   g | ]}|j qS r%   r@   )rN   xr%   r%   r&   rS   3  s    z,BraBase._enumerate_state.<locals>.<listcomp>)r?   r0   )r"   r/   r$   dual_statesr%   r%   r&   r0   1  s   zBraBase._enumerate_statec                 C   s   |    S r5   )r:   r   r>   r%   r%   r&   r   5  s   zBraBase.default_argsc                 C   r   r5   )r   r>   r%   r%   r&   r:   9  r   zBraBase.dual_classc                 C   r   )zBraBase*otherr   r   )r   r   r   r   r   r   r   r%   r%   r&   r   =  r   zBraBase.__mul__c                 C   r   )zother*BraBaser   r   )r   r   r   r   r   r   r   r%   r%   r&   r   E  r   zBraBase.__rmul__c                 K   s"   ddl m} || jjdi |S )z0A default represent that uses the Ket's version.r   )DaggerNr%   )sympy.physics.quantum.daggerr   r?   r2   )r"   r$   r   r%   r%   r&   r2   M  s   zBraBase._representN)r   r   r   r   r\   rE   rb   rF   r]   rB   rc   rD   r{   r|   r   r'   r*   r0   r   r:   r   r   r2   r%   r%   r%   r&   r     s&    


r   c                   @      e Zd ZdZdS )r   DGeneral abstract quantum state used as a base class for Ket and Bra.Nr   r   r   r   r%   r%   r%   r&   r   S      r   c                   @      e Zd ZdZedd ZdS )r   a  A general time-independent Ket in quantum mechanics.

    Inherits from State and KetBase. This class should be used as the base
    class for all physical, time-independent Kets in a system. This class
    and its subclasses will be the main classes that users will use for
    expressing Kets in Dirac notation [1]_.

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the
        ket. This will usually be its symbol or its quantum numbers. For
        time-dependent state, this will include the time.

    Examples
    ========

    Create a simple Ket and looking at its properties::

        >>> from sympy.physics.quantum import Ket
        >>> from sympy import symbols, I
        >>> k = Ket('psi')
        >>> k
        |psi>
        >>> k.hilbert_space
        H
        >>> k.is_commutative
        False
        >>> k.label
        (psi,)

    Ket's know about their associated bra::

        >>> k.dual
        <psi|
        >>> k.dual_class()
        <class 'sympy.physics.quantum.state.Bra'>

    Take a linear combination of two kets::

        >>> k0 = Ket(0)
        >>> k1 = Ket(1)
        >>> 2*I*k0 - 4*k1
        2*I*|0> - 4*|1>

    Compound labels are passed as tuples::

        >>> n, m = symbols('n,m')
        >>> k = Ket(n,m)
        >>> k
        |nm>

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Bra-ket_notation
    c                 C   r   r5   )r   r>   r%   r%   r&   r:     r   zKet.dual_classNr   r   r   r   r   r:   r%   r%   r%   r&   r   X  s    ;r   c                   @   r   )r   aL  A general time-independent Bra in quantum mechanics.

    Inherits from State and BraBase. A Bra is the dual of a Ket [1]_. This
    class and its subclasses will be the main classes that users will use for
    expressing Bras in Dirac notation.

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the
        ket. This will usually be its symbol or its quantum numbers. For
        time-dependent state, this will include the time.

    Examples
    ========

    Create a simple Bra and look at its properties::

        >>> from sympy.physics.quantum import Bra
        >>> from sympy import symbols, I
        >>> b = Bra('psi')
        >>> b
        <psi|
        >>> b.hilbert_space
        H
        >>> b.is_commutative
        False

    Bra's know about their dual Ket's::

        >>> b.dual
        |psi>
        >>> b.dual_class()
        <class 'sympy.physics.quantum.state.Ket'>

    Like Kets, Bras can have compound labels and be manipulated in a similar
    manner::

        >>> n, m = symbols('n,m')
        >>> b = Bra(n,m) - I*Bra(m,n)
        >>> b
        -I*<mn| + <nm|

    Symbols in a Bra can be substituted using ``.subs``::

        >>> b.subs(n,m)
        <mm| - I*<mm|

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Bra-ket_notation
    c                 C   r   r5   )r   r>   r%   r%   r&   r:     r   zBra.dual_classNr   r%   r%   r%   r&   r     s    7r   c                   @   sl   e Zd ZdZedd Zedd Zedd Zdd	 Z	e	Z
e	Zd
d Zdd Zdd Zdd Zdd ZdS )r   aF  Base class for a general time-dependent quantum state.

    This class is used as a base class for any time-dependent state. The main
    difference between this class and the time-independent state is that this
    class takes a second argument that is the time in addition to the usual
    label argument.

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the ket. This
        will usually be its symbol or its quantum numbers. For time-dependent
        state, this will include the time as the final argument.
    c                 C   r   )N)r   tr%   r>   r%   r%   r&   r     r   zTimeDepState.default_argsc                 C   s   | j dd S )zThe label of the state.Nr=   r>   r%   r%   r&   label  s   zTimeDepState.labelc                 C   
   | j d S )zThe time of the state.r   r   r>   r%   r%   r&   time  s   
zTimeDepState.timec                 G   s   |j | jg|R  S r5   _printr   )r"   rp   r=   r%   r%   r&   _print_time  r   zTimeDepState._print_timec                 G   s   |j | jg|R  }|S r5   r   )r"   rp   r=   ry   r%   r%   r&   _print_time_pretty  s   zTimeDepState._print_time_prettyc                 G   s0   | j |g|R  }| j|g|R  }d||f S Nz%s;%s)_print_labelr   r"   rp   r=   r   r   r%   r%   r&   rn     s   zTimeDepState._print_contentsc                 G   s6   | j | jd|g|R  }| j|g|R  }d||f S )N,z%s,%s)_print_sequencer   _print_time_reprr   r%   r%   r&   _print_label_repr  s   zTimeDepState._print_label_reprc                 G   s6   | j |g|R  }| j|g|R  }|j||fddS )N;)	delimiter)_print_label_prettyr   
_print_seqr   r%   r%   r&   ru     s   z#TimeDepState._print_contents_prettyc                 G   s8   | j | j| j|g|R  }| j|g|R  }d||f S r   )r   r   _label_separator_print_time_latexr   r%   r%   r&   r}     s   
z"TimeDepState._print_contents_latexN)r   r   r   r   r   r   r   r   r   r   r   r   r   rn   r   ru   r}   r%   r%   r%   r&   r     s     


r   c                   @   r   )r   a  General time-dependent Ket in quantum mechanics.

    This inherits from ``TimeDepState`` and ``KetBase`` and is the main class
    that should be used for Kets that vary with time. Its dual is a
    ``TimeDepBra``.

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the ket. This
        will usually be its symbol or its quantum numbers. For time-dependent
        state, this will include the time as the final argument.

    Examples
    ========

    Create a TimeDepKet and look at its attributes::

        >>> from sympy.physics.quantum import TimeDepKet
        >>> k = TimeDepKet('psi', 't')
        >>> k
        |psi;t>
        >>> k.time
        t
        >>> k.label
        (psi,)
        >>> k.hilbert_space
        H

    TimeDepKets know about their dual bra::

        >>> k.dual
        <psi;t|
        >>> k.dual_class()
        <class 'sympy.physics.quantum.state.TimeDepBra'>
    c                 C   r   r5   )r   r>   r%   r%   r&   r:   L  r   zTimeDepKet.dual_classNr   r%   r%   r%   r&   r   %  s    &r   c                   @   r   )r   a  General time-dependent Bra in quantum mechanics.

    This inherits from TimeDepState and BraBase and is the main class that
    should be used for Bras that vary with time. Its dual is a TimeDepBra.

    Parameters
    ==========

    args : tuple
        The list of numbers or parameters that uniquely specify the ket. This
        will usually be its symbol or its quantum numbers. For time-dependent
        state, this will include the time as the final argument.

    Examples
    ========

        >>> from sympy.physics.quantum import TimeDepBra
        >>> b = TimeDepBra('psi', 't')
        >>> b
        <psi;t|
        >>> b.time
        t
        >>> b.label
        (psi,)
        >>> b.hilbert_space
        H
        >>> b.dual
        |psi;t>
    c                 C   r   r5   )r   r>   r%   r%   r&   r:   p  r   zTimeDepBra.dual_classNr   r%   r%   r%   r&   r   Q  s    r   c                   @   r   )r   r   Nr   r%   r%   r%   r&   r   u  r   r   c                   @   s$   e Zd ZdZedd Zdd ZdS )r   a  Orthogonal Ket in quantum mechanics.

    The inner product of two states with different labels will give zero,
    states with the same label will give one.

        >>> from sympy.physics.quantum import OrthogonalBra, OrthogonalKet
        >>> from sympy.abc import m, n
        >>> (OrthogonalBra(n)*OrthogonalKet(n)).doit()
        1
        >>> (OrthogonalBra(n)*OrthogonalKet(n+1)).doit()
        0
        >>> (OrthogonalBra(n)*OrthogonalKet(m)).doit()
        <n|m>
    c                 C   r   r5   )r   r>   r%   r%   r&   r:     r   zOrthogonalKet.dual_classc                 K   sp   t | jt |jkrtdt| j|jD ]\}}|| }| }|j}|du r-tj  S |d u r4 d S qtjS )Nz<Cannot multiply a ket that has a different number of labels.F)	lenr=   rd   zipexpandis_zeror   ZeroOne)r"   r   r   argbra_argdiffr   r%   r%   r&   r     s   
z OrthogonalKet._eval_innerproductN)r   r   r   r   r   r:   r   r%   r%   r%   r&   r   y  s
    
r   c                   @   r   )r   z)Orthogonal Bra in quantum mechanics.
    c                 C   r   r5   )r   r>   r%   r%   r&   r:     r   zOrthogonalBra.dual_classNr   r%   r%   r%   r&   r     s    r   c                       s   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Ze	dd Z
e	dd Zedd Ze	dd Ze	dd Ze	dd Ze	dd Ze	edd Zdd Zdd Z  ZS ) r   a	  Class for representations in continuous bases

    This class takes an expression and coordinates in its constructor. It can
    be used to easily calculate normalizations and probabilities.

    Parameters
    ==========

    expr : Expr
           The expression representing the functional form of the w.f.

    coords : Symbol or tuple
           The coordinates to be integrated over, and their bounds

    Examples
    ========

    Particle in a box, specifying bounds in the more primitive way of using
    Piecewise:

        >>> from sympy import Symbol, Piecewise, pi, N
        >>> from sympy.functions import sqrt, sin
        >>> from sympy.physics.quantum.state import Wavefunction
        >>> x = Symbol('x', real=True)
        >>> n = 1
        >>> L = 1
        >>> g = Piecewise((0, x < 0), (0, x > L), (sqrt(2//L)*sin(n*pi*x/L), True))
        >>> f = Wavefunction(g, x)
        >>> f.norm
        1
        >>> f.is_normalized
        True
        >>> p = f.prob()
        >>> p(0)
        0
        >>> p(L)
        0
        >>> p(0.5)
        2
        >>> p(0.85*L)
        2*sin(0.85*pi)**2
        >>> N(p(0.85*L))
        0.412214747707527

    Additionally, you can specify the bounds of the function and the indices in
    a more compact way:

        >>> from sympy import symbols, pi, diff
        >>> from sympy.functions import sqrt, sin
        >>> from sympy.physics.quantum.state import Wavefunction
        >>> x, L = symbols('x,L', positive=True)
        >>> n = symbols('n', integer=True, positive=True)
        >>> g = sqrt(2/L)*sin(n*pi*x/L)
        >>> f = Wavefunction(g, (x, 0, L))
        >>> f.norm
        1
        >>> f(L+1)
        0
        >>> f(L-1)
        sqrt(2)*sin(pi*n*(L - 1)/L)/sqrt(L)
        >>> f(-1)
        0
        >>> f(0.85)
        sqrt(2)*sin(0.85*pi*n/L)/sqrt(L)
        >>> f(0.85, n=1, L=1)
        sqrt(2)*sin(0.85*pi)
        >>> f.is_commutative
        False

    All arguments are automatically sympified, so you can define the variables
    as strings rather than symbols:

        >>> expr = x**2
        >>> f = Wavefunction(expr, 'x')
        >>> type(f.variables[0])
        <class 'sympy.core.symbol.Symbol'>

    Derivatives of Wavefunctions will return Wavefunctions:

        >>> diff(f, x)
        Wavefunction(2*x, x)

    c                    s^   dd |D }d}|D ]}t |trt| ||< n|||< |d7 }qt j| g|R i |S )Nc                 S   s   g | ]}d qS r5   r%   rM   r%   r%   r&   rS     s    z(Wavefunction.__new__.<locals>.<listcomp>r   r+   )r   tupler   super__new__)clsr=   r$   new_argsctr   	__class__r%   r&   r     s   

zWavefunction.__new__c                 O   s   | j }t|t|krtdd}|D ]8}| j| \}}t|| tr2||| jv s2||| jv s2q|| |k dksB|| |kdkrGtj  S |d7 }q| j	}t
|jD ]}	t|	| v rj|t|	 }
||	|
}qT|t||S )Nz*Incorrect number of arguments to function!r   Tr+   )	variablesr   r!   limitsr   r   free_symbolsr   r   exprliststrkeyssubsr   )r"   r=   r$   varr   vlowerupperr   symbolvalr%   r%   r&   __call__  s,    

zWavefunction.__call__c                 C   s*   | j }||}t|g| jdd  R  S Nr+   )r   _eval_derivativer   r=   )r"   r   r   derivr%   r%   r&   r   1  s   
zWavefunction._eval_derivativec                 C   s    t t| jg| jdd  R  S r   )r   r	   r   r=   r>   r%   r%   r&   _eval_conjugate7  s    zWavefunction._eval_conjugatec                 C   s   | S r5   r%   r>   r%   r%   r&   _eval_transpose:  r9   zWavefunction._eval_transposec                 C   s   | j jS r5   )r   r   r>   r%   r%   r&   r   =  s   zWavefunction.free_symbolsc                 C   r   )zr
        Override Function's is_commutative so that order is preserved in
        represented expressions
        Fr%   r>   r%   r%   r&   is_commutativeA  s   zWavefunction.is_commutativec                 G   r4   r5   r%   )r"   r=   r%   r%   r&   evalI  r   zWavefunction.evalc                 C   s    dd | j dd D }t|S )a  
        Return the coordinates which the wavefunction depends on

        Examples
        ========

            >>> from sympy.physics.quantum.state import Wavefunction
            >>> from sympy import symbols
            >>> x,y = symbols('x,y')
            >>> f = Wavefunction(x*y, x, y)
            >>> f.variables
            (x, y)
            >>> g = Wavefunction(x*y, x)
            >>> g.variables
            (x,)

        c                 S   s"   g | ]}t |tr|d  n|qS )r   )r   r   rN   gr%   r%   r&   rS   `  s   " z*Wavefunction.variables.<locals>.<listcomp>r+   N)_argsr   )r"   r   r%   r%   r&   r   M  s   zWavefunction.variablesc                 C   s,   dd | j dd D }tt| jt|S )a  
        Return the limits of the coordinates which the w.f. depends on If no
        limits are specified, defaults to ``(-oo, oo)``.

        Examples
        ========

            >>> from sympy.physics.quantum.state import Wavefunction
            >>> from sympy import symbols
            >>> x, y = symbols('x, y')
            >>> f = Wavefunction(x**2, (x, 0, 1))
            >>> f.limits
            {x: (0, 1)}
            >>> f = Wavefunction(x**2, x)
            >>> f.limits
            {x: (-oo, oo)}
            >>> f = Wavefunction(x**2 + y**2, x, (y, -1, 2))
            >>> f.limits
            {x: (-oo, oo), y: (-1, 2)}

        c                 S   s0   g | ]}t |tr|d  |d fnt tfqS )r+   rI   )r   r   r   r   r%   r%   r&   rS   z  s    (z'Wavefunction.limits.<locals>.<listcomp>r+   N)r   dictr   r   r   )r"   r   r%   r%   r&   r   c  s   zWavefunction.limitsc                 C   r   )ae  
        Return the expression which is the functional form of the Wavefunction

        Examples
        ========

            >>> from sympy.physics.quantum.state import Wavefunction
            >>> from sympy import symbols
            >>> x, y = symbols('x, y')
            >>> f = Wavefunction(x**2, x)
            >>> f.expr
            x**2

        r   )r   r>   r%   r%   r&   r   ~  s   
zWavefunction.exprc                 C   s   t | jdS )a  
        Returns true if the Wavefunction is properly normalized

        Examples
        ========

            >>> from sympy import symbols, pi
            >>> from sympy.functions import sqrt, sin
            >>> from sympy.physics.quantum.state import Wavefunction
            >>> x, L = symbols('x,L', positive=True)
            >>> n = symbols('n', integer=True, positive=True)
            >>> g = sqrt(2/L)*sin(n*pi*x/L)
            >>> f = Wavefunction(g, (x, 0, L))
            >>> f.is_normalized
            True

        r+   )r   normr>   r%   r%   r&   is_normalized  s   zWavefunction.is_normalizedc                 C   sN   | j t| j  }| j}| j}|D ]}|| }t|||d |d f}qt|S )a  
        Return the normalization of the specified functional form.

        This function integrates over the coordinates of the Wavefunction, with
        the bounds specified.

        Examples
        ========

            >>> from sympy import symbols, pi
            >>> from sympy.functions import sqrt, sin
            >>> from sympy.physics.quantum.state import Wavefunction
            >>> x, L = symbols('x,L', positive=True)
            >>> n = symbols('n', integer=True, positive=True)
            >>> g = sqrt(2/L)*sin(n*pi*x/L)
            >>> f = Wavefunction(g, (x, 0, L))
            >>> f.norm
            1
            >>> g = sin(n*pi*x/L)
            >>> f = Wavefunction(g, (x, 0, L))
            >>> f.norm
            sqrt(2)*sqrt(L)/2

        r   r+   )r   r	   r   r   r   r
   )r"   expr   r   r   curr_limitsr%   r%   r&   r     s   zWavefunction.normc                 C   s:   | j }|tu rtdt|d | j g| jdd R  S )aU  
        Return a normalized version of the Wavefunction

        Examples
        ========

            >>> from sympy import symbols, pi
            >>> from sympy.functions import sin
            >>> from sympy.physics.quantum.state import Wavefunction
            >>> x = symbols('x', real=True)
            >>> L = symbols('L', positive=True)
            >>> n = symbols('n', integer=True, positive=True)
            >>> g = sin(n*pi*x/L)
            >>> f = Wavefunction(g, (x, 0, L))
            >>> f.normalize()
            Wavefunction(sqrt(2)*sin(pi*n*x/L)/sqrt(L), (x, 0, L))

        z!The function is not normalizable!r   r+   N)r   r   r!   r   r   r=   )r"   constr%   r%   r&   	normalize  s   $zWavefunction.normalizec                 C   s   t | jt| j g| jR  S )a
  
        Return the absolute magnitude of the w.f., `|\psi(x)|^2`

        Examples
        ========

            >>> from sympy import symbols, pi
            >>> from sympy.functions import sin
            >>> from sympy.physics.quantum.state import Wavefunction
            >>> x, L = symbols('x,L', real=True)
            >>> n = symbols('n', integer=True)
            >>> g = sin(n*pi*x/L)
            >>> f = Wavefunction(g, (x, 0, L))
            >>> f.prob()
            Wavefunction(sin(pi*n*x/L)**2, x)

        )r   r   r	   r   r>   r%   r%   r&   prob  s   zWavefunction.prob)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r%   r%   r   r&   r     s4    W#






$r   N)-r   sympy.core.cacher   sympy.core.containersr   sympy.core.exprr   sympy.core.functionr   sympy.core.numbersr   r   sympy.core.singletonr   $sympy.functions.elementary.complexesr	   (sympy.functions.elementary.miscellaneousr
   sympy.integrals.integralsr   rt   r   sympy.physics.quantum.qexprr   r   __all__r\   r`   rb   r]   ra   rc   r   r   r   r   r   r   r   r   r   r   r   r   r   r%   r%   r%   r&   <module>   sB     O9AAK,$(	