ó
¡¼™\c           @  s‹   d  Z  d d l m Z m Z d d l m Z m Z d d l m Z d d l	 m
 Z
 d d l m Z m Z d g Z d e f d „  ƒ  YZ d	 S(
   s   Symbolic inner product.iÿÿÿÿ(   t   print_functiont   division(   t   Exprt	   conjugate(   t
   prettyForm(   t   Dagger(   t   KetBaset   BraBaset   InnerProductc           B  sq   e  Z d  Z e Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z RS(
   sû  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, InnerProduct
        >>> 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
    c         C  s]   t  | t ƒ s" t d | ƒ ‚ n  t  | t ƒ sD t d | ƒ ‚ n  t j |  | | ƒ } | S(   Ns"   KetBase subclass expected, got: %rs"   BraBase subclass expected, got: %r(   t
   isinstanceR   t	   TypeErrorR   R   t   __new__(   t   clst   brat   kett   obj(    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyR   M   s    c         C  s   |  j  d S(   Ni    (   t   args(   t   self(    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyR   U   s    c         C  s   |  j  d S(   Ni   (   R   (   R   (    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyR   Y   s    c         C  s   t  t |  j ƒ t |  j ƒ ƒ S(   N(   R   R   R   R   (   R   (    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyt   _eval_conjugate]   s    c         G  s5   d |  j  j | j |  j | Œ | j |  j | Œ f S(   Ns	   %s(%s,%s)(   t	   __class__t   __name__t   _printR   R   (   R   t   printerR   (    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyt
   _sympyrepr`   s    c         G  s4   t  |  j ƒ } t  |  j ƒ } d | d  | d f S(   Ns   %s|%siÿÿÿÿi   (   t   strR   R   (   R   R   R   t   sbrat   sket(    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyt	   _sympystrd   s    c         G  sÜ   |  j  j | | Œ } |  j j | | Œ } t | j ƒ  | j ƒ  ƒ } | j } |  j  j | | ƒ \ } } |  j j | | ƒ \ }	 }
 t | j | ƒ Œ  } t | j	 |	 ƒ Œ  } t | j	 | ƒ Œ  } t | j	 |
 ƒ Œ  } | S(   N(
   R   t   _print_contents_prettyR   t   maxt   heightt   _use_unicodet   _pretty_bracketsR   t   leftt   right(   R   R   R   R   R   R   t   use_unicodet   lbrackett   _t   cbrackett   rbrackett   pform(    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyt   _prettyi   s    	c         G  s8   |  j  j | | Œ } | j |  j | Œ } d | | f S(   Ns   \left\langle %s \right. %s(   R   t   _print_contents_latexR   R   (   R   R   R   t	   bra_labelR   (    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyt   _latexy   s    c         K  s†   y |  j  j |  j |  } WnS t k
 rq y( t |  j j j |  j  j |  ƒ } Wqr t k
 rm d  } qr Xn X| d  k	 r‚ | S|  S(   N(   R   t   _eval_innerproductR   t   NotImplementedErrorR   t   dualt   None(   R   t   hintst   r(    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyt   doit~   s    %(   R   t
   __module__t   __doc__t   Truet
   is_complexR   t   propertyR   R   R   R   R   R)   R,   R3   (    (    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyR      s   4						N(   R5   t
   __future__R    R   t   sympyR   R   t    sympy.printing.pretty.stringpictR   t   sympy.physics.quantum.daggerR   t   sympy.physics.quantum.stateR   R   t   __all__R   (    (    (    sA   lib/python2.7/site-packages/sympy/physics/quantum/innerproduct.pyt   <module>   s   	