ó
¡¼™\c           @  sÖ   d  d l  m Z m Z d  d l m Z m Z m Z m Z m Z d  d l m	 Z	 m
 Z
 m Z m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d l m Z d  d l m Z d	 e f d
 „  ƒ  YZ e Z d S(   iÿÿÿÿ(   t   print_functiont   division(   t   St   sympifyt   Exprt   Rationalt   Dummy(   t   Addt   Mult   expand_power_baset
   expand_log(   t   cacheit(   t   default_sort_keyt   is_sequence(   t   Tuple(   t
   Complement(   t   uniqt   Orderc           B  s×   e  Z d  Z e Z g  Z e d „  ƒ Z d „  Z e	 d „  ƒ Z
 e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z d „  Z d „  Z d	 „  Z d
 „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sä   Represents the limiting behavior of some function

    The order of a function characterizes the function based on the limiting
    behavior of the function as it goes to some limit. Only taking the limit
    point to be a number is currently supported. This is expressed in
    big O notation [1]_.

    The formal definition for the order of a function `g(x)` about a point `a`
    is such that `g(x) = O(f(x))` as `x \rightarrow a` if and only if for any
    `\delta > 0` there exists a `M > 0` such that `|g(x)| \leq M|f(x)|` for
    `|x-a| < \delta`.  This is equivalent to `\lim_{x \rightarrow a}
    \sup |g(x)/f(x)| < \infty`.

    Let's illustrate it on the following example by taking the expansion of
    `\sin(x)` about 0:

    .. math ::
        \sin(x) = x - x^3/3! + O(x^5)

    where in this case `O(x^5) = x^5/5! - x^7/7! + \cdots`. By the definition
    of `O`, for any `\delta > 0` there is an `M` such that:

    .. math ::
        |x^5/5! - x^7/7! + ....| <= M|x^5| \text{ for } |x| < \delta

    or by the alternate definition:

    .. math ::
        \lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| < \infty

    which surely is true, because

    .. math ::
        \lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| = 1/5!


    As it is usually used, the order of a function can be intuitively thought
    of representing all terms of powers greater than the one specified. For
    example, `O(x^3)` corresponds to any terms proportional to `x^3,
    x^4,\ldots` and any higher power. For a polynomial, this leaves terms
    proportional to `x^2`, `x` and constants.

    Examples
    ========

    >>> from sympy import O, oo, cos, pi
    >>> from sympy.abc import x, y

    >>> O(x + x**2)
    O(x)
    >>> O(x + x**2, (x, 0))
    O(x)
    >>> O(x + x**2, (x, oo))
    O(x**2, (x, oo))

    >>> O(1 + x*y)
    O(1, x, y)
    >>> O(1 + x*y, (x, 0), (y, 0))
    O(1, x, y)
    >>> O(1 + x*y, (x, oo), (y, oo))
    O(x*y, (x, oo), (y, oo))

    >>> O(1) in O(1, x)
    True
    >>> O(1, x) in O(1)
    False
    >>> O(x) in O(1, x)
    True
    >>> O(x**2) in O(x)
    True

    >>> O(x)*x
    O(x**2)
    >>> O(x) - O(x)
    O(x)
    >>> O(cos(x))
    O(1)
    >>> O(cos(x), (x, pi/2))
    O(x - pi/2, (x, pi/2))

    References
    ==========

    .. [1] `Big O notation <https://en.wikipedia.org/wiki/Big_O_notation>`_

    Notes
    =====

    In ``O(f(x), x)`` the expression ``f(x)`` is assumed to have a leading
    term.  ``O(f(x), x)`` is automatically transformed to
    ``O(f(x).as_leading_term(x),x)``.

        ``O(expr*f(x), x)`` is ``O(f(x), x)``

        ``O(expr, x)`` is ``O(1)``

        ``O(0, x)`` is 0.

    Multivariate O is also supported:

        ``O(f(x, y), x, y)`` is transformed to
        ``O(f(x, y).as_leading_term(x,y).as_leading_term(y), x, y)``

    In the multivariate case, it is assumed the limits w.r.t. the various
    symbols commute.

    If no symbols are passed then all symbols in the expression are used
    and the limit point is assumed to be zero.

    c           sD  t  | ƒ } | sX | j r0 | j } | j ‰  q
t | j ƒ } t j g t | ƒ ‰  n² t t	 | ƒ rm | n | g ƒ } g  g  } ‰  t	 | d ƒ rß xq | D]; } t t
 t  | ƒ ƒ \ } } | j | ƒ ˆ  j | ƒ q Wn+ t t
 t  | ƒ ƒ } t j g t | ƒ ‰  t d „  | Dƒ ƒ s3t d | ƒ ‚ n  t t t | ƒ ƒ ƒ t | ƒ k rjt d | ƒ ‚ n  | j r\t | j d ƒ } t | ƒ }	 t t | ˆ  ƒ ƒ }
 xX |
 j ƒ  D]J \ } } | |	 j ƒ  k rô| |	 | k rþt d ƒ ‚ qþq´| |	 | <q´Wt | j ƒ  ƒ t |	 j ƒ  ƒ k r*| St |	 j ƒ  ƒ } g  | D] } |	 | ^ qC‰  n  | t j k rrt j St ‡  f d †  | Dƒ ƒ r¡t d ˆ  ƒ ‚ n  | rt ‡  f d	 †  ˆ  Dƒ ƒ rÒt d
 ƒ ‚ n  ˆ  d t j k rd „  | Dƒ } d „  | j ƒ  Dƒ } nœ ˆ  d t j k rJd „  | Dƒ } d „  | j ƒ  Dƒ } n` ˆ  d t j k	 ržt ‡  f d †  | Dƒ ƒ } t ‡  f d †  | j ƒ  Dƒ ƒ } n d } d } | j | ƒ } | j rád d l m } | | ƒ } n  | rt g  | j ƒ  D] } | d ^ q÷ƒ } n t | ƒ } t | ƒ d k r@| j  ƒ  } n  | j rƒ| j! | ƒ } t" g  | D] \ } } | j# ^ qbŒ  } nø| r{| j$ | Œ  } | j% d t& | Œ d } t' | ƒ } t( | ƒ } t | ƒ d k r{| d } t t) j* | j% | d t& ƒd ƒ ƒ } xYt+ | ƒ D]K\ } } | j, r| j \ } } | | | f k r{| j- r{| j. | ƒ r{| | | | <qe| j, rÚ| j/ j. | ƒ rÚ| j \ } } | | | f k rb| j- rb| | | | | <qbqe| j0 re| j d t j1 k re| } | j, rb| j/ j. | ƒ rb| j \ } } | | | f k r_| j- r_| | | | | <q_qbqeqqWt) | Œ  } q{n  | j | ƒ } n  | t j k r | S| j rµ| j# } n  | j. | Œ  sÐt j2 } n  t t | ˆ  ƒ ƒ }
 | j3 d t4 ƒ g  | D] } |
 | ^ qü‰  | f t5 t | ˆ  ƒ Œ  } t6 j7 |  | Œ } | S(   Ni    c         s  s   |  ] } | j  Vq d  S(   N(   t	   is_symbol(   t   .0t   v(    (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>—   s    s!   Variables are not symbols, got %ss3   Variables are supposed to be unique symbols, got %si   s2   Mixing Order at different points is not supported.c         3  s+   |  ]! } ˆ  D] } | | j  k Vq q d  S(   N(   t   free_symbols(   R   t   xt   p(   t   point(    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>±   s    s   Got %s as a point.c         3  s   |  ] } | ˆ  d  k Vq d S(   i    N(    (   R   R   (   R   (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>µ   s    s;   Multivariable orders at different points are not supported.c         S  s    i  |  ] } d  t  ƒ  | “ q S(   i   (   R   (   R   t   k(    (    s1   lib/python2.7/site-packages/sympy/series/order.pys
   <dictcomp>¹   s   	 c         S  s'   i  |  ] \ } } d  | d  | “ q S(   i   (    (   R   R   R   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pys
   <dictcomp>º   s   	 c         S  s    i  |  ] } d  t  ƒ  | “ q S(   iÿÿÿÿ(   R   (   R   R   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pys
   <dictcomp>¼   s   	 c         S  s'   i  |  ] \ } } d  | d  | “ q S(   iÿÿÿÿ(    (   R   R   R   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pys
   <dictcomp>½   s   	 c         3  s&   |  ] } | t  ƒ  ˆ  d  f Vq d S(   i    N(   R   (   R   R   (   R   (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>¿   s    c         3  s1   |  ]' \ } } | ˆ  d  | ˆ  d  f Vq d S(   i    N(    (   R   R   R   (   R   (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>À   s    iÿÿÿÿ(   t   expand_multinomialt   as_Addt   key(    (    (8   R   t   is_Ordert	   variablesR   t   listR   R   t   Zerot   lenR   t   mapt   appendt   allt	   TypeErrorR   t
   ValueErrort   dictt   argst   zipt   itemst   keyst   NotImplementedErrort   sett   NaNt   anyt   Infinityt   NegativeInfinityt   subst   is_Addt   sympyR   t   tuplet   expandt   extract_leading_orderR   t   exprt   as_leading_termt   as_independentt   FalseR	   R
   R   t	   make_argst	   enumeratet   is_Powt   is_realt   hast   expt   is_Mult   NegativeOnet   Onet   sortR   R   R   t   __new__(   t   clsR8   R(   t   kwargsR   t   aR   R   t   expr_vpt   new_vpt   vpt   st   rsR   t   rt   lstt   et   fR   t   margst   it   tt   bt   qt   obj(    (   R   s1   lib/python2.7/site-packages/sympy/series/order.pyRF   €   sÎ    		!$	$ %	,	+
		,"	c         C  s   |  S(   N(    (   t   selfR   t   nt   logx(    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   _eval_nseries  s    c         C  s   |  j  d S(   Ni    (   R(   (   RY   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR8     s    c         C  s0   |  j  d r( t d „  |  j  d Dƒ ƒ Sd Sd  S(   Ni   c         s  s   |  ] } | d  Vq d S(   i    N(    (   R   R   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>  s    (    (   R(   R5   (   RY   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR     s    c         C  s0   |  j  d r( t d „  |  j  d Dƒ ƒ Sd Sd  S(   Ni   c         s  s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>#  s    (    (   R(   R5   (   RY   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR      s    c         C  s   |  j  j t |  j ƒ BS(   N(   R8   R   R-   R   (   RY   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR   '  s    c         C  sJ   | j  r0 | j r0 |  j |  j | |  j d Œ S| t d ƒ k rF |  Sd  S(   Ni   (   t	   is_Numbert   is_nonnegativet   funcR8   R(   t   O(   RV   RQ   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   _eval_power+  s
    c           s"  ˆ  d  k r ˆ j d ‰  nó t ‡  f d †  ˆ  Dƒ ƒ ro t ‡ f d †  ˆ j Dƒ ƒ ro t d ˆ j ƒ ‚ n  ˆ  rŸ ˆ  d d ˆ j d k rŸ t d ƒ ‚ n  t ˆ  ƒ ‰  xF t ˆ j d ƒ j ƒ  D]+ \ } } | ˆ  j ƒ  k rÅ | ˆ  | <qÅ qÅ Wt ˆ  j ƒ  d d „  ƒ‰  ˆ j	 t
 ˆ  ƒ f S(	   Ni   c         3  s'   |  ] } | d  ˆ  d d  k Vq d S(   i   i    N(    (   R   t   o(   t   order_symbols(    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>6  s    c         3  s"   |  ] } | ˆ  j  d  k Vq d S(   i    N(   R   (   R   R   (   RY   (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>7  s    sD   Order at points other than 0 or oo not supported, got %s as a point.i    s7   Multiplying Order at different points is not supported.R   c         S  s   t  |  d ƒ S(   Ni    (   R   (   R   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   <lambda>A  t    (   t   NoneR(   R$   R   R,   R'   R*   R+   t   sortedR8   R5   (   RY   Rc   RM   R   (    (   Rc   RY   s1   lib/python2.7/site-packages/sympy/series/order.pyt   as_expr_variables2  s     !&c         C  s   t  j S(   N(   R   R    (   RY   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   removeOD  s    c         C  s   |  S(   N(    (   RY   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   getOG  s    c           sz  d d l  m } | t j k r# t S| t j k r6 t S|  j rL |  j d n t j ‰  | j rƒt	 ‡  f d †  | j Dƒ ƒ sœ t	 ‡  f d †  |  j Dƒ ƒ r  d S| j |  j k rã t g  | j d D] } | |  j d k ^ qÃ ƒ S| j j rt g  | j j D] } |  j | ƒ ^ qÿ ƒ S|  j j ruˆ  t j k rut	 g  |  j j D]( } |  j | |  j d Œ j | ƒ ^ qFƒ S|  j r»| j r»t g  |  j D] } | | j k r”| ^ q”ƒ } n |  j rÐ|  j } n	 | j } | sãd S|  j j rÉt |  j ƒ d k rÉ|  j | j k rÉ|  j d } | j j | d t ƒd } | j rÉ| j | k rÉ|  j j | k rÉˆ  t j k r‘|  j j | j j } n  ˆ  j r³|  j j | j j } n  | d k	 rÆ| SqÉn  d }	 |  j | j }
 | |
 d t d	 d
 ƒ}
 x… | D]} } d d l m } | |
 | ˆ  ƒ j d t ƒ } t | | ƒ sP| d k } n d } |	 d k rk| }	 qþ|	 | k rþd SqþW|	 S|  j j rTt |  j ƒ d k rT|  j d } | j | d t ƒd } | j rT| j | k rT|  j j | k rTˆ  t j k r|  j j | j j } n  ˆ  j r>|  j j | j j } n  | d k	 rQ| SqTn  |  j | |  j d Œ } |  j | ƒ S(   sÿ   
        Return True if expr belongs to Order(self.expr, \*self.variables).
        Return False if self belongs to expr.
        Return None if the inclusion relation cannot be determined
        (e.g. when self and expr have different symbols).
        iÿÿÿÿ(   t   powsimpi    c         3  s   |  ] } | ˆ  k Vq d  S(   N(    (   R   R   (   R   (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>Y  s    c         3  s   |  ] } | ˆ  k Vq d  S(   N(    (   R   R   (   R   (    s1   lib/python2.7/site-packages/sympy/series/order.pys	   <genexpr>Z  s    i   R   t   deept   combineRA   (   t   Limitt
   heuristicsN(   R4   Rk   R   R    t   TrueR.   R;   R   R   R/   Rf   R8   R$   R(   R3   t   containsR_   R   R5   R>   R!   R:   t   baseRA   t   is_nonpositivet   is_infiniteR^   t   sympy.series.limitsRn   t   doitt
   isinstance(   RY   R8   Rk   R   RM   t   common_symbolst   symbolt   othert   rvRO   t   ratioRn   t   lRX   (    (   R   s1   lib/python2.7/site-packages/sympy/series/order.pyRq   J  s€    	1,91		!	
	!	
c         C  s.   |  j  | ƒ } | d  k r* t d ƒ ‚ n  | S(   Ns#   contains did not evaluate to a bool(   Rq   Rf   R%   (   RY   Rz   t   result(    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   __contains__š  s    c         C  s<  | |  j  k r8|  j j | | ƒ } |  j  j | ƒ } t |  j  ƒ } t |  j ƒ } | j rj | | | <n¸| j } t | ƒ d k s‘ | | k rº| | k r­ |  j  | } n | j	 ƒ  } | j | |  j | ƒ }	 |	 |  j | k r£d d l
 m }
 t ƒ  } |
 | | j | | ƒ | ƒ } t | t ƒ r_| j d } | j d } t | ƒ t | ƒ } n  t t | f | ƒ ƒ g } | j | d ƒ j | |  j | ƒ }	 n  | | | <|	 | | <nh | | k r| | =| | =| r"| |  j | k r"| j | ƒ | j t j g t | ƒ ƒ q"n d  St | t | | ƒ Œ Sd  S(   Ni   iÿÿÿÿ(   t   solveseti    (   R   R8   R2   t   indexR   R   R   R   R!   t   popt   sympy.solvers.solvesetR€   R   Rw   R   R(   R-   R'   R)   t   limitt   extendR   R    R   (   RY   t   oldt   newt   newexprRT   t   newvarst   newptt   symst   varR   R€   t   dt   solt   e1t   e2t   res(    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt
   _eval_subs   s@    			)
#c         C  s6   |  j  j ƒ  } | d  k	 r2 |  j | |  j d Œ Sd  S(   Ni   (   R8   t   _eval_conjugateRf   R_   R(   (   RY   R8   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR“   È  s    c         C  s)   |  j  |  j j | ƒ |  j d Œ p( |  S(   Ni   (   R_   R8   t   diffR(   (   RY   R   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   _eval_derivativeÍ  s    c         C  s6   |  j  j ƒ  } | d  k	 r2 |  j | |  j d Œ Sd  S(   Ni   (   R8   t   _eval_transposeRf   R_   R(   (   RY   R8   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR–   Ð  s    c         C  s   t  d ƒ j ƒ  S(   Ni    (   R   t   _sage_(   RY   (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR—   Õ  s    (   t   __name__t
   __module__t   __doc__Rp   R   t	   __slots__R   RF   R\   t   propertyR8   R   R   R   Ra   Rh   Ri   Rj   Rq   R   R’   R“   R•   R–   R—   (    (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyR      s(   n’					P		(			N(   t
   __future__R    R   t
   sympy.coreR   R   R   R   R   R   R   R	   R
   t   sympy.core.cacheR   t   sympy.core.compatibilityR   R   t   sympy.core.containersR   t   sympy.sets.setsR   t   sympy.utilities.iterablesR   R   R`   (    (    (    s1   lib/python2.7/site-packages/sympy/series/order.pyt   <module>   s   ("ÿ Î