
    sg                     d    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e      Zy	)
zSymbolic inner product.    )Expr)	conjugate)
prettyForm)Dagger)KetBaseBraBaseInnerProductc                   ^    e Zd ZdZdZd Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zy)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                     t        |t              st        d|z        t        |t              st        d|z        t	        j
                  | ||      }|S )Nz"KetBase subclass expected, got: %rz"BraBase subclass expected, got: %r)
isinstancer   	TypeErrorr   r   __new__)clsbraketobjs       U/var/www/html/venv/lib/python3.12/site-packages/sympy/physics/quantum/innerproduct.pyr   zInnerProduct.__new__L   sO    #w'@3FGG#w'@3FGGll3S)
    c                      | j                   d   S )Nr   argsselfs    r   r   zInnerProduct.braT       yy|r   c                      | j                   d   S )N   r   r   s    r   r   zInnerProduct.ketX   r   r   c                 f    t        t        | j                        t        | j                              S N)r	   r   r   r   r   s    r   _eval_conjugatezInnerProduct._eval_conjugate\   s!    F488,fTXX.>??r   c                     | j                   j                  d |j                  | j                  g| d |j                  | j                  g| dS )N(,))	__class____name___printr   r   )r   printerr   s      r   
_sympyreprzInnerProduct._sympyrepr_   sH    "nn55GNN488+d+^W^^DHH-Lt-LN 	Nr   c                     |j                  | j                        }|j                  | j                        }|d d d|dd  S )N|r   )r&   r   r   )r   r'   r   sbraskets        r   	_sympystrzInnerProduct._sympystrc   s=    ~~dhh'~~dhh's)T!"X..r   c                     | j                   j                  |g| } | j                  j                  |g| }t        |j	                         |j	                               }|j
                  }| j                   j                  ||      \  }}| j                  j                  ||      \  }	}
t        |j                  |       }t        |j                  |	       }t        |j                  |       }t        |j                  |
       }|S r   )
r   _print_contents_prettyr   maxheight_use_unicode_pretty_bracketsr   leftright)r   r'   r   r   r   r2   use_unicodelbracket_cbracketrbracketpforms               r   _prettyzInnerProduct._prettyh   s    -dhh--g==-dhh--g==SZZ\3::<0**hh//D!!XX66v{K(CHHX./EKK12EKK,-EKK12r   c                      | j                   j                  |g| } |j                  | j                  g| }d|d|S )Nz\left\langle z	 \right. )r   _print_contents_latexr&   r   )r   r'   r   	bra_labelr   s        r   _latexzInnerProduct._latexx   sA    2DHH227BTB	gnnTXX--093??r   c                 *   	  | j                   j                  | j                  fi |}||S | S # t        $ rZ 	 t	         | j                  j
                  j                  | j                   j
                  fi |      }n# t        $ r d }Y nw xY wY hw xY wr   )r   _eval_innerproductr   NotImplementedErrorr   dual)r   hintsrs      r   doitzInnerProduct.doit}   s    	+++DHH>>A =H # 	4DHHMM44TXX]]LeL ' 	s3   '/ 	BAA>=B>B	BBBBN)r%   
__module____qualname____doc__
is_complexr   propertyr   r   r   r(   r.   r=   rA   rH    r   r   r	   r	      s]    3h J    @N/
 @
r   N)rK   sympy.core.exprr   $sympy.functions.elementary.complexesr    sympy.printing.pretty.stringpictr   sympy.physics.quantum.daggerr   sympy.physics.quantum.stater   r   __all__r	   rN   r   r   <module>rU      s1       : 7 / 8 t4 tr   