o
    h                     @   sZ   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
 dgZG dd deZd	S )
zSymbolic inner product.    )Expr)
NumberKind)	conjugate)
prettyForm)DaggerInnerProductc                   @   sh   e Zd ZdZe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   aT  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 quantum expressions, inner products will be automatically
    identified and created::

        >>> b*k
        <b|k>

    In more complex expressions, where there is ambiguity in whether inner or
    outer products should be created, inner products have high priority::

        >>> 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   sN   ddl m}m} t||std| t||std| t| ||}|S )Nr   )KetBaseBraBasez"KetBase subclass expected, got: %rz"BraBase subclass expected, got: %r)sympy.physics.quantum.stater   r	   
isinstance	TypeErrorr   __new__)clsbraketr   r	   obj r   X/var/www/html/ai/venv/lib/python3.10/site-packages/sympy/physics/quantum/innerproduct.pyr   J   s   

zInnerProduct.__new__c                 C   
   | j d S )Nr   argsselfr   r   r   r   U      
zInnerProduct.brac                 C   r   )N   r   r   r   r   r   r   Y   r   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   s2   d| j j|j| jg|R  |j| jg|R  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   sbrasketr   r   r   	_sympystrd   s   zInnerProduct._sympystrc                 G   s   | j j|g|R  }| jj|g|R  }t| | }|j}| j ||\}}| j||\}	}
t|| }t|	|	 }t|	| }t|	|
 }|S r   )
r   _print_contents_prettyr   maxheight_use_unicode_pretty_bracketsr   leftright)r   r    r   r   r   r(   use_unicodelbracket_cbracketrbracketpformr   r   r   _prettyi   s   zInnerProduct._prettyc                 G   s4   | j j|g|R  }|j| jg|R  }d||f S )Nz\left\langle %s \right. %s)r   _print_contents_latexr   r   )r   r    r   	bra_labelr   r   r   r   _latexy   s   zInnerProduct._latexc                 K   sx   z| j j| jfi |}W n& ty3   zt| jjj| j jfi |}W n ty0   d }Y nw Y nw |d ur:|S | S r   )r   _eval_innerproductr   NotImplementedErrorr   dual)r   hintsrr   r   r   doit~   s   zInnerProduct.doitN)r   
__module____qualname____doc__r   kind
is_complexr   propertyr   r   r   r!   r%   r3   r6   r<   r   r   r   r   r      s    /

N)r?   sympy.core.exprr   sympy.core.kindr   $sympy.functions.elementary.complexesr    sympy.printing.pretty.stringpictr   sympy.physics.quantum.daggerr   __all__r   r   r   r   r   <module>   s    