K i2tdZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)ddl*m+Z+m,Z,ddl-m.Z/m0Z1dZ2dZ3dZ4d Z5d Z6d Z7d Z8d Z9dZ:dZ;dZdZ?dZ@dZAdZBdZCdZDdZEdZFdZGdZHdZIdZJdZKd ZLd!ZMd"ZNd#ZOd$ZPd%ZQd&ZRd'ZSd(ZTd)ZUd*ZVd+ZWd,ZXd-ZYd.ZZd/Z[d0Z\d1Z]d8d3Z^d4Z_d8d5Z`d6Zad7Zby2)9zHAdvanced tools for dense recursive polynomials in ``K[x]`` or ``K[X]``. ) dup_add_term dmp_add_term dup_lshiftdup_adddmp_adddup_subdmp_subdup_muldmp_muldup_sqrdup_divdup_remdmp_remdup_mul_grounddmp_mul_grounddup_quo_grounddmp_quo_grounddup_exquo_grounddmp_exquo_ground) dup_strip dmp_strip dup_convert dmp_convert dup_degree dmp_degree dmp_to_dict dmp_from_dictdup_LCdmp_LC dmp_ground_LCdup_TCdmp_TCdmp_zero dmp_ground dmp_zero_pdup_to_raw_dictdup_from_raw_dict dmp_zeros dmp_include)MultivariatePolynomialError DomainError)ceillog2c |dks|s|S|jg|z}tt|D]N\}}|dz}td|D] }|||zdzz}|j d|j |||P|S)a Computes the indefinite integral of ``f`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x = ring("x", QQ) >>> R.dup_integrate(x**2 + 2*x, 1) 1/3*x**3 + x**2 >>> R.dup_integrate(x**2 + 2*x, 2) 1/12*x**4 + 1/3*x**3 r)zero enumeratereversedrangeinsertexquo)fmKgicnjs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/densetools.py dup_integrater?'s  AvQ  A(1+&&1 Eq! A QNA  AGGAqt$% & Hc 6|s t|||S|dks t||r|St||dz ||dz }}tt |D]J\}}|dz}t d|D] } ||| zdzz}|j dt|||||L|S)a& Computes the indefinite integral of ``f`` in ``x_0`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x,y = ring("x,y", QQ) >>> R.dmp_integrate(x + 2*y, 1) 1/2*x**2 + 2*x*y >>> R.dmp_integrate(x + 2*y, 2) 1/6*x**3 + x**2*y rr/)r?r%r(r1r2r3r4r) r6r7ur8r9vr:r;r<r=s r> dmp_integraterDGs Q1%%AvAq! QAq !1q5qA(1+&31 Eq! A QNA  N1adAq12 3 Hr@c ||k(rt||||S|dz |dz}}t|Dcgc]}t||||||c}|Scc}w)z.Recursive helper for :func:`dmp_integrate_in`.r/)rDr_rec_integrate_inr9r7rCr:r=r8wr;s r>rFrFjsVAvQ1a(( q5!a%qA AGq(Aq!Q:G KKGAcV|dks||kDrtd||fzt|||d||S)a+ Computes the indefinite integral of ``f`` in ``x_j`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x,y = ring("x,y", QQ) >>> R.dmp_integrate_in(x + 2*y, 1, 0) 1/2*x**2 + 2*x*y >>> R.dmp_integrate_in(x + 2*y, 1, 1) x*y + y**2 rz(0 <= j <= u expected, got u = %d, j = %d) IndexErrorrFr6r7r=rBr8s r>dmp_integrate_inrMts;  1uACq!fLMM Q1aA ..r@cT|dkr|St|}||krgSg}|dk(r5|d| D]!}|j|||z|dz}#t|S|d| D]@}|}t|dz ||z dD]}||z} |j|||z|dz}Bt|S)a# ``m``-th order derivative of a polynomial in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_diff(x**3 + 2*x**2 + 3*x + 4, 1) 3*x**2 + 4*x + 3 >>> R.dup_diff(x**3 + 2*x**2 + 3*x + 4, 2) 6*x + 4 rr/N)rappendr3r)r6r7r8r<derivcoeffkr:s r>dup_diffrTs  Av1 A1u EAvsV E LL1e $ FA  U sV EA1q5!a%, Q  LL1e $ FA  U r@c |s t|||S|dkr|St||}||kr t|Sg|dz }}|dk(r4|d| D]*}|jt ||||||dz},nR|d| D]I}|}t |dz ||z dD]} || z} |jt ||||||dz}Kt ||S)a3 ``m``-th order derivative in ``x_0`` of a polynomial in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = x*y**2 + 2*x*y + 3*x + 2*y**2 + 3*y + 1 >>> R.dmp_diff(f, 1) y**2 + 2*y + 3 >>> R.dmp_diff(f, 2) 0 rr/NrO)rTrr#rPrr3r) r6r7rBr8r<rQrCrRrSr:s r>dmp_diffrVs $ 1a  Av1aA1u{1q51EAvsV E LLqtQ: ; FA sV EA1q5!a%, Q  LLqtQ: ; FA  UA r@c ||k(rt||||S|dz |dz}}t|Dcgc]}t||||||c}|Scc}w)z)Recursive helper for :func:`dmp_diff_in`.r/)rVr _rec_diff_inrGs r>rXrXUAv1a## q5!a%qA qB!|Aq!Q15BA FFBrIcX|dks||kDrtd|d|t|||d||S)aS ``m``-th order derivative in ``x_j`` of a polynomial in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = x*y**2 + 2*x*y + 3*x + 2*y**2 + 3*y + 1 >>> R.dmp_diff_in(f, 1, 0) y**2 + 2*y + 3 >>> R.dmp_diff_in(f, 1, 1) 2*x*y + 2*x + 4*y + 3 r 0 <= j <=  expected, got )rKrXrLs r> dmp_diff_inr]6$ 1uAAqABB 1aAq ))r@cz|s|jt||S|j}|D] }||z}||z }|S)z Evaluate a polynomial at ``x = a`` in ``K[x]`` using Horner scheme. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_eval(x**2 + 2*x + 3, 2) 11 )convertr!r0)r6ar8resultr;s r>dup_evalrcsM yy1&& VVF ! !  Mr@c|s t|||S|s t||St|||dz }}|ddD]}t||||}t ||||} |S)z Evaluate a polynomial at ``x_0 = a`` in ``K[X]`` using the Horner scheme. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_eval(2*x*y + 3*x + y + 2, 2) 5*y + 8 r/N)rcr"rrr)r6rarBr8rbrCrRs r>dmp_evalre st 1a  a|q! a!eAF12.1a01-. Mr@c ||k(rt||||S|dz |dz}}t|Dcgc]}t||||||c}|Scc}w)z)Recursive helper for :func:`dmp_eval_in`.r/)rer _rec_eval_in)r9rarCr:r=r8r;s r>rgrg=rYrIcX|dks||kDrtd|d|t|||d||S)a2 Evaluate a polynomial at ``x_j = a`` in ``K[X]`` using the Horner scheme. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = 2*x*y + 3*x + y + 2 >>> R.dmp_eval_in(f, 2, 0) 5*y + 8 >>> R.dmp_eval_in(f, 2, 1) 7*x + 4 rr[r\)rKrg)r6rar=rBr8s r> dmp_eval_inriGr^r@c ||k(rt||d|S|Dcgc]}t||dz|||}}||t|z dzkr|St||| |zdz |Scc}w)z+Recursive helper for :func:`dmp_eval_tail`.rOr/)rc_rec_eval_taillen)r9r:ArBr8r;hs r>rkrk_s{Av1R5!$$9: >> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = 2*x*y + 3*x + y + 2 >>> R.dmp_eval_tail(f, [2]) 7*x + 4 >>> R.dmp_eval_tail(f, [2, 2]) 18 rr/)r%r#rlrkr)r6rmrBr8es r> dmp_eval_tailrqlsd$ !QCF ##q!Q1%ACFQJAAJ''r@c||k(rtt|||||||S|dz |dz}}t|Dcgc]}t|||||||c}|Scc}w)z+Recursive helper for :func:`dmp_diff_eval`.r/)rerVr_rec_diff_eval)r9r7rarCr:r=r8r;s r>rsrssbAvAq!,aA66 q5!a%qA AGq~aAq!Q:G KKGsAc ||kDrtd|d|d||stt|||||||St||||d||S)a] Differentiate and evaluate a polynomial in ``x_j`` at ``a`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = x*y**2 + 2*x*y + 3*x + 2*y**2 + 3*y + 1 >>> R.dmp_diff_eval_in(f, 1, 2, 0) y**2 + 2*y + 3 >>> R.dmp_diff_eval_in(f, 1, 2, 1) 6*x + 11 -z <= j < r\r)rKrerVrs)r6r7rar=rBr8s r>dmp_diff_eval_inrvsS$ 1uQ1EFF Aq!,aA66 !Q1aA ..r@c||jrGg}|D]5}||z}||dzkDr|j||z %|j|7t |S|jr7t|}|Dcgc]}|t||z}}t |S|Dcgc]}||z }}t |Scc}wcc}w)z Reduce a ``K[x]`` polynomial modulo a constant ``p`` in ``K``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_trunc(2*x**3 + 3*x**2 + 5*x + 7, ZZ(3)) -x**3 - x + 1 )is_ZZrPis_FiniteFieldintr)r6pr8r9r;pis r> dup_truncr~s ww  AAA16zQ   Q<   V&' )aA n ) ) Q< a!e  Q< * s /B4 B9c ^t|Dcgc]}t|||dz |c}|Scc}w)a9 Reduce a ``K[X]`` polynomial modulo a polynomial ``p`` in ``K[Y]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3 >>> g = (y - 1).drop(x) >>> R.dmp_trunc(f, g) 11*x**2 + 11*x + 5 r/)rr)r6r|rBr8r;s r> dmp_truncrs." ;1wq!QUA.;Q ??;s*c |s t|||S|dz }t|Dcgc]}t||||c}|Scc}w)a  Reduce a ``K[X]`` polynomial modulo a constant ``p`` in ``K``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3 >>> R.dmp_ground_trunc(f, ZZ(3)) -x**2 - x*y - y r/)r~rdmp_ground_trunc)r6r|rBr8rCr;s r>rrsF Aq!! AA Q@'1a3@! DD@s;cb|s|St||}|j|r|St|||S)a7 Divide all coefficients by ``LC(f)`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x = ring("x", ZZ) >>> R.dup_monic(3*x**2 + 6*x + 9) x**2 + 2*x + 3 >>> R, x = ring("x", QQ) >>> R.dup_monic(3*x**2 + 4*x + 2) x**2 + 4/3*x + 2/3 )ris_oner)r6r8lcs r> dup_monicrs6$  1Bxx|2q))r@c|s t||St||r|St|||}|j|r|St ||||S)a Divide all coefficients by ``LC(f)`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x,y = ring("x,y", ZZ) >>> f = 3*x**2*y + 6*x**2 + 3*x*y + 9*y + 3 >>> R.dmp_ground_monic(f) x**2*y + 2*x**2 + x*y + 3*y + 1 >>> R, x,y = ring("x,y", QQ) >>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3 >>> R.dmp_ground_monic(f) x**2*y + 8/3*x**2 + 5/3*x*y + 2*x + 2/3*y + 1 )rr%r rr)r6rBr8rs r>dmp_ground_monicrsQ, A!Q q!Q Bxx|2q!,,r@cddlm}|s |jS|j}||k(r|D]}|j||}|S|D](}|j||}|j |s'|S|S)aA Compute the GCD of coefficients of ``f`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x = ring("x", ZZ) >>> f = 6*x**2 + 8*x + 12 >>> R.dup_content(f) 2 >>> R, x = ring("x", QQ) >>> f = 6*x**2 + 8*x + 12 >>> R.dup_content(f) 2 rQQ)sympy.polys.domainsrr0gcdr)r6r8rcontr;s r> dup_contentr?s,' vv 66DBw "A55q>D " K  A55q>Dxx~ K   Kr@c Fddlm}|s t||St||r |jS|j|dz }}||k(r&|D]}|j |t |||}!|S|D]3}|j |t |||}|j|s2|S|S)aa Compute the GCD of coefficients of ``f`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x,y = ring("x,y", ZZ) >>> f = 2*x*y + 6*x + 4*y + 12 >>> R.dmp_ground_content(f) 2 >>> R, x,y = ring("x,y", QQ) >>> f = 2*x*y + 6*x + 4*y + 12 >>> R.dmp_ground_content(f) 2 rrr/)rrrr%r0rdmp_ground_contentr)r6rBr8rrrCr;s r>rris,' 1a  !Qvv ffa!e!DBw >> from sympy.polys import ring, ZZ, QQ >>> R, x = ring("x", ZZ) >>> f = 6*x**2 + 8*x + 12 >>> R.dup_primitive(f) (2, 3*x**2 + 4*x + 6) >>> R, x = ring("x", QQ) >>> f = 6*x**2 + 8*x + 12 >>> R.dup_primitive(f) (2, 3*x**2 + 4*x + 6) )r0rrr)r6r8rs r> dup_primitiversI, vvqy q! Dxx~Qw^AtQ///r@c|s t||St||r|j|fSt|||}|j |r||fS|t ||||fS)a Compute content and the primitive form of ``f`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x,y = ring("x,y", ZZ) >>> f = 2*x*y + 6*x + 4*y + 12 >>> R.dmp_ground_primitive(f) (2, x*y + 3*x + 2*y + 6) >>> R, x,y = ring("x,y", QQ) >>> f = 2*x*y + 6*x + 4*y + 12 >>> R.dmp_ground_primitive(f) (2, x*y + 3*x + 2*y + 6) )rr%r0rrr)r6rBr8rs r>dmp_ground_primitiversd, Q""!Qvvqy aA &Dxx~Qw^AtQ222r@ct||}t||}|j||}|j|st|||}t|||}|||fS)a Extract common content from a pair of polynomials in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_extract(6*x**2 + 12*x + 18, 4*x**2 + 8*x + 12) (2, 3*x**2 + 6*x + 9, 2*x**2 + 4*x + 6) )rrrr)r6r9r8fcgcrs r> dup_extractrs^ Q B Q B %%B-C 88C= 1c1 % 1c1 % 19r@ct|||}t|||}|j||}|j|st||||}t||||}|||fS)a Extract common content from a pair of polynomials in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_ground_extract(6*x*y + 12*x + 18, 4*x*y + 8*x + 12) (2, 3*x*y + 6*x + 9, 2*x*y + 4*x + 6) )rrrr)r6r9rBr8rrrs r>dmp_ground_extractrsf Aq! $B Aq! $B %%B-C 88C= 1c1a ( 1c1a ( 19r@c<|js|jstd|ztd}td}|s||fS|j|j gg|jgggg}t |dd}|ddD])}t||d|}t|t |ddd|}+t|}|jD]Q\}}|dz} | st||d|}| dk(rt||d|}0| dk(rt||d|}Dt||d|}S||fS)a Find ``f1`` and ``f2``, such that ``f(x+I*y) = f1(x,y) + f2(x,y)*I``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dup_real_imag(x**3 + x**2 + x + 1) (x**3 + x**2 - 3*x*y**2 + x - y**2 + 1, 3*x**2*y + 2*x*y - y**3 + y) >>> from sympy.abc import x, y, z >>> from sympy import I >>> (z**3 + z**2 + z + 1).subs(z, x+I*y).expand().collect(I) x**3 + x**2 - 3*x*y**2 + x - y**2 + I*(3*x**2*y + 2*x*y - y**3 + y) + 1 z;computing real and imaginary parts is not supported over %sr/rrxN) ryis_QQr+r#oner0r$r rr&itemsrr ) r6r8f1f2r9rnr;HrSr7s r> dup_real_imagrs<& 77177WZ[[\\ !B !B 2v 55!&&/ aeeWbM*A1Q4A qrU7 Aq!Q  Jq!,aA 67 A &1 EQ1%B !VQ1%B !VQ1%BQ1%B & r6Mr@cjt|}tt|dz ddD] }|| ||< |S)z Evaluate efficiently the composition ``f(-x)`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_mirror(x**3 + 2*x**2 - 4*x + 2) -x**3 + 2*x**2 + 4*x + 2 rxrO)listr3rl)r6r8r:s r> dup_mirrorrCsC QA 3q6A:r2 &!u! Hr@ct|t|dz |}}}t|dz ddD]}|||z||zc||<}|S)z Evaluate efficiently composition ``f(a*x)`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_scale(x**2 - 2*x + 1, ZZ(2)) 4*x**2 - 4*x + 1 r/rOrrlr3)r6rar8r<br:s r> dup_scalerYs[1gs1vz1!qA 1q5"b !AaD&!A#!a Hr@ct|t|dz }}t|ddD])}td|D]}||dzxx|||zz cc<+|S)z Evaluate efficiently Taylor shift ``f(x + a)`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_shift(x**2 - 2*x + 1, ZZ(2)) x**2 + 2*x + 1 r/rrOr)r6rar8r<r:r=s r> dup_shiftrosf 7CFQJqA 1a_q! A a!eH!A$ H  Hr@c |st||d|St||r|S|d|dd}}t|r|Dcgc]}t|||dz |}}n t |}|rbt |dz }t |ddD]D}t d|D]3} t|| ||dz |} t|| dz| |dz ||| dz<5Ft||Scc}w)a Evaluate efficiently Taylor shift ``f(X + A)`` in ``K[X]``. Examples ======== >>> from sympy import symbols, ring, ZZ >>> x, y = symbols('x y') >>> R, _, _ = ring([x, y], ZZ) >>> p = x**2*y + 2*x*y + 3*x + 4*y + 5 >>> R.dmp_shift(R(p), [ZZ(1), ZZ(2)]) x**2*y + 2*x**2 + 4*x*y + 11*x + 7*y + 22 >>> p.subs({x: x + 1, y: y + 2}).expand() x**2*y + 2*x**2 + 4*x*y + 11*x + 7*y + 22 rr/NrO) rr%any dmp_shiftrrlr3rrr) r6rarBr8a0a1r;r<r:r=afjs r>rrs& AaD!$$!Q qT1QR5B 2w01 31i2qsA& 3 3 G FQJq!R :A1a[ :$QqT2qsA6"1QU8S!A#q9!a% : : Q? 4sCc4|sgSt|dz }|dg|jgg}}td|D]!}|jt |d||#t |dd|ddD],\}}t |||}t |||}t|||}.|S)a  Evaluate functional transformation ``q**n * f(p/q)`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_transform(x**2 - 2*x + 1, x**2 + 1, x - 1) x**4 - 2*x**3 + 5*x**2 - 4*x + 4 r/rrON)rlrr3rPr ziprr) r6r|qr8r<rnQr:r;s r> dup_transformrs   A A aD6QUUG9qA 1a[' 21%&'AabE1QR5!1 Aq!  1a # Aq!  Hr@c t|dkr!tt|t|||gS|sgS|dg}|ddD]}t |||}t ||d|}|S)z Evaluate functional composition ``f(g)`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_compose(x**2 + x, x - 1) x**2 - x r/rN)rlrrcrr r)r6r9r8rnr;s r> dup_composersy 1v{(1fQlA6788  1A qrU% Aq!  Aq! $% Hr@c|s t|||St||r|S|dg}|ddD]}t||||}t||d||}!|S)z Evaluate functional composition ``f(g)`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_compose(x*y + 2*x + y, y) y**2 + 3*y rr/N)rr%r r)r6r9rBr8rnr;s r> dmp_composersn 1a##!Q 1A qrU( Aq!Q  Aq!Q '( Hr@ct|dz }t||}t|}||ji}||z}t d|D]t}|j }t d|D]9} || z|z |vr|| z |vr||| z|z ||| z } } |||| zz | z| zz };|j |||z|z|||z <vt||S)+Helper function for :func:`_dup_decompose`.r/r)rlrr&rr3r0quor') r6sr8r<rr9rr:rRr=rrs r>_dup_right_decomposer s A A 1BA QUU A QA 1a[ (q! %Aq519>q5A:q1uqy\1QU8B a!A#gr\"_ $E %55!B'!a% ( Q ""r@cid}}|r8t|||\}}t|dkDryt||||<||dz}}|r8t||S)rrNr/)r rrr')r6rnr8r9r:rrs r>_dup_left_decomposer&s_ qqA q!Q1 a=1 !Q_dup_decomposer6sf Q!B 1b\  6Q;  Aq ) =#Aq!,A}!t   r@cLg} t||}| |\}}|g|z}nn|g|zS)ae Computes functional decomposition of ``f`` in ``K[x]``. Given a univariate polynomial ``f`` with coefficients in a field of characteristic zero, returns list ``[f_1, f_2, ..., f_n]``, where:: f = f_1 o f_2 o ... f_n = f_1(f_2(... f_n)) and ``f_2, ..., f_n`` are monic and homogeneous polynomials of at least second degree. Unlike factorization, complete functional decompositions of polynomials are not unique, consider examples: 1. ``f o g = f(x + b) o (g - b)`` 2. ``x**n o x**m = x**m o x**n`` 3. ``T_n o T_m = T_m o T_n`` where ``T_n`` and ``T_m`` are Chebyshev polynomials. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_decompose(x**4 - 2*x**3 + x**2) [x**2, x**2 - x] References ========== .. [1] [Kozen89]_ )r)r6r8Frbrns r> dup_decomposerIsHH A 1%  DAqaA   37Nr@c|js |jr t|||S|jr t |||St d)a Convert polynomial from ``K(a)[X]`` to ``K[a,X]``. Examples ======== >>> from sympy.polys.densetools import dmp_alg_inject >>> from sympy import QQ, sqrt >>> K = QQ.algebraic_field(sqrt(2)) >>> p = [K.from_sympy(sqrt(2)), K.zero, K.one] >>> P, lev, dom = dmp_alg_inject(p, 0, K) >>> P [[1, 0, 0], [1]] >>> lev 1 >>> dom QQ z3computation can be done only in an algebraic domain)is_GaussianRingis_GaussianField_dmp_alg_inject_gaussian is_Algebraic_dmp_alg_inject_algr+)r6rBr8s r>dmp_alg_injectr{sF, A..'1a00 "1a++OPPr@ct||i}}|jD]2\}}|j|j}}|r||d|z<|s+||d|z<4t ||dz|j }||dz|j fS)+Helper function for :func:`dmp_alg_inject`.)r)r/r/)rrxyrdom) r6rBr8rnf_monomr9rrrs r>rrs q! bqAggi" ssACC1 !AdWn  !AdWn  " aQ&A a!eQUU?r@ct||i}}|jD]3\}}|jjD] \}}||||z<5t||dz|j}||dz|jfS)rr/)rrto_dictrr) r6rBr8rnrr9g_monomr;rs r>rrs q! bqAggi% ))+++- %JGQ#$Ag  %% aQ&A a!eQUU?r@c ddlm}t|||\}}}|jj }t |t td|dzd|}|||||S)aO Convert algebraic coefficients to integers in ``K[X]``. Examples ======== >>> from sympy.polys import ring, QQ >>> from sympy import I >>> K = QQ.algebraic_field(I) >>> R, x = ring("x", K) >>> f = x**2 + K([QQ(1), QQ(0)])*x + K([QQ(2), QQ(0)]) >>> R.dmp_lift(f) x**4 + x**2 + 4*x + 4 r/) dmp_resultantr) euclidtoolsrrmodto_listr)rr3) r6rBr8rrrCK2p_aP_As r>dmp_liftrsZ(+aA&HAq" %%--/C c4aQ0!R 8C CB ''r@chfd}jsjs jr j}nЉjrj j r|}njs jrtjdk(rmjjs"jjs jr5jdjrjdj r|}ntdzjd}}|D]}|||zr|dz }|s|}|S)z Compute the number of sign variations of ``f`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_sign_variations(x**4 - x**2 - x + 1) 2 cD|sytj|dkS)NFr)boolto_sympy)rar8s r>is_negative_sympyz.dup_sign_variations..is_negative_sympys# 1 )* *r@r/rz-sign variation counting not supported over %s)ryris_RR is_negativeis_AlgebraicFieldext is_comparableis_PolynomialRingis_FractionFieldrlsymbolsris_transcendentalr+r0)r6r8rrprevrSrRs ` r>dup_sign_variationsrs +  ww!''QWWmm  !4!4'  !"4"4#aii.A:M 55;;!%%++)<)< ))A, ( (QYYq\-G-G( IAMNNffa!D uTz " FA D  Hr@Nc ||jr|j}n|}|j}|D]#}|j||j |}%|j |r|s||fS|t |||fS|Dcgc]5}|j||j||j |z7}}|s|t |||fS||fScc}w)a@ Clear denominators, i.e. transform ``K_0`` to ``K_1``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x = ring("x", QQ) >>> f = QQ(1,2)*x + QQ(1,3) >>> R.dup_clear_denoms(f, convert=False) (6, 3*x + 2) >>> R.dup_clear_denoms(f, convert=True) (6, 3*x + 2) ) has_assoc_Ringget_ringrlcmdenomrrnumerr)r6K0K1r`commonr;s r>dup_clear_denomsr s$ z  BB VVF - ,- yy19 ;q"b11 1;<rr8s{ VVF  1AVVFBHHQK0F 1 M E EAVVF$5aB$CDF E Mr@c|st||||S||jr|j}n|}t||||}|j |st ||||}|s||fS|t ||||fS)aV Clear denominators, i.e. transform ``K_0`` to ``K_1``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x,y = ring("x,y", QQ) >>> f = QQ(1,2)*x + QQ(1,3)*y + 1 >>> R.dmp_clear_denoms(f, convert=False) (6, 3*x + 2*y + 6) >>> R.dmp_clear_denoms(f, convert=True) (6, 3*x + 2*y + 6) )r`)rrrrrrr)r6rBrrr`rs r>dmp_clear_denomsrHs$ 2r7;; z  BB q!R ,F 99V  1fa , qy{1aR000r@c|jt||g}|j|j|jg}t t t |}td|dzD]Z}t||d|}t|t|||}tt|||||}t|t||}\|S)a Compute ``f**(-1)`` mod ``x**n`` using Newton iteration. This function computes first ``2**n`` terms of a polynomial that is a result of inversion of a polynomial modulo ``x**n``. This is useful to efficiently compute series expansion of ``1/f``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x = ring("x", QQ) >>> f = -QQ(1,720)*x**6 + QQ(1,24)*x**4 - QQ(1,2)*x**2 + 1 >>> R.dup_revert(f, 8) 61/720*x**6 + 5/24*x**4 + 1/2*x**2 + 1 r/rx)revertr!rr0r{_ceil_log2r3rr r rrrr) r6r<r8r9rnNr:rars r> dup_revertrns( &A,  A A E%(OA 1a!e_, 1adA & Awq!}a ( GAq!$a + q*Q- + , Hr@c8|s t|||St||)z Compute ``f**(-1)`` mod ``x**n`` using Newton iteration. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x,y = ring("x,y", QQ) )rr*)r6r9rBr8s r> dmp_revertr s# !Q"")!Q//r@)NF)c__doc__sympy.polys.densearithrrrrrrr r r r r rrrrrrrrsympy.polys.densebasicrrrrrrrrrrr r!r"r#r$r%r&r'r(r)sympy.polys.polyerrorsr*r+mathr,rr-rr?rDrFrMrTrVrXr]rcrergrirkrqrsrvr~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r@r>rs\N             . @  FL/,(V,^G*04:G*0 1(@L/4D@(E0*:!-H'T*Z0B!3H441h , , .(V > : :#8 # &/dQ<  (<4 n*Z  #1L D0r@