K i @dZddlmZmZddlmZmZmZddlm Z ddl m Z ddl m Z mZmZmZddlmZddlmZmZmZdd lmZdd lmZdd lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)dd lm*Z*ddl+Z+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZd"Z?d#Z@d$ZAd%ZBd&ZCd'ZDd(ZEd)ZFd*ZGd+ZHd,ZId-ZJd.ZKd/ZLd0ZMd1ZNd2ZOd3ZPd4ZQd5ZRd6ZSd7ZTd8ZUd9ZVd:ZWd;ZXd<ZYd=ZZdNd>Z[d?Z\d@dAdBdCdDdEdFdGdHdI Z]dJZ^dKZ_dLZ`y)Oa9Power series evaluation and manipulation using sparse Polynomials Implementing a new function --------------------------- There are a few things to be kept in mind when adding a new function here:: - The implementation should work on all possible input domains/rings. Special cases include the ``EX`` ring and a constant term in the series to be expanded. There can be two types of constant terms in the series: + A constant value or symbol. + A term of a multivariate series not involving the generator, with respect to which the series is to expanded. Strictly speaking, a generator of a ring should not be considered a constant. However, for series expansion both the cases need similar treatment (as the user does not care about inner details), i.e, use an addition formula to separate the constant part and the variable part (see rs_sin for reference). - All the algorithms used here are primarily designed to work for Taylor series (number of iterations in the algo equals the required order). Hence, it becomes tricky to get the series of the right order if a Puiseux series is input. Use rs_puiseux? in your function if your algorithm is not designed to handle fractional powers. Extending rs_series ------------------- To make a function work with rs_series you need to do two things:: - Many sure it works with a constant term (as explained above). - If the series contains constant terms, you might need to extend its ring. You do so by adding the new terms to the rings as generators. ``PolyRing.compose`` and ``PolyRing.add_gens`` are two functions that do so and need to be called every time you expand a series containing a constant term. Look at rs_sin and rs_series for further reference. )QQEX) PolyElementringsring) PuiseuxPoly) DomainError) monomial_min monomial_mul monomial_div monomial_ldiv)ifac) PoleErrorFunctionExpr)Rational)igcd) sincostanatanexpatanhasinhtanhlogceilingsinhcosh)as_int) giant_stepsNc(t|j}|j|j}|j}|j }|j }|j}t||D]\}}||||dz f<|S)a Compute ``x**n * p1(1/x)`` for a univariate polynomial ``p1`` in ``x``. Examples ======== >>> from sympy.polys.domains import ZZ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import _invert_monoms >>> R, x = ring('x', ZZ) >>> p = x**2 + 2*x + 3 >>> _invert_monoms(p) 3*x**2 + 2*x + 1 See Also ======== sympy.polys.densebasic.dup_reverse r) listitemssortdegreerzero listcoeffs listmonomszip) p1termsdegRpcvmvmvicvis ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/ring_series.py_invert_monomsr5=s(  E JJL ))+C A A B BBK!S 3Q>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_trunc >>> R, x = ring('x', QQ) >>> p = x**10 + x**5 + x + 1 >>> rs_trunc(p, x, 12) x**10 + x**5 + x + 1 >>> rs_trunc(p, x, 10) x**5 + x + 1 )rgensindex)r+xprecr.r/iexp1s r4rs_truncrEdsX$ A A  QA 7d? T($ Q4Kr6c|jjj|}|jD].}||t ||k7ry||dks"t d|zy)a Test if ``p`` is Puiseux series in ``x``. Raise an exception if it has a negative power in ``x``. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.puiseux import puiseux_ring >>> from sympy.polys.ring_series import rs_is_puiseux >>> R, x = puiseux_ring('x', QQ) >>> p = x**QQ(2,5) + x**QQ(2,3) + x >>> rs_is_puiseux(p, x) True TrzThe series is not regular in %sF)rr?r@ itermonomsint ValueError)r/rAr@ks r4 rs_is_puiseuxrKsk" FFKK  a E \\^D U8s1U8} $ U8a<>BC C D r6c T|jjj|}d}|D]|}||}t|tr/|j \}} t || zt|| z}G|t |k7sV|j} t || zt|| z}~|dk7rkt|||} || |||z} td|} t| tr&t| D cgc]} t| || c} } | St| || } | S||||} | Scc} w)a Return the puiseux series for `f(p, x, prec)`. To be used when function ``f`` is implemented only for regular series. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.puiseux import puiseux_ring >>> from sympy.polys.ring_series import rs_puiseux, rs_exp >>> R, x = puiseux_ring('x', QQ) >>> p = x**QQ(2,5) + x**QQ(2,3) + x >>> rs_puiseux(rs_exp,p, x, 1) 1 + x**(2/5) + x**(2/3) + 1/2*x**(4/5) ) rr?r@ isinstanceras_numer_denomrHr denominatorpow_xinrtuple)fr/rArBr@nrJpowernumdenr+rn1rxs r4 rs_puiseuxr[s1" FFKK  a E A +% eX &++-HCAcET!S\)*A c%j ##CAcET!S\)*A+ Av Qq ! b!T!V  1X a :"wr5"-:;A H5"%A H aDM H ;s-D%c|jjj|}d}|D]j}||}t|tr&|j \} } || zt || z}>|t|k7sM|j} || zt || z}l|dk7r6t|||} || ||||z} td|} t| || } | S|||||} | S)z Return the puiseux series for `f(p, q, x, prec)`. To be used when function ``f`` is implemented only for regular series. rM) rr?r@rNrrOrrHrPrQr)rSr/qrArBr@rTrJrUrVrWr+rXrYs r4 rs_puiseux2r^s FFKK  a E A &% eX &++-HC#a%A c%j ##C#a%A& Av Qq ! b!QQ  1X Aub ! H aAt  Hr6c|j}i}|j|jjk7s||jk7r td|jj |t |t tfs td||jk(r|j}|j}|jfd|jdk(rJ|jD]6\}} |D],\} } |d| dz} | |kr| f} || d| | zz|| <,68nY|j} |jD]:\}} |D]0\} } || z|kr| || } || d| | zz|| <0:<||S)a Return the product of the given two series, modulo ``O(x**prec)``. ``x`` is the series variable or its position in the generators. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_mul >>> R, x = ring('x', QQ) >>> p1 = x**2 + 2*x + 1 >>> p2 = x + 1 >>> rs_mul(p1, p2, x, 3) 3*x**2 + 3*x + 1 z!p1 and p2 must have the same ringzp2 must be a polynomialc|dSNreivs r4zrs_mul..s!A$r(r6keyrMr)r __class__rIr?r@rNrrgetr,r%ngens itertermsr )r+p2rArBr.r/rjitems2rDv1exp2v2rr res @r4rs_mulrrs$ A A{{bgg'''1<<== aB b; 4 5233BGG|ee * + 77a<LLN b &HD"q'DG+CTz"g!$S!r"u!4#  >>LLLN b &HD"Bx$r(*T1*46!$S!r"u!4#   Q4Kr6c|j}i}|jj||j}|j }|j fd|j }tt|D]M}||\} } t|D]5} || \} } | | z|kr|| | }||d| | zz||<5MO|jDcic] \}}|d|z }}}|j}|jD],\}}d|z|ks|||}||d|dzz||<.||Scc}}w)aA Square the series modulo ``O(x**prec)`` Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_square >>> R, x = ring('x', QQ) >>> p = x**2 + 2*x + 1 >>> rs_square(p, x, 3) 6*x**2 + 4*x + 1 c|dSrarbrcs r4rfzrs_square..sQqT"Xr6rgrr8) rr?r@rjr,r%r rangelenr$rl)r+rArBr.r/rjr$r rCrDrojrprqrmvexpve2res @r4 rs_squarer| s^ A A aB %%C HHJE JJ%J&>>L 3u: 8bq AQxHD"Bx$r("T)"4.S!r"u,#  GGI&DAqAaC&A& %%C<<>&a T"X: dD)BAJA%AbE& Q4K 'sEc|j}t|trbt|j}t|j }|dk7r#t ||||}|dk7rt||||}|St||||}|St|}|dk(r|r|dStd|dkrt|| ||}t|||S|dk(r t|||S|dk(r t|||S|dk(rt|||}t||||S|d} |dzrt|| ||} |dz}|s | St|||}|dz}0)a4 Return ``p1**n`` modulo ``O(x**prec)`` Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_pow >>> R, x = ring('x', QQ) >>> p = x + 1 >>> rs_pow(p, 4, x, 3) 6*x**2 + 4*x + 1 rMrz0**0 is undefinedr8)rrNrrHr/r] rs_nth_rootrs_powr rIrs_series_inversionrEr|rr) r+rTrArBr.npnqr<rmr/s r4rr1sv A!X X X 7b"a.CQwS"a. RD)C q AAv Q4K01 11u BAt $"2q$//AvAt$$AvQ%%Av r1d #b"a&& !A q5r1a&A FA Hr1d # F r6c|j}|j}|d}t|D]}|j|||df<|D]}||||j |df<|d} t |j } | D]} |d} t|D]}| |} | dk(r|| f|vrtt| d\}}|dk(r||f|vrt|||f||||| f<nB|| dz f|vr!t||| dz f||df||||| f<nt||df| ||||| f<t| ||| f||} | | || zz } | S)a Substitution with truncation according to the mapping in ``rules``. Return a series with precision ``prec`` in the generator ``x`` Note that substitutions are not done one after the other >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_subs >>> R, x, y = ring('x, y', QQ) >>> p = x**2 + y**2 >>> rs_subs(p, {x: x+ y, y: x+ 2*y}, x, 3) 2*x**2 + 6*x*y + 5*y**2 >>> (x + y)**2 + (x + 2*y)**2 2*x**2 + 6*x*y + 5*y**2 which differs from >>> rs_subs(rs_subs(p, {x: x+ y}, x, 3), {y: x+ 2*y}, x, 3) 5*x**2 + 12*x*y + 8*y**2 Parameters ---------- p : :class:`~.PolyElement` Input series. rules : ``dict`` with substitution mappings. x : :class:`~.PolyElement` in which the series truncation is to be done. prec : :class:`~.Integer` order of the series after truncation. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_subs >>> R, x, y = ring('x, y', QQ) >>> rs_subs(x**2+y**2, {y: (x+y)**2}, x, 3) 6*x**2*y**2 + x**2 + 4*x*y**3 + y**4 rrMr8) rrkrur?r@sortedkeysdivmodr|rrr)r/rulesrArBr.rkdrCvarr+p_keysrzrmrUr]rXs r4rs_subsrgsP A GGE !A 5\FF1I1a& *$Sz1773< * 1B AFFH F qTu 4AGEz5z"eQ'16q!fk$-aAiD$AAq%jM^q($*1a^+>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import _has_constant_term >>> R, x = ring('x', QQ) >>> p = x**2 + x + 1 >>> _has_constant_term(p, x) True rrMc3<K|]}t|k(ywN)r ).0rzmivzms r4 z%_has_constant_term..s;|D#&",;s)rr?r@ zero_monomrkrRany)r/rAr.rearrs @@r4_has_constant_termrsZ A aB B AGG A AbE (C ;; ;;r6c|j}|jj|}|j}dg|jz}d||<t |}d}|D]"}t |||k(s|||||iz }$|S)zReturn constant term in p with respect to x Note that it is not simply `p[R.zero_monom]` as there might be multiple generators in the ring R. We want the `x`-free term which can contain other generators. rrM)rr?r@rrkrRr ) r/rAr.rCrrrcrzs r4_get_constant_termrs A  QA B AGG A AaD (C A$ c "b ( D!D'?# #A$ Hr6c|jjj|t|fd}|dkrt d|z|fS)Nc|SrrbrJr@s r4rfz#_check_series_var.. QuXr6rgrz7Asymptotic expansion of %s around [oo] not implemented.)rr?r@minr)r/rAnamerxr@s @r4_check_series_varrsW FFKK  a E A%&u-A1u')-./ / !8Or6c:t||rtt|||S|j}|j}||}|t |k(r t |}||vr t dt||z |r t d|jj|st d|d|j|d}|jturd}||k7r |d|z }n|d}t|D]$}dt||||z } |t|| ||z}&|S)a Univariate series inversion ``1/p`` modulo ``O(x**prec)``. The Newton method is used. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import _series_inversion1 >>> R, x = ring('x', QQ) >>> p = x + 1 >>> _series_inversion1(p, x, 4) -x**3 + x**2 - x + 1 No constant term in seriesz8p cannot contain a constant term depending on parameterszConstant term z must be a unit in rM) rKr[_series_inversion1rrrHrIrdomainis_unitrr=rr) r/rArBr.rroner+precxts r4rrs/"Q,aD99 A B "A s4y4y {566!a%#&' ' 88  A >!,?zJKK A$Cxx2~Cx qT!V qTd#* r1a' ' &Q5) )* Ir6c|j}||jk(rt|j}|jj |t |fd}|rt|| }||z}||vr tdt|||z |r tdt|||}|dk7rt|| }|S)a Multivariate series inversion ``1/p`` modulo ``O(x**prec)``. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_series_inversion >>> R, x, y = ring('x, y', QQ) >>> rs_series_inversion(1 + x*y**2, x, 4) -x**3*y**6 + x**2*y**4 - x*y**2 + 1 >>> rs_series_inversion(1 + x*y**2, y, 4) -x*y**2 + 1 >>> rs_series_inversion(x + x**2, x, 4) x**3 - x**2 + x - 1 + x**(-1) c|Srrbrs r4rfz%rs_series_inversion..$rr6rgrz>p - p[0] must not have a constant term in the series variablesr) rr'ZeroDivisionErrorrr?r@rmul_xinNotImplementedErrorrr)r/rArBr.rrxrXr@s @r4rr s$ AAFF{ B FFLLOE A%&u-A Auqb !ax {!">??!ae)Q'!#9: :1a&AAv Auqb ! Hr6c|\}}|j}dg|jz}|||<t|}|d}|D]}|||k(s |||t||<|S)z2Coefficient of `x_i**j` in p, where ``t`` = (i, j)r)rrkrRr )r/rrCrwr.expv1r+rzs r4_coefficient_tr3st DAq A CKEE!H %LE 1B4 7a<,-dGB|D%( )4 Ir6ct||rt|j}|jj |}||}|jj |}t ||r t dt||df}|j}||vrt|dk(sJ||}||z } td|D]1} t||| i|| dz} t| || f|| zz} | | |z z} 3| S)ab Reversion of a series. ``p`` is a series with ``O(x**n)`` of the form $p = ax + f(x)$ where $a$ is a number different from 0. $f(x) = \sum_{k=2}^{n-1} a_kx_k$ Parameters ========== a_k : Can depend polynomially on other variables, not indicated. x : Variable with name x. y : Variable with name y. Returns ======= Solve $p = y$, that is, given $ax + f(x) - y = 0$, find the solution $x = r(y)$ up to $O(y^n)$. Algorithm ========= If $r_i$ is the solution at order $i$, then: $ar_i + f(r_i) - y = O\left(y^{i + 1}\right)$ and if $r_{i + 1}$ is the solution at order $i + 1$, then: $ar_{i + 1} + f(r_{i + 1}) - y = O\left(y^{i + 2}\right)$ We have, $r_{i + 1} = r_i + e$, such that, $ae + f(r_i) = O\left(y^{i + 2}\right)$ or $e = -f(r_i)/a$ So we use the recursion relation: $r_{i + 1} = r_i - f(r_i)/a$ with the boundary condition: $r_1 = y$ Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_series_reversion, rs_trunc >>> R, x, y, a, b = ring('x, y, a, b', QQ) >>> p = x - x**2 - 2*b*x**2 + 2*a*b*x**2 >>> p1 = rs_series_reversion(p, x, 3, y); p1 -2*y**2*a*b + 2*y**2*b + y**2 + y >>> rs_trunc(p.compose(x, p1), y, 3) y z9p must not contain a constant term in the series variablerMr8) rKrrr?r@rrIrrrvrur) r/rArTyr.nxnyrrrXrCsps r4rs_series_reversionr@shQ!! A aB !A aB!Q$% %q2q'"A B 7s1v{" " "A !A 1a[ QA1q5 ) BQ (A - RT  Hr6c|j}t|}|s<|d}|d|z}td|D]} t||||}||| |zz }|St t j |dz} t|| \} } | r| dz } |dg} |d}t|dkr1td| D]!} t||||}| j|#nLtd| D]=} | dzdk(rt| | dz||}nt||||}| j|?t| d|||}|d}|d}t| dz D]S}| |z} || }td| D]}||| |z| |zz }t||||}||z }t||||}|rSn| dz }| |z} | |krM|| |dz}td| D]}| |z|k\rn||| |z| |zz }t||||}||z }|S)a_ Return a series `sum c[n]*p**n` modulo `O(x**prec)`. It reduces the number of multiplications by summing concurrently. `ax = [1, p, p**2, .., p**(J - 1)]` `s = sum(c[i]*ax[i]` for i in `range(r, (r + 1)*J))*p**((K - 1)*J)` with `K >= (n + 1)/J` Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_series_from_list, rs_trunc >>> R, x = ring('x', QQ) >>> p = x**2 + x + 1 >>> c = [1, 2, 3] >>> rs_series_from_list(p, c, x, 4) 6*x**3 + 11*x**2 + 8*x + 6 >>> rs_trunc(1 + 2*p + 3*p**2, x, 4) 6*x**3 + 11*x**2 + 8*x + 6 >>> pc = R.from_list(list(reversed(c))) >>> rs_trunc(pc.compose(x, p), x, 4) 6*x**3 + 11*x**2 + 8*x + 6 See Also ======== sympy.polys.rings.PolyRing.compose rMrr8) rrvrurrrHr9sqrtrappendr|)r/rrArBconcurr.rTr]srCJKrXaxpjbrJs1rws r4rs_series_from_listrsyB A AA  aD aDFq! Aq!Q%A 1aKA  DIIaL1 A !Q>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_diff >>> R, x, y = ring('x, y', QQ) >>> p = x + x**2*y**3 >>> rs_diff(p, x) 2*x*y**3 + 1 rrM)rr?r@rkrRr domain_new)r/rAr.rTr+mnrzrds r4rs_diffrs( A  QA B QWWB BqE rB2 7dB'ALL4a1BqE2 R5Lr6c |j}i}|jj|}dg|jz}d||<t |}|D].}t ||}|j ||||dzz ||<0||S)a Integrate ``p`` with respect to ``x``. Parameters ========== x : :class:`~.PolyElement` with respect to which ``p`` is integrated. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_integrate >>> R, x, y = ring('x, y', QQ) >>> p = x + x**2*y**3 >>> rs_integrate(p, x) 1/3*x**3*y**3 + 1/2*x**2 rrM)rr?r@rkrRr r)r/rAr.r+rTrrzrds r4 rs_integraters( A B  QA QWWB BqE rB4 r " QtWd1gk2314 R5Lr6c|j}td|j\}}t|d}|dd||fz}|j}||vr|||z} |||z } n|} |} t |t rt | ||} n || g|} t| j} dg|z} | D]}|d| |dd<t| | |d|d} | S)a  Function of a multivariate series computed by substitution. The case with f method name is used to compute `rs\_tan` and `rs\_nth\_root` of a multivariate series: `rs\_fun(p, tan, iv, prec)` tan series is first computed for a dummy variable _x, i.e, `rs\_tan(\_x, iv, prec)`. Then we substitute _x with p to get the desired series Parameters ========== p : :class:`~.PolyElement` The multivariate series to be expanded. f : `ring\_series` function to be applied on `p`. args[-2] : :class:`~.PolyElement` with respect to which, the series is to be expanded. args[-1] : Required order of the expanded series. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_fun, _tan1 >>> R, x, y = ring('x, y', QQ) >>> p = x + x*y + x**2*y + x**3*y**2 >>> rs_fun(p, _tan1, x, 4) 1/3*x**3*y**3 + 2*x**3*y**2 + x**3*y + 1/3*x**3 + x**2*y + x*y + x _xrNrrM) rrrHrrNstrgetattrrr$r)r/rSargs_RR1rhargs1rx1r+r]rrrAs r4rs_funrs@ B $ "FB DH A "IQ E B Qw !B%Z 2Y  !S GBNE " bM5MqwwyA AA qT!A$q'  RDHd2h 7B Ir6c|j}i}|jD]+\}}t|}||xx|z cc<||t|<-||S)zF Return `p*x_i**n`. `x\_i` is the ith variable in ``p``. rr,r#rRr/rCrTr.r]rJryk1s r4rrUsY A A 1 !W 1 %)  Q4Kr6c|j}i}|jD]+\}}t|}||xx|zcc<||t|<-||S)aH >>> from sympy.polys.domains import QQ >>> from sympy.polys.puiseux import puiseux_ring >>> from sympy.polys.ring_series import pow_xin >>> R, x, y = puiseux_ring('x, y', QQ) >>> p = x**QQ(2,5) + x + x**QQ(2,3) >>> index = p.ring.gens.index(x) >>> pow_xin(p, index, 15) x**6 + x**10 + x**15 rrs r4rQrQcsY A A 1 !W 1 %)  Q4Kr6ct||rtt||||S|j}|j}||vr t dt |}||dk(sJ|d}|dk(r|S|dk(r|dS|dk(r|S|dkr| }d}nd}t|D]/}t||dz||} t| |||} |||z | |z z z }1|r|St|||S)z_ Univariate series expansion of the nth root of ``p``. The Newton method is used. rrMr) rKr^ _nth_root1rrrr r=rrrr) r/rTrArBr.rr+signrtmps r4rrvs Q:q!Q55 A B {!">??q A R5A:: 1BAvAvt Av1u Bd#RQ5)S!Q& bdSUl  !"a..r6c |dk(r!|dk(r td|jdS|dk(r t|||S|j}|jj | t | fd }t | | }||z}t|dz |rs|j}||}t|tr' |j}||td|z} n ||td|z} t||z |||| z} nt!||||} |rt||z }t | |} | S#t$r tdwxYw#t$r tdwxYw)a Multivariate series expansion of the nth root of ``p``. Parameters ========== p : Expr The polynomial to computer the root of. n : integer The order of the root to be computed. x : :class:`~.PolyElement` prec : integer Order of the expanded series. Notes ===== The result of this function is dependent on the ring over which the polynomial has been defined. If the answer involves a root of a constant, make sure that the polynomial is over a real field. It cannot yet handle roots of symbols. Examples ======== >>> from sympy.polys.domains import QQ, RR >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_nth_root >>> R, x, y = ring('x, y', QQ) >>> rs_nth_root(1 + x + x*y, -3, x, 3) 2/9*x**2*y**2 + 4/9*x**2*y + 2/9*x**2 - 1/3*x*y - 1/3*x + 1 >>> R, x, y = ring('x, y', RR) >>> rs_nth_root(3 + x + x*y, 3, x, 2) 0.160249952256379*x*y + 0.160249952256379*x + 1.44224957030741 rz0**0 expressionrMc|Srrbrs r4rfzrs_nth_root..rr6rg3The given series cannot be expanded in this domain.)rIrrEr?r@rrrrrNras_exprrr rrr) r/rTrArBr.rxrrc_exprconstr<r@s @r4rrsH Av 6./ /66!9 Av1d## A FFLLOE A%&u-A51"AAID!a%# \\ bE a % $&2a8,-  $!Xa^+,!A#q!T*50Aq$' qEAIc5!$ J $!##$$ $  $!##$$ $s8%D6E6E E#cHt||rtt|||S|j}|dk(r |jSt ||}|rfd}|dk(r |j }|t|}|j|}t|t|||||dz }t|||zSt#t$rb|jtg}|j|}|j|}|j|}|t|}YwxYw)a The Logarithm of ``p`` modulo ``O(x**prec)``. Notes ===== Truncation of ``integral dx p**-1*d p/dx`` is used. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.puiseux import puiseux_ring >>> from sympy.polys.ring_series import rs_log >>> R, x = puiseux_ring('x', QQ) >>> rs_log(1 + x, x, 8) x + -1/2*x**2 + 1/3*x**3 + -1/4*x**4 + 1/5*x**5 + -1/6*x**6 + 1/7*x**7 >>> rs_log(x**QQ(3, 2) + 1, x, 5) x**(3/2) + -1/2*x**3 + 1/3*x**(9/2) rMr)rKr[rs_logrr'rrrrIadd_gensset_ringdiffrrrrr)r/rArBr.rrrdlogs r4rrs*Q&!Q-- AAvvv 1a A 6  #YY[Fc&kNEvvayd.q!T:AtaxHD!$u,,!! # CK=)A 1 A 1 A 1 Ac&kNE  #s!B66A(D! D!c~t||rtt|||S|j}|d}t ||r t d||j vrat|D]Q}t|||}t|||||z }t||dz||}t|||}t||||} || z}S|St )a Calculate the series expansion of the principal branch of the Lambert W function. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_LambertW >>> R, x, y = ring('x, y', QQ) >>> rs_LambertW(x + x*y, x, 3) -x**2*y**2 - 2*x**2*y - x**2 + x*y + x See Also ======== LambertW rz>Polynomial must not have constant term in the series variablesrM) rKr[ rs_LambertWrrrr?r=rs_exprrr) r/rArBr.r+rrdrmp3rs r4rrs(Q+q!T22 A 1B!Q!#9: :AFF{!$' Er1e$A2q%(1,B261e,B$RE2BRE*C #IB   !!r6c|j}|d}t|D]%}|t|||z }t||||}||z }'|S)zHelper function for `rs\_exp`. rM)rr=rrr)r/rArBr.r+rptrs r4_exp1r8s[ A 1Bd# Au% %RQ& c  Ir6ct||rtt|||S|j}t ||}|r7 |j }|t |}||z }|t|||zSt|dkDr t|||S|d}d} g}t|D] } |j|| z | dz } | | z} "t||||} | S#t$rb|jt g}|j|}|j|}|j|}|t |}YwxYw)a: Exponentiation of a series modulo ``O(x**prec)`` Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_exp >>> R, x = ring('x', QQ) >>> rs_exp(x**2, x, 7) 1/6*x**6 + 1/2*x**4 + x**2 + 1 rrM)rKr[rrrrrrIrrrvrrurr) r/rArBr.rrrr+rrTrJrXs r4rrBsFQ&!Q-- A1a A #YY[Fc&kNEUVB4((( 1v{Q4  A$C A A 4[ Q Q Q Aq!T*A H1 # CK=)A 1 A 1 A 1 Ac&kNE  #s!CA(E?Ec|j}|d}| g}t|||}td|D]}|j||zd|zdzz !t ||||}t ||||}|S)zS Expansion using formula. Faster on very small and univariate series. rrMr8rr|rurrrr) r/rerBr.morrmrJrs r4_atanrrs A 2B A 1b$ B 1d^" Q!a!"B2t,Aq!RA Hr6cDt||rtt|||S|j}d}t ||}|r" |j }|t |}|j|}t||||dz}t|||dz }t||||dz }t|||zS#t$rb|jt g}|j|}|j|}|j|}|t |}YwxYw)a The arctangent of a series Return the series expansion of the atan of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_atan >>> R, x, y = ring('x, y', QQ) >>> rs_atan(x + x*y, x, 4) -1/3*x**3*y**3 - x**3*y**2 - x**3*y - 1/3*x**3 + x*y + x See Also ======== atan rrM)rKr[rs_atanrrrrrIrrrr|rrrr r/rArBr.rrrdpr+s r4rrs*Q'1a.. A E1a A $YY[Fd6lOE B 1a 1 %B RD1H -B B4!8 $B A  && $ DL>*A 1 A 1 A 1 Ad6lOE  $s!B44A(DDc*t||rtt|||St||r t d|j }||j vrt|dkDrMt||}dt|||dz z }t|d||dz }t||||dz }t||S|d}d|dg}td|dD]9}|j|dz dz|dz||dz zz |jd;t||||St)a Arcsine of a series Return the series expansion of the asin of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_asin >>> R, x, y = ring('x, y', QQ) >>> rs_asin(x, x, 8) 5/112*x**7 + 3/40*x**5 + 1/6*x**3 + x See Also ======== asin z:Polynomial must not have constant term in series variablesrrMrrr~r8)rKr[rs_asinrrrr?rvrr|rrrrrurr) r/rArBr.rr+rrrJs r4rrs-*Q'1a..!Q!#78 8 AAFF{ q6B;ABYq!TAX..BRQq1BB4!8,BA& &d QKq$" A HHa!eaZ"%q!a%y1 2 HHQK #1aD11"!r6c |j}|d}t|D]3}|t|||z }t|dt |||z||}||z }5|S)a Helper function of :func:`rs_tan`. Return the series expansion of tan of a univariate series using Newton's method. It takes advantage of the fact that series expansion of atan is easier than that of tan. Consider `f(x) = y - \arctan(x)` Let r be a root of f(x) found using Newton's method. Then `f(r) = 0` Or `y = \arctan(x)` where `x = \tan(y)` as required. rrM)rr=rrrr|r/rArBr.r+rrs r4_tan1rsk A 1Bd#'"a''S!iAu55q%@ c  Ir6cbt||rtt|||}|S|j}d}t ||}|rX |j }|t |}||z }t|||} td|| zz ||} t|| z| ||S|jdk(r t|||St|t||S#t$rb|jt g}|j|}|j|}|j|}|t |}YwxYw)a Tangent of a series. Return the series expansion of the tan of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_tan >>> R, x, y = ring('x, y', QQ) >>> rs_tan(x + x*y, x, 4) 1/3*x**3*y**3 + x**3*y**2 + x**3*y + 1/3*x**3 + x*y + x See Also ======== _tan1, tan rrM)rKr[rs_tanrrrrrIrrrrrrkrr) r/rArBrXr.rrrr+t2rs r4rrs'*Q vq!T * A E1a A #YY[Fc&kNEUB4  E"H a 6ebj!Q--ww!|Q4  aD))% # CM?+A 1 A 1 A 1 Ac&kNE  #s!CA(D.-D.c0t||rtt|||}|St||d\}}t |d|zz}t |||\}}t ||| }t|||}t||||} t | || } t| ||} | S)a Cotangent of a series Return the series expansion of the cot of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_cot >>> R, x, y = ring('x, y', QQ) >>> rs_cot(x, x, 6) -2/945*x**5 - 1/45*x**3 - 1/3*x + x**(-1) See Also ======== cot cotr8) rKr[rs_cotrrH rs_cos_sinrrrrrE) r/rArBrXrCrxprec1rrr<s r4rr%s.Q vq!T * Q5 )DAq qs OE aE "DAq1qbAAq%(A Aq% C #q1" C 34 C Jr6ct||rtt|||S|j}|s|dSt ||}|rS |j }|t ||t|}}||z }t|||\} } | |z| |zzSt|dkDrM|jdk(r>t|dz ||} t| ||}t!d|z||}t#|d| z||S|d} d} dg}t%d|dzdD]3}|j'| | z |j'd| | |dzzz} 5t)||||S#t$r~|jt t|g}|j|}|j|}|j|}|t ||t|}}YbwxYw)a9 Sine of a series Return the series expansion of the sin of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.puiseux import puiseux_ring >>> from sympy.polys.ring_series import rs_sin >>> R, x, y = puiseux_ring('x, y', QQ) >>> rs_sin(x + x*y, x, 4) x + x*y + -1/6*x**3 + -1/2*x**3*y + -1/2*x**3*y**2 + -1/6*x**3*y**3 >>> rs_sin(x**QQ(3, 2) + x*y**QQ(7, 5), x, 4) x*y**(7/5) + x**(3/2) + -1/6*x**3*y**(21/5) + -1/2*x**(7/2)*y**(14/5) See Also ======== sin rrrMr8)rKr[rs_sinrrrrrrIrrrrvrkrr|rrrrurrr/rArBr.rrt1rr+p_cosp_sinrrrTrJs r4r r Is.Q&!Q-- A t 1a A 4YY[Fs6{^Qs6{^BU""a. uRx%("" 1v{qww!| 1Q34  q!T " RD 1b!A#q$'' A$C A A 1dQh " Q   aRQZ q!Q --7 4 CKV56A 1 A 1 A 1 As6{^Qs6{^B  4s2EBGGct||rtt|||S|j}t ||}|rS |j }|t ||t|}}||z }t|||\} } | |z| |zz St|dkDrM|jdk(r>t|dz ||} t| ||}t!d|z||}t#|d|z ||S|d} d} g}t%d|dzdD]3}|j'| | z |j'd| | |dz zz} 5t)||||S#t$r~|jt t|g}|j|}|j|}|j|}|t ||t|}}YawxYw)a Cosine of a series Return the series expansion of the cos of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.puiseux import puiseux_ring >>> from sympy.polys.ring_series import rs_cos >>> R, x, y = puiseux_ring('x, y', QQ) >>> rs_cos(x + x*y, x, 4) 1 + -1/2*x**2 + -1*x**2*y + -1/2*x**2*y**2 >>> rs_cos(x + x*y, x, 4)/x**QQ(7, 5) x**(-7/5) + -1/2*x**(3/5) + -1*x**(3/5)*y + -1/2*x**(3/5)*y**2 See Also ======== cos rrMr8r)rKr[rs_cosrrrrrrIrrrrvrkrr|rrrrurrr s r4rrs.Q&!Q-- A1a A 4YY[Fs6{^Qs6{^BU""a. uRx%("" 1v{qww!| 1Q34  q!T " 2q$ /b!b&!T** A$C A A 1dQh " Q   aRQZ q!Q --5 4 CKV56A 1 A 1 A 1 As6{^Qs6{^B  4s2EBG Gc>t||rtt|||S|j}|s|d|dfSt ||}|r^ |j }|t ||t|}}||z }t|||\} } | |z| |zz | |z| |zzfSt|dkDr^|jdk(rOt|dz ||} t| ||}td|z||}t!|d|z ||t!|d| z||fS|d} g} d\}}t#d|dzdD]7}| j%| |z dfd| |z fg| |z|dz z| |z|dzz}}9t'| \}}t)||||t)||||fS#t$r~|jt t|g}|j|}|j|}|j|}|t ||t|}}YwxYw)a Cosine and sine of a series Return the series expansion of the cosine and sine of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_cos_sin >>> R, x, y = ring('x, y', QQ) >>> c, s = rs_cos_sin(x + x*y, x, 4) >>> c -1/2*x**2*y**2 - x**2*y - 1/2*x**2 + 1 >>> s -1/6*x**3*y**3 - 1/2*x**3*y**2 - 1/2*x**3*y - 1/6*x**3 + x*y + x See Also ======== rs_cos, rs_sin rrrMr8)rMrM)rKr[rrrrrrrIrrrvrkrr|rrrruextendr*r)r/rArBr.rrr rr+rrrrcoeffscnsnrJrs r4rrs=0Q*aD11 A tQqTz1a A 4YY[Fs6{^Qs6{^BU!"a. uRx%("E"HuRx$777 1v{qww!| 1Q34  q!T " RD 1r1r61d+VB!Q-EFF A$C F FB 1d1fa . B{QBK01QAAq1u B. >> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_atanh >>> R, x, y = ring('x, y', QQ) >>> rs_atanh(x + x*y, x, 4) 1/3*x**3*y**3 + x**3*y**2 + x**3*y + 1/3*x**3 + x*y + x See Also ======== atanh rrrM)rKr[rs_atanhrrrrrIr rr|rrrrrs r4rrs*Q(Aq$// A E1a A YY[FeFm$E AB Q4 1 $B RD1H -B B4!8 $B A  &&    s !B**B?ct||rtt|||S|j}d}t ||}|r" |j }|t |}t||}t|||}||dz} t| d||dz } t|| ||dz } t| ||zS#t$r tdwxYw)a Hyperbolic arcsine of a series Return the series expansion of the arcsinh of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_asinh >>> R, x = ring('x', QQ) >>> rs_asinh(x, x, 9) -5/112*x**7 + 3/40*x**5 - 1/6*x**3 + x See Also ======== asinh rrrMr)rKr[rs_asinhrrrrrIr rr|rrrr) r/rArBr.rrrr p_squareddenomr+s r4rr:s*Q(Aq$// A E1a A YY[FeFm$E AB!Q%I ! E UB4!8 ,B B4!8 $B A  &&    s !B22Cct||rtt|||S|j}|s|dSt ||}|rS |j }|t ||t|}}||z }t|||\} } | |z| |zzSt|||} t| ||}| |z dz S#t$r}|jt t|g}|j|}|j|}|j|}|t ||t|}}YwxYw)a Hyperbolic sine of a series Return the series expansion of the sinh of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_sinh >>> R, x, y = ring('x, y', QQ) >>> rs_sinh(x + x*y, x, 4) 1/6*x**3*y**3 + 1/2*x**3*y**2 + 1/2*x**3*y + 1/6*x**3 + x*y + x See Also ======== sinh rr8)rKr[rs_sinhrrrrrrIrr rs_cosh_sinhrr r/rArBr.rrr rr+p_coshp_sinhrs r4r r f2*Q'1a.. A t 1a A 6YY[FtF|_aV oBU%b!T2{Vb[((q!TA Q4 (B FA: 6 DL$v,78A 1 A 1 A 1 AtF|_aV oB  62B88BD>=D>ct||rtt|||S|j}|s|dSt ||}|rS |j }|t ||t|}}||z }t|||\} } | |z| |zzSt|||} t| ||}| |zdz S#t$r}|jt t|g}|j|}|j|}|j|}|t ||t|}}YwxYw)a Hyperbolic cosine of a series Return the series expansion of the cosh of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_cosh >>> R, x, y = ring('x, y', QQ) >>> rs_cosh(x + x*y, x, 4) 1/2*x**2*y**2 + x**2*y + 1/2*x**2 + 1 See Also ======== cosh rr8)rKr[rs_coshrrrrrrIrrr!rrr"s r4r(r(r%r&ct||rtt|||S|j}|s|d|dfSt ||}|r^ |j }|t ||t|}}||z }t|||\} } | |z| |zz| |z| |zzfSt|||} t| ||}| |zdz | |z dz fS#t$r}|jt t|g}|j|}|j|}|j|}|t ||t|}}YwxYw)a2 Hyperbolic cosine and sine of a series Return the series expansion of the hyperbolic cosine and sine of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_cosh_sinh >>> R, x, y = ring('x, y', QQ) >>> c, s = rs_cosh_sinh(x + x*y, x, 4) >>> c 1/2*x**2*y**2 + x**2*y + 1/2*x**2 + 1 >>> s 1/6*x**3*y**3 + 1/2*x**3*y**2 + 1/2*x**3*y + 1/6*x**3 + x*y + x See Also ======== rs_cosh, rs_sinh rr8) rKr[r!rrrrrrIrrrrr"s r4r!r!sZ0Q,1d33 A tQqTz1a A 6YY[FtF|_aV oBU%b!T2{Vb[(&2+ *CCCq!TA Q4 (B FA:Bz !! 6 DL$v,78A 1 A 1 A 1 AtF|_aV oB  6s 2CBEEc |j}|d}t|D]3}|t|||z }t|dt |||z ||}||z }5|S)a  Helper function of :func:`rs_tanh` Return the series expansion of tanh of a univariate series using Newton's method. It takes advantage of the fact that series expansion of atanh is easier than that of tanh. See Also ======== _tanh rrM)rr=rrrr|rs r4_tanhr+sk A 1Bd#(2q%((S!iAt44a? c  Ir6c^t||rtt|||S|j}d}t ||}|rX |j }|t |}||z }t|||}td||zz||} t||z| ||S|jdk(r t|||St|t||S#t$rb|jt g}|j|}|j|}|j|}|t |}YwxYw)a Hyperbolic tangent of a series Return the series expansion of the tanh of ``p``, about 0. Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_tanh >>> R, x, y = ring('x, y', QQ) >>> rs_tanh(x + x*y, x, 4) -1/3*x**3*y**3 - x**3*y**2 - x**3*y - 1/3*x**3 + x*y + x See Also ======== tanh rrM)rKr[rs_tanhrrrrrIrrrrrrkr+r) r/rArBr.rrrr+r rs r4r-r- s!*Q'1a.. A E1a A $YY[Fd6lOEU RD ! E"H a 6ebj!Q--ww!|Q4  a4(( $ DL>*A 1 A 1 A 1 Ad6lOE  $s!CA(D,+D,c|j}t|}t|||}t|j ||||}|||zz }|S)aO Compute the truncated Newton sum of the polynomial ``p`` Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_newton >>> R, x = ring('x', QQ) >>> p = x**2 - 2 >>> rs_newton(p, x, 5) 8*x**4 + 4*x**2 + 2 )r&r5rrrr)r/rArBr-r+rmrr<s r4 rs_newtonr/8sQ ((*C  B RD )B  B4 (B 1*C Jr6cD|j}|jtk7rt|j}|s7|j D]"\}}|t t|dz ||<$|S|j D]"\}}|t t|dz||<$|S)a Return ``sum f_i/i!*x**i`` from ``sum f_i*x**i``, where ``x`` is the first variable. If ``inverse=True`` return ``sum f_i*i!*x**i`` Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_hadamard_exp >>> R, x = ring('x', QQ) >>> p = 1 + x + x**2 + x**3 >>> rs_hadamard_exp(p) 1/6*x**3 + 1/2*x**2 + x + 1 r)rrrrr'r$rHr)r+inverser.r/rDros r4rs_hadamard_expr2Ns$ Axx2~!! A   ,HD"T$q']++AdG , H  ,HD"T$q']++AdG , Hr6c|j}|jd}|j|jzdz}t|||}t |}t|||}t |}t ||||} t | d} | d| z |z } t | |} t| ||} t| } | jd} |j|jz| jz } | r| || zz} | S)a} compute the composed sum ``prod(p2(x - beta) for beta root of p1)`` Examples ======== >>> from sympy.polys.domains import QQ >>> from sympy.polys.rings import ring >>> from sympy.polys.ring_series import rs_compose_add >>> R, x = ring('x', QQ) >>> f = x**2 - 2 >>> g = x**2 - 3 >>> rs_compose_add(f, g) x**4 - 10*x**2 + 1 References ========== .. [1] A. Bostan, P. Flajolet, B. Salvy and E. Schost "Fast Computation with Two Algebraic Numbers", (2002) Research Report 4579, Institut National de Recherche en Informatique et en Automatique rrMT)r) rr?r&r/r2rrrrr5 primitive)r+rmr.rArBnp1np1enp2np2enp3enp3np3ar]rs r4rs_compose_addr<ls0 A q A 99;ryy{ "Q &D B4 C 3 D B4 C 3 D $a &D $ %C IOq DT1Aq!TAqA aA RYY[ 188: -B aeG Hr6r rrrrrr r(r-) rrrrrrrrrcd}d}|dk(rt||||}|dz}|dk(r|j}||}|jj|t |fdS)z=Find the minimum power of `a` in the series expansion of exprrr8c|Srrb)rrCs r4rfzrs_min_pow..s QqTr6rg) _rs_seriesrr?r@r)expr series_rsrseriesrTr.rCs @r4 rs_min_powrCsm F A A+D)Q2 Q A+  A !A  QA v> *1 --r6c |j}|j}td|Ds|js|S|j |s|S|jr|d}t |dkDrt t|tdd\}}t||||} |j|j| j}| j|} ttt|j| |||}|S|j r#t |} |D]1}|j"rt|dd\}} |j|}3t%t't(||Dcgc] }|| c}|gt |z} t+| } |d}t-| D]p}t||||||t/|| z | |z}|j|j}|j|}|j|}||z}rt1||||}|S|j2rt |} |d}t-| D]^}t|||||||}|j|j}|j|}|j|}||z }`|S|j4rt|j6tdd\}} |j|}t|j6||j6||} t9| |j:| j||St=|t>r&|jArt|tdddSt cc}w)Nc3FK|]}|jtywr)hasr)rargs r4rz_rs_series..s1Sswwx 1s!rrMFTrexpandrB)rIrB)!rrr is_FunctionrFrvrrrr?composereval _convert_funcrfuncis_Mul is_Numberr#maprCsumrurrEis_Addis_PowbaserrrNr is_constant)r@rArrBrr.rGrrB series_innerrT_min_powssum_powsrC_seriess r4r?r?sD 99DA 1D1 1$:J:J 88A;  1g t9q=% %3r%E F!#vq$7  IIbM ! !,"3"3 4#,,Q/ 4mC N34\ aD$  I "C==c%=AIIbM "J.F#qv.F CD Mx=1q A a!DG*aB%a[B):*+G ',,'A&&q)G__Q'F g F  &!A$-  I1q A a!DG*a>G ',,'A&&q)G__Q'F g F    dii5FA IIbM!$))Qtyy\1dC lDHHl.?.?.BDII D$ D$4$4$6T"U4@CC"!M/Gs'N c0t|tdd\}}||jvr|j|g}|j |}t ||||}|j }||}|j|dz}||k\r t|||StddD]}t |||||z}|j |j }|j|dz} | |k7rt|||z |z| |z z z} t |||| }|j|dz|krGt |||| }|j |j }| dz} |j|dz|krGnntdt|d |t|||S) a/Return the series expansion of an expression about 0. Parameters ========== expr : :class:`~.Expr` a : :class:`~.Symbol` with respect to which expr is to be expanded prec : order of the series expansion Currently supports multivariate Taylor series expansion. This is much faster that SymPy's series method as it uses sparse polynomial operations. It automatically creates the simplest ring required to represent the series expansion through repeated calls to sring. Examples ======== >>> from sympy.polys.ring_series import rs_series >>> from sympy import sin, cos, exp, tan, symbols, QQ >>> a, b, c = symbols('a, b, c') >>> rs_series(sin(a) + exp(a), a, 5) 1/24*a**4 + 1/2*a**2 + 2*a + 1 >>> series = rs_series(tan(a + b)*cos(a + c), a, 2) >>> series.as_expr() -a*sin(c)*tan(b) + a*cos(c)*tan(b)**2 + a*cos(c) + cos(c)*tan(b) >>> series = rs_series(exp(a**QQ(1,3) + a**QQ(2, 5)), a, 1) >>> series.as_expr() a**(11/15) + a**(4/5)/2 + a**(2/5) + a**(2/3)/2 + a**(1/3) + 1 FTrHrM )rBr8zCould not calculate z terms for ) rrsymbolsrrr?rr&rErurrIr) r@rrBr.rBgenprec_gotmorer+new_precprec_dos r4 rs_seriesrd s@d2eDAIAv  JJu  __Q F fa .F A A$C}}S!A%H4T** !QK 2DD&!$+>B,,rww'Cyy~)H8#!$$/4)?B*#fag>iinq(4/#D&!'BB,,rww/CqLGiinq(4/ 2  #D 412 2C&&r6)rM)F)a__doc__sympy.polys.domainsrrsympy.polys.ringsrrrsympy.polys.puiseuxrsympy.polys.polyerrorsr sympy.polys.monomialsr r r r mpmath.libmp.libintmathr sympy.corerrrsympy.core.numbersrsympy.core.intfuncrsympy.functionsrrrrrrrrrrrrsympy.utilities.miscr r!r9r5r=rErKr[r^rrr|rrrrrrrrrrrrrrrQrrrrrrrrrrrrr rrrrrr r(r!r+r-r/r2r<rMrCr?rdrbr6r4rqs)V'66+.22(00'#2222'/  >62% N 20d%N4 lBH<. &.`$ L F PS j@@6p &!/FGR-"^%"N. ` ,'\+"Z*1*f"H<.|9.v;Tz )'V*'X,\,\/"d*-)^, <0 h   .S"jB'r6