o
    jg·  ã                   @   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   úZ/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/physics/quantum/innerproduct.pyr   L   s   

zInnerProduct.__new__c                 C   ó
   | j d S )Nr   ©Úargs©Úselfr   r   r   r   T   ó   
zInnerProduct.brac                 C   r   )Né   r   r   r   r   r   r   X   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   ÚsbraÚsketr   r   r   Ú	_sympystrc   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   Ú_prettyh   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   Ú_latexx   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__Ú
is_complexr   Úpropertyr   r   r   r   r#   r1   r4   r:   r   r   r   r   r      s    4

N)r=   Úsympy.core.exprr   Ú$sympy.functions.elementary.complexesr   Ú sympy.printing.pretty.stringpictr   Úsympy.physics.quantum.daggerr   Úsympy.physics.quantum.stater   r   Ú__all__r   r   r   r   r   Ú<module>   s    ÿ