
    Xh3                         d dl 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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mZ d d	l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Z%d Z& G d de          Z'dS )    )AccumBounds)SSymbolAddsympifyExpr	PoleErrorMul)factor_terms)Float_illegal)AppliedUndef)Dummy)	factorial)Abssignargre)explog)gamma)PolynomialErrorfactor)Order   )gruntz+c                 N    t          | |||                              d          S )aQ  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, 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='+-')
    zoo
    >>> 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.
    F)deep)Limitdoit)ezz0dirs       e/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/sympy/series/limits.pylimitr'      s*    f Ar3$$%$000    c                    d}|t           j        u rLt          |                     |d|z            |t           j        d          }t          |t                    rdS n| j        s,| j        s%| j	        s| j
        r|t          | t                    sfg }ddlm} | j        D ]}t          ||||          }|                    t           j                  r|j        t          | t"                    rt%          |           }	t          |	t&                    s ||	          }	t          |	t&                    st)          |           }	t          |	t&                    rt+          |	|||          c S  dS  dS t          |t                    r dS |t           j        u r dS |                    |           |rB | j        | }|t           j        u r| j        rt3          d |D                       rg }
g }t5          |          D ]P\  }}t          |t6                    r|
                    |           0|                    | j        |                    Qt9          |          dk    r9t'          |                                 }t          ||||          }|t'          |
 z  }|t           j        u rL	 ddlm}  ||           }n# t@          $ r Y dS w xY w|t           j        u s|| k    rdS t          ||||          S |S )a+  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.
    Nr   r   r   )togetherc              3   @   K   | ]}t          |t                    V  d S N)
isinstancer   ).0rrs     r&   	<genexpr>zheuristics.<locals>.<genexpr>j   s-      /X/XPR
2{0K0K/X/X/X/X/X/Xr(   )ratsimp)!r   Infinityr'   subsZeror-   r    is_Mulis_Addis_Powis_Functionr   sympy.simplify.simplifyr*   argshas	is_finiter   r   r
   r   
heuristicsNaNappendfuncany	enumerater   lensimplifysympy.simplify.ratsimpr1   r   )r"   r#   r$   r%   rvrr*   almr2e2iirvale3r1   rat_es                    r&   r=   r=   E   s!    
B	QZ166!QqS>>1afc22b%   	F	
( .0ah .0!( .0q} .0ZPQS_E`E` .0444444 	 	AaB$$AuuQZ   Q[%8a%% $QA%a-- ($HQKK%a-- &"1II!!S)) 9)!QC88888FFAu%% ae 	0BQU{{qx{C/X/XVW/X/X/X,X,X{ )! . .HB!$44 .		$		!&*----r77Q;;b**,,Bb!R--AS"XBQU{{>>>>>>#GAJJEE&   FFAE>>UaZZFUAr3///Is   +J= =
K
Kc                   <    e Zd ZdZddZed             Zd Zd ZdS )	r    a  Represents an unevaluated limit.

    Examples
    ========

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

    r   c                    t          |          }t          |          }t          |          }|t          j        t          j        t          j        z  fv rd}n)|t          j        t          j        t          j        z  fv rd}|                    |          rt          d|d|d          t          |t                    rt          |          }n4t          |t                    st          dt          |          z            t          |          dvrt          d|z            t          j        |           }||||f|_        |S )	N-r   z7Limits approaching a variable point are not supported (z -> )z6direction must be of type basestring or Symbol, not %s)r   rS   +-z1direction must be one of '+', '-' or '+-', not %s)r   r   r2   ImaginaryUnitNegativeInfinityr;   NotImplementedErrorr-   strr   	TypeErrortype
ValueErrorr   __new___args)clsr"   r#   r$   r%   objs         r&   r]   zLimit.__new__   sL   AJJAJJR[[!*aoaj8999CCA&8J(JKKKC66!99 	;%%3411bbb': ; ; ;c3 	2++CCC(( 	2 %'+Cyy1 2 2 2s88+++ &(+, - - - l32sO	
r(   c                     | j         d         }|j        }|                    | j         d         j                   |                    | j         d         j                   |S )Nr   r      )r:   free_symbolsdifference_updateupdate)selfr"   isymss      r&   rc   zLimit.free_symbols   sQ    IaL	! 9:::TYq\.///r(   c                    | j         \  }}}}|j        |j        }}|                    |          s0t	          |t          |          z  ||          }t          |          S t	          |||          }t	          |||          }	|	t          j        u r@|t          j        t          j	        fv r&t	          ||dz
  z  ||          }t          |          S |	t          j	        u r|t          j        u rt          j
        S d S d S )Nr   )r:   baser   r;   r'   r   r   Oner2   rW   ComplexInfinity)
rf   r"   _r#   r$   b1e1resex_limbase_lims
             r&   pow_heuristicszLimit.pow_heuristics   s    i1b!Bvvayy 	3r77
Ar**Cs88Or1b!!Q##qu!*a&8999BQKB//3xxq)))f
.B.B$$ *).B.Br(   c           	         | j         \  }t                    dk    rt          |d          }t          |d          }t          |t                    r3t          |t                    r|j         d         |j         d         k    r| S ||k    r|S |j        r|j        rt          j        S t          d|d|          t          j        u rt          d          j        rHt                    }|t          |          z  }|                    |z            }dt          j        |                    d	d
          r' |j        di |} j        di | j        di ||k    rS |                              s|S t          j        u rt          j        S  |j        t$           r| S |j        r.t)          t          |j                  g|j         dd         R  S t          j        }t                    dk    rt          j        }nt                    dk    rt          j        }fd|                    t2                    rddlm}  ||          } |          }|                              rt          j        u r|                    dz            }| }n|                    z             }	 |                    |          \  }}	|	dk    rt          j        S |	dk    r|S |dk    st=          |	          dz  st          j        t          |          z  S |dk    rt          j        t          |          z  S t          j        S # t          $ r Y nw xY wt          j        u rW|j         rtC          |          }tE          dj#        j$        j%                  }
|                    d|
z            }| }|
}n|                    z             }}	 |                    ||          \  }}	t          |tL                    r|	t          j        k    r|S |                    t          j        t          j        t          j        t          j                  r| S |                    |          s|	j#        rt          j        S |	dk    r|S |	j$        rm|dk    rt          j        t          |          z  S |dk    r9t          j        t          |          z  t          j        t          j        |	z   z  z  S t          j        S t          d|	z            n# t          t          tN          f$ r ddl(m)}  ||          }|j*        r| +                    |          }||cY S 	 |,                    ||          }||k    rc|                    tZ                    s|                    t          j.                  r*t_          ||dta          |          j$        rdnd          cY S n# t          t          tN          f$ r Y nw xY wY nw xY wj1        r |2                    tf          th                    }d}	 t_          |          }|t          j        u s|t          j        u rtO                      n2# tN          t          f$ r | tk          |          }|| cY S Y nw xY w|S )aP  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.
        rU   r   )r%   rS   r   z1The limit does not exist since left hand limit = z and right hand limit = z.Limits at complex infinity are not implementedr   Tr   Nc                    | j         s| S t          fd| j         D                       }|| j         k    r
 | j        | } t          | t                    }t          | t
                    }t          | t                    }|s|s|r	 t          | j         d         	          }|j        r t          d| j         d         z  	          }|j	        rg|dk     dk    r*|r| j         d          n|rt          j        nt          j        S |dk    dk    r)|r| j         d         n|rt          j        nt          j        S n# t          $ r | cY S w xY w| S )Nc              3   .   K   | ]} |          V  d S r,    )r.   r   	set_signss     r&   r0   z0Limit.doit.<locals>.set_signs.<locals>.<genexpr>  s+      @@sIIcNN@@@@@@r(   r   r   T)r:   tupler@   r-   r   r   r   r'   is_zerois_extended_realr   NegativeOnePirj   r4   rX   )
exprnewargsabs_flagarg_flag	sign_flagsigr%   rw   r#   r$   s
         r&   rw   zLimit.doit.<locals>.set_signs  s   9 @@@@di@@@@@G$)## ty'*!$,,H!$,,H"4..I D9 D DD	!aS99C{ @#AdilNAr3?? + D!G,,5= %ITYq\MM5>$HAMMADJ!Ag$..4< %CDIaLL-6$BAEEAFD +      KKK  Ks   AD9 9EE)	nsimplify)cdirr#   )positivenegativerealzNot sure of sign of %s)powsimprv   )6r:   rY   r'   r-   r    is_infiniter   rk   r\   rX   r   absr3   r2   getr!   r;   r>   r   is_Orderr   r}   r4   rj   r{   r   r9   r   is_meromorphicleadtermintrW   r5   r   r   is_positiveis_negativeis_realr   r	   sympy.simplify.powsimpr   r7   rr   as_leading_termr   Exp1r   r   is_extended_nonnegativerewriter   r   r=   )rf   hintsr"   rG   rI   r   r   newecoeffexdummynewzr   r%   rw   r#   r$   s                @@@@r&   r!   z
Limit.doit   s9    	1b#s88taBC(((AaBC(((A!U##  
1e(<(<  6!9q	))KAvv} ) )((* !11& ' ' ' """% 'C D D D > 	88DD		>Dq$q&!!ACB99VT"" 	"AA!!5!!B66IuuQxx 	H;;5L15( 	K: 	<qvq"--;qrr
;;;;vs88s??5DDXX__=D	 	 	 	 	 	 	 	4 55<< 	
 :99999	!AIaLL Ar"" 	-QZvva1~~uvvaR((- MM!$M77	r 666M1WW L199CGGaK9:d5kk11RZZ-d5kk99,,     x $ OO#TUT]^^^E66!QuW%%D5DDD66!QV$$DD"	Md66IE2  %-- ",,yyQ%79JAERR 99T?? M> M6M1WW L^ Mqyy z$u++55 1$u++=amaeVXj>YYY 00-.F.KLLLM' /; 	 	 	666666

Ax ''**=HHH,,T,==D==eiinn=		!&8I8I=!%qD9M2V##SVWWWWW 3Y?   	L % 	,		)U++A		q!R%%AAEzzQ!%ZZkk! (:& 	 	 	}1aS))Ay y		 sb   M+ +
M87M8<T6 6AX"A=X>X"X"XX"XX"!X"<Z *Z;:Z;Nr   )	__name__
__module____qualname____doc__r]   propertyrc   rr   r!   rv   r(   r&   r    r       sp            6   X% % %$A A A A Ar(   r    Nr   )(!sympy.calculus.accumulationboundsr   
sympy.corer   r   r   r   r   r	   r
   sympy.core.exprtoolsr   sympy.core.numbersr   r   sympy.core.functionr   sympy.core.symbolr   (sympy.functions.combinatorial.factorialsr   $sympy.functions.elementary.complexesr   r   r   r   &sympy.functions.elementary.exponentialr   r   'sympy.functions.special.gamma_functionsr   sympy.polysr   r   sympy.series.orderr   r   r'   r=   r    rv   r(   r&   <module>r      s   9 9 9 9 9 9 D D D D D D D D D D D D D D D D D D - - - - - - . . . . . . . . , , , , , , # # # # # # > > > > > > E E E E E E E E E E E E = = = = = = = = 9 9 9 9 9 9 / / / / / / / / $ $ $ $ $ $      31 31 31 31l< < <~F F F F FD F F F F Fr(   