
    Цi+2                         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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)	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       R/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/sympy/series/limits.pylimitr$      s     f r$$%$00    c                 
   SnU[         R                  L aH  [        U R                  USU-  5      U[         R                  S5      n[        U[        5      (       a  g U$ U R                  (       d4  U R                  (       d#  U R                  (       d  U R                  (       GaP  / 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 R.                  " U6 nU[         R*                  L a  U R                  (       a  [1        S U 5       5      (       a  / n
/ n[3        U5       HK  u  p[        U[4        5      (       a  U
R-                  U5        M-  UR-                  U R                  U   5        MM     [7        U5      S:  a-  [%        U6 R9                  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>h   s     /XVWPR
2{0K0KVWs   )ratsimp) r   Infinityr$   subsZeror+   r   is_Mulis_Addis_Powis_Functionsympy.simplify.simplifyr(   argshas	is_finiter   r   r
   r   
heuristicsNaNappendfuncany	enumerater   lensimplifysympy.simplify.ratsimpr0   r   )r   r    r!   r"   rvrr(   almr2e2iirvale3r0   rat_es                    r#   r<   r<   C   sG    
B	QZZ166!QqS>1affc2b%   !b I_ 
QXXQ]]]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   >K5 5
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'   rS   +-z1direction must be one of '+', '-' or '+-', not %s)r   r   r1   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      )r9   free_symbolsdifference_updateupdate)selfr   isymss      r#   rd   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   )r9   baser   r:   r$   r   r   Oner1   rW   ComplexInfinity)
rg   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           	        ^^^^ 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 $ Sn[        T5      S:X  a  SnO[        T5      S:X  a  SnUUUU4S jmUR!                  [,        5      (       a  SSKJn  U" U5      nT" U5      nUR3                  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R5                  TUS9u  pU	S:  a  [        R6                  $ U	S:X  a  U$ US:X  d  [9        U	5      S-  (       d  [        R                  [        U5      -  $ US:X  a  [        R:                  [        U5      -  $ [        R                  $ T[        R                  L a5  UR<                  (       a  [?        U5      nUR                  TST-  5      nU* nOUR                  TTT-   5      n UR5                  TUS9u  p[        U[@        5      (       a  U	[        R6                  :X  a  U$ UR!                  [        R                  [        R:                  [        R                  [        R"                  5      (       a  U $ UR!                  T5      (       d  U	RB                  (       a  [        R6                  $ U	S:X  a  U$ U	RD                  (       ay  US:X  a  [        R                  [        U5      -  $ US:X  aA  [        R:                  [        U5      -  [        RF                  [        RH                  U	-   -  -  $ [        R                  $ [        SU	-  5      e TR^                  (       a  URa                  [b        [d        5      nSn [[        UTTT5      nU[        R"                  L d  U[        R"                  L a
  [K        5       e U$ ! [         a     GNBf = f! [        [        [J        4 a    SSK&J'n
  U
" U5      nURP                  (       a  U RS                  U5      nUb  Us $  URU                  TUS9nX:w  aj  UR!                  [V        5      (       d$  UR!                  [        RX                  5      (       a,  [[        UTS[]        U5      RD                  (       a  SOS5      s $  GNO! [        [        [J        4 a      GNhf = ff = f! [J        [        4 a    Ub  e [g        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.
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                   > 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 $ )Nc              3   4   >#    U  H  nT" U5      v   M     g 7fr*    )r,   r   	set_signss     r#   r.   0Limit.doit.<locals>.set_signs.<locals>.<genexpr>  s     @isIcNNis   r   r   T)r9   tupler?   r+   r   r   r   r$   is_zerois_extended_realr   NegativeOnePirl   r3   )
exprnewargsabs_flagarg_flag	sign_flagsigr"   r{   r    r!   s
         r#   r{   Limit.doit.<locals>.set_signs
  s'   99@dii@@G))#yy'*!$,H!$,H"4.I9DIIaL!R5;;$))A,2s;C''aD(191 F1:F@AF'd*08		! @)2@89@Kr%   )	nsimplify)cdirzNot sure of sign of %s)powsimprz   )4r9   rY   r$   r+   r   is_infiniter   rm   r\   rX   r   absr2   r1   getr   r:   r=   r   is_Orderr   r   r   r8   r   is_meromorphicleadtermr3   intrW   r4   r   r   is_positiveis_negativer   rl   r	   sympy.simplify.powsimpr   r6   rt   as_leading_termr   Exp1r   r   is_extended_positiverewriter   r   r<   )rg   hintsr   rF   rH   r   r   newecoeffexr   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
;;s8s?DX_D	 	, 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66!QqS>D5D66!QV$D"	Mad3IE  %--",yyQ%7%79J9JAEERR99Q<<>>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! ( ]  0 /; 	6
Axx''*=H,,QT,:=eiinn		!&&8I8I!%Abh6J6JsPSTT 3Y? 	^ :& 	}1aS)Ay  	sV   $V0 W />Z1 0
V>=V>A
Z.A<Z
Z.Z*%Z.)Z**Z.1'[[rz   Nr'   )__name__
__module____qualname____firstlineno____doc__r]   propertyrd   rt   r   __static_attributes__rz   r%   r#   r   r      s+    6  %$zr%   r   Nr   )$!sympy.calculus.accumulationboundsr   
sympy.corer   r   r   r   r   r	   r
   sympy.core.exprtoolsr   sympy.core.numbersr   r   (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   rz   r%   r#   <module>r      sI    9 D D D - . > E E = 9 / $ 31l<~D r%   