ó
¡¼™\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 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 d  d l m Z d  d l  m! Z! d d l" m" Z" d d „ Z# d „  Z$ d e f d „  ƒ  YZ% d S(   iÿÿÿÿ(   t   print_functiont   division(   t   St   Symbolt   Addt   sympifyt   Exprt	   PoleErrort   Mul(   t   string_types(   t   factor_terms(   t   GoldenRatio(   t   Dummy(   t	   factorial(   t	   fibonacci(   t   gamma(   t   PolynomialErrort   factor(   t   Order(   t   ratsimp(   t   togetheri   (   t   gruntzt   +c         C  s    | d k r} t  |  | | d d ƒj d t ƒ } t  |  | | d d ƒj d t ƒ } | | k rd | St d | | f ƒ ‚ n t  |  | | | ƒ j d t ƒ Sd S(   sä  Computes the limit of ``e(z)`` at the point ``z0``.

    Parameters
    ==========

    e : expression, the limit of which is to be taken

    z : symbol representing the variable in the limit.
        Other symbols are treated as constants. Multivariate limits
        are not supported.

    z0 : the value toward which ``z`` tends. Can be any expression,
        including ``oo`` and ``-oo``.

    dir : string, optional (default: "+")
        The limit is bi-directional if ``dir="+-"``, from the right
        (z->z0+) if ``dir="+"``, and from the left (z->z0-) if
        ``dir="-"``. For infinite ``z0`` (``oo`` or ``-oo``), the ``dir``
        argument is determined from the direction of the infinity
        (i.e., ``dir="-"`` for ``oo``).

    Examples
    ========

    >>> from sympy import limit, sin, Symbol, oo
    >>> from sympy.abc import x
    >>> limit(sin(x)/x, x, 0)
    1
    >>> limit(1/x, x, 0) # default dir='+'
    oo
    >>> limit(1/x, x, 0, dir="-")
    -oo
    >>> limit(1/x, x, 0, dir='+-')
    Traceback (most recent call last):
        ...
    ValueError: The limit does not exist since left hand limit = -oo and right hand limit = oo

    >>> limit(1/x, x, oo)
    0

    Notes
    =====

    First we try some heuristics for easy and frequent cases like "x", "1/x",
    "x**2" and similar, so that it's fast. For all other cases, we use the
    Gruntz algorithm (see the gruntz() function).

    See Also
    ========

     limit_seq : returns the limit of a sequence.
    s   +-t   dirt   -t   deepR   sM   The limit does not exist since left hand limit = %s and right hand limit = %sN(   t   Limitt   doitt   Falset
   ValueError(   t   et   zt   z0R   t   llimt   rlim(    (    s2   lib/python2.7/site-packages/sympy/series/limits.pyt   limit   s    6$$c           s  d d l  m ‰  d } t | ƒ t j k r~ t |  j | d | ƒ | t j | t j k r_ d n d ƒ } t	 | t
 ƒ rd Sn|  j s¢ |  j s¢ |  j s¢ |  j rg  } xû |  j D]ð } t | | | | ƒ } | j t j ƒ ro| j d k rot	 |  t ƒ rkt |  ƒ } t	 | t ƒ s't | ƒ } n  t	 | t ƒ sEt |  ƒ } n  t	 | t ƒ rgt | | | | ƒ Sd Sd St	 | t
 ƒ r‚d S| t j k r•d S| j | ƒ q² W| r|  j | Œ  } | t j k r¢|  j r¢t ‡  f d †  | Dƒ ƒ r¢g  }	 g  }
 xU t t | ƒ ƒ D]A } t	 | | ˆ  ƒ r;|	 j | | ƒ q|
 j |  j | ƒ qWt |
 ƒ d k r¢t |
 Œ  j ƒ  } t | | | | ƒ } | t |	 Œ  } q¢n  | t j k ry t |  ƒ } Wn t  k
 rÕd SX| t j k sñ| |  k rõd St | | | | ƒ Sqn  | S(	   s+  Computes the limit of an expression term-wise.
    Parameters are the same as for the ``limit`` function.
    Works with the arguments of expression ``e`` one by one, computing
    the limit of each and then combining the results. This approach
    works only for simple limits, but it is fast.
    iÿÿÿÿ(   t   AccumBoundsi   R   R   Nc         3  s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   t
   isinstance(   t   .0t   rr(   R$   (    s2   lib/python2.7/site-packages/sympy/series/limits.pys	   <genexpr>z   s    i    (!   t   sympy.calculus.utilR$   t   Nonet   absR   t   InfinityR#   t   subst   ZeroR%   R   t   is_Mult   is_Addt   is_Powt   is_Functiont   argst   hast	   is_finiteR   R
   R   R   R   t
   heuristicst   NaNt   appendt   funct   anyt   ranget   lent   simplifyR   R   (   R   R   R    R   t   rvt   rt   at   lt   mt   r2t   e2t   iit   e3t   rat_e(    (   R$   s2   lib/python2.7/site-packages/sympy/series/limits.pyR5   U   s`    =$!4R   c           B  s2   e  Z d  Z d d „ Z e d „  ƒ Z d „  Z RS(   s  Represents an unevaluated limit.

    Examples
    ========

    >>> from sympy import Limit, sin, Symbol
    >>> from sympy.abc import x
    >>> Limit(sin(x)/x, x, 0)
    Limit(sin(x)/x, x, 0)
    >>> Limit(1/x, x, 0, dir="-")
    Limit(1/x, x, 0, dir='-')

    R   c         C  sç   t  | ƒ } t  | ƒ } t  | ƒ } | t j k r< d } n | t j k rT d } n  t | t ƒ rr t | ƒ } n( t | t ƒ sš t d t | ƒ ƒ ‚ n  t	 | ƒ d k r¿ t
 d | ƒ ‚ n  t j |  ƒ } | | | | f | _ | S(   NR   R   s6   direction must be of type basestring or Symbol, not %ss   +-s1   direction must be one of '+', '-' or '+-', not %s(   R   R   s   +-(   R   R   R+   t   NegativeInfinityR%   R	   R   t	   TypeErrort   typet   strR   R   t   __new__t   _args(   t   clsR   R   R    R   t   obj(    (    s2   lib/python2.7/site-packages/sympy/series/limits.pyRK   ¢   s$    		c         C  sH   |  j  d } | j } | j |  j  d j ƒ | j |  j  d j ƒ | S(   Ni    i   i   (   R2   t   free_symbolst   difference_updatet   update(   t   selfR   t   isyms(    (    s2   lib/python2.7/site-packages/sympy/series/limits.pyRO   º   s
    	c   
        s’  d d l  m } d d l m } |  j \ } ‰ } } | t j k rS t d ƒ ‚ n  | j d t	 ƒ r• | j
 |   } ˆ j
 |   ‰ | j
 |   } n  | ˆ k r¥ | S| j ˆ ƒ s¸ | S| j rÜ | j t | g t ƒ } n  | j rït | ƒ t j k rït | ƒ } | j t t ƒ } ‡ f d †  ‰  t ‡  f d †  | j ƒ  Dƒ ƒ rìt d t	 ƒ } | t j k r€| j ˆ d | ƒ } n | j ˆ d	 | ƒ } y< t | j | ƒ | t j d
 ƒ }	 t |	 t ƒ rÍ|  S|	 SWqét  k
 råqéXqìqïn  | j! rt" t | j# ˆ | ƒ | j d	 Œ Sy4 t$ | ˆ | | ƒ }	 |	 t j% k rNt& ƒ  ‚ n  Wn< t& t  f k
 rt' | ˆ | | ƒ }	 |	 d k rŽ|  Sn X|	 S(   sP  Evaluates the limit.

        Parameters
        ==========

        deep : bool, optional (default: True)
            Invoke the ``doit`` method of the expressions involved before
            taking the limit.

        hints : optional keyword arguments
            To be passed to ``doit`` methods; only used if deep is True.
        iÿÿÿÿ(   t	   limit_seq(   t   RisingFactorials.   Limits at complex infinity are not implementedR   c           s2   ˆ  |  j  k o1 t ‡  f d †  t j |  ƒ Dƒ ƒ S(   Nc         3  sC   |  ]9 } | j  ˆ  ƒ p: t ‡  f d  †  t j | ƒ Dƒ ƒ Vq d S(   c         3  s-   |  ]# } ˆ  | j  k o$ | j ˆ  ƒ Vq d  S(   N(   RO   t   is_polynomial(   R&   RA   (   R   (    s2   lib/python2.7/site-packages/sympy/series/limits.pys	   <genexpr>ñ   s   N(   RV   R9   R   t	   make_args(   R&   R?   (   R   (    s2   lib/python2.7/site-packages/sympy/series/limits.pys	   <genexpr>ð   s   (   RO   R9   R   RW   (   t   w(   R   (    s2   lib/python2.7/site-packages/sympy/series/limits.pyt   <lambda>ï   s   c         3  s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   R&   RX   (   t   ok(    s2   lib/python2.7/site-packages/sympy/series/limits.pys	   <genexpr>ô   s    t   positivei   R   N()   t   sympy.series.limitseqRT   t   sympy.functionsRU   R2   R   t   ComplexInfinityt   NotImplementedErrort   gett   TrueR   R3   t   is_positivet   rewriteR   R   R.   R*   R+   R
   R   R   t   allt   as_numer_denomR   RG   R,   R#   t   as_leading_termR-   R%   R   R   t   is_OrderR   t   exprR   R6   R   R5   R)   (
   RR   t   hintsRT   RU   R   R    R   t   ut   inveR>   (    (   RZ   R   s2   lib/python2.7/site-packages/sympy/series/limits.pyR   Ã   sV    		"!	#(   t   __name__t
   __module__t   __doc__RK   t   propertyRO   R   (    (    (    s2   lib/python2.7/site-packages/sympy/series/limits.pyR   “   s   	N(&   t
   __future__R    R   t
   sympy.coreR   R   R   R   R   R   R   t   sympy.core.compatibilityR	   t   sympy.core.exprtoolsR
   t   sympy.core.numbersR   t   sympy.core.symbolR   t(   sympy.functions.combinatorial.factorialsR   t%   sympy.functions.combinatorial.numbersR   t'   sympy.functions.special.gamma_functionsR   t   sympy.polysR   R   t   sympy.series.orderR   t   sympy.simplify.ratsimpR   t   sympy.simplify.simplifyR   R   R#   R5   R   (    (    (    s2   lib/python2.7/site-packages/sympy/series/limits.pyt   <module>   s    4D	>