ó
¡¼™\c           @  s‘   d  Z  d d l m Z m Z d d l m Z m Z m Z m Z d d l	 m
 Z
 d d l m Z d d l m Z d g Z d e f d „  ƒ  YZ d	 S(
   s+   The anti-commutator: ``{A,B} = A*B + B*A``.iÿÿÿÿ(   t   print_functiont   division(   t   St   Exprt   Mult   Integer(   t
   prettyForm(   t   Operator(   t   Daggert   AntiCommutatorc           B  sb   e  Z d  Z e Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z RS(	   sõ  The standard anticommutator, in an unevaluated state.

    Evaluating an anticommutator is defined [1]_ as: ``{A, B} = A*B + B*A``.
    This class returns the anticommutator in an unevaluated form.  To evaluate
    the anticommutator, use the ``.doit()`` method.

    Canonical ordering of an anticommutator is ``{A, B}`` for ``A < B``. The
    arguments of the anticommutator are put into canonical order using
    ``__cmp__``. If ``B < A``, then ``{A, B}`` is returned as ``{B, A}``.

    Parameters
    ==========

    A : Expr
        The first argument of the anticommutator {A,B}.
    B : Expr
        The second argument of the anticommutator {A,B}.

    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy.physics.quantum import AntiCommutator
    >>> from sympy.physics.quantum import Operator, Dagger
    >>> x, y = symbols('x,y')
    >>> A = Operator('A')
    >>> B = Operator('B')

    Create an anticommutator and use ``doit()`` to multiply them out.

    >>> ac = AntiCommutator(A,B); ac
    {A,B}
    >>> ac.doit()
    A*B + B*A

    The commutator orders it arguments in canonical order:

    >>> ac = AntiCommutator(B,A); ac
    {A,B}

    Commutative constants are factored out:

    >>> AntiCommutator(3*x*A,x*y*B)
    3*x**2*y*{A,B}

    Adjoint operations applied to the anticommutator are properly applied to
    the arguments:

    >>> Dagger(AntiCommutator(A,B))
    {Dagger(A),Dagger(B)}

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Commutator
    c         C  s;   |  j  | | ƒ } | d  k	 r" | St j |  | | ƒ } | S(   N(   t   evalt   NoneR   t   __new__(   t   clst   At   Bt   rt   obj(    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyR   O   s
    c         C  sÝ   | o	 | s t  j S| | k r1 t d ƒ | d S| j sC | j rU t d ƒ | | S| j ƒ  \ } } | j ƒ  \ } } | | } | r· t t | Œ  |  t j | ƒ t j | ƒ ƒ ƒ S| j | ƒ d k rÙ |  | | ƒ Sd  S(   Ni   i   (   R   t   ZeroR   t   is_commutativet   args_cncR   t
   _from_argst   compare(   R   t   at   bt   cat   ncat   cbt   ncbt   c_part(    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyR
   V   s    
.c         K  sÇ   |  j  d } |  j  d } t | t ƒ r® t | t ƒ r® y | j | |  } WnA t k
 r‘ y | j | |  } Wq’ t k
 r d } q’ Xn X| d k	 r® | j |   Sn  | | | | j |   S(   s    Evaluate anticommutator i    i   N(   t   argst
   isinstanceR   t   _eval_anticommutatort   NotImplementedErrorR   t   doit(   t   selft   hintsR   R   t   comm(    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyR"   k   s    c         C  s'   t  t |  j d ƒ t |  j d ƒ ƒ S(   Ni    i   (   R	   R   R   (   R#   (    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyt   _eval_adjoint{   s    c         G  s7   d |  j  j | j |  j d ƒ | j |  j d ƒ f S(   Ns	   %s(%s,%s)i    i   (   t	   __class__t   __name__t   _printR   (   R#   t   printerR   (    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyt
   _sympyrepr~   s    c         G  s   d |  j  d |  j  d f S(   Ns   {%s,%s}i    i   (   R   (   R#   R*   R   (    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyt	   _sympystr„   s    c         G  s~   | j  |  j d | Œ } t | j t d ƒ ƒ Œ  } t | j | j  |  j d | Œ ƒ Œ  } t | j d d d d ƒ Œ  } | S(   Ni    u   ,i   t   leftt   {t   rightt   }(   R)   R   R   R/   t   parens(   R#   R*   R   t   pform(    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyt   _pretty‡   s
    (c         G  s0   d t  g  |  j D] } | j | | Œ ^ q ƒ S(   Ns   \left\{%s,%s\right\}(   t   tupleR   R)   (   R#   R*   R   t   arg(    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyt   _latexŽ   s    (   R(   t
   __module__t   __doc__t   FalseR   R   t   classmethodR
   R"   R&   R+   R,   R3   R6   (    (    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyR	      s   8						N(   R8   t
   __future__R    R   t   sympyR   R   R   R   t    sympy.printing.pretty.stringpictR   t   sympy.physics.quantum.operatorR   t   sympy.physics.quantum.daggerR   t   __all__R	   (    (    (    sC   lib/python2.7/site-packages/sympy/physics/quantum/anticommutator.pyt   <module>   s   "	