
\c           @  s  d  d l  m Z m Z d  d l m Z m Z m Z m Z m Z m	 Z	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z m Z m Z m Z d  d l m Z m Z d  d l m Z m Z m Z d  d l 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 e f d     YZ* d e f d     YZ+ d e f d     YZ, d e f d     YZ- d e f d     YZ. d e f d     YZ/ d e f d     YZ0 d e f d     YZ1 d e f d     YZ2 d  e f d!     YZ3 d"   Z4 d# e f d$     YZ5 e6 d%  Z7 e8 e6 d&  Z9 e6 d'  Z: i  e6 d(  Z; d  d) l m< Z= e- e= _> [= d* S(+   i(   t   print_functiont   division(   t   St   Addt   Mult   sympifyt   Symbolt   Dummyt   Basic(   t   Expr(   t   factor_terms(   t   Functiont
   Derivativet   ArgumentIndexErrort   AppliedUndef(   t	   fuzzy_nott   fuzzy_or(   t   pit   It   oo(   t   Eq(   t   expt	   exp_polart   log(   t   ceiling(   t   sqrt(   t	   Piecewise(   t   atant   atan2t   rec           B  sb   e  Z d  Z e Z e Z e d    Z e d  Z d   Z	 d   Z
 d   Z d   Z d   Z RS(   s)  
    Returns real part of expression. This function performs only
    elementary analysis and so it will fail to decompose properly
    more complicated expressions. If completely simplified result
    is needed then use Basic.as_real_imag() or perform complex
    expansion on instance of this function.

    Examples
    ========

    >>> from sympy import re, im, I, E
    >>> from sympy.abc import x, y
    >>> re(2*E)
    2*E
    >>> re(2*I + 17)
    17
    >>> re(2*I)
    0
    >>> re(im(x) + x*I + 2)
    2

    See Also
    ========
    im
    c         C  s  | t  j k r t  j S| t  j k r, t  j S| j r9 | S| j sR t  j | j rY t  j S| j rp | j   d S| j	 r t
 | t  r t | j d  Sg  g  g  } } } t j |  } x | D] } | j t  j  } | d  k	 r| j sh| j |  qhq | j t  j  r/| j r/| j |  q | j d |  } | r[| j | d  q | j |  q Wt |  t |  k rd   | | | g D \ }	 }
 } |  |	  t |
  | Sd  S(   Ni    t   ignorec         s  s   |  ] } t  |   Vq d  S(   N(   R   (   t   .0t   xs(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys	   <genexpr>Y   s    (   R   t   NaNt   ComplexInfinityt   is_realt   is_imaginaryt   ImaginaryUnitt   Zerot	   is_Matrixt   as_real_imagt   is_Functiont
   isinstancet	   conjugateR   t   argsR   t	   make_argst   as_coefficientt   Nonet   appendt   hast   lent   im(   t   clst   argt   includedt   revertedt   excludedR,   t   termt   coefft	   real_imagt   at   bt   c(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   eval4   s8    			"c         K  s   |  t  j f S(   sE   
        Returns the real number with a zero imaginary part.
        (   R   R&   (   t   selft   deept   hints(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR(   ]   s    c         C  s~   | j  s |  j d j  r9 t t |  j d | d t  S| j sR |  j d j rz t j t t |  j d | d t  Sd  S(   Ni    t   evaluate(	   R#   R,   R   R   t   TrueR$   R   R%   R3   (   R@   t   x(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_derivativec   s
     c         K  s#   |  j  d t j t |  j  d  S(   Ni    (   R,   R   R%   R3   (   R@   R5   t   kwargs(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_rewrite_as_imj   s    c         C  s   |  j  d j S(   Ni    (   R,   t   is_algebraic(   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_algebraicm   s    c         C  s$   t  |  j d j |  j d j g  S(   Ni    (   R   R,   R$   t   is_zero(   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_zerop   s    c         C  s)   d d  l  j } | j |  j d j    S(   Nii    (   t   sage.allt   allt	   real_partR,   t   _sage_(   R@   t   sage(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRP   t   s    (   t   __name__t
   __module__t   __doc__RD   R#   t
   unbranchedt   classmethodR?   R(   RF   RH   RJ   RL   RP   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR      s   )				R3   c           B  sb   e  Z d  Z e Z e Z e d    Z e d  Z d   Z	 d   Z
 d   Z d   Z d   Z RS(   s/  
    Returns imaginary part of expression. This function performs only
    elementary analysis and so it will fail to decompose properly more
    complicated expressions. If completely simplified result is needed then
    use Basic.as_real_imag() or perform complex expansion on instance of
    this function.

    Examples
    ========

    >>> from sympy import re, im, E, I
    >>> from sympy.abc import x, y
    >>> im(2*E)
    0
    >>> re(2*I + 17)
    17
    >>> im(x*I)
    re(x)
    >>> im(re(x) + y)
    im(y)

    See Also
    ========

    re
    c         C  s  | t  j k r t  j S| t  j k r, t  j S| j r< t  j S| j sU t  j | j ra t  j | S| j rx | j   d S| j	 r t
 | t  r t | j d  Sg  g  g  } } } t j |  } x | D] } | j t  j  } | d  k	 r| j s	| j |  qq| j |  q | j t  j  s5| j r | j d |  } | ra| j | d  qq| j |  q q Wt |  t |  k rd   | | | g D \ }	 }
 } |  |	  t |
  | Sd  S(   Ni   i    R   c         s  s   |  ] } t  |   Vq d  S(   N(   R   (   R   R    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys	   <genexpr>   s    (   R   R!   R"   R#   R&   R$   R%   R'   R(   R)   R*   R+   R3   R,   R   R-   R.   R/   R0   R1   R2   R   (   R4   R5   R6   R7   R8   R,   R9   R:   R;   R<   R=   R>   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?      s8    			"c         K  s   |  t  j f S(   s   
        Return the imaginary part with a zero real part.

        Examples
        ========

        >>> from sympy.functions import im
        >>> from sympy import I
        >>> im(2 + 3*I).as_real_imag()
        (3, 0)
        (   R   R&   (   R@   RA   RB   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR(      s    c         C  s~   | j  s |  j d j  r9 t t |  j d | d t  S| j sR |  j d j rz t j t t |  j d | d t  Sd  S(   Ni    RC   (	   R#   R,   R3   R   RD   R$   R   R%   R   (   R@   RE   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRF      s
     c         C  s)   d d  l  j } | j |  j d j    S(   Nii    (   RM   RN   t	   imag_partR,   RP   (   R@   RQ   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRP      s    c         K  s$   t  j |  j d t |  j d  S(   Ni    (   R   R%   R,   R   (   R@   R5   RG   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_rewrite_as_re   s    c         C  s   |  j  d j S(   Ni    (   R,   RI   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRJ      s    c         C  s   |  j  d j S(   Ni    (   R,   R#   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRL      s    (   RR   RS   RT   RD   R#   RU   RV   R?   R(   RF   RP   RX   RJ   RL   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR3   y   s   (				t   signc           B  s   e  Z d  Z e Z e Z 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 RS(   sH  
    Returns the complex sign of an expression:

    If the expression is real the sign will be:

        * 1 if expression is positive
        * 0 if expression is equal to zero
        * -1 if expression is negative

    If the expression is imaginary the sign will be:

        * I if im(expression) is positive
        * -I if im(expression) is negative

    Otherwise an unevaluated expression will be returned. When evaluated, the
    result (in general) will be ``cos(arg(expr)) + I*sin(arg(expr))``.

    Examples
    ========

    >>> from sympy.functions import sign
    >>> from sympy.core.numbers import I

    >>> sign(-1)
    -1
    >>> sign(0)
    0
    >>> sign(-3*I)
    -I
    >>> sign(1 + I)
    sign(1 + I)
    >>> _.evalf()
    0.707106781186548 + 0.707106781186548*I

    See Also
    ========

    Abs, conjugate
    c         K  s6   |  j  d j t k r2 |  j  d t |  j  d  S|  S(   Ni    (   R,   RK   t   Falset   Abs(   R@   RB   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   doit  s    c   	      C  s  | j  r | j   \ } } g  } t |  } x{ | D]s } | j rM | } q4 | j rY q4 t |  } | j r | j r | t j	 9} | j r | } q q4 | j
 |  q4 W| t j k r t |  t |  k r d  S| |  | j |    S| t j k rt j S| j rt j S| j r#t j S| j r3t j S| j rRt | t  rR| Sn  | j r| j r}| j t j k r}t j	 St j	 | } | j rt j	 S| j rt j	 Sn  d  S(   N(   t   is_Mult   as_coeff_mulRY   t   is_negativet   is_positiveR3   R$   t   is_comparableR   R%   R0   t   OneR2   R/   t   _new_rawargsR!   RK   R&   t   NegativeOneR)   R*   t   is_PowR   t   Half(	   R4   R5   R>   R,   t   unkt   sR<   t   ait   arg2(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?     sJ    		
		'							c         C  s!   t  |  j d j  r t j Sd  S(   Ni    (   R   R,   RK   R   Rb   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt	   _eval_AbsF  s    c         C  s   t  t |  j d   S(   Ni    (   RY   R+   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_conjugateJ  s    c         C  s   |  j  d j rO d d l m } d t |  j  d | d t | |  j  d  S|  j  d j r d d l m } d t |  j  d | d t | t j |  j  d  Sd  S(   Ni    i(   t
   DiracDeltai   RC   (	   R,   R#   t'   sympy.functions.special.delta_functionsRm   R   RD   R$   R   R%   (   R@   RE   Rm   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRF   M  s    /c         C  s   |  j  d j r t Sd  S(   Ni    (   R,   t   is_nonnegativeRD   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_nonnegativeW  s    c         C  s   |  j  d j r t Sd  S(   Ni    (   R,   t   is_nonpositiveRD   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_nonpositive[  s    c         C  s   |  j  d j S(   Ni    (   R,   R$   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_imaginary_  s    c         C  s   |  j  d j S(   Ni    (   R,   R#   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_integerb  s    c         C  s   |  j  d j S(   Ni    (   R,   RK   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRL   e  s    c         C  s3   t  |  j d j  r/ | j r/ | j r/ t j Sd  S(   Ni    (   R   R,   RK   t
   is_integert   is_evenR   Rb   (   R@   t   other(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_powerh  s    		c         C  s)   d d  l  j } | j |  j d j    S(   Nii    (   RM   RN   t   sgnR,   RP   (   R@   RQ   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRP   p  s    c         K  s;   | j  r7 t d | d k f d | d k  f d t f  Sd  S(   Ni   i    i(   R#   R   RD   (   R@   R5   RG   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_rewrite_as_Piecewiset  s    	c         K  s/   d d l  m } | j r+ | |  d d Sd  S(   Ni(   t	   Heavisidei   i   (   Rn   R{   R#   (   R@   R5   RG   R{   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_rewrite_as_Heavisidex  s    	c         C  s   |  j  |  j d j    S(   Ni    (   t   funcR,   t   factor(   R@   t   ratiot   measuret   rationalt   inverse(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_simplify}  s    (   RR   RS   RT   RD   t	   is_finitet
   is_complexR\   RV   R?   Rk   Rl   RF   Rp   Rr   Rs   Rt   RL   Rx   RP   Rz   R|   R   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRY      s$   '	/			
									R[   c           B  s   e  Z d  Z e Z e Z e Z d 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 RS(   s  
    Return the absolute value of the argument.

    This is an extension of the built-in function abs() to accept symbolic
    values.  If you pass a SymPy expression to the built-in abs(), it will
    pass it automatically to Abs().

    Examples
    ========

    >>> from sympy import Abs, Symbol, S
    >>> Abs(-1)
    1
    >>> x = Symbol('x', real=True)
    >>> Abs(-x)
    Abs(x)
    >>> Abs(x**2)
    x**2
    >>> abs(-x) # The Python built-in
    Abs(x)

    Note that the Python built-in will return either an Expr or int depending on
    the argument::

        >>> type(abs(-1))
        <... 'int'>
        >>> type(abs(S.NegativeOne))
        <class 'sympy.core.numbers.One'>

    Abs will always return a sympy object.

    See Also
    ========

    sign, conjugate
    i   c         C  s0   | d k r t  |  j d  St |  |   d S(   s   
        Get the first derivative of the argument to Abs().

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy.functions import Abs
        >>> Abs(-x).fdiff()
        sign(x)
        i   i    N(   RY   R,   R   (   R@   t   argindex(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   fdiff  s    c           sE  d d l  m } d d l m } t   d  rN   j   } | d  k	 rN | Sn  t   t  sv t	 d t
      n  |   d t     j r+g  } g  } xP   j D]E } |  |  } t | |   r | j | j d  q | j |  q Wt |   } | r|  t |   d t n t j } | | S  t j k rAt j S  t j k rWt j S  j rn  j   \ }	 }
 |	 j r"|
 j r|
 j r  S|	 t j k rt j St |	 |   r|
 t j k r  St |	  |
 S|	 j r|	 t |
  S|	 j r|	 t |
  t t j  t! |
   Sd  S|	 j" t#  snt$ |	  j%   \ } } | t& | } t t |
 |   Sn  t   t  rt t   j d   St   t'  rd  S  j( r  j" t j t j)  rt* d     j%   D  rt j Sn    j+ rt j, S  j r  S  j- r  S  j. r@t j/   } | j r@| Sn  |   j0   d t   j1 t0    j1 t0  } | rt2   f d	   | D  rd  S   k rA   k rA  j1 t  }   j3 d
   | D  } g  | j4 D] } | j d  k r| ^ q} | s*t2  f d   | D  rAt5 |      Sn  d  S(   Ni(   t   signsimp(   t
   expand_mulRk   s   Bad argument type for Abs(): %sRC   i    c         s  s   |  ] } | j  Vq d  S(   N(   t   is_infinite(   R   R<   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys	   <genexpr>  s    c         3  s%   |  ] }   j  | j d   Vq d S(   i    N(   R1   R,   (   R   t   i(   R5   (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys	   <genexpr>  s    c         S  s"   i  |  ] } t  d  t  |  q S(   t   real(   R   RD   (   R   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys
   <dictcomp>  s   	 c         3  s$   |  ] }   j  t |   Vq d  S(   N(   R1   R+   (   R   t   u(   t   conj(    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys	   <genexpr>
  s    (6   t   sympy.simplify.simplifyR   t   sympy.core.functionR   t   hasattrRk   R/   R*   R	   t	   TypeErrort   typeRZ   R]   R,   R0   R   R   Rb   R!   R"   t   InfinityRe   t   as_base_expR#   Ru   Rv   Rd   R[   Ro   R   R_   R   t   PiR3   R1   R   R   R(   R   R   t   is_Addt   NegativeInfinityt   anyRK   R&   Rq   R$   R%   R+   t   atomsRN   t   xreplacet   free_symbolsR   (   R4   R5   R   R   t   objt   knownRg   t   tt   tnewt   baset   exponentR<   R=   t   zRj   t   new_conjR   t   abs_free_arg(    (   R5   R   sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?     s    	'						'!
					"+$c         C  s"   |  j  d j r |  j  d j Sd  S(   Ni    (   R,   R#   Ru   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRt     s    c         C  s   t  |  j d j  S(   Ni    (   R   t   _argsRK   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_nonzero  s    c         C  s   |  j  d j S(   Ni    (   R   RK   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRL     s    c         C  s   |  j  } | d  k	 r | Sd  S(   N(   RK   R/   (   R@   t   is_z(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_positive  s    	c         C  s"   |  j  d j r |  j  d j Sd  S(   Ni    (   R,   R#   t   is_rational(   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_rational  s    c         C  s"   |  j  d j r |  j  d j Sd  S(   Ni    (   R,   R#   Rv   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_even   s    c         C  s"   |  j  d j r |  j  d j Sd  S(   Ni    (   R,   R#   t   is_odd(   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_is_odd$  s    c         C  s   |  j  d j S(   Ni    (   R,   RI   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRJ   (  s    c         C  sg   |  j  d j rc | j rc | j r1 |  j  d | S| t j k	 rc | j rc |  j  d | d |  Sn  d  S(   Ni    i   (   R,   R#   Ru   Rv   R   Rd   t
   is_Integer(   R@   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRx   +  s    	c         C  sz   |  j  d j |  d } |  j  d j | d | d | } t | d  } t | j | d  | f t |  | t f  S(   Ni    t   nt   logx(   R,   t   leadtermt   _eval_nseriesR   R   t   subsRY   RD   (   R@   RE   R   R   t	   directionRh   t   when(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR   3  s    "c         C  s)   d d  l  j } | j |  j d j    S(   Nii    (   RM   RN   t   abs_symbolicR,   RP   (   R@   RQ   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRP   <  s    c         C  s   |  j  d j s  |  j  d j rQ t |  j  d | d t t t |  j  d   St |  j  d  t t |  j  d  | d t t |  j  d  t t |  j  d  | d t t	 |  j  d  } | j
 t  S(   Ni    RC   (   R,   R#   R$   R   RD   RY   R+   R   R3   R[   t   rewrite(   R@   RE   t   rv(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRF   @  s     )*"c         K  s6   d d l  m } | j r2 | | |  | |  Sd  S(   Ni(   R{   (   Rn   R{   R#   (   R@   R5   RG   R{   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR|   I  s    	c         K  s-   | j  r) t | | d k f | t f  Sd  S(   Ni    (   R#   R   RD   (   R@   R5   RG   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRz   P  s    	c         K  s   | t  |  S(   N(   RY   (   R@   R5   RG   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_rewrite_as_signT  s    (   RR   RS   RT   RD   R#   RZ   R_   RU   R   RV   R?   Rt   R   RL   R   R   R   R   RJ   Rx   R   RP   RF   R|   Rz   R   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR[     s*   $Q																R5   c           B  s;   e  Z d  Z e Z e Z e d    Z d   Z d   Z	 RS(   s5  
    Returns the argument (in radians) of a complex number. For a positive
    number, the argument is always 0.

    Examples
    ========

    >>> from sympy.functions import arg
    >>> from sympy import I, sqrt
    >>> arg(2.0)
    0
    >>> arg(I)
    pi/2
    >>> arg(sqrt(2) + I*sqrt(2))
    pi/4

    c         C  s  t  | t  r t | t  S| j s t |  j   \ } } | j r t g  | j	 D]* } t
 |  d k rq | n	 t
 |  ^ qS   } n  t
 |  | } n | } | j t  r d  S| j   \ } } t | |  } | j r | S| | k r |  | d t Sd  S(   Nii   RC   (   ii   (   R*   R   t   periodic_argumentR   t   is_AtomR
   t   as_coeff_MulR]   R   R,   RY   R   R   R(   R   t	   is_numberRZ   (   R4   R5   R>   t   arg_R<   RE   t   yR   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?   n  s"    		=	c         C  sW   |  j  d j   \ } } | t | | d t | t | | d t | d | d S(   Ni    RC   i   (   R,   R(   R   RD   (   R@   R   RE   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRF     s    c         K  s&   |  j  d j   \ } } t | |  S(   Ni    (   R,   R(   R   (   R@   R5   RG   RE   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_rewrite_as_atan2  s    (
   RR   RS   RT   RD   R#   R   RV   R?   RF   R   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR5   X  s   	R+   c           B  sS   e  Z d  Z e d    Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   s-  
    Returns the `complex conjugate` Ref[1] of an argument.
    In mathematics, the complex conjugate of a complex number
    is given by changing the sign of the imaginary part.

    Thus, the conjugate of the complex number
    :math:`a + ib` (where a and b are real numbers) is :math:`a - ib`

    Examples
    ========

    >>> from sympy import conjugate, I
    >>> conjugate(2)
    2
    >>> conjugate(I)
    -I

    See Also
    ========

    sign, Abs

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Complex_conjugation
    c         C  s    | j    } | d  k	 r | Sd  S(   N(   Rl   R/   (   R4   R5   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?     s    c         C  s   t  |  j d d t S(   Ni    RC   (   R[   R,   RD   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRk     s    c         C  s   t  |  j d  S(   Ni    (   t	   transposeR,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_adjoint  s    c         C  s   |  j  d S(   Ni    (   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRl     s    c         C  sW   | j  r) t t |  j d | d t  S| j rS t t |  j d | d t  Sd  S(   Ni    RC   (   R#   R+   R   R,   RD   R$   (   R@   RE   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRF     s    	 	c         C  s   t  |  j d  S(   Ni    (   t   adjointR,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _eval_transpose  s    c         C  s   |  j  d j S(   Ni    (   R,   RI   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRJ     s    (   RR   RS   RT   RV   R?   Rk   R   Rl   RF   R   RJ   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR+     s   					R   c           B  s8   e  Z d  Z e d    Z d   Z d   Z d   Z RS(   s#   
    Linear map transposition.
    c         C  s    | j    } | d  k	 r | Sd  S(   N(   R   R/   (   R4   R5   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?     s    c         C  s   t  |  j d  S(   Ni    (   R+   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s    c         C  s   t  |  j d  S(   Ni    (   R   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRl     s    c         C  s   |  j  d S(   Ni    (   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s    (   RR   RS   RT   RV   R?   R   Rl   R   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s
   		R   c           B  sM   e  Z d  Z e d    Z d   Z d   Z d   Z d d  Z	 d   Z
 RS(   s5   
    Conjugate transpose or Hermite conjugation.
    c         C  sB   | j    } | d  k	 r | S| j   } | d  k	 r> t |  Sd  S(   N(   R   R/   R   R+   (   R4   R5   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?     s    c         C  s   |  j  d S(   Ni    (   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s    c         C  s   t  |  j d  S(   Ni    (   R   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRl     s    c         C  s   t  |  j d  S(   Ni    (   R+   R,   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s    c         G  sF   | j  |  j d  } d | } | rB d | | j  |  f } n  | S(   Ni    s   %s^{\dagger}s   \left(%s\right)^{%s}(   t   _printR,   (   R@   t   printerR   R,   R5   t   tex(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _latex  s
    
c         G  sY   d d l  m } | j |  j d |  } | j rE | | d  } n | | d  } | S(   Ni(   t
   prettyFormi    u   †t   +(   t    sympy.printing.pretty.stringpictR   R   R,   t   _use_unicode(   R@   R   R,   R   t   pform(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _pretty  s    	N(   RR   RS   RT   RV   R?   R   Rl   R   R/   R   R   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s   				t
   polar_liftc           B  s;   e  Z d  Z e Z e Z e d    Z d   Z	 d   Z
 RS(   s4  
    Lift argument to the Riemann surface of the logarithm, using the
    standard branch.

    >>> from sympy import Symbol, polar_lift, I
    >>> p = Symbol('p', polar=True)
    >>> x = Symbol('x')
    >>> polar_lift(4)
    4*exp_polar(0)
    >>> polar_lift(-4)
    4*exp_polar(I*pi)
    >>> polar_lift(-I)
    exp_polar(-I*pi/2)
    >>> polar_lift(I + 2)
    polar_lift(2 + I)

    >>> polar_lift(4*x)
    4*polar_lift(x)
    >>> polar_lift(4*p)
    4*p

    See Also
    ========

    sympy.functions.elementary.exponential.exp_polar
    periodic_argument
    c         C  sL  d d l  m } | j ra | |  } | d t d t d t f k ra t t |  t |  Sn  | j rv | j } n	 | g } g  } g  } g  } xM | D]E } | j	 r | | g 7} q | j
 r | | g 7} q | | g 7} q Wt |  t |  k  rH| rt | |   t t |    S| r1t | |   St |   t d  Sn  d  S(   Ni(   R5   i    i   (   t$   sympy.functions.elementary.complexesR5   R   R   R   R   t   absR]   R,   t   is_polarR`   R2   R   R   (   R4   R5   t   argumentt   arR,   R6   R8   t   positive(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?   '  s.    	!				c         C  s   |  j  d j |  S(   s.    Careful! any evalf of polar numbers is flaky i    (   R,   t   _eval_evalf(   R@   t   prec(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR   I  s    c         C  s   t  |  j d d t S(   Ni    RC   (   R[   R,   RD   (   R@   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyRk   M  s    (   RR   RS   RT   RD   R   RZ   Ra   RV   R?   R   Rk   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s   "	R   c           B  s5   e  Z d  Z e d    Z e d    Z d   Z RS(   s  
    Represent the argument on a quotient of the Riemann surface of the
    logarithm. That is, given a period P, always return a value in
    (-P/2, P/2], by using exp(P*I) == 1.

    >>> from sympy import exp, exp_polar, periodic_argument, unbranched_argument
    >>> from sympy import I, pi
    >>> unbranched_argument(exp(5*I*pi))
    pi
    >>> unbranched_argument(exp_polar(5*I*pi))
    5*pi
    >>> periodic_argument(exp_polar(5*I*pi), 2*pi)
    pi
    >>> periodic_argument(exp_polar(5*I*pi), 3*pi)
    -pi
    >>> periodic_argument(exp_polar(5*I*pi), pi)
    0

    See Also
    ========

    sympy.functions.elementary.exponential.exp_polar
    polar_lift : Lift argument to the Riemann surface of the logarithm
    principal_branch
    c         C  s   | j  r | j } n	 | g } d } x | D] } | j sM | t |  7} q+ t | t  rv | | j j   d 7} q+ | j r | j j   \ } } | | t	 | j
  | t t | j
   7} q+ t | t  r | t | j d  7} q+ d  Sq+ W| S(   Ni    i   (   R]   R,   R   R5   R*   R   R   R(   Re   t   unbranched_argumentR   R   R   R   R/   (   R4   R   R,   RU   R<   R   R3   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   _getunbranchedl  s"    					(c         C  s[  | j  s d  S| t k r5 t | t  r5 t | j   St | t  rh | d t k rh t | j d |  S| j	 r g  | j D] } | j  s{ | ^ q{ } t
 |  t
 | j  k r t t |   |  Sn  |  j |  } | d  k r d  S| j t t t  r d  S| t k r| S| t k rWt | | t d  d  | } | j t  sW| | Sn  d  S(   Ni   i    i   (   R`   R/   R   R*   t   principal_branchR   R,   R   R   R]   R2   R   R   R1   R   R   R   R   (   R4   R   t   periodRE   t   newargsRU   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?     s*    		%"c         C  s   |  j  \ } } | t k rG t j |  } | d  k r: |  S| j |  St | t  j |  } | t | | t d  d  | j |  S(   Ni   i   (   R,   R   R   R   R/   R   R   R   (   R@   R   R   R   RU   t   ub(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s    (   RR   RS   RT   RV   R   R?   R   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR   Q  s   c         C  s   t  |  t  S(   N(   R   R   (   R5   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s    R   c           B  s2   e  Z d  Z e Z e Z e d    Z d   Z	 RS(   s  
    Represent a polar number reduced to its principal branch on a quotient
    of the Riemann surface of the logarithm.

    This is a function of two arguments. The first argument is a polar
    number `z`, and the second one a positive real number of infinity, `p`.
    The result is "z mod exp_polar(I*p)".

    >>> from sympy import exp_polar, principal_branch, oo, I, pi
    >>> from sympy.abc import z
    >>> principal_branch(z, oo)
    z
    >>> principal_branch(exp_polar(2*pi*I)*3, 2*pi)
    3*exp_polar(0)
    >>> principal_branch(exp_polar(2*pi*I)*3*z, 2*pi)
    3*principal_branch(z, 2*pi)

    See Also
    ========

    sympy.functions.elementary.exponential.exp_polar
    polar_lift : Lift argument to the Riemann surface of the logarithm
    periodic_argument
    c           s  d d l  m } m } m } m } m  m   t |   rQ t | j	 d |  S| | k ra | St
 | |  } t
 | |  } | | k rZ| j t
  rZ| j t
  rZ |  }	    f d   }
 |	 j  |
  }	 t
 |	 |  } |	 j   sZ| | k r | | | |  |	 } n |	 } | j rS| j |  rS| | d  9} n  | Sn  | j ss| d } } n | j | j   \ } } g  } x1 | D]) } | j r| | 9} q| | g 7} qWt |  } t
 | |  } | j t
  rd  S| j rt |  | k s2| d k r| d k r| d k r| d k r[t |  t | |   |  St | | |  | |   |  t |  S| j rt |  | d k  t k s| | d k r| d	 k r| | |  t |  Sd  S(
   Ni(   R   R   R   R   R   R   i    c           s   t  |     s  |   S|  S(   N(   R*   (   t   expr(   R   R   (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   mr  s    
i   i   (    (    (    (   t   sympyR   R   R   R   R   R   R*   R   R,   R   R1   t   replaceR   R   R^   R`   t   tupleR/   R   R   R   RD   (   R@   RE   R   R   R   R   R   R   t   bargt   plR   t   resR>   t   mt   othersR   R5   (    (   R   R   sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR?     sP    .		$+5c         C  s   d d l  m } m } m } |  j \ } } t | |  j |  } t |  | k sb | | k rf |  St |  | | |  j |  S(   Ni(   R   R   R   (   R   R   R   R   R,   R   R   R   (   R@   R   R   R   R   R   R   t   p(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s    (
   RR   RS   RT   RD   R   RZ   Ra   RV   R?   R   (    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s
   4c         C  s  d d l  m } |  j r |  S|  j r7 | r7 t |   St |  t  r] | r] | r] t |   S|  j rj |  S|  j r |  j	 g  |  j
 D] } t | | d t ^ q   } | r t |  S| S|  j r |  j	 g  |  j
 D] } t | | d t ^ q   St |  |  rt |  j | d | } g  } xa |  j
 d D]R } t | d d t d | }	 t | d d | d | }
 | j |	 f |
  q1W| | f t |    S|  j	 g  |  j
 D]0 } t | t  rt | | d | n | ^ q  Sd  S(   Ni(   t   Integralt   pausei   i    t   lift(   R   R   R   R   R   R*   R   R   R   R}   R,   t	   _polarifyRD   R)   RZ   t   functionR0   R   R	   (   t   eqR   R   R   R5   t   rR}   t   limitst   limitt   vart   rest(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR     s4    	

		4
	2	c         C  sj   | r t  } n  t t |   |  }  | s. |  Sd   |  j D } |  j |  }  |  d   | j   D f S(   s  
    Turn all numbers in eq into their polar equivalents (under the standard
    choice of argument).

    Note that no attempt is made to guess a formal convention of adding
    polar numbers, expressions like 1 + x will generally not be altered.

    Note also that this function does not promote exp(x) to exp_polar(x).

    If ``subs`` is True, all symbols which are not already polar will be
    substituted for polar dummies; in this case the function behaves much
    like posify.

    If ``lift`` is True, both addition statements and non-polar symbols are
    changed to their polar_lift()ed versions.
    Note that lift=True implies subs=False.

    >>> from sympy import polarify, sin, I
    >>> from sympy.abc import x, y
    >>> expr = (-x)**y
    >>> expr.expand()
    (-x)**y
    >>> polarify(expr)
    ((_x*exp_polar(I*pi))**_y, {_x: x, _y: y})
    >>> polarify(expr)[0].expand()
    _x**_y*exp_polar(_y*I*pi)
    >>> polarify(x, lift=True)
    polar_lift(x)
    >>> polarify(x*(1+y), lift=True)
    polar_lift(x)*polar_lift(y + 1)

    Adds are treated carefully:

    >>> polarify(1 + sin((1 + I)*x))
    (sin(_x*polar_lift(1 + I)) + 1, {_x: x})
    c         S  s(   i  |  ] } t  | j d  t |  q S(   t   polar(   R   t   nameRD   (   R   Rh   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys
   <dictcomp>P  s   	 c         S  s   i  |  ] \ } } | |  q S(    (    (   R   Rh   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pys
   <dictcomp>R  s   	 (   RZ   R   R   R   R   t   items(   R   R   R   t   reps(    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   polarify&  s    %	c         C  s  t  |  t  s |  j r |  S| s%t  |  t  rH t t |  j |   St  |  t  r |  j d d t k r t |  j d |  S|  j	 s |  j
 s |  j s |  j r |  j d k r d |  j k s |  j d k r |  j g  |  j D] } t | |  ^ q   St  |  t  r%t |  j d |  Sn  |  j rht |  j |  } t |  j | | j oY|  } | | S|  j rt |  j d t  r|  j g  |  j D] } t | | |  ^ q  S|  j g  |  j D] } t | | t  ^ q  S(	   Ni   i   i    s   ==s   !=RU   (   s   ==s   !=(   s   ==s   !=(   R*   R   R   R   R   t   _unpolarifyR   R,   R   R   R]   t
   is_Booleant   is_Relationalt   rel_opR}   R   Re   R   Ru   R)   t   getattrRZ   RD   (   R   t   exponents_onlyR   RE   t   expoR   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR   U  s.    &	,		&c         C  s   t  |  t  r |  St |   }  | i  k r> t |  j |   St } t } | rY t } n  xP | r t } t |  | |  } | |  k r t } | }  n  t  | t  r\ | Sq\ W| j i d t d  6d t	 d  6 S(   s  
    If p denotes the projection from the Riemann surface of the logarithm to
    the complex line, return a simplified version eq' of `eq` such that
    p(eq') == p(eq).
    Also apply the substitution subs in the end. (This is a convenience, since
    ``unpolarify``, in a certain sense, undoes polarify.)

    >>> from sympy import unpolarify, polar_lift, sin, I
    >>> unpolarify(polar_lift(I + 2))
    2 + I
    >>> unpolarify(sin(polar_lift(I + 7)))
    sin(7 + I)
    i   i    (
   R*   t   boolR   t
   unpolarifyR   RD   RZ   R   R   R   (   R   R   R   t   changedR   R   (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyR  u  s$    			(   t   basicN(?   t
   __future__R    R   t
   sympy.coreR   R   R   R   R   R   R   t   sympy.core.exprR	   t   sympy.core.exprtoolsR
   R   R   R   R   R   t   sympy.core.logicR   R   t   sympy.core.numbersR   R   R   t   sympy.core.relationalR   t&   sympy.functions.elementary.exponentialR   R   R   t#   sympy.functions.elementary.integersR   t(   sympy.functions.elementary.miscellaneousR   t$   sympy.functions.elementary.piecewiseR   t(   sympy.functions.elementary.trigonometricR   R   R   R3   RY   R[   R5   R+   R   R   R   R   R   R   RZ   R   RD   R   R   R  R  t   _t   abs_(    (    (    sC   lib/python2.7/site-packages/sympy/functions/elementary/complexes.pyt   <module>   s>   4"cm59,JX	Z/ '	