
    \h3                         S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
Jr  S SKJrJr  S SKJr  S SKJr  S SKJr  S SKJrJrJrJr  S S	KJrJr  S S
KJr  S SKJ r J!r!  S SK"J#r#  SSK$J$r$  SS jr%S r& " S S\5      r'g)    )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   )gruntzc                 4    [        XX#5      R                  SS9$ )a  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       K/var/www/auris/envauris/lib/python3.13/site-packages/sympy/series/limits.pylimitr&      s     f r$$%$00    c                 6   SnU[         R                  L aH  [        U R                  USU-  5      U[         R                  S5      n[        U[        5      (       a  g U$ U R                  (       dJ  U R                  (       d9  U R                  (       d(  U R                  (       Gaf  [        U [        5      (       GdP  / nSSKJn  U R                   GH  n[        XqX#5      nUR                  [         R                  5      (       a  UR                   c  [        U ["        5      (       am  [%        U 5      n	[        U	[&        5      (       d  U" U	5      n	[        U	[&        5      (       d  [)        U 5      n	[        U	[&        5      (       a  [+        XX#5      s  $   g  g[        U[        5      (       a    gU[         R,                  L a    gUR/                  U5        GM     U(       Ga-  U R0                  " U6 nU[         R,                  L a  U R                  (       a  [3        S U 5       5      (       a  / n
/ n[5        U5       HK  u  p[        U[6        5      (       a  U
R/                  U5        M-  UR/                  U R                  U   5        MM     [9        U5      S:  a-  ['        U6 R;                  5       n[        XX#5      nU['        U
6 -  nU[         R,                  L a6   SSKJn  U" U 5      nU[         R,                  L d  UU :X  a  g[        UXU5      $ U$ ! [@         a     gf = f)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   )togetherc              3   B   #    U  H  n[        U[        5      v   M     g 7fN)
isinstancer   ).0rrs     r%   	<genexpr>heuristics.<locals>.<genexpr>j   s     /XVWPR
2{0K0KVWs   )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.ratsimpr2   r   )r!   r"   r#   r$   rvrr*   almr2e2iirvale3r2   rat_es                    r%   r>   r>   E   sU    
B	QZZ166!QqS>1affc2b%   !b I_ ((ahh!((q}}}ZPQS_E`E`4AaB$AuuQZZ  Q[[%8a%%$QA%a--$QK%a--"1I!!S)))!88Au%%aee% & BQUU{qxxC/XVW/X,X,X )!HB!$44		$		!&&*-	 !- r7Q;b**,BbR-AS"XBQUU{>#AJE AEE>UaZUA3//I ' s   L 
LLc                   >    \ rS rSrSrS	S jr\S 5       rS rS r	Sr
g)
r      zRepresents 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='-')

c                    [        U5      n[        U5      n[        U5      nU[        R                  [        R                  [        R                  -  4;   a  SnO7U[        R                  [        R                  [        R                  -  4;   a  SnUR                  U5      (       a  [        SU< SU< S35      e[        U[        5      (       a  [        U5      nO,[        U[        5      (       d  [        S[        U5      -  5      e[        U5      S;  a  [        SU-  5      e[        R                  " U 5      nXX44Ul        U$ )	N-r)   z7Limits approaching a variable point are not supported (z -> )z6direction must be of type basestring or Symbol, not %s)r)   rU   +-z1direction must be one of '+', '-' or '+-', not %s)r   r   r3   ImaginaryUnitNegativeInfinityr<   NotImplementedErrorr-   strr   	TypeErrortype
ValueErrorr   __new___args)clsr!   r"   r#   r$   objs         r%   r_   Limit.__new__   s   AJAJR[!**aooajj899CA&&8J8J(JKKC66!99%34b': ; ;c3+CC(( %'+Cy1 2 2s8++ &(+, - - ll32O	
r'   c                     U R                   S   nUR                  nUR                  U R                   S   R                  5        UR                  U R                   S   R                  5        U$ )Nr   r      )r;   free_symbolsdifference_updateupdate)selfr!   isymss      r%   rf   Limit.free_symbols   sS    IIaL		! 9 9:TYYq\../r'   c                    U R                   u  p#pBUR                  UR                  peUR                  U5      (       d#  [	        U[        U5      -  X45      n[        U5      $ [	        XcU5      n[	        XSU5      n	U	[        R                  L a@  U[        R                  [        R                  4;   a  [	        XeS-
  -  X45      n[        U5      $ U	[        R                  L a$  U[        R                  L a  [        R                  $ g g )Nr   )r;   baser   r<   r&   r   r   Oner3   rY   ComplexInfinity)
ri   r!   _r"   r#   b1e1resex_limbase_lims
             r%   pow_heuristicsLimit.pow_heuristics   s    iibBvvayy3r7
A*Cs8Orb!#quu!**a&8&899BQK/3xq)))f

.B$$$ /C)r'   c           	      l  ^^^^ U R                   u  nmmm[        T5      S:X  a  [        UTTSS9n[        UTTSS9n[        U[        5      (       a7  [        U[        5      (       a"  UR                   S   UR                   S   :X  a  U $ X4:X  a  U$ UR
                  (       a!  UR
                  (       a  [        R                  $ [        SU< SU< 35      eT[        R                  L a  [        S5      eTR
                  (       a@  [        T5      nU[        U5      -  nUR                  TUT-  5      nSm[        R                  mUR                  S	S
5      (       a6  UR                  " S0 UD6nTR                  " S0 UD6mTR                  " S0 UD6mUT:X  a  T$ UR!                  T5      (       d  U$ T[        R"                  L a  [        R"                  $ UR                   " [$        6 (       a  U $ UR&                  (       a.  [)        [        UR*                  TT5      /UR                   SS Q76 $ [        R,                  n[        T5      S:X  a  [        R.                  nO[        T5      S:X  a  [        R0                  nUUUU4S jmUR!                  [2        5      (       a  SSKJn  U" U5      nT" U5      nUR9                  TT5      (       a  T[        R                  L a  UR                  TST-  5      nU* nOUR                  TTT-   5      n UR;                  TUS9u  pU	S:  a  [        R,                  $ U	S:X  a  U$ US:X  d  [=        U	5      S-  (       d  [        R                  [        U5      -  $ US:X  a  [        R>                  [        U5      -  $ [        R                  $ T[        R                  L aa  UR@                  (       a  [C        U5      n[E        STRF                  TRH                  TRJ                  S9n
UR                  TSU
-  5      nU* nU
nOUR                  TTT-   5      nTn UR;                  XS9u  p[        U[L        5      (       a  U	[        R,                  :X  a  U$ UR!                  [        R                  [        R>                  [        R                  [        R"                  5      (       a  U $ UR!                  U5      (       d  U	RF                  (       a  [        R,                  $ U	S:X  a  U$ U	RH                  (       ay  US:X  a  [        R                  [        U5      -  $ US:X  aA  [        R>                  [        U5      -  [        R0                  [        R.                  U	-   -  -  $ [        R                  $ [        SU	-  5      e TRb                  (       a  URe                  [f        [h        5      nSn [_        UTTT5      nU[        R"                  L d  U[        R"                  L a
  [O        5       e U$ ! [         a     GNof = f! [        [        [N        4 a    SSK(J)n  U" U5      nURT                  (       a  U RW                  U5      nUb  Us $  URY                  XS9nX:w  ai  UR!                  [Z        5      (       d$  UR!                  [        R\                  5      (       a+  [_        XS[a        U5      RH                  (       a  SOS5      s $  GNM! [        [        [N        4 a      GNff = ff = f! [N        [        4 a    Ub  e [k        UTTT5      nUc  U s $  U$ f = f)a  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.
rW   r)   )r$   rU   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                 ,  > U R                   (       d  U $ [        U4S jU R                    5       5      nXR                   :w  a  U R                  " U6 n [        U [        5      n[        U [
        5      n[        U [        5      nU(       d  U(       d  U(       a   [        U R                   S   TT	T5      nUR                  (       a  [        SU R                   S   -  TT	T5      nUR                  (       a  US:  S:X  a>  U(       a  U R                   S   * $ U(       a  [        R                  $ [        R                  $ US:  S:X  a=  U(       a  U R                   S   $ U(       a  [        R                  $ [        R                  $ U $ U $ ! [         a    U s $ f = f)Nc              3   4   >#    U  H  nT" U5      v   M     g 7fr,    )r.   r   	set_signss     r%   r0   0Limit.doit.<locals>.set_signs.<locals>.<genexpr>  s     @isIcNNis   r   r   T)r;   tuplerA   r-   r   r   r   r&   is_zerois_extended_realr   NegativeOnePirn   r5   rZ   )
exprnewargsabs_flagarg_flag	sign_flagsigr$   r|   r"   r#   s
         r%   r|   Limit.doit.<locals>.set_signs  sI   99@dii@@G))#yy'*!$,H!$,H"4.I9D		!aS9C{{#AdiilNAr3? ++!G,5=TYYq\M J5>AMMJDEDDJ!Ag$.4<DIIaL D-6AEED<=FFDK4K +  K s   A
F FF)	nsimplify)cdirr"   )positivenegativerealzNot sure of sign of %s)powsimpr{   )6r;   r[   r&   r-   r   is_infiniter   ro   r^   rZ   r   absr4   r3   getr    r<   r?   r   is_Orderr   r   r5   rn   r   r   r:   r   is_meromorphicleadtermintrY   r6   r   r   is_positiveis_negativeis_realr   r	   sympy.simplify.powsimpr   r8   rv   as_leading_termr   Exp1r   r   is_extended_nonnegativerewriter   r   r>   )ri   hintsr!   rH   rJ   r   r   newecoeffexdummynewzr   r$   r|   r"   r#   s                @@@@r%   r    
Limit.doit   s    		1b#s8taBC(AaBC(A!U##
1e(<(<66!9q	)Kv}}((( !1& ' ' """% 'C D D >>8DD	>Dq$q&!ACB99VT""AA!5!B6IuuQxxH;55L55(K::qvvq"-;qr
;;vvs8s?55DX_==D	 	4 55<<
 :!AaL Ar""QZZvva1~uvvaR(- MM!$M7	 666M1W L19CGaK::d5k11RZ--d5k99,,,xx O#TUT]T]^E66!QuW%D5DD66!QV$DD"	Md6IE  %--",yyQ%7%79J9JAEERR99T??>>66M1W L^^qy zz$u+55 11$u+=ammaeeVXj>YYY 000-.F.KLL #& %%		)U+A		q!R%AAEEzQ!%%Zk! ( c  6 /; 	6
Axx''*=H,,T,==eiinn		!&&8I8I!%qD9M9M#SVWW 3Y? 	^ :& 	}1aS)Ay  	sV   X 1X >\ 
XXA
\%A:[%\%[?:\>[??\'\32\3r{   Nr)   )__name__
__module____qualname____firstlineno____doc__r_   propertyrf   rv   r    __static_attributes__r{   r'   r%   r   r      s+    6  %$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   r{   r'   r%   <module>r      sO    9 D D D - . , # > E E = 9 / $ 31l<~FD Fr'   