
\c           @  s  d  d l  m Z m Z d  d l m Z d  d l m Z d  d l 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 d l m Z m Z d d l m Z m Z d d l m Z d d l m Z d f  d     YZ e e
 j  Z d   Z d   Z d e e f d     YZ  d d  Z! e" e# d  Z$ d   Z% d d l& m' Z' d d l( m) Z) d d l* m+ Z+ m, Z, m- Z- d S(   i(   t   print_functiont   division(   t   defaultdict(   t
   cmp_to_keyNi   (   t   sympify(   t   Basic(   t   S(   t   AssocOp(   t   cacheit(   t	   fuzzy_nott   _fuzzy_group(   t   reducet   range(   t   Expr(   t   global_distributet	   NC_Markerc           B  s&   e  Z e Z e Z e Z e Z e Z RS(    (   t   __name__t
   __module__t   Falset   is_Ordert   is_Mult	   is_Numbert   is_Polyt   is_commutative(    (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR      s
   c         C  s   |  j  d t  d  S(   Nt   key(   t   sortt   _args_sortkey(   t   args(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _mulsort    s    c          G  s   t  |   }  g  } g  } t j } x |  r |  j   } | j r | j   \ } } |  j |  | r | j t j	 |   q q$ | j
 r | | 9} q$ | j |  q$ Wt |  | t j k	 r | j d |  n  | r | j t j	 |   n  t j	 |  S(   s   Return a well-formed unevaluated Mul: Numbers are collected and
    put in slot 0, any arguments that are Muls will be flattened, and args
    are sorted. Use this when args have changed but you still want to return
    an unevaluated Mul.

    Examples
    ========

    >>> from sympy.core.mul import _unevaluated_Mul as uMul
    >>> from sympy import S, sqrt, Mul
    >>> from sympy.abc import x
    >>> a = uMul(*[S(3.0), x, S(2)])
    >>> a.args[0]
    6.00000000000000
    >>> a.args[1]
    x

    Two unevaluated Muls with the same arguments will
    always compare as equal during testing:

    >>> m = uMul(sqrt(2), sqrt(3))
    >>> m == uMul(sqrt(3), sqrt(2))
    True
    >>> u = Mul(sqrt(3), sqrt(2), evaluate=False)
    >>> m == uMul(u)
    True
    >>> m == Mul(*m.args)
    False

    i    (   t   listR   t   Onet   popR   t   args_cnct   extendt   appendt   Mult
   _from_argsR   R   t   insert(   R   t   newargst   ncargst   cot   at   ct   nc(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _unevaluated_Mul%   s(    				
R#   c           B  so  e  Z g  Z e Z e d     Z d   Z e d    Z d   Z	 e
 d    Z e d    Z e d    Z e d    Z e d  Z e d	  Z e d
    Z d   Z e d    Z e d    Z d   Z d   Z i  e d  Z i  d  Z e d    Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d    Z* d!   Z+ d"   Z, d#   Z- d$   Z. d%   Z/ d&   Z0 d'   Z1 d(   Z2 d)   Z3 d*   Z4 d+   Z5 d,   Z6 d-   Z7 d.   Z8 d/   Z9 d0   Z: d1   Z; d2   Z< d3   Z= d4   Z> d5   Z? e e d6  Z@ eA d7  ZB e
 d8    ZC RS(9   c   4        s  d d l  m } d d l m   d } t |  d k r| \ }   j ri  | }  |  g } n  | t j k	 s~ t	  | j
 r| j r j   \ }   j r| t j k	 r |  | |  d t g g  d f } qt d r j r j   \ }  g  t j   D] } t | |  ^ q} t |  | | } | r`| j d |  n  t j |  g } | g  d f } qqn  | r| Sn  g  }	 g  }
 g  } t j } g  } g  } t j } i  } d } x| D]} | j r| j |  \ } } n  | j rs| j r&| j | j  qx7 | j D], } | j rO| j |  q0| j |  q0W| j t  qq| j r	| t j  k s| t j! k r| t j k rt j  g g  d f S| j st" | |  r| | 9} | t j  k rt j  g g  d f Sqqqt" | |  r-| j# |  } qq| t j! k r| sUt j  g g  d f S| t j! k rwt j! g g  d f St j! } qq| t j$ k r| t j% 7} qq| j r| j&   \  } | j' r j r| j rs| j( r | t)  |  9} qnB | j* r%| j t)  |   qn  j* rB| | 7}   n   t j k	 r| j+  g   j |  qqq j, s| j- r| j  | f  qqqn  | j  | f  q| t k	 r| j |  n  x | r| j. d  } |
 s|
 j |  qn  |
 j.   } | j&   \ } } | j&   \ } } | | } | | k r| j r| | } | j r}| j |  qq| j d |  q|
 j |  |
 j |  qWqWd   } | |  } | |  } xt/ d  D]} g  } t } x+| D]#\  } | j
 rg j s  j rt0  f d   t j! t j1 t j2 f D  rt j  g g  d f Sqn  | t j k r j r|  9} qn   }  n  | t j k	 rt)  |  }  |  j' r j' r } |  j&   \  }  | k rt3 } qqn  |	 j |   | j  | f  qW| rct t4 d	   | D   t |  k rcg  }	 | |  } qPqWi  }! x- | D]% \  } |! j+ | g   j   quWx* |! j5   D] \ }  |     |! | <qW|	 j g  |! j5   D]! \ }  | rt)  |  ^ q i  }" x9 | j5   D]+ \  } |" j+ t |   g   j   qW~ g  }# x |" j5   D] \ }  |      | j6 d
 k r| t)  |  9} q^n  | j7 | j6 k rt8 | j7 | j6  \ }$ }% | t)  |$  9} t9 |% | j6  } n  |# j  | f  q^W~" t: t;  }& d } x| t |#  k  r|# | \ } }' g  }( xt/ | d
 t |#   D] }) |# |) \ }* }+ | j< |*  }, |, t j k	 rd	|' |+ } | j6 d
 k r	| t) |, |  9} nh | j7 | j6 k r
t8 | j7 | j6  \ }$ }% | t) |, |$  9} t9 |% | j6  } n  |( j |, | f  |* |, |+ f |# |) <| |, } | t j k rc
Pqc
qd	qd	W| t j k	 r
t) | |'  }- |- j r
| |- 9} q
x_ t= j |-  D]K }- |- j r
| |- 9} q
|- j' s
t	  |- j \ } }' |& |' j |  q
Wn  |# j |(  | d
 7} q"	Wx* |& j5   D] \ }  |     |& | <q%W| r | j>   \ }  } t8 |  |  \ }. }  |. d r| } n  | d k r|	 j t j$  q |  r t9 |  |  } x` |& j5   D]0 \ }  | | k r j, r |& | <PqqW|	 j t) t j? | d t  q n  |	 j g  |& j5   D] \ }  t)  |  ^ q3 | t j1 k ss| t j2 k rd   }/ |/ |	 d
  \ }	 }0 |/ |
 |0  \ }
 }0 | |0 9} n  | t j! k r3g  |	 D]* }1 t@ |1 j
  o|1 jA d k	 s|1 ^ q}	 g  |
 D]* }1 t@ |1 j
  o!|1 jA d k	 s |1 ^ q }
 nt | t j k rt0   f d   |
 D  rn| g |
 | f St0 d   |	 D  rt j  g g  | f S| g g  | f Sg  }2 x1 |	 D]) } | j r| | 9} q|2 j |  qW|2 }	 tB |	  | t j k	 r|	 j d |  n  t d r|
 rt |	  d k r|	 d j r|	 d jC r|	 d
 j r|	 d } t g  |	 d
 j D] }3 | |3 ^ qx  g }	 n  |	 |
 | f S(   s.  Return commutative, noncommutative and order arguments by
        combining related terms.

        Notes
        =====
            * In an expression like ``a*b*c``, python process this through sympy
              as ``Mul(Mul(a, b), c)``. This can have undesirable consequences.

              -  Sometimes terms are not combined as one would like:
                 {c.f. https://github.com/sympy/sympy/issues/4596}

                >>> from sympy import Mul, sqrt
                >>> from sympy.abc import x, y, z
                >>> 2*(x + 1) # this is the 2-arg Mul behavior
                2*x + 2
                >>> y*(x + 1)*2
                2*y*(x + 1)
                >>> 2*(x + 1)*y # 2-arg result will be obtained first
                y*(2*x + 2)
                >>> Mul(2, x + 1, y) # all 3 args simultaneously processed
                2*y*(x + 1)
                >>> 2*((x + 1)*y) # parentheses can control this behavior
                2*y*(x + 1)

                Powers with compound bases may not find a single base to
                combine with unless all arguments are processed at once.
                Post-processing may be necessary in such cases.
                {c.f. https://github.com/sympy/sympy/issues/5728}

                >>> a = sqrt(x*sqrt(y))
                >>> a**3
                (x*sqrt(y))**(3/2)
                >>> Mul(a,a,a)
                (x*sqrt(y))**(3/2)
                >>> a*a*a
                x*sqrt(y)*sqrt(x*sqrt(y))
                >>> _.subs(a.base, z).subs(z, a.base)
                (x*sqrt(y))**(3/2)

              -  If more than two terms are being multiplied then all the
                 previous terms will be re-processed for each new argument.
                 So if each of ``a``, ``b`` and ``c`` were :class:`Mul`
                 expression, then ``a*b*c`` (or building up the product
                 with ``*=``) will process all the arguments of ``a`` and
                 ``b`` twice: once when ``a*b`` is computed and again when
                 ``c`` is multiplied.

                 Using ``Mul(a, b, c)`` will process all arguments once.

            * The results of Mul are cached according to arguments, so flatten
              will only be called once for ``Mul(a, b, c)``. If you can
              structure a calculation so the arguments are most likely to be
              repeats then this can save time in computing the answer. For
              example, say you had a Mul, M, that you wished to divide by ``d[i]``
              and multiply by ``n[i]`` and you suspect there are many repeats
              in ``n``. It would be better to compute ``M*n[i]/d[i]`` rather
              than ``M/d[i]*n[i]`` since every time n[i] is a repeat, the
              product, ``M*n[i]`` will be returned without flattening -- the
              cached value will be returned. If you divide by the ``d[i]``
              first (and those are more unique than the ``n[i]``) then that will
              create a new Mul, ``M/d[i]`` the args of which will be traversed
              again when it is multiplied by ``n[i]``.

              {c.f. https://github.com/sympy/sympy/issues/5706}

              This consideration is moot if the cache is turned off.

            NB
            --
              The validity of the above notes depends on the implementation
              details of Mul and flatten which may change at any time. Therefore,
              you should only consider them when your code is highly performance
              sensitive.

              Removal of 1 from the sequence is already handled by AssocOp.__new__.
        i(   t   AccumBounds(   t
   MatrixExpri   t   evaluatei    c         S  s   i  } xM |  D]E \ } } | j    } | j | i   j | d g   j | d  q WxG | j   D]9 \ } } x* | j   D] \ } } t |   | | <q| Wqc Wg  } xP | j   D]B \ } } | j g  | j   D] \ }	 }
 | |
 |	 f ^ q  q W| S(   Ni   i    (   t   as_coeff_Mult
   setdefaultR"   t   itemst   AddR!   (   t   c_powerst   common_bt   bt   eR(   t   dt   dit   lit   new_c_powerst   tR*   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _gathert  s    :c         3  s   |  ] } |   j  k Vq d  S(   N(   R   (   t   .0t   infty(   R6   (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s   c         s  s   |  ] \ } } | Vq d  S(   N(    (   R>   R6   R7   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    i   c         S  sV   g  } xC |  D]; } | j  r" q n  | j r; | d 9} q n  | j |  q W| | f S(   Ni(   t   is_positivet   is_negativeR"   (   t   c_partt
   coeff_signt
   new_c_partR<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _handle_for_oo2  s    		
c         3  s   |  ] } t  |    Vq d  S(   N(   t
   isinstance(   R>   R*   (   R.   (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>P  s    c         s  s   |  ] } | j  t k Vq d  S(   N(   t	   is_finiteR   (   R>   R*   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>R  s    N(D   t   sympy.calculus.utilR-   t   sympy.matrices.expressionsR.   t   Nonet   lent   is_RationalR   R   t   AssertionErrort   is_zeroR0   t   is_AddR   R   R   t   as_coeff_AddR3   t	   make_argst   _keep_coefft   _addsortR%   R$   t   ZeroR   t   as_expr_variablesR   R!   R   R"   R   R   t   NaNt   ComplexInfinityRF   t   __mul__t   ImaginaryUnitt   Halft   as_base_expt   is_Powt
   is_Integert   PowRA   R1   R@   t
   is_integerR   R   t   anyt   Infinityt   NegativeInfinityt   Truet   setR2   t   qt   pt   divmodt   RationalR   R   t   gcdR#   t   as_numer_denomt   NegativeOneR	   t   is_realR   RG   (4   t   clst   seqR-   t   rvR)   t   rt   bit   bargst   arRB   t   nc_partt   nc_seqt   coeffR4   t   num_expt   neg1et   pnum_ratt   order_symbolst   oRe   R7   t   o1t   b1t   e1t   b2t   e2t   new_expt   o12R=   t   iR;   t   changedRf   t   inv_exp_dictt   comb_et   num_ratt   e_it   ept   pnewt   eit   growt   jt   bjt   ejt   gt   objt   nRE   RC   R*   t   _newt   f(    (   R.   R6   s-   lib/python2.7/site-packages/sympy/core/mul.pyt   flattena   s   O		(+

							-
								

	

			!	
	";# 

		

%5	
	
#'
0c         C  s  |  j  d t  \ } } | j ri t g  | D] }  t |  | d t ^ q+   t t j |  | d t S| j r]| j d k r]d d l m	 } d d l
 m } |  j r]|  j   d } | j rZt | d  j   \ } } | | d  \ } }	 |	 rW| | d  \ } }	 |	 rTt |  | }
 t |
 | j d | |  t j | j  SqWqZq]n  t |  | d t } | j s| j r| j   S| S(   Nt   split_1R/   i   i(   t   integer_nthroot(   t   signi   (   R    R   R]   R#   R^   R$   RL   Re   t   sympy.core.powerR   t$   sympy.functions.elementary.complexesR   t   is_imaginaryt   as_real_imagt   absRj   R   R,   Rf   R   RY   t   is_Floatt   _eval_expand_power_base(   R6   R7   t   cargsR+   R   R   R)   R   R8   R<   Rp   Rf   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_powero  s*    	+		8
c         C  s   d d |  j  f S(   Ni   i    (   R   (   Rm   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt	   class_key  s    c         C  s   |  j    \ } } | t j k rn | j r@ t j | |  } q | j |  } | d  k	 rd | } n  | } n t j |  |  } | j r | j   S| S(   N(	   R0   R   Rk   R   R   t   _eval_evalfRJ   t	   is_numbert   expand(   t   selft   precR*   t   mRo   t   mnew(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR     s    		
	
c         C  s_   d d l  m } m } |  j   \ } } | | k sC t d   n  | d  j | |  j f S(   s;   
        Convert self to an mpmath mpc if possible
        i(   t   It   Floats7   Cannot convert Mul to mpc. Must be of the form Number*Ii    (   t   sympy.core.numbersR   R   R0   t   AttributeErrort   _mpf_(   R   R   R   t   im_partt	   imag_unit(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _mpc_  s
    c         C  s]   |  j  } t |  d k r( t j |  f St |  d k r> | S| d |  j | d   f Sd S(   sL  Return head and tail of self.

        This is the most efficient way to get the head and tail of an
        expression.

        - if you want only the head, use self.args[0];
        - if you want to process the arguments of the tail then use
          self.as_coef_mul() which gives the head and a tuple containing
          the arguments of the tail when treated as a Mul.
        - if you want the coefficient when self is treated as an Add
          then use self.as_coeff_add()[0]

        >>> from sympy.abc import x, y
        >>> (3*x*y).as_two_terms()
        (3, x*y)
        i   i   i    N(   R   RK   R   R   t   _new_rawargs(   R   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   as_two_terms  s    	c         C  sd   t  t  } |  j } t |  d k s5 | d j rE t j | |  <n | d | |  j | d   <| S(   s  Return a dictionary mapping terms to their coefficient.
        Since the dictionary is a defaultdict, inquiries about terms which
        were not present will return a coefficient of 0. The dictionary
        is considered to have a single term.

        Examples
        ========

        >>> from sympy.abc import a, x
        >>> (3*a*x).as_coefficients_dict()
        {a*x: 3}
        >>> _[a]
        0
        i   i    (   R   t   intR   RK   R   R   R   R   (   R   R8   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   as_coefficients_dict  s    	 c         O  s   | j  d t  } | r} g  } g  } x= |  j D]2 } | j |   rS | j |  q. | j |  q. W|  j |   t |  f S|  j } | d j r | s | d j r | d | d f S| d j	 r t
 j | d f | d f Sn  t
 j | f S(   Nt   rationali    i   (   R   Rc   R   t   hasR"   R   t   tupleR   RL   RA   R   Rk   R   (   R   t   depst   kwargsR   t   l1t   l2R   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   as_coeff_mul  s     	 c         C  s   |  j  d |  j  d } } | j r | s4 | j rj t |  d k rT | | d f S| |  j |   f Sq | j r t j |  j | f |   f Sn  t j |  f S(   s2   Efficiently extract the coefficient of a product. i    i   (	   R   R   RL   RK   R   RA   R   Rk   R   (   R   R   Rv   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR0     s    		!c         K  s  d d l  m } m } m } m } g  } g  } g  }	 t j }
 x |  j D] } | j   \ } } | j	 rx | j
 |  qG | j	 r |	 j
 | t j  qG | j rx t |  D]@ \ } } | | j   k r | j
 | |  d  | | =Pq q W| j r|
 | 9}
 q%| j
 |  qG | j
 |  qG W|  j |   } | j d  | k rQd  St |	  d ry| |	 j d   } n	 t j } |  j | |	   } | | |  | | |  } } |
 d k r*| d k r| t j k r| t j f St j | | f Sn  | t j k r| | f S| | | | f S| |
 d t j   \ } } | t j k ry| | | | | | | | f S| | | | } } | | | | | | | | f Sd  S(   Ni(   t   Abst
   expand_mult   imt   rei   t   ignorei    i   t   deep(   t   sympyR   R   R   R   R   R   R   R   RN   R"   RY   R   t	   enumeratet	   conjugateRO   t   funct   getRK   R   RT   R   (   R   R   t   hintsR   R   R   R   t   othert   coeffrt   coeffit   addtermsR)   Rp   R   t   xR   t   imcot   recot   addret   addim(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR     sT    "						!
"c         C  s   t  |   } | d k r# |  d j Sg  } t j |  | d   } t j |  | d  } g  | D]" } | D] } t | |  ^ qh q^ } t |   } t j |  S(   sk   
        Helper function for _eval_expand_mul.

        sums must be a list of instances of Basic.
        i   i    i   (   RK   R   R#   t   _expandsumsR3   RQ   (   t   sumst   Lt   termst   leftt   rightR)   R6   t   added(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR   =  s    /c         K  s  d d l  m } |  } | |  \ } } | j r g  | | f D]$ } | j r\ | j |   n | ^ q> \ } } | | } | j s | Sn  g  g  t } } }	 x\ | j D]Q }
 |
 j r | j |
  t }	 q |
 j	 r | j |
  q | j t
 |
   q W|	 s| S|  j |   } | r| j d t  } |  j j |  } g  } xd | D]\ } |  j | |  } | j rt d   | j D  r| r| j   } n  | j |  qKWt |   S| Sd  S(   Ni(   t   fractionR   c         s  s   |  ] } | j  Vq d  S(   N(   RO   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>s  s    (   R   R   R   t   _eval_expand_mulR   R   RO   R"   Rc   R   R   R   R   R   R`   R3   (   R   R   R   t   exprR   R8   R   t   plainR   t   rewritet   factorR   R   R   t   termR<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR   P  s>    	:
				(
c         C  s   t  |  j  } g  } xl t t |   D]X } | | j |  } | r( | j t d   | |  | g | | d t j   q( q( Wt	 j
 |  S(   Nc         S  s   |  | S(   N(    (   R   t   y(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   <lambda>  t    i   (   R   R   R   RK   t   diffR"   R   R   R   R3   t   fromiter(   R   t   sR   R   R   R8   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_derivativez  s    =c         C  s(  d d l  m } m } m } m } m } d d l m } d d l m	 }	 d d l
 m }
 m } m } t | |	  r t | |
  r t t |   j | |  S|  j } t |  } t | t | f  rEg  } xk | | |  D]Z \ } } | g  t | |  D]! \ } } | j | | f  ^ q  } | j | |  q Wt |   S| d | d | } | t |  } | |  } | | t | |   | |  | g  t | d  D]# } | | j | | | f  ^ q | d j | | d	 |  f  g  | D] } | d	 | f ^ q} } | | |  S(
   Ni(   t   Integert	   factorialt   prodt   Sumt   Max(   t!   multinomial_coefficients_iteratori   (   t   AppliedUndef(   t   Symbolt   symbolst   Dummys   k1:%iRm   i    (   R   R   R   R   R   R   t   sympy.ntheory.multinomialR   t   functionR   t   symbolR   R   R   RF   t   superR#   t   _eval_derivative_n_timesR   RK   R   t   zipR   R"   R3   t   sumt   mapR   (   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   kvalsR*   t   kt   argRf   t   klastt   nfactR<   R7   t   l(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR     s*    ( 	=
^ &c         C  sh   d d l  m } |  j d } t |  j d   } | j | | |  | | | |  | | | |  | S(   Ni(   t   difference_deltai    i   (   t   sympy.series.limitseqR   R   R#   t   subs(   R   R   t   stept   ddt   arg0t   rest(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_difference_delta  s
    2c         C  s`   |  j    \ } } t j |  } t |  d k r\ |  j j | |  } | d j | |  Sd  S(   Ni   i    (   R0   R#   RQ   RK   t	   __class__t   _combine_inverset   matches(   R   R   t	   repl_dictRv   R   t   newexpr(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _matches_simple  s    c   	      C  s\  t  |  } |  j r4 | j r4 t j |  | | |  S|  j | j k	 rJ d  S|  j   \ } } | j   \ } } | j   } | r | s d g } n  |  j |   } t | t  r | j |  j |   | |  } q | j	 |  j |   |  } n  | rR|  j |   } t | |  j  r4| j
 |  j |   |  } qR| j	 |  j |   |  } n  | p[d  S(   Ni   (   R   R   R   t   _matches_commutativeRJ   R    t   copyR   RF   R
  t   _matches(	   R   R   R  t   oldt   c1t   nc1t   c2t   nc2R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR
    s*    !c         C  s`  d d l  m } d } |  j   \ } } | t j k r^ | j rJ | } q^ | j | |  Sn  t |  } | j r | j d t j k r | } | } n  | j st	 |  j  d k r| | k r | j t
 |  |  S| j | |  } | d  k r d  S| j t
 |  |  } | Sd  S| j   } t |  j  }	 t | j  }
 x= |  j D]2 } | | j k rP|
 j |  |	 j |  qPqPWt	 |	  d k rt |	 d |  rt	 |
  d k r| |
 d | |	 d <n | | j |
   | |	 d <| St	 |
  t	 |	  k rd  SxH t |	 |
  D]7 \ } } | j |  j | |  } | d  k r!d  Sq!W| S(   Ni(   t   Wildi   i    i   (   R   R  R   R   Rk   R   R
  R   R   RK   Rh   RJ   R  R   t   removeRF   R   R   t   xreplace(   R   R   R  R  R   R)   R6   R  R8   t   ppt   eeRf   R7   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR    sP    	

	%c         C  s   |  | k r t  j Sd   } | |  |  s: | | |   rA t  j S|  j r | j r t |  j  } d g } xe | j D]Z } | | k r | j |  qu | | k r | j |  | j d  qu | j |  qu W|  j |   | j |   S|  | S(   s~   
        Returns lhs/rhs, but treats arguments like symbols, so things like
        oo/oo return 1, instead of a nan.
        c         S  s8   |  j  r4 | j r4 |  j d  | j   j d  k St S(   Ni    (   R   t   is_comparablet   __add__t   evalfR   (   R   Rp   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   check  s    "i   i(   R   R   R   R   R   R  R"   R   (   t   lhst   rhsR  R)   R6   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR	    s"    		c         C  sF   t  t  } x3 |  j D]( } | j   \ } } | | c | 7<q W| S(   N(   R   R   R   R[   (   R   R8   R   R6   R7   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   as_powers_dict%  s
    c         C  sP   t  t g  |  j D] } | j   ^ q    \ } } |  j |   |  j |   f S(   N(   R   R   R   Rj   R   (   R   R   t   numerst   denoms(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyRj   ,  s    4c         C  s   d  } g  } d } x |  j D]u } | j   \ } } | j sJ | d 7} n  | d  k r_ | } n% | | k sw | d k r |  t j f S| j |  q W|  j |   | f S(   Ni    i   (   RJ   R   R[   R   R   R   R"   R   (   R   R~   t   basesR+   R   R6   R7   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR[   3  s    		c           s   t    f d   |  j D  S(   Nc         3  s   |  ] } | j     Vq d  S(   N(   t   _eval_is_polynomial(   R>   R   (   t   syms(    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>C  s    (   t   allR   (   R   R&  (    (   R&  s-   lib/python2.7/site-packages/sympy/core/mul.pyR%  B  s    c           s   t    f d   |  j D  S(   Nc         3  s   |  ] } | j     Vq d  S(   N(   t   _eval_is_rational_function(   R>   R   (   R&  (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>F  s    (   R'  R   (   R   R&  (    (   R&  s-   lib/python2.7/site-packages/sympy/core/mul.pyR(  E  s    c           s   t    f d   |  j D  S(   Nc         3  s   |  ] } | j     Vq d  S(   N(   t   _eval_is_algebraic_expr(   R>   R   (   R&  (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>I  s    (   R'  R   (   R   R&  (    (   R&  s-   lib/python2.7/site-packages/sympy/core/mul.pyR)  H  s    c         C  s   t  d   |  j D  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   RG   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>L  s    (   R
   R   (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR   K  s   c         C  s   t  d   |  j D  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   R   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>N  s    (   R
   R   (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR   M  s   c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t
   is_complex(   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>P  s    t
   quick_exit(   R
   R   Rc   (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR   O  s   c         C  sa   t  d   |  j D  r] t  d   |  j D  r< t j j St  d   |  j D  rY d  St Sd  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_infinite(   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>S  s    c         s  s   |  ] } | j  Vq d  S(   N(   RN   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>T  s    c         s  s   |  ] } | j  d  k Vq d  S(   N(   RN   RJ   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>V  s    (   R`   R   R   RV   R,  RJ   Rc   (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_infiniteR  s    
c         C  s@   t  d   |  j D d t } | r) | S| t k r< |  j Sd  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_rational(   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>[  s    R+  (   R
   R   Rc   R   RN   (   R   Rp   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_rationalZ  s
    c         C  s@   t  d   |  j D d t } | r) | S| t k r< |  j Sd  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_algebraic(   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>b  s    R+  (   R
   R   Rc   R   RN   (   R   Rp   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_algebraica  s
    c         C  s   t  } } xp |  j D]e } | j } | r< | r3 d  St } q | j sX | rO d  St } n  | t  k r | d  k r d  } q q W| S(   N(   R   R   RN   Rc   RG   RJ   (   R   t   zerot   infiniteR)   t   z(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_zeroh  s    
				c         C  sd   |  j  } | rP |  j   \ } } | t j k r4 t S| t d  k r` | j Sn | t k r` t Sd  S(   Ni   (   R.  Rj   R   R   Rc   t   is_evenR   (   R   R.  R   R8   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_integery  s    	
c         C  s6   t  d   |  j D  } | o5 t d   |  j D  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_polar(   R>   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    c         s  s!   |  ] } | j  p | j Vq d  S(   N(   R8  R@   (   R>   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    (   R`   R   R'  (   R   t	   has_polar(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_polar  s    c         C  s   |  j  t  S(   N(   t   _eval_real_imagRc   (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_real  s    c         C  sN  t  } d  } x |  j D] } | j t  k r/ t  S| j rB | } q | j r | s | j } | rv | t  k rv | } q | r t d   |  j D  r t Sd  Sq q | j t  k r | r d  S| } q | j t  k r | r d  S| } q d  Sq W| r0| j t  k r| r| Sn  | j t  k rJ| s-| SqJn | t  k r@| S| rJ| Sd  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   RG   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    (	   R   RJ   R   R*  R   Rl   RN   R'  Rc   (   R   t   realR2  t   t_not_re_imR<   R4  (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR;    sH    	
			
		
c         C  s0   |  j  } | r t S| t k r, |  j t  Sd  S(   N(   RN   R   R;  (   R   R4  (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_imaginary  s
    	c         C  s   |  j  t  S(   N(   t   _eval_herm_antihermRc   (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_hermitian  s    c         C  s  t  } } } x |  j D] } | j s: | r1 d  St } n  | j rM | } q | j r | s | j } | r | t  k r | } q | r t d   |  j D  r t Sd  Sq q | j t  k r | r d  St } q d  Sq W| r | r| Sn | t  k s | r| Sd  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   RG   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    (   R   R   R   Rc   t   is_antihermitiant   is_hermitianRN   R'  (   R   R=  t   one_ncR2  t   one_neitherR<   R4  (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR@    s6    			
			
	c         C  s0   |  j  } | r t S| t k r, |  j t  Sd  S(   N(   RN   R   R@  (   R   R4  (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_antihermitian  s
    	c         C  sq   xj |  j  D]_ } | j } | rY t |  j   } | j |  t d   | D  rU t Sd  S| d  k r
 d  Sq
 Wt S(   Nc         s  s-   |  ]# } | j  o t | j  t k Vq d  S(   N(   R.  R	   RN   Rc   (   R>   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    (   R   t   is_irrationalR   R  R'  Rc   RJ   R   (   R   R<   R)   t   others(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_irrational  s    	c         C  s   |  j  d  S(   sb  Return True if self is positive, False if not, and None if it
        cannot be determined.

        This algorithm is non-recursive and works by keeping track of the
        sign which changes when a negative or nonpositive is encountered.
        Whether a nonpositive or nonnegative is seen is also tracked since
        the presence of these makes it impossible to return True, but
        possible to return False if the end result is nonpositive. e.g.

            pos * neg * nonpositive -> pos or zero -> None is returned
            pos * neg * nonnegative -> neg or zero -> False is returned
        i   (   t   _eval_pos_neg(   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_positive  s    c         C  s   t  } } x |  j D] } | j r) q q | j r< | } q | j rf t d   |  j D  rb t  Sd  S| j r | } t } q | j r t } q | j t  k r | } | r d  St } q | j t  k r | r d  St } q d  Sq W| d k r| t  k r| t  k rt S| d k  rt  Sd  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   RG   (   R>   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    i   i    (	   R   R   R@   RA   RN   R'  t   is_nonpositiveRc   t   is_nonnegative(   R   R   t   saw_NONt   saw_NOTR<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyRJ    s:    
		
							$c         C  s(   |  j  d d k r |  j S|  j d  S(   Ni    i(   R   R@   RJ  (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_negative%  s    c         C  s   |  j  } | r t d } } x |  j D] } | j  s9 d  S| j rK t } nU | j  r | t k rc q | d k r | | j r t } q | j d  k r d  } q n  | } q& W| S| t k r t Sd  S(   Ni   (   R_   Rc   R   RJ   R6  R   t   is_odd(   R   R_   Rp   t   accR<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_odd*  s&    						
c         C  s0   |  j  } | r t |  j  S| t k r, t Sd  S(   N(   R_   R	   RQ  R   (   R   R_   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_evenB  s
    	c         C  s]   |  j  rY |  j rY d } x+ |  j D]  } | d j r" | d 7} q" q" W| d k rY t Sn  d  S(   Ni    i   (   R_   R@   R   Rc   (   R   t   number_of_argsR   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_is_compositeK  s    c   (        s1  d d l  m  d d l m } d d l m  d d l m } | j sM d  S| j
 d j r | j
 d d k  r |  j
 d j r |  j
 d d k  r |  j | |  Sd  Sn  d        f d   }   f d	   } d
   } d  } | |   \ }	 }
 |  } |
 t j k	 r_|	 j | |  |
 j | |  } | j sG| j | |  S| |  k r_| } q_n  | j
 d } | j
 d } d  } | j r| j r| | k r| j |  } qn | j r| S| |  \  } | |  \  } | rf| j rft |  d k rft | t |  |   }  j |  |  k rK | c | 7<n
 |  | <| | | } n d } t } t |  t |  k rt } n t   t   k rt } n t d   | D  j t d   | D   rt } nO t   j t    rt } n+ t    f d    D  r;t } n  | sE| S sTd  } n] g  } xH  j   D]: \ } }  | } | j | | |   | d sg| SqgWt |  } | sd  } x|t t |   D] } | | |   | | <qWnKd } t |  } | pt j } g  } d } x| r| | t |  k rt } g  } xut |  D] } | | | d | | d k rPn | d k r| j | | | | d | | d   nn | | d k r| j | | | | d | | d   n1 | | | d | | d k rPn | j d  | d 7} qVWt |  }  |  r| d k r| rkt | |   }  n  t | |   | | | d | | d |  | d d  | | <n d }  | | | d | | d |  | d d  }! | }" | | d }# | |# d | |# d |  | d d f }$ |$ d r| | t |  k  ra|! |" |$ g | | | | +q| |$   }$ |! |" |$ g | | | | +n |! |" g | | | | +| |  8} | |  7} t } n  | s| j |  n  | d 7} q!W| s| S| j t | t |    x. | D]& } | | |   j  | |  | | <qW| d  k rQ| }% n$ | d  k rf| }% n t | |  }% g  }& xo  D]g } |  k r |  | |% }' |& j | | |'   q|& j | | j  | |   |   qW| r| rt | |  g |& }& n  | | j! |&   | j! |   S(   Ni(   R   (   t   multiplicity(   t	   powdenest(   R   i    c         S  s?   d d l  m } |  j s( t |  |  r2 |  j   S|  t j f S(   Ni(   t   exp(   R   RY  R\   RF   R[   R   R   (   R)   RY  (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   base_expk  s    
c           s   t  t  t   } } x t j |   D] }  |  }   |  \ } } | t j k	 r | j   \ } } t | | |  } | } n  | j	 r | | c | 7<q& | j
 | | g  q& W| | f S(   s   break up powers of eq when treated as a Mul:
                   b**(Rational*e) -> b**e, Rational
                commutatives come back as a dictionary {b**e: Rational}
                noncommutatives come back as a list [(b**e, Rational)]
            (   R   R   R   R#   RQ   R   R   R   R^   R   R"   (   t   eqR*   R+   R)   R6   R7   R(   t   _(   RZ  RX  (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   breakupt  s    		c           s#     |   \ }  } t  |  | |  S(   s   
            Put rational back with exponent; in general this is not ok, but
            since we took it from the exponent for analysis, it's ok to put
            it back.
            (   R^   (   R6   R(   R7   (   RZ  (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   rejoin  s    c         S  s4   | j  |  j  s" |  j  | j  r0 t |  |  Sd S(   s   if b divides a in an extractive way (like 1/4 divides 1/2
            but not vice versa, and 2/5 does not divide 1/3) then return
            the integer number of times it divides, else return 0.
            i    (   Re   R   (   R)   R6   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   ndiv  s    "i   c         s  s   |  ] } | d  Vq d S(   i    N(    (   R>   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    c         3  s/   |  ]% }    |    |  k Vq d  S(   N(    (   R>   R6   (   R*   t   old_cR   (    s-   lib/python2.7/site-packages/sympy/core/mul.pys	   <genexpr>  s    ("   R   R   t   sympy.ntheory.factor_RW  t   sympy.simplify.powsimpRX  t   sympy.simplify.radsimpR   R   RJ   R   R   t   _subsR   R   RL   t   extract_multiplicativelyR   R   Rc   RK   R   Rd   t
   differenceR`   R2   R"   t   minR   Ra   R^   R!   R  R   ((   R   R  t   newRW  R   R]  R^  R_  Ro   R   R8   t   self2t   co_selft   co_oldt   co_xmulR+   t   old_nct   multt   co_residualt   okt   cdidt   ratR6   t   old_et   c_et   ncdidR   t   taket   limitt   failedt   hitR   t   ndoR   t   midt   irRp   t   dot   margsR7   (    (   RZ  R*   R`  RX  R   s-   lib/python2.7/site-packages/sympy/core/mul.pyt
   _eval_subs[  s   	#		
	"		!
		/		"		

 -- )


	$		*c   	      C  s   d d l  m } m } g  |  j D]! } | j | d | d | ^ q  } | |  j |   j   d d d t } | j |  r | | | | |  7} n  | S(   Ni(   t   Ordert   powsimpR   t   logxt   combineRY  R   (	   R   R  R  R   t   nseriesR   R   Rc   R   (	   R   R   R   R  R  R  R<   R   t   res(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_nseriesc  s    1'c         C  s,   |  j  g  |  j D] } | j |  ^ q   S(   N(   R   R   t   as_leading_term(   R   R   R<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_as_leading_termk  s    c         C  s)   |  j  g  |  j D] } | j   ^ q   S(   N(   R   R   R   (   R   R<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_conjugaten  s    c         C  s6   |  j  g  |  j d  d  d  D] } | j   ^ q   S(   Ni(   R   R   t	   transpose(   R   R<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_transposeq  s    c         C  s6   |  j  g  |  j d  d  d  D] } | j   ^ q   S(   Ni(   R   R   t   adjoint(   R   R<   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _eval_adjointt  s    c         C  s.   d } x! |  j  D] } | | j   9} q W| S(   Ni   (   R   t   _sage_(   R   R   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR  w  s    c   	      C  s   t  j } g  } xd t |  j  D]S \ } } | j d | d |  \ } } | | 9} | t  j k	 r | j |  q q W| |  j |   f S(   sU  Return the tuple (R, self/R) where R is the positive Rational
        extracted from self.

        Examples
        ========

        >>> from sympy import sqrt
        >>> (-3*sqrt(2)*(2 - 2*sqrt(2))).as_content_primitive()
        (6, -sqrt(2)*(1 - sqrt(2)))

        See docstring of Expr.as_content_primitive for more examples.
        t   radicalt   clear(   R   R   R   R   t   as_content_primitiveR"   R   (	   R   R  R  t   coefR   R   R)   R*   Rf   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR  }  s    	
c           s3   |  j    \ } } | j d   f d    | | S(   s  Transform an expression into an ordered list of factors.

        Examples
        ========

        >>> from sympy import sin, cos
        >>> from sympy.abc import x, y

        >>> (2*x*y*sin(x)*cos(x)).as_ordered_factors()
        [2, x, y, sin(x), cos(x)]

        R   c           s   |  j  d    S(   Nt   order(   t   sort_key(   R   (   R  (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR     R   (   R    R   (   R   R  t   cpartt   ncpart(    (   R  s-   lib/python2.7/site-packages/sympy/core/mul.pyt   as_ordered_factors  s    c         C  s   t  |  j    S(   N(   R   R  (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   _sorted_args  s    (D   R   R   t	   __slots__Rc   R   t   classmethodR   R   R   R   t   propertyR   R   R   R   R   R   R0   R   t   staticmethodR   R   R   R   R  R  R
  R  R	  R!  Rj   R[   R%  R(  R)  t   _eval_is_finitet   _eval_is_commutativet   _eval_is_complexR-  R/  R1  R5  R7  R:  R<  R;  R?  RA  R@  RF  RI  RK  RJ  RP  RS  RT  RV  R  R  R  R  R  R  R  R  RJ   R  R  (    (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR#   [   s|     		5	*			9 																	*			!				 						 							c         C  s   t  t j |  |  S(   s  Return product of elements of a. Start with int 1 so if only
       ints are included then an int result is returned.

    Examples
    ========

    >>> from sympy import prod, S
    >>> prod(range(3))
    0
    >>> type(_) is int
    True
    >>> prod([S(2), 3])
    6
    >>> _.is_Integer
    True

    You can start the product at something other than 1:

    >>> prod([1, 2], 3)
    6

    (   R   t   operatort   mul(   R)   t   start(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR     s    c   
      C  ss  |  j  s- | j  r" |  | } }  q- |  | Sn  |  t j k r@ | S|  t j k r[ | r[ | S| j r | r |  j r |  j d k r t |  j  } xJ | j D]< } | j   \ } } | | } | t	 |  k r |  | Sq Wn  t
 |  | d t S| j rgt | j  }	 |	 d j  rJ|	 d c |  9<|	 d d k rZ|	 j d  qZn |	 j d |   t
 j |	  S|  | Sd S(   s  Return ``coeff*factors`` unevaluated if necessary.

    If ``clear`` is False, do not keep the coefficient as a factor
    if it can be distributed on a single factor such that one or
    more terms will still have integer coefficients.

    If ``sign`` is True, allow a coefficient of -1 to remain factored out.

    Examples
    ========

    >>> from sympy.core.mul import _keep_coeff
    >>> from sympy.abc import x, y
    >>> from sympy import S

    >>> _keep_coeff(S.Half, x + 2)
    (x + 2)/2
    >>> _keep_coeff(S.Half, x + 2, clear=False)
    x/2 + 1
    >>> _keep_coeff(S.Half, (x + 2)*y, clear=False)
    y*(x + 2)/2
    >>> _keep_coeff(S(-1), x + y)
    -x - y
    >>> _keep_coeff(S(-1), x + y, sign=True)
    -(x + y)
    i   R/   i    N(   R   R   R   Rk   RO   RL   Re   R   R0   R   R#   R   R   R   R   R%   R$   (
   Rv   t   factorsR  R   Re   R   R*   R<   Rp   R~  (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyRR     s4    			
	c         C  s&   d d l  m } d   } | |  |  S(   Ni(   t	   bottom_upc         S  sX   |  j  rT |  j   \ } } | j rT | j rT t g  | j D] } | | ^ q:   Sn  |  S(   N(   R   R0   R   RO   t   _unevaluated_AddR   (   R7   R*   Rp   t   ri(    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyR}    s
    	'(   t   sympy.simplify.simplifyR  (   R7   R  R}  (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   expand_2arg  s    	(   Rh   (   R^   (   R3   RS   R  (.   t
   __future__R    R   t   collectionsR   t	   functoolsR   R  R   t   basicR   t	   singletonR   t
   operationsR   t   cacheR   t   logicR	   R
   t   compatibilityR   R   R   R   R/   R   R   t   compareR   R   R,   R#   R   Rc   R   RR   R  t   numbersRh   t   powerR^   t   addR3   RS   R  (    (    (    s-   lib/python2.7/site-packages/sympy/core/mul.pyt   <module>   s:   
		6      X;	