K i3ddlmZddlmZmZmZmZmZmZm Z ddl m Z ddl m Z mZddlmZddlmZddlmZddlmZmZmZmZdd lmZmZdd lmZdd lm Z m!Z!dd l"m#Z#d dl$m$Z$ddZ%dZ&GddeZ'y)) AccumBounds)SSymbolAddsympifyExpr PoleErrorMul) factor_terms)Float_illegal) AppliedUndef)Dummy) factorial)Abssignargre)explog)gamma)PolynomialErrorfactor)Order)gruntzc>t||||jdS)aQComputes 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)Limitdoit)ezz0dirs Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/series/limits.pylimitr&s$f Ar3  $ $% $ 00cd}|tjurBt|j|d|z |tjd}t |t ry|S|js6|js*|js|jr)t |tsg}ddl m }|jD]}t||||}|jtjr~|j rt |t"r`t%|} t | t&s|| } t | t&s t)|} t | t&rt+| |||cSyyt |t ry|tj,ury|j/||r|j0|}|tj,ur|jrt3d|Drg} g} t5|D]E\} } t | t6r| j/| (| j/|j| Gt9| dkDr/t'| j;}t||||}|t'| z}|tj,ur5 ddlm}||}|tj,us||k(ryt||||S|S#t@$rYywxYw)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)togetherc3<K|]}t|tywN) isinstancer).0rrs r% zheuristics..js/XPR 2{0K/Xs)ratsimp)!rInfinityr&subsZeror-ris_Mulis_Addis_Pow is_Functionrsympy.simplify.simplifyr*argshas is_finiterr r r heuristicsNaNappendfuncany enumeraterlensimplifysympy.simplify.ratsimpr1r)r!r"r#r$rvrr*almr2e2iirvale3r1rat_es r%r=r=EsL B QZZ 166!QqS>1affc 2 b% ` I_ ((ahh!((q}}ZPQS_E` 4 AaB$AuuQZZ Q[[%8a%$QA%a-$QK%a-"1I!!S))!QC88Au%aee % & BQUU{qxxC/XVW/X,X )! .HB!$ 4 $ !&&*- . r7Q;b**,Bb!R-AS"XBQUU{>#AJEAEE>UaZUAr3// I 's=J33 J?>J?c4eZdZdZddZedZdZdZy)raRepresents 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`t|}t|}t|}|tjtjtjzfvrd}n5|tjtjtjzfvrd}|j |rt d|d|dt|tr t|}n't|tstdt|zt|dvrtd|ztj|}||||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)rrr2 ImaginaryUnitNegativeInfinityr;NotImplementedErrorr-strr TypeErrortype ValueErrorr__new___args)clsr!r"r#r$objs r%r]z Limit.__new__s AJ AJ R[ !**aooajj89 9C A&&8J8J(JK KC 66!9%34b':; ; c3 +CC(%'+Cy12 2 s8+ +&(+,- -ll32sO  r'c|jd}|j}|j|jdj|j|jdj|S)Nrr)r: free_symbolsdifference_updateupdate)selfr!isymss r%rczLimit.free_symbolssS IIaL  ! 9 9: TYYq\../ r'c|j\}}}}|j|j}}|j|s$t |t |z||}t|St |||}t |||} | t jur@|t jt jfvrt ||dz z||}t|S| t jur#|t jurt jSyy)Nr) r:baserr;r&rrOner2rWComplexInfinity) rfr!_r"r#b1e1resex_limbase_lims r%pow_heuristicszLimit.pow_heuristicssii 1b!Bvvay3r7 Ar*Cs8Or1b!Q# quu !**a&8&899BQKB/3x q)) )f .B$$ $/C )r'c v |j\} t dk(rt|d}t|d}t|tr1t|tr!|jd|jdk(r|S||k(r|S|j r|j rt jStd|d|t jur tdj r@t}|t|z }|j|z}d t j|jd d r6|jdi|}jdi|jdi||k(rS|j!s|St j"urt j"S|j t$r|S|j&r.t)t|j*g|jd d St j,}t dk(rt j.}nt dk(rt j0} fd |j!t2rddlm}||}|}|j9rӉt jur|jd z }| }n|jz} |j;|\}} | dkDrt j,S| dk(r|S|d k(st=| d zst jt|zS|dk(rt j>t|zSt jSt jur_|j@r tC|}tEdjFjHjJ} |jd | z }| }| } n|jz}} |j;| |\}} t|tLr| t j,k(r|S|j!t jt j>t jt j"r|S|j!| s| jFrt j,S| dk(r|S| jHrw|d k(rt jt|zS|dk(rAt j>t|zt j0t j.| zzzSt jStd| zjbr|jetfth}d } t_| }|t j"us|t j"ur tO |S#t$rYKwxYw#tttNf$rddl(m)} | |}|jTr|jW|}||cYS |jY| |}||k7r[|j!tZs|j!t j\r't_|| dta|jHrdndcYSn#tttNf$rYnwxYwYOwxYw#tNtf$r|tk| }||cYSY|SwxYw)aPEvaluates 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. rUr))r$rSrz1The limit does not exist since left hand limit = z and right hand limit = z.Limits at complex infinity are not implementedrTrNc|js|Stfd|jD}||jk7r|j|}t|t}t|t }t|t }|s|s|r t|jd }|jrtd|jdz  }|jrw|dkdk(r4|r|jd S|rtjStjS|dkDdk(r3|r|jdS|rtjStjS|S|S#t$r|cYSwxYw)Nc3.K|] }|ywr,)r.r set_signss r%r0z0Limit.doit..set_signs..s@sIcN@srrT)r:tupler@r-rrrr&is_zerois_extended_realr NegativeOnePirjr4rX) exprnewargsabs_flagarg_flag sign_flagsigr$rwr"r#s r%rwzLimit.doit..set_signs sM99 @dii@@G$))# tyy'*!$,H!$,H"4.I9 D ! aS9C{{#AdiilNAr3?++!G,5=TYYq\MJ5>AMMJDEDDJ!Ag$.4r is_Orderrr}r4rjr{r r9ris_meromorphicleadtermintrWr5r r is_positive is_negativeis_realrr sympy.simplify.powsimprr7rras_leading_termrExp1rris_extended_nonnegativerewriterrr=)rfhintsr!rGrIrrnewecoeffexdummynewzrr$rwr"r#s @@@@r%r z Limit.doits 1b# s8t aBC(AaBC(A!U# 1e(<66!9q )KAv}}((( !1&' ' "" "%'CD D >>8DD >Dq$q&!ACB 99VT "AA!5!B 6IuuQxH ;55L 155( K ::qvvq"-;qr ; ;vv s8s?55D X_==D 4 55< :! A aL  Ar "QZZvva1~uvvaR( - MM!$M7 r666M1W L19CGaK::d5k11RZ--d5k99,,,  xx O#  TUT]T]^E66!QuW%D5DD66!QV$DD" M d 6IE2 %-", yyQ%7%79J9JAEER 99T?>>66M1W L^^qy zz$u+55 11$u+=ammaeeVXj>YYY 000-.F.KLL  % % )U+A  q!R%AAEEzQ!%%Zk!(c  6/;  6 Axx''*=H ,,T,=D=eiin !&&8I!%qD9M9M#SVWW 3Y?   ^:& }1aS)Ay  sbV#-V3$rsO9DDD-.,#>EE=9/$31l<~FDFr'