o
    GZŽ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)Zsympy.physics.quantum.stater   r	   Ú
isinstanceÚ	TypeErrorr   Ú__new__)ÚclsÚbraÚketr   r	   Úobj© r   úQ/var/www/auris/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|%séÿÿÿÿr   )r   r   r   )r   r   r   ZsbraZ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   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   Ú_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   Z_print_contents_latexr   r   )r   r   r   Z	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   Z_eval_innerproductr   ÚNotImplementedErrorr   Zdual)r   ÚhintsÚrr   r   r   Údoit~   s   ÿÿ€ûzInnerProduct.doitN)r   Ú
__module__Ú__qualname__Ú__doc__r   ÚkindZ
is_complexr   Úpropertyr   r   r   r    r"   r(   r)   r-   r   r   r   r   r      s    /

N)r0   Zsympy.core.exprr   Zsympy.core.kindr   Z$sympy.functions.elementary.complexesr   Z sympy.printing.pretty.stringpictr   Zsympy.physics.quantum.daggerr   Ú__all__r   r   r   r   r   Ú<module>   s    ÿ