K iT<dZddlmZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZmZddlmZddlmZddlmZddlmZddlmZmZmZmZdd lmZmZdd l m!Z!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'm(Z(m)Z)dd l*m+Z+dd l,m-Z-m.Z.ddl/m0Z0m1Z1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8ddl9m:Z:m;Z;ddlm?Z?dgZ@GddZAeAaBeAaCdZDdZEe1d"dZFe1GddeZGe1GddeGZHeHZIe=eHeHdZJe=eHedZJe1Gd d!eZKy)#z2Implementation of RootOf class and related tools. )Basic) SExprIntegerFloatIooAddLambdasymbolssympifyRationalDummy)cacheit)is_le)ordered)QQ)MultivariatePolynomialErrorGeneratorsNeededPolynomialError DomainError) symmetrizeviete) roots_linearroots_quadraticroots_binomialpreprocess_rootsroots)PolyPurePolyfactor)together)dup_isolate_complex_roots_sqfdup_isolate_real_roots_sqf)lambdifypublicsiftnumbered_symbols)mpfmpcfindrootworkprec) dps_to_prec prec_to_dps)dispatch)chainCRootOfc(eZdZdZdZdZdZdZy)_pure_key_dicta A minimal dictionary that makes sure that the key is a univariate PurePoly instance. Examples ======== Only the following actions are guaranteed: >>> from sympy.polys.rootoftools import _pure_key_dict >>> from sympy import PurePoly >>> from sympy.abc import x, y 1) creation >>> P = _pure_key_dict() 2) assignment for a PurePoly or univariate polynomial >>> P[x] = 1 >>> P[PurePoly(x - y, x)] = 2 3) retrieval based on PurePoly key comparison (use this instead of the get method) >>> P[y] 1 4) KeyError when trying to retrieve a nonexisting key >>> P[y + 1] Traceback (most recent call last): ... KeyError: PurePoly(y + 1, y, domain='ZZ') 5) ability to query with ``in`` >>> x + 1 in P False NOTE: this is a *not* a dictionary. It is a very basic object for internal use that makes sure to always address its cache via PurePoly instances. It does not, for example, implement ``get`` or ``setdefault``. ci|_yN)_dictselfs ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/rootoftools.py__init__z_pure_key_dict.__init__Ss  ct|ts;t|trt|jdk(st t|d}|j |S)NFexpand) isinstancer rlen free_symbolsKeyErrorr6r8ks r9 __getitem__z_pure_key_dict.__getitem__VsE!X&q$'C,?1,D5)Azz!}r;ct|ts@t|trt|jdk(s t dt|d}||j |<y)Nr=zexpecting univariate expressionFr>)r@r rrArB ValueErrorr6)r8rEvs r9 __setitem__z_pure_key_dict.__setitem__]sK!X&q$'C,?1,D !BCC5)A 1 r;c. ||y#t$rYywxYw)NTF)rCrDs r9 __contains__z_pure_key_dict.__contains__ds#  G  s  N)__name__ __module__ __qualname____doc__r:rFrJrLr;r9r3r3&s+Xr;r3cx|j\}}|Dcgc]\}}t|d|fc}}Scc}}w)NFr>) factor_listr )poly_factorsfms r9 _pure_factorsrYos8!!#JAw7> ?tq!Xa & * ?? ?s6cd|jDcgc] \\}}||f }}}td|Dry|Dcgc]\}}|t|z|zf}}}tjt |t d}t|jt tScc}}wcc}}w)zZReturn the number of imaginary roots for irreducible univariate polynomial ``f``. c3,K|] \}}|dzyw)NrQ).0ijs r9 z(_imag_count_of_factor..ys #TQ1q5 #srx) termsanyrr from_dictdictrint count_rootsr )rWr^r_rbevens r9_imag_count_of_factorrits$%779 -aaV -E - #U ##$) *DAqQ1QK *D * >>$t*eCj 1D tR( )) . +s B&B,Nc"t|||||S)aAn indexed root of a univariate polynomial. Returns either a :obj:`ComplexRootOf` object or an explicit expression involving radicals. Parameters ========== f : Expr Univariate polynomial. x : Symbol, optional Generator for ``f``. index : int or Integer radicals : bool Return a radical expression if possible. expand : bool Expand ``f``. indexradicalsr?)r1)rWrarlrmr?s r9rootofrns( 1aux GGr;ceZdZdZdZddZy)RootOfzRepresents a root of a univariate polynomial. Base class for roots of different kinds of polynomials. Only complex roots are currently supported. )rTNc"t|||||S)z>Construct a new ``CRootOf`` object for ``k``-th root of ``f``.rk)rn)clsrWrarlrmr?s r9__new__zRootOf.__new__sa%(6JJr;NTT)rMrNrOrP __slots__rsrQr;r9rprps IKr;rpcHeZdZdZdZdZdZdZdZd.dZ e dZ dZ e dZe d Ze d Zd Zd Ze d/d Ze d/dZe d/dZe d/dZe d/dZe d/dZe dZe dZe dZe dZe dZe dZe dZe d0dZ dZ!dZ"e dZ#dZ$e d/dZ%e e&d Z'e d!Z(e d"Z)e d#Z*e d$Z+e d%Z,e d&Z-d'Z.d(Z/d)Z0d*Z1d0d+Z2d,Z3d1d-Z4y)2 ComplexRootOfaRepresents an indexed complex root of a polynomial. Roots of a univariate polynomial separated into disjoint real or complex intervals and indexed in a fixed order: * real roots come first and are sorted in increasing order; * complex roots come next and are sorted primarily by increasing real part, secondarily by increasing imaginary part. Currently only rational coefficients are allowed. Can be imported as ``CRootOf``. To avoid confusion, the generator must be a Symbol. Examples ======== >>> from sympy import CRootOf, rootof >>> from sympy.abc import x CRootOf is a way to reference a particular root of a polynomial. If there is a rational root, it will be returned: >>> CRootOf.clear_cache() # for doctest reproducibility >>> CRootOf(x**2 - 4, 0) -2 Whether roots involving radicals are returned or not depends on whether the ``radicals`` flag is true (which is set to True with rootof): >>> CRootOf(x**2 - 3, 0) CRootOf(x**2 - 3, 0) >>> CRootOf(x**2 - 3, 0, radicals=True) -sqrt(3) >>> rootof(x**2 - 3, 0) -sqrt(3) The following cannot be expressed in terms of radicals: >>> r = rootof(4*x**5 + 16*x**3 + 12*x**2 + 7, 0); r CRootOf(4*x**5 + 16*x**3 + 12*x**2 + 7, 0) The root bounds can be seen, however, and they are used by the evaluation methods to get numerical approximations for the root. >>> interval = r._get_interval(); interval (-1, 0) >>> r.evalf(2) -0.98 The evalf method refines the width of the root bounds until it guarantees that any decimal approximation within those bounds will satisfy the desired precision. It then stores the refined interval so subsequent requests at or below the requested precision will not have to recompute the root bounds and will return very quickly. Before evaluation above, the interval was >>> interval (-1, 0) After evaluation it is now >>> r._get_interval() # doctest: +SKIP (-165/169, -206/211) To reset all intervals for a given polynomial, the :meth:`_reset` method can be called from any CRootOf instance of the polynomial: >>> r._reset() >>> r._get_interval() (-1, 0) The :meth:`eval_approx` method will also find the root to a given precision but the interval is not modified unless the search for the root fails to converge within the root bounds. And the secant method is used to find the root. (The ``evalf`` method uses bisection and will always update the interval.) >>> r.eval_approx(2) -0.98 The interval needed to be slightly updated to find that root: >>> r._get_interval() (-1, -1/2) The ``evalf_rational`` will compute a rational approximation of the root to the desired accuracy or precision. >>> r.eval_rational(n=2) -69629/71318 >>> t = CRootOf(x**3 + 10*x + 1, 1) >>> t.eval_rational(1e-1) 15/256 - 805*I/256 >>> t.eval_rational(1e-1, 1e-4) 3275/65536 - 414645*I/131072 >>> t.eval_rational(1e-4, 1e-4) 6545/131072 - 414645*I/131072 >>> t.eval_rational(n=2) 104755/2097152 - 6634255*I/2097152 Notes ===== Although a PurePoly can be constructed from a non-symbol generator RootOf instances of non-symbols are disallowed to avoid confusion over what root is being represented. >>> from sympy import exp, PurePoly >>> PurePoly(x) == PurePoly(exp(x)) True >>> CRootOf(x - 1, 0) 1 >>> CRootOf(exp(x) - 1, 0) # would correspond to x == 0 Traceback (most recent call last): ... sympy.polys.polyerrors.PolynomialError: generator must be a Symbol See Also ======== eval_approx eval_rational )rlTNct|}||jrd|}}n t|}||jr t|}ntd|zt ||d|}|j s t d|jjs t d|j}|dkrt d|z|| ks||k\rtd | |d z |fz|dkr||z }|j}|js|j}|j||} | | |St|\} }|j}|j st#d |z|j%||d } | |j'| |zS)z Construct an indexed complex root of a polynomial. See ``rootof`` for the parameters. The default value of ``radicals`` is ``False`` to satisfy ``eval(srepr(expr) == expr``. Nz&expected an integer root index, got %sF)greedyr?'only univariate polynomials are allowedzgenerator must be a Symbolrz&Cannot construct CRootOf object for %sz(root index out of [%d, %d] range, got %dr=z CRootOf is not supported over %sT)lazy)r is_IntegerrfrHr is_univariatergen is_Symboldegree IndexError get_domainis_Exactto_exact_roots_trivialris_ZZNotImplementedError _indexed_root_postprocess_root) rrrWrarlrmr?rTrdomrcoeffroots r9rszComplexRootOf.__new__0s AJ =Q\\QuAENE  !1!1JEEMN N1U6:!!!"KL Lxx!!"">? ? Q;!"JQ"NO O F7?evoG%gvz59:; ; QY VOEoo||==?D""42  < &t, tooyy%&H3&NO O  u4 8s,,T8<<  %1$%7L ")9$)? SXX &     s4A$$ A10A1c2|j|jfSr5)rTrlr7s r9_hashable_contentzComplexRootOf._hashable_content|s 4::&&r;c6|jjSr5rTas_exprr7s r9exprzComplexRootOf.expryy  ""r;cD|jt|jfSr5)rrrlr7s r9argszComplexRootOf.argss 74::.//r;ctSr5)setr7s r9rBzComplexRootOf.free_symbolss u r;ct|j|jtt|jkS)z%Return ``True`` if the root is real. )_ensure_reals_initrlrArrTr7s r9 _eval_is_realzComplexRootOf._eval_is_reals+ !zzC TYY 7888r;c|j|jtt|jk\r,|j }|j |jzdkSy)z*Return ``True`` if the root is imaginary. rF)rrlrArrT _get_intervalaxbx)r8ivls r9_eval_is_imaginaryz ComplexRootOf._eval_is_imaginarysP ! ::\$))45 5$$&C66#&&=A% %r;c(|jd||S)z Get real roots of a polynomial. _real_roots _get_rootsrrrTrms r9 real_rootszComplexRootOf.real_rootss~~mT8<Get complex root isolating intervals for a square-free factor.Tr)rr#rrr)rrrr complex_parts r9_get_complexes_sqfz ComplexRootOf._get_complexes_sqfsf *::+M:L .!!))+]->->-B-BTS S ] +lr;c Fg}|D]9\}} |stt|}|j|Dcgc]}|||f c};|j |}|Scc}w#t$r>|j||}|D cgc]} | ||f ncc} w} } |j| YwxYw)z=Compute real root isolating intervals for a list of factors. )rCrextendr _reals_sorted) rrrVrrealsrrErr^rrnews r9 _get_realszComplexRootOf._get_realss ' " M1 " "N / Q?q-3?@ "!!%( @ "..}iH |j ||}|D cgc]} | ||f ncc} w} } |j| YwxYw)z@Compute complex root isolating intervals for a list of factors. )rrCrrr_complexes_sorted) rrrVr complexesrrEcr^rrrs r9_get_complexeszComplexRootOf._get_complexess ' 0 & M1 & "N$]3  !CA1mQ"7!CD &)))4 "D &"55mYO z-ComplexRootOf._reals_sorted..sAaDFFr;)key) enumeraterefine_disjointsortedappenditemsr)rrrcacher^urWrEr_rIgrXrrrUs r9rzComplexRootOf._reals_sorteds%e, !LAy1a )%A- 8 - 9Aq!((+1$%q!9a!eai  -1ayE!H  !u"23&+ . "D-%m$++D1(,vm$  . $);;= / M4*.L ' / r;c t|d}g}t|D]S}t|}|dk(rl||D]c\}}}|j|jzdkr-|j }|j|jzdkr-|j |||fettt||} t|dkDsJt|D]q}|||\}}}|j|jzdkDr|j|=|j|jk7sW|j }|||f|||<st||k(rn|j||V|S)Nc |dS)Nr=rQ)rs r9rz1ComplexRootOf._refine_imaginary..s 1Q4r;rr=) r'rrirr _inner_refinerlistrangerAremover) rrrsiftedrWnimagrrEpotential_imagr^s r9_refine_imaginaryzComplexRootOf._refine_imaginaryspi0  ,A)!,Ez%ay0GAq!$$qtt)q.OO-$$qtt)q.$$aAY/0 "&eCq N&;!<~.222!.13"()A,1a449q=*11!4TTQTT\ ! 1A+,a7F1IaL 3>*e3  +- ,.r;ct|D]P\}\}}}t||dzdD]+\}\}}} |j|\}}||| f|||zdz<-|||f||<R|j|}t|D]Z\}\}}}|j|jzdkr-|j }|j|jzdkr-|||f||<\|S)areturn complexes such that no bounding rectangles of non-conjugate roots would intersect. In addition, assure that neither ay nor by is 0 to guarantee that non-real roots are distinct from real roots in terms of the y-bounds. r=Nr)rrraybyrefine) rrrr^rrWrEr_rIrrXs r9_refine_complexeszComplexRootOf._refine_complexess&i0 %LAy1a ))AEF*; < 1 9Aq!((+1()1ay !a%!)$ 1q!9IaL  %)))4 &i0 #LAy1a$$qtt)q.HHJ$$qtt)q.a7IaL #r;c|j|}d\}}|Dchc]}|| }}tdt|D]1}|||||dz |k7s|j||dz |3t |D]\}}||j |dzdk(urJi}|D]'\}} } |j | gj|)|jD]\} }|t| <|Scc}w)z:Make complex isolating intervals disjoint and sort roots. )rr=r=r\r) rrrArrconj setdefaultrrr) rrrCFr^fscmplxrrrrUs r9rzComplexRootOf._complexes_sorted5s0)))4 1% &qad & &q#i.) /A|A)AE"21"55 )AE*1-.  / "), 1HAu8==QUaZ0 00 1 &/ = "D-   ]B / 6 6t < =$);;= 3 M4.2 ] + 3+'s C/cd}t|D]9\}\}}}|||zkr#|d}}|d|D]\}}}||k(s |dz }||fcS||z };y)ze Map initial real root index to an index in a factor where the root belongs. rNr=)r) rrrrlr^r_rUrrErTs r9 _reals_indexzComplexRootOf._reals_indexTs (1%(8  $A$=!q1u}+Qe+0!9#'A}a$, #U{"Q r;cd}t|D]N\}\}}}|||zkr8|d}}|d|D]\}}}||k(s |dz }|tt|z }||fcS||z }Py)zh Map initial complex root index to an index in a factor where the root belongs. rNr=)rrAr) rrrrlr^r_rUrrErTs r9_complexes_indexzComplexRootOf._complexes_indexhs (1)(<  $A$=!q1u}+Qe+4Ra=#'A}a$, #\$/00U{"Q r;c&td|DS)z>Count the number of real or complex roots with multiplicities.c3(K|] \}}}| ywr5rQ)r]rUrEs r9r`z-ComplexRootOf._count_roots..s*Aq1*s)sum)rrrs r9 _count_rootszComplexRootOf._count_roots}s*E***r;c t|}|r#t|dk(r|dddk(r |dd|fS|j|}|j|}||kr|j ||S|j |}|j |||z S)z/Get a root of a composite polynomial by index. r=r)rYrArrrrr)rrrTrlr{rVr reals_countrs r9rzComplexRootOf._indexed_roots % CLA%'!*Q-1*<1:a=%' 'w'&&u- ; ##E51 1**73I'' 5;3FG Gr;cv|jtvr'|j|j|jyy)z5Ensure that our poly has entries in the reals cache. N)rTrrrlr7s r9rz ComplexRootOf._ensure_reals_inits+ 99L (   tyy$** 5 )r;cv|jtvr'|j|j|jyy)z9Ensure that our poly has entries in the complexes cache. N)rTrrrlr7s r9_ensure_complexes_initz$ComplexRootOf._ensure_complexes_inits, 99, ,   tyy$** 5 -r;ct|}|j|}|j|}g}td|D]$}|j|j ||&|S)z*Get real roots of a composite polynomial. r)rYrrrrr)rrrTrVrrrrls r9rzComplexRootOf._real_rootssi %w'&&u- 1k* 9E ELL))%7 8 9 r;c>|j|jdy)z% Reset all intervals FrN)rrTr7s r9_resetzComplexRootOf._resets  U3r;c|t|}|j||}|j|}g}td|D]$}|j|j ||&|j ||}|j|} td| D]$}|j|j||&|S)z6Get real and complex roots of a composite polynomial. rr)rYrrrrrrr) rrrTrrVrrrrlrcomplexes_counts r9rzComplexRootOf._all_rootss %w)<&&u- 1k* 9E ELL))%7 8 9&&w)&D **951o. AE ELL--i? @ A r;c|jdk(r t|S|sy|jdk(r t|S|jdk(r|j r t |Sy)z7Compute roots in linear, quadratic and binomial cases. r=Nr\)rrrlengthTCrrs r9rzComplexRootOf._roots_trivials` ;;=A % % ;;=A "4( ( [[]a DGGI!$' 'r;c|j}|js|j}t|\}}|j}|jst d|z||fS)zBTake heroic measures to make ``poly`` compatible with ``CRootOf``.z"sorted roots not supported over %s)rrrrrr)rrrTrrs r9_preprocess_rootszComplexRootOf._preprocess_rootssdoo||==?D&t, tooyy%4s:< <d{r;cb|\}}|j||}|||S|j||S)z:Return the root if it is trivial or a ``CRootOf`` object. )rr)rrrrmrTrlrs r9rzComplexRootOf._postprocess_roots@ e""42  < 88D%( (r;cv|js td|j}t}|j |j |}t d}|jDchc] }t|}}tt dftdD]$}|j|vs|j||}n|js |jr|j|||S|j s|j"s |j$r|j'|||S|j|||Scc}w)z.Return postprocessed roots of specified kind. rzra)r}rrrsubsr~r rBstrr0r(namereplaceis_QQr _get_roots_qqis_AlgebraicFieldis_ZZ_Iis_QQ_I_get_roots_alg) rrmethodrTrmrdrar^ free_namess r9rzComplexRootOf._get_rootss!!!"KL Loo Gyy1% CL'+&7&78c!f8 8 (8(=> AvvZ'||Aq)  99 $$VT8< <  " "ckkS[[%%fdH= =$$VT8< <9s'D6c|j|\}}g}t|||D]'}|j||j||z)|S)zbReturn postprocessed roots of specified kind for polynomials with rational coefficients. )rgetattrrr)rrrrTrmrrrs r9r zComplexRootOf._get_roots_qqsc++D1 t(GC(. FD ELLs44T8DD E F r;c|j||j|}i}|jdD]>\}}|dk(r|j|}n|dk(r|j |}D]} ||| < @t } g} |D]7} | |vs| | vs || }| j | g|z| j| 9| S)aGReturn postprocessed roots of specified kind for polynomials with algebraic coefficients. It assumes the domain is already an algebraic field. First it finds the roots using _get_roots_qq, then uses the square-free factors to filter roots and get the correct multiplicity. r=rr)r liftsqf_listwhich_real_rootswhich_all_rootsrradd) rrrrTrmrsubrootsrWrX roots_filtr roots_seen roots_flats r9r zComplexRootOf._get_roots_alg$s!!&$))+x@MMOA& DAq&//6 <'..u5     U   "AH}*!4QK!!1#'*q!  " r;c,tatay)agReset cache for reals and complexes. The intervals used to approximate a root instance are updated as needed. When a request is made to see the intervals, the most current values are shown. `clear_cache` will reset all CRootOf instances back to their original state. See Also ======== _reset N)r3rr)rrs r9 clear_cachezComplexRootOf.clear_cacheDs&' )+r;c|j|jr t|j|jSt t|j}|j t|j|j|z S)z@Internal function for retrieving isolation interval from cache. ris_realrrTrlrArr)r8rs r9rzComplexRootOf._get_intervalVsi ! << *4::6 6l49956K  ' ' )#DII.tzzK/GH Hr;c|j|jr!|t|j|j<yt t|j}|j |t|j|j|z <y)zf$rYwxYw#1swYxYw)a@Evaluate this complex root to the given precision. This uses secant method and root bounds are used to both generate an initial guess and to check that the root returned is valid. If ever the method converges outside the root bounds, the bounds will be made smaller and updated. ra0r=N)%r-r,rTr~rr is_imaginaryrr%rrrr!r)rrbcenterdxrrr*dyrrmapr+boolimagrealUnboundLocalErrorrHrr$rr_mpf_)r8n return_mpmathprecrrr*rr#rr0rx0x1rrrrs r9 eval_approxzComplexRootOf.eval_approxtsW1~ d^E - A;;#J$$FA499>>!Q#78yy$$99>>!QqS1D4())+H<<C O,AC O,AAv S12Bc#hkk"23A55B&&C ,-AC ,-AAv"3s8Q/S!345Bc#hkk"23A55BS-.BS-.BS-.BS-.BRxB"H"2r{c#x78Bc3sX[[(++,F#GHJJB$D2r(3D||t'8'8#DII$,,> !TQ#00'*3s8TYY'?! /R/B$))4Ir4I$??,oE -R 8$ K 499??D1 ejj$/ /0 1*:6GE -E -s=K#Q;BP9<Q=0P9-Q9Q Q Q  QQc V|jt|j|S)z2Evaluate this complex root to the given precision.r:) eval_rationalr._evalf)r8r<kwargss r9 _eval_evalfzComplexRootOf._eval_evalfs(!!K$5!6==dCCr;c|xs|}|rOd}t|tr|ntt|}t|tr|ntt|}ntd|dz z}|j } |j rs|rt |j|z}|j|}|j}t|}tj}|r|jt ||zkr0n0|jrz|rt |jd|z}d}|j||}|jd}t|}tj}|r|jt ||zkrn|r6t |jd|z}t |jd|z}|j||}|j}tt|\}}|r<|jt |d|zkr|jt |d|zkrn|j||t|zzS)a Return a Rational approximation of ``self`` that has real and imaginary component approximations that are within ``dx`` and ``dy`` of the true values, respectively. Alternatively, ``n`` digits of precision can be specified. The interval is refined with bisection and is sure to converge. The root bounds are updated when the refinement is complete so recalculation at the same or lesser precision will not have to repeat the refinement and should be much faster. The following example first obtains Rational approximation to 1e-8 accuracy for all roots of the 4-th order Legendre polynomial. Since the roots are all less than 1, this will ensure the decimal representation of the approximation will be correct (including rounding) to 6 digits: >>> from sympy import legendre_poly, Symbol >>> x = Symbol("x") >>> p = legendre_poly(4, x, polys=True) >>> r = p.real_roots()[-1] >>> r.eval_rational(10**-8).n(6) 0.861136 It is not necessary to a two-step calculation, however: the decimal representation can be computed directly: >>> r.evalf(17) 0.86113631159405258 N r\)r2r=)r2r3r)r@rrrrr!absr1 refine_sizeZeror2r/r3r4r$r) r8r2r3r:rtolr#rr7r6s r9rBzComplexRootOf.eval_rationalsBX2 D!"h/Xc"g5FB!"h/Xc"g5FB R5AE(?D%%'||X__T12B#//2/6OO{vvx{{S4[8""X__Q/45BB#//2"/=OOA&{vvx{{S4[8X__Q/45BX__Q/45B#//B7OO 1- d c!A$t)n4 c!A$t)n4=D 8$af}r;)NFTT)F)NN)5rMrNrOrPru is_complex is_number is_finite is_algebraicrs classmethodrrpropertyrrrBrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrr$r'r+r?rErBrQr;r9rwrws@DIJIIL:=x  '##00 9 ==<<  $$088<&(++HH,6 6   4 (     ))==:  >,,"IMM V1pD Pr;rwc ||k(Sr5rQ)lhsrhss r9 _eval_is_eqrW's #:r;c|jsy|jsy|jj|jjj |j }|dury|j|jf}|j|jf}d|vsJ||k7rd|vry|j\}}|jrc|ry|j}|j|jfDcgc]}tt|c}\} } t| |kxr|| kS|j}|j |j"|j$|j&fD cgc]} tt| c} \} } }}t)| |xr(t)|| xrt)||xr t)||Scc}wcc} w)NF)rOrPrrrBpopis_zeror!r/ as_real_imagrrr0rrr rrrrr)rUrVzosreimr^rUrr0r_r1r2i1i2s r9rWrW-s == ==  chh++//137??AEz S%%%A S%%%A q==Av$a-    FB {{     +,33*5QQ 51qCx,C1H-- A addADD!$$1 !1hs1v&!NBB R= KU2b\ KeBrl KuR|K 6!s 4G*GceZdZdZdZddZeddZeddZedZ edZ ed Z d Z e d Ze d Ze d Ze dZdZdZdZy)RootSumz:Represents a sum of all roots of a univariate polynomial. )rTfunautoNc |j||\}}|js td|!t|j|j}nbt |dd}|rEd|j vr7t|ts5t|j||j}ntd|z|jd|j}} |tjur|j| || z}|j} |j| s| |zS|j r|j#| \} }ntj$} |j&r|j#| \} }ntj} t| |}|j)||} t+|g}}|D]\}}|j,r|t/|d}nW|r+|j0rt3t5|t7|}n*| r|s|j9|||}n|j;||}|j=||z| t?|z| | zzS)z>Construct a new ``RootSum`` instance of roots of a polynomial.rz is_FunctionFr=z&expected a univariate function, got %sr) _transformr}rr r~rnargsr@rH variablesrrOnerrhasis_Addas_independentrJis_Mul_is_func_rationalrY is_linearr is_quadraticrr4rr_rational_caserr )rrrr*rarh quadraticrrTis_funcvardeg add_const mul_constrationalrVrbrEterms r9rszRootSum.__new__Ss nnT1- t!!-9; ; <$((DHH-DdM59G1 ?!$/!$((DN;D .s1a #q!1sF)domainr?NT)formal)r rrmrrr"as_numer_denomrr?rziprbrrrrrrrAregensrr!)rrrTr*rrWpqrp_monomp_coeffq_monomq_coeffcoeffsmappingformulasvaluessymrUvalr^rr:rrys @@r9rvzRootSum._rational_cases ./NN1%tyy T 151 1{))+1E HHJ HHJ /Qve4A #AGGI GW /Qve4A #AGGI GW$Ww%6tD u-r&"%gx"8 & HS!hq# MM3* % &'v. +MAzq 6*F1I + L!** =T#gw/0:166:BBDADQ =T#gw/0:166:BBDADQac{I  $twA $  $twA $s$G<>H<H HH#"H#c2|j|jfSr5)rTrgr7s r9rzRootSum._hashable_contents 488$$r;c6|jjSr5rr7s r9rz RootSum.exprrr;c\|j|j|jjfSr5)rrgrTr~r7s r9rz RootSum.argss 488TYY]]33r;c\|jj|jjzSr5)rTrBrgr7s r9rBzRootSum.free_symbolss!yy%%(=(===r;cy)NTrQr7s r9is_commutativezRootSum.is_commutativesr;c |jdds|St|jd}t||jj kr|St |Dcgc]}|j |c}Scc}w)NrT)multiple)getrrTrArr rg)r8hints_rootsrs r9doitz RootSum.doitsdyy$'Ktyy40 v;))+ +Kf5!56 65sA9c |jjt|}t|Dcgc]}|j |c}Scc}w#t t f$r|cYSwxYw)NrA)rTnrootsr.r rgrr)r8r<rrs r9rEzRootSum._eval_evalfsa 7YY%% D(9%:Ff5!56 65_- K s%AA A%$A%c|jj\}}t||j|}|j |j ||j Sr5)rgrr diffrrTrh)r8raryrr*s r9_eval_derivativezRootSum._eval_derivativesBHHMM Tc499Q<(xx 433r;)NNTFrL)rMrNrOrPrursrRrrrkrsrvrrSrrrBrrrErrQr;r9rfrfMsD'I:5x 2 2&& .. 33j%##44>> 774r;rfrt)LrPsympy.core.basicr sympy.corerrrrrr r r r r rrsympy.core.cachersympy.core.relationalrsympy.core.sortingrsympy.polys.domainsrsympy.polys.polyerrorsrrrrsympy.polys.polyfuncsrrsympy.polys.polyrootsrrrrrsympy.polys.polytoolsrr r!sympy.polys.rationaltoolsr"sympy.polys.rootisolationr#r$sympy.utilitiesr%r&r'r(mpmathr)r*r+r,mpmath.libmp.libmpfr-r.sympy.multipledispatchr/ itertoolsr0__all__r3rrrYrirnrprwr1rWrfrQr;r9rsR8#''''$'&" 498. ED//8+ +CCJ !#@ *HH, KT K Kz Fz z z  -'(  -L L>D4dD4D4r;