U
    L?h                     @   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gZG dd deZd	S )
zSymbolic inner product.    )Expr)	conjugate)
prettyForm)Dagger)KetBaseBraBaseInnerProductc                   @   sd   e Zd ZdZdZdd Zedd Zedd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd ZdS )r   a  An unevaluated inner product between a Bra and a Ket [1].

    Parameters
    ==========

    bra : BraBase or subclass
        The bra on the left side of the inner product.
    ket : KetBase or subclass
        The ket on the right side of the inner product.

    Examples
    ========

    Create an InnerProduct and check its properties:

        >>> from sympy.physics.quantum import Bra, Ket
        >>> b = Bra('b')
        >>> k = Ket('k')
        >>> ip = b*k
        >>> ip
        <b|k>
        >>> ip.bra
        <b|
        >>> ip.ket
        |k>

    In simple products of kets and bras inner products will be automatically
    identified and created::

        >>> b*k
        <b|k>

    But in more complex expressions, there is ambiguity in whether inner or
    outer products should be created::

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

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

        >>> k*(b*k)*b
        <b|k>*|k>*<b|

    Notice how the inner product <b|k> moved to the left of the expression
    because inner products are commutative complex numbers.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Inner_product
    Tc                 C   s>   t |tstd| t |ts,td| t| ||}|S )Nz"KetBase subclass expected, got: %rz"BraBase subclass expected, got: %r)
isinstancer   	TypeErrorr   r   __new__)clsbraketobj r   T/var/www/html/venv/lib/python3.8/site-packages/sympy/physics/quantum/innerproduct.pyr   L   s    

zInnerProduct.__new__c                 C   s
   | j d S )Nr   argsselfr   r   r   r   T   s    zInnerProduct.brac                 C   s
   | j d S )N   r   r   r   r   r   r   X   s    zInnerProduct.ketc                 C   s   t t| jt| jS N)r   r   r   r   r   r   r   r   _eval_conjugate\   s    zInnerProduct._eval_conjugatec                 G   s.   d| j j|j| jf| |j| jf| f S )Nz	%s(%s,%s))	__class____name___printr   r   )r   printerr   r   r   r   
_sympyrepr_   s     zInnerProduct._sympyreprc                 G   s4   | | j}| | j}d|d d |dd  f S )Nz%s|%sr   )r   r   r   )r   r   r   ZsbraZsketr   r   r   	_sympystrc   s    zInnerProduct._sympystrc                 G   s   | j j|f| }| jj|f| }t| | }|j}| j ||\}}| j||\}	}
t|| }t|	|	 }t|	| }t|	|
 }|S r   )
r   Z_print_contents_prettyr   maxheightZ_use_unicodeZ_pretty_bracketsr   leftright)r   r   r   r   r   r!   Zuse_unicodeZlbracket_ZcbracketZrbracketZpformr   r   r   _prettyh   s    zInnerProduct._prettyc                 G   s0   | j j|f| }|j| jf| }d||f S )Nz\left\langle %s \right. %s)r   Z_print_contents_latexr   r   )r   r   r   Z	bra_labelr   r   r   r   _latexx   s    zInnerProduct._latexc                 K   st   z| j j| jf|}W nL tk
rb   zt| jjj| j jf|}W n tk
r\   d }Y nX Y nX |d k	rp|S | S r   )r   Z_eval_innerproductr   NotImplementedErrorr   Zdual)r   hintsrr   r   r   doit}   s    zInnerProduct.doitN)r   
__module____qualname____doc__Z
is_complexr   propertyr   r   r   r   r   r%   r&   r*   r   r   r   r   r      s   4

N)r-   Zsympy.core.exprr   Z$sympy.functions.elementary.complexesr   Z sympy.printing.pretty.stringpictr   Zsympy.physics.quantum.daggerr   Zsympy.physics.quantum.stater   r   __all__r   r   r   r   r   <module>   s   