
\c           @  s>  d  d l  m Z m Z d  d l m Z d  d l m Z d d l m Z d d l	 m
 Z
 m Z m Z d d l m Z m Z 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 e e j  Z d   Z d   Z d e e f d     YZ  d d l! m" Z" m# Z# m$ Z$ d  d l% m& Z& d S(   i(   t   print_functiont   division(   t   defaultdict(   t
   cmp_to_keyi   (   t   Basic(   t   reducet   is_sequencet   range(   t   _fuzzy_groupt   fuzzy_ort	   fuzzy_not(   t   S(   t   AssocOp(   t   cacheit(   t   ilcmt   igcd(   t   Exprc         C  s   |  j  d t  d  S(   Nt   key(   t   sortt   _args_sortkey(   t   args(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _addsort   s    c          G  s   t  |   }  g  } t j } xU |  rr |  j   } | j rL |  j | j  q | j rb | | 7} q | j |  q Wt	 |  | r | j
 d |  n  t j |  S(   s  Return a well-formed unevaluated Add: Numbers are collected and
    put in slot 0 and args are sorted. Use this when args have changed
    but you still want to return an unevaluated Add.

    Examples
    ========

    >>> from sympy.core.add import _unevaluated_Add as uAdd
    >>> from sympy import S, Add
    >>> from sympy.abc import x, y
    >>> a = uAdd(*[S(1.0), x, S(2)])
    >>> a.args[0]
    3.00000000000000
    >>> a.args[1]
    x

    Beyond the Number being in slot 0, there is no other assurance of
    order for the arguments since they are hash sorted. So, for testing
    purposes, output produced by this in some other function can only
    be tested against the output of this function or as one of several
    options:

    >>> opts = (Add(x, y, evaluated=False), Add(y, x, evaluated=False))
    >>> a = uAdd(x, y)
    >>> assert a in opts and a == uAdd(x, y)
    >>> uAdd(x + 1, x + 2)
    x + x + 3
    i    (   t   listR   t   Zerot   popt   is_Addt   extendR   t	   is_Numbert   appendR   t   insertt   Addt
   _from_args(   R   t   newargst   cot   a(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _unevaluated_Add   s    				
R   c           B  s  e  Z g  Z e Z e d     Z e d    Z d   Z e	 d    Z
 e d  Z d   Z e	 d    Z d   Z d   Z i  e d	  Z e 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   Z( d    Z) d!   Z* d"   Z+ d#   Z, e	 d1 d$   Z. e d%  Z/ d&   Z0 d'   Z1 d(   Z2 d)   Z3 d*   Z4 d+   Z5 d,   Z6 e e d-  Z7 e8 d.    Z9 d/   Z: e8 d0    Z; RS(2   c         C  s  d d l  m } d d l m } d d l m } d	 } t |  d k r | \ } } | j rm | | } } n  | j r | j	 r | | g g  d	 f } q n  | r t
 d   | d D  r | Sg  | d d	 f Sn  i  } t j }	 g  }
 g  } x| D]} | j rtx' |
 D] } | j |  r
d	 } Pq
q
W| d	 k r?q n  | g g  |
 D] } | j |  sL| ^ qL}
 q n| j r	| t j k s|	 t j k r| j t k r| rt j g g  d	 f S|	 j r |	 | 7}	 |	 t j k r| rt j g g  d	 f Sq q nrt | |  r-| j |	  }	 q nNt | |  rO| j |  q n,t | |  r|	 rs| j |	  n | }	 q n | t j k r|	 j t k r| rt j g g  d	 f St j }	 q n | j r| j | j  q n | j	 r| j   \ } } nx | j rl| j   \ } } | j rY| j sB| j rY| j rY| j | |  q n  t j | } } n t j } | } | | k r| | c | 7<| | t j k r| rt j g g  d	 f Sq | | | <q Wg  } t } x | j    D] \ } } | t j k rqn | t j k r.| j |  np | j	 r`| j! | f | j   } | j |  n> | j r| j t" | | d t  n | j t" | |   | p| j# } qW|	 t j$ k rg  | D]' } | j% p| j& o| j s| ^ q} nF |	 t j' k r>g  | D]' } | j( p,| j& o,| j s| ^ q} n  |	 t j k rg  | D]$ } | j oo| j& d	 k	 sT| ^ qT} n  |
 rg  } xT | D]L } x' |
 D] } | j |  rd	 } PqqW| d	 k	 r| j |  qqW| |
 } x- |
 D]" } | j |	  rt j }	 PqqWn  t) |  |	 t j k	 rJ| j* d |	  n  | rc| | 7} t+ } n  | rvg  | d	 f S| g  d	 f Sd	 S(
   s  
        Takes the sequence "seq" of nested Adds and returns a flatten list.

        Returns: (commutative_part, noncommutative_part, order_symbols)

        Applies associativity, all terms are commutable with respect to
        addition.

        NB: the removal of 0 is already handled by AssocOp.__new__

        See also
        ========

        sympy.core.mul.Mul.flatten

        i(   t   AccumBounds(   t
   MatrixExpr(   t   TensExpri   c         s  s   |  ] } | j  Vq d  S(   N(   t   is_commutative(   t   .0t   s(    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>l   s    i    t   evaluateN(,   t   sympy.calculus.utilR$   t   sympy.matrices.expressionsR%   t   sympy.tensor.tensorR&   t   Nonet   lent   is_Rationalt   is_Mult   allR   R   t   is_Ordert   containsR   t   NaNt   ComplexInfinityt	   is_finitet   Falset
   isinstancet   __add__R   R   R   R   t   as_coeff_Mult   is_Powt   as_base_expt
   is_Integert   is_negativet   Onet   itemst   _new_rawargst   MulR'   t   Infinityt   is_nonnegativet   is_realt   NegativeInfinityt   is_nonpositiveR   R   t   True(   t   clst   seqR$   R%   R&   t   rvR"   t   bt   termst   coefft   order_factorst   extrat   ot   o1t   cR)   t   et   newseqt   noncommutativet   cst   ft   newseq2t   t(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   flattenN   s    					)		
								**	
	

	c         C  s   d d |  j  f S(   s   Nice order of classesi   i   (   t   __name__(   RJ   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt	   class_key#  s    c         C  s   t  t  } x4 |  j D]) } | j   \ } } | | j |  q WxM | j   D]? \ } } t |  d k r | d | | <qP t |   | | <qP Wt  t  } | j	 |  | S(   s  Return a dictionary mapping terms to their Rational coefficient.
        Since the dictionary is a defaultdict, inquiries about terms which
        were not present will return a coefficient of 0. If an expression is
        not an Add it is considered to have a single term.

        Examples
        ========

        >>> from sympy.abc import a, x
        >>> (3*x + a*x + 4).as_coefficients_dict()
        {1: 4, x: 3, a*x: 1}
        >>> _[a]
        0
        >>> (3*a*x).as_coefficients_dict()
        {a*x: 3}
        i   i    (
   R   R   R   R;   R   RA   R/   R   t   intt   update(   R"   t   dt   aiRT   t   mt   kt   vt   di(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   as_coefficients_dict(  s    c         G  s   | rk g  } g  } x= |  j  D]2 } | j |   rA | j |  q | j |  q W|  j |   t |  f S|  j  d j   \ } } | t j k	 r | | |  j  d f St j |  j  f S(   sR  
        Returns a tuple (coeff, args) where self is treated as an Add and coeff
        is the Number term and args is a tuple of all other terms.

        Examples
        ========

        >>> from sympy.abc import x
        >>> (7 + 3*x).as_coeff_add()
        (7, (3*x,))
        >>> (7*x).as_coeff_add()
        (0, (7*x,))
        i    i   (   R   t   hasR   RB   t   tuplet   as_coeff_addR   R   (   t   selft   depst   l1t   l2RY   RO   t   notrat(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyRj   G  s    c         C  sT   |  j  d |  j  d } } | j r+ | s4 | j rG | |  j |   f St j |  f S(   s4   Efficiently extract the coefficient of a summation. i    i   (   R   R   R0   RB   R   R   (   Rk   t   rationalRO   R   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   as_coeff_Addd  s    c         C  sV  | j  rR|  j rRd d l m } d d l m } d d l m } d d l m	 } d d l
 m } d d l m } | |   } | rR| \ }	 }
 | j d k r| |	 d |
 d  } | j  rL| | | |	 d   | j } | | | |	 t |
  | |
  t j | j  SqO| d k rO| |	 |
 t j d	 |	 d |
 d  SqRn  d  S(
   Ni(   t   pure_complex(   t   _unevaluated_Mul(   t   factor_terms(   t   expand_multinomial(   t   sign(   t   sqrti   i   (   R0   t	   is_numbert   sympy.core.evalfRr   t   sympy.core.mulRs   t   sympy.core.exprtoolsRt   t   sympy.core.functionRu   t$   sympy.functions.elementary.complexesRv   t(   sympy.functions.elementary.miscellaneousRw   t   qt   pt   absR   t   ImaginaryUnit(   Rk   RU   Rr   Rs   Rt   Ru   Rv   Rw   t   rit   rt   it   Dt   root(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_powerp  s(    	!1c         C  s,   |  j  g  |  j D] } | j |  ^ q   S(   N(   t   funcR   t   diff(   Rk   R)   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_derivative  s    c         C  s>   g  |  j  D]! } | j | d | d | ^ q
 } |  j |   S(   Nt   nt   logx(   R   t   nseriesR   (   Rk   t   xR   R   R[   RN   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_nseries  s    1c         C  s@   |  j    \ } } t |  d k r< | d j | | |  Sd  S(   Ni   i    (   Rj   R/   t   matches(   Rk   t   exprt	   repl_dictRO   RN   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _matches_simple  s    c         C  s   t  j |  | | |  S(   N(   R   t   _matches_commutative(   Rk   R   R   t   old(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s    c           s   d d l  m } d d l m } t j t j f } |  j |   sP | j |   r | d    i   t j 6  t j 6} d   | j   D } | |  j	 |  | j	 |   } | j    r | j
   f d   d    } n  | j	 |  S| |  |  Sd S(	   sp   
        Returns lhs - rhs, but treats oo like a symbol so oo - oo
        returns 0, instead of a nan.
        i(   t
   expand_mul(   t   Dummyt   ooc         S  s   i  |  ] \ } } | |  q S(    (    (   R(   Rd   Re   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys
   <dictcomp>  s   	 c           s   |  j  o |  j   k S(   N(   R<   t   base(   R   (   R   (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   <lambda>  t    c         S  s   |  j  S(   N(   R   (   R   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     R   N(   R|   R   t   sympy.core.symbolR   R   RD   RG   Rh   RA   t   xreplacet   replace(   t   lhst   rhsR   R   t   inft   repst   irepst   eq(    (   R   s-   lib/python2.7/site-packages/sympy/core/add.pyt   _combine_inverse  s     
"c         C  s!   |  j  d |  j |  j  d   f S(   sZ  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_add() which gives the head and a tuple containing
          the arguments of the tail when treated as an Add.
        - if you want the coefficient when self is treated as a Mul
          then use self.as_coeff_mul()[0]

        >>> from sympy.abc import x, y
        >>> (3*x - 2*y + 5).as_two_terms()
        (5, 3*x - 2*y)
        i    i   (   R   RB   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   as_two_terms  s    c         C  s  |  j    \ } } | j   \ } } t t  } x4 | j D]) } | j   \ } } | | j |  q: Wt |  d k r | j   \ }	 }
 |  j g  |
 D] } t	 | |  ^ q   t	 | |	  f SxP | j
   D]B \ }	 }
 t |
  d k r |
 d | |	 <q |  j |
   | |	 <q Wg  t t | j
      D] } t |  ^ q/\ } } |  j g  t t |   D]- } t | |  | | g | | d   ^ qf  t |   }
 }	 t	 | |
  t	 | |	  f S(   Ni   i    (   t	   primitivet   as_numer_denomR   R   R   R   R/   t   popitemR   t   _keep_coeffRA   t   zipt   iterR   RC   (   Rk   t   contentR   t   ncont   dcont   ndRY   t   niRf   Ra   R   R   t   denomst   numers(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s$    27	Sc           s   t    f d   |  j D  S(   Nc         3  s   |  ] } | j     Vq d  S(   N(   t   _eval_is_polynomial(   R(   t   term(   t   syms(    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    (   R2   R   (   Rk   R   (    (   R   s-   lib/python2.7/site-packages/sympy/core/add.pyR     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/add.pys	   <genexpr>  s    (   R2   R   (   Rk   R   (    (   R   s-   lib/python2.7/site-packages/sympy/core/add.pyR     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/add.pys	   <genexpr>  s    (   R2   R   (   Rk   R   (    (   R   s-   lib/python2.7/site-packages/sympy/core/add.pyR     s    c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   RF   (   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    t
   quick_exit(   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     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/add.pys	   <genexpr>  s    R   (   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s   c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_antihermitian(   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    R   (   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s   c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   R7   (   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    R   (   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s   c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_hermitian(   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    R   (   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s   c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t
   is_integer(   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    R   (   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s   c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_rational(   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    R   (   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     s   c         C  s   t  d   |  j D d t S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   t   is_algebraic(   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    R   (   R   R   RI   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     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/add.pys	   <genexpr>  s    (   R   R   (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR      s   c         C  s   g  } g  } x |  j  D] } | j rW | j r1 q | j t k rP | j |  q d  Sq | j rw | j | t j  q t j | j r | j | t j  q d  Sq W|  j |   } | j r t	 |  j |   j  S| j t k r t Sd  S(   N(
   R   RF   t   is_zeroR8   R   t   is_imaginaryR   R   R   R
   (   Rk   t   nzt   im_IR"   RM   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_is_imaginary  s&    				c         C  sR  |  j  t k r d  Sg  } d } t } t } x |  j D]z } | j r | j rZ | d 7} q | j t k ry | j |  q d  Sq5 | j r t } q5 t j	 | j r t } q5 d  Sq5 W| t
 |  j  k r t St
 |  d k s t
 |  t
 |  j  k r d  S|  j |   } | j r;| r'| r't S| r;| r;t Sn  | j t k rNt Sd  S(   Ni    i   (   R'   R8   R   RF   R   R   R   RI   R   R   R/   R.   R   (   Rk   R   t   zt   im_or_zt   imR"   RM   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_is_zero  s<    					-	c         C  sZ   g  |  j  D] } | j t k	 r
 | ^ q
 } | s5 t S| d j rV |  j | d   j Sd  S(   Ni    i   (   R   t   is_evenRI   R8   t   is_oddRB   (   Rk   RY   t   l(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_is_odd>  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  t k Vq d  S(   N(   R   RI   (   R(   R   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>K  s    (   R   t   is_irrationalR   t   removeR2   RI   R.   R8   (   Rk   R[   R"   t   others(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_is_irrationalE  s    	c         C  sI  d d l  m } |  j r, t t |   j   S|  j   \ } } | j s | |  } | d  k	 r | | } | |  k r | j	 r | j
 r t St |  j  d k r | |   } | d  k	 r | |  k r | j	 r t Sq q n  t } } } }	 t   }
 g  |  j D] } | j s | ^ q } | s$t Sx | D] } | j	 } | j } | r|
 j t | | j
 f   t |
 k rt |
 k rd  Sn  | rt } q+n* | j
 rt } q+n | j rt } q+n  | d  k rd  St }	 q+W|
 r t |
  d k rd  S|
 j   S|	 r
d  S| r"| r"| r"t S| r3| r3t S| rE| rEt Sd  S(   Ni(   t   _monotonic_signi   (   R{   R   Rx   t   superR   t   _eval_is_positiveRq   R   R.   t   is_positiveRE   RI   R/   t   free_symbolsR8   t   setR   t   is_infinitet   addR	   RH   R   (   Rk   R   RT   R"   Re   R)   t   post   nonnegt   nonpost   unknown_signt   saw_INFR   t   ispost   infinite(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR   R  sd    		
!	%				

c         C  s   d d l  m } |  j s |  j   \ } } | j r | j r | |  } | d  k	 r | | } | |  k ry | j ry t St |  j	  d k r | |   } | d  k	 r | |  k r | j r t Sq q q n  d  S(   Ni(   R   i   (
   R{   R   Rx   Rq   R   RE   R.   RI   R/   R   (   Rk   R   RT   R"   Re   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_is_nonnegative  s    	
!c         C  s   d d l  m } |  j s |  j   \ } } | j r | j r | |  } | d  k	 r | | } | |  k ry | j ry t St |  j	  d k r | |   } | d  k	 r | |  k r | j r t Sq q q n  d  S(   Ni(   R   i   (
   R{   R   Rx   Rq   R   RH   R.   RI   R/   R   (   Rk   R   RT   R"   Re   R)   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_is_nonpositive  s    	
!c         C  sI  d d l  m } |  j r, t t |   j   S|  j   \ } } | j s | |  } | d  k	 r | | } | |  k r | j	 r | j
 r t St |  j  d k r | |   } | d  k	 r | |  k r | j	 r t Sq q n  t } } } }	 t   }
 g  |  j D] } | j s | ^ q } | s$t Sx | D] } | j	 } | j } | r|
 j t | | j
 f   t |
 k rt |
 k rd  Sn  | rt } q+n* | j
 rt } q+n | j rt } q+n  | d  k rd  St }	 q+W|
 r t |
  d k rd  S|
 j   S|	 r
d  S| r"| r"| r"t S| r3| r3t S| rE| rEt Sd  S(   Ni(   R   i   (   R{   R   Rx   R   R   t   _eval_is_negativeRq   R   R.   R?   RH   RI   R/   R   R8   R   R   R   R   R	   RE   R   (   Rk   R   RT   R"   Re   R)   t   negR   R   R   R   R   t   isnegR   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR     sd    		
!	%				

c      	   C  s  | j  sB | t j k r> | |  j k r> |  j i | | 6 Sd  S|  j   \ } } | j   \ } } | j r | j r | | k r |  j | | |  S| | k r |  j | | |  Sn  | j r | j s | | k r|  j j	 |  |  j j	 |  } } t
 |  t
 |  k  rt |  }	 t |  }
 |
 |	 k  r{|	 |
 } |  j | | | g  | D] } | j | |  ^ q\ S|  j j	 |  } t |  }
 |
 |	 k  r|	 |
 } |  j | | | g  | D] } | j | |  ^ q Sqn  d  S(   N(   R   R   RD   R   R   R.   Rq   R0   R   t	   make_argsR/   R   t   _subs(   Rk   R   t   newt
   coeff_selft
   terms_selft	   coeff_oldt	   terms_oldt   args_oldt	   args_selft   self_sett   old_sett   ret_setR)   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt
   _eval_subs  s:    		
&	

c         C  s2   g  |  j  D] } | j s
 | ^ q
 } |  j |   S(   N(   R   R3   RB   (   Rk   R"   R   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   removeO  s    %c         C  s<   g  |  j  D] } | j r
 | ^ q
 } | r8 |  j |   Sd  S(   N(   R   R3   RB   (   Rk   R"   R   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   getO  s    %c         C  sV  d d l  m } g  } t t |  r+ | n | g  } | sS d g t |  } n  g  |  j D]$ } | | | t | |   f ^ q] } x | D] \ } } x9 | D]1 \ }	 }
 |
 j |  r |
 | k r d } Pq q W| d k r q n  | | f g } xH | D]@ \ }	 }
 | j |
  r+|
 | k r+q n  | j	 |	 |
 f  q W| } q Wt
 |  S(   s`  
        Returns the leading term and its order.

        Examples
        ========

        >>> from sympy.abc import x
        >>> (x + 1 + 1/x**5).extract_leading_order(x)
        ((x**(-5), O(x**(-5))),)
        >>> (1 + x).extract_leading_order(x)
        ((1, O(1)),)
        >>> (x + x**2).extract_leading_order(x)
        ((x, O(x)),)

        i(   t   Orderi    N(   t   sympyR   R   R   R/   R   R   R4   R.   R   Ri   (   Rk   t   symbolst   pointR   t   lstRY   RK   t   eft   ofRU   RR   t   new_lst(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   extract_leading_order
  s(    !4
c   	      K  su   |  j  } g  g  } } x@ | D]8 } | j d |  \ } } | j |  | j |  q W|  j |   |  j |   f S(   s4  
        returns a tuple representing a complex number

        Examples
        ========

        >>> from sympy import I
        >>> (7 + 9*I).as_real_imag()
        (7, 9)
        >>> ((1 + I)/(1 - I)).as_real_imag()
        (0, 1)
        >>> ((1 + 2*I)*(1 + 3*I)).as_real_imag()
        (-5, 5)
        t   deep(   R   t   as_real_imagR   R   (	   Rk   R   t   hintst   sargst   re_partt   im_partR   t   reR   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR   0  s    	c         C  si  d d l  m } m } |  } | |   } | j s> | j |  Sg  | j D] } | j rH | ^ qH } | j g  | j D] } | j |  ^ qs   j   } | s | j	 |  S| t
 j k r | j j |  S| j s | S| j g  | j |  D] \ } }	 | ^ q   }
 | |
 d t } | j   } | | j k ra| j r]|
 j t k	 r]| |
 j |  S| S| Sd  S(   Ni(   R   Rt   t   fraction(   R   R   Rt   R   t   as_leading_termR   R   R   R   t   compute_leading_termR   R5   R   R   R8   t   simplifyR   R   RI   t   _eval_as_leading_term(   Rk   R   R   Rt   R   R   R[   R   R)   t   _t   plainRL   t   rv_simplify(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR	  G  s*    	%4	1c         C  s)   |  j  g  |  j D] } | j   ^ q   S(   N(   R   R   t   adjoint(   Rk   R[   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_adjointg  s    c         C  s)   |  j  g  |  j D] } | j   ^ q   S(   N(   R   R   t	   conjugate(   Rk   R[   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_conjugatej  s    c         C  s)   |  j  g  |  j D] } | j   ^ q   S(   N(   R   R   t	   transpose(   Rk   R[   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_transposem  s    c         C  s   |  d S(   Ni(    (   Rk   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   __neg__p  s    c         C  s.   d } x! |  j  D] } | | j   7} q W| S(   Ni    (   R   t   _sage_(   Rk   R)   R   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR  s  s    c         C  s  g  } t  } xo |  j D]d } | j   \ } } | j sI t j } | } n  | p[ | t j k } | j | j | j	 | f  q W| s t
 t g  | D] } | d ^ q d  } t
 t g  | D] } | d ^ q d  } nf t
 t g  | D] } | d r | d ^ q d  } t
 t g  | D] } | d r| d ^ qd  } | | k oVd k n rht j |  f S| sx t |  D]: \ }	 \ }
 } } t t |
 | | |  |  | |	 <q{Wnp xm t |  D]_ \ }	 \ }
 } } | rt t |
 | | |  |  | |	 <qt t |
 |  |  | |	 <qW| d j sL| d t j k r^| j d  } n d } t |  | r| j d |  n  t | |  |  j |   f S(   s  
        Return ``(R, self/R)`` where ``R``` is the Rational GCD of ``self```.

        ``R`` is collected only from the leading coefficient of each term.

        Examples
        ========

        >>> from sympy.abc import x, y

        >>> (2*x + 4*y).primitive()
        (2, x + 2*y)

        >>> (2*x/3 + 4*y/9).primitive()
        (2/9, 3*x + 2*y)

        >>> (2*x/3 + 4.2*y).primitive()
        (1/3, 2*x + 12.6*y)

        No subprocessing of term factors is performed:

        >>> ((2 + 2*x)*x + 2).primitive()
        (1, x*(2*x + 2) + 2)

        Recursive processing can be done with the ``as_content_primitive()``
        method:

        >>> ((2 + 2*x)*x + 2).as_content_primitive()
        (2, x*(x + 1) + 1)

        See also: primitive() function in polytools.py

        i    i   N(   R8   R   R;   R0   R   R@   R6   R   R   R   R   R   R   t	   enumerateR   t   RationalR   R   R.   R   R   RB   (   Rk   RN   R   R"   RT   Rc   R[   t   ngcdt   dlcmR   R   R   R   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR   y  s<    #			 ),33","( 	 
c      	   C  s  |  j  g  |  j D]$ } t | j d | d |    ^ q   j   \ } } | r | j r | j r | j   \ } } | | } t d   | j D  r | } q | | } n  | r| j r| j } g  }	 d }
 x| D] } t
 t  } xq t j |  D]` } | j r | j   \ } } | j r[| j r[| | j j t t |   | j  q[q q W| siPn  |
 d k rt | j    }
 n  |
 t | j    @}
 |
 sPn  |	 j |  q Wxl |	 D]d } x6 t | j    D]" } | |
 k r| j |  qqWx" | D] } t | |  | | <qWqWg  } x` |
 D]X } t t g  |	 D] } | | ^ qJd  } | d k r7| j | t d |   q7q7W| rt |   } g  | D] } | | ^ q} | | j  |   } qn  | | f S(   s  Return the tuple (R, self/R) where R is the positive Rational
        extracted from self. If radical is True (default is False) then
        common radicals will be removed and included as a factor of the
        primitive expression.

        Examples
        ========

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

        Radical content can also be factored out of the primitive:

        >>> (2*sqrt(2) + 4*sqrt(10)).as_content_primitive(radical=True)
        (2, sqrt(2)*(1 + 2*sqrt(5)))

        See docstring of Expr.as_content_primitive for more examples.
        t   radicalt   clearc         s  s"   |  ] } | j    d  j Vq d S(   i    N(   R;   R>   (   R(   R"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pys	   <genexpr>  s    i    i   N(   R   R   R   t   as_content_primitiveR   R>   R   R   t   anyR.   R   R   RC   R   R<   R=   R0   R   R   R   R_   R   R   t   keysR   t   prodR   R   R  (   Rk   R  R  R"   t   cont   primRa   t   _pR   t   radst   common_qRc   t	   term_radsRb   RM   RU   R   R   t   Gt   g(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR    sV    	@
			1)!c         C  s)   d d l  m } t t |  j d |  S(   Ni(   t   default_sort_keyR   (   t   sympy.core.compatibilityR'  Ri   t   sortedR   (   Rk   R'  (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _sorted_args  s    c         C  s?   d d l  m } |  j g  |  j D] } | | | |  ^ q    S(   Ni(   t   difference_delta(   t   sympy.series.limitseqR+  R   R   (   Rk   R   t   stept   ddR"   (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _eval_difference_delta  s    c         C  sq   d d l  m } m } |  j   \ } } | j   \ } } | | k sU t d   n  | |  j | |  j f S(   s;   
        Convert self to an mpmath mpc if possible
        i(   t   It   Floats@   Cannot convert Add to mpc. Must be of the form Number + Number*I(   t   sympy.core.numbersR0  R1  Rq   R;   t   AttributeErrort   _mpf_(   Rk   R0  R1  R  t   restR  t	   imag_unit(    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   _mpc_  s    N(<   R]   t
   __module__t	   __slots__RI   R   t   classmethodR\   R^   Rg   R   Rj   R8   Rq   R   R   R   R   R   t   staticmethodR   R   R   R   R   R   t   _eval_is_realt   _eval_is_complext   _eval_is_antihermitiant   _eval_is_finitet   _eval_is_hermitiant   _eval_is_integert   _eval_is_rationalt   _eval_is_algebraict   _eval_is_commutativeR   R   R   R   R   R   R   R   R   R   R   R.   R   R   R	  R  R  R  R  R  R   R  t   propertyR*  R/  R7  (    (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyR   H   sh   					 														$			6			6	%		%	 						PH	(   RC   R   R  (   R  N('   t
   __future__R    R   t   collectionsR   t	   functoolsR   t   basicR   t   compatibilityR   R   R   t   logicR   R	   R
   t	   singletonR   t
   operationsR   t   cacheR   t   numbersR   R   R   R   t   compareR   R   R#   R   t   mulRC   R   R  R2  R  (    (    (    s-   lib/python2.7/site-packages/sympy/core/add.pyt   <module>   s&   		0   