K iBdZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZddlmZmZdZdZdZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-d Z.d!Z/d"Z0d#Z1d$Z2d%Z3d&Z4d'Z5d(Z6d)Z7d*Z8d+Z9d,Z:d-Z;d.Zd1Z?d2Z@d3ZAd4ZBd5ZCd6ZDd7ZEd8ZFd9ZGd:ZHd;ZId<ZJd=ZKd>ZLd?ZMd@ZNdAZOdBZPdCZQyD)EzEArithmetics for dense recursive polynomials in ``K[x]`` or ``K[X]``. ) dup_slicedup_LCdmp_LC dup_degree dmp_degree dup_strip dmp_strip dmp_zero_pdmp_zero dmp_one_pdmp_one dmp_ground dmp_zeros)ExactQuotientFailedPolynomialDivisionFailedc|s|St|}||z dz }||dz k(rt|d|zg|ddzS||k\r|g|jg||z zz|zS|d||||zgz||dzdzS)z Add ``c*x**i`` to ``f`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_add_term(x**2 - 1, ZZ(2), 4) 2*x**4 + x**2 - 1 rNlenrzerofciKnms \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/densearith.py dup_add_termrs  AA A AAEz!A$(ae+,, 63!&&1q5))A- -Ra5AaD1H:%!a%& 1 1c<|st||||S|dz }t||r|St|}||z dz }||dz k(r"tt |d|||g|ddz|S||k\r|gt ||z ||z|zS|d|t |||||gz||dzdzS)z Add ``c(x_2..x_u)*x_0**i`` to ``f`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_add_term(x*y + 1, 2, 2) 2*x**2 + x*y + 1 rrN)rr rr dmp_addrrrrurvrrs r dmp_add_termr&+s Aq!Q'' AA!Q AA A AAEz'!A$1a01AabE91== 631q5!Q//!3 3Ra5GAaD!Q233aAi? ?r c|s|St|}||z dz }||dz k(rt|d|z g|ddzS||k\r| g|jg||z zz|zS|d||||z gz||dzdzS)z Subtract ``c*x**i`` from ``f`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_sub_term(2*x**4 + x**2 - 1, ZZ(2), 4) x**2 - 1 rrNrrs r dup_sub_termr(Ms  AA A AAEz!A$(ae+,, 6B4166(AE**Q. .Ra5AaD1H:%!a%& 1 1r cT|st|| ||S|dz }t||r|St|}||z dz }||dz k(r"tt |d|||g|ddz|S||k\r"t |||gt ||z ||z|zS|d|t |||||gz||dzdzS)z Subtract ``c(x_2..x_u)*x_0**i`` from ``f`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_sub_term(2*x**2 + x*y + 1, 2, 2) x*y + 1 rrN)rr rr dmp_subdmp_negrr#s r dmp_sub_termr,js Ar1a(( AA!Q AA A AAEz'!A$1a01AabE91== 6Aq!$% !a%A(>>B BRa5GAaD!Q233aAi? ?r c`|r|sgS|Dcgc]}||z c}|jg|zzScc}w)z Multiply ``f`` by ``c*x**i`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_mul_term(x**2 - 1, ZZ(3), 2) 3*x**4 - 3*x**2 r)rrrrcfs r dup_mul_termr0s5 A "#%Ba% 22%s +c |st||||S|dz }t||r|St||r t|S|Dcgc]}t||||c}t |||zScc}w)z Multiply ``f`` by ``c(x_2..x_u)*x_0**i`` in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_mul_term(x**2*y + x, 3*y, 2) 3*x**4*y**2 + 3*x**3*y r)r0r r dmp_mulr)rrrr$rr%r/s r dmp_mul_termr3sq Aq!Q'' AA!Q!Q{013"Q1%3i1a6HHH3sA%ct||d|S)z Add an element of the ground domain to ``f``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_add_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4)) x**3 + 2*x**2 + 3*x + 8 r)rrrrs rdup_add_groundr6 1a ##r c:t|t||dz d||S)z Add an element of the ground domain to ``f``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_add_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4)) x**3 + 2*x**2 + 3*x + 8 rr)r&rrrr$rs rdmp_add_groundr:" :aQ/Aq 99r ct||d|S)z Subtract an element of the ground domain from ``f``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_sub_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4)) x**3 + 2*x**2 + 3*x r)r(r5s rdup_sub_groundr=r7r c:t|t||dz d||S)z Subtract an element of the ground domain from ``f``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_sub_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4)) x**3 + 2*x**2 + 3*x rr)r,rr9s rdmp_sub_groundr?r;r c>|r|sgS|Dcgc]}||z c}Scc}w)z Multiply ``f`` by a constant value in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_mul_ground(x**2 + 2*x - 1, ZZ(3)) 3*x**2 + 6*x - 3 rrrr/s rdup_mul_groundrCs& A "#%Ba%%%s c l|s t|||S|dz }|Dcgc]}t||||c}Scc}w)z Multiply ``f`` by a constant value in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_mul_ground(2*x + 2*y, ZZ(3)) 6*x + 6*y r)rCdmp_mul_groundrrr$rr%r/s rrErEs> aA&& AA34 6R^B1a ( 66 61c|s td|s|S|jr |Dcgc]}|j||c}S|Dcgc]}||z c}Scc}wcc}w)a) Quotient by a constant in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x = ring("x", ZZ) >>> R.dup_quo_ground(3*x**2 + 2, ZZ(2)) x**2 + 1 >>> R, x = ring("x", QQ) >>> R.dup_quo_ground(3*x**2 + 2, QQ(2)) 3/2*x**2 + 1 polynomial division)ZeroDivisionErroris_FieldquorBs rdup_quo_groundrM)sZ$  566 zz()+"r1++#$&Rq&&,&s A Ac l|s t|||S|dz }|Dcgc]}t||||c}Scc}w)a= Quotient by a constant in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_quo_ground(2*x**2*y + 3*x, ZZ(2)) x**2*y + x >>> R, x,y = ring("x,y", QQ) >>> R.dmp_quo_ground(2*x**2*y + 3*x, QQ(2)) x**2*y + 3/2*x r)rMdmp_quo_groundrFs rrOrOFs>$ aA&& AA34 6R^B1a ( 66 6rGcn|s td|s|S|Dcgc]}|j||c}Scc}w)z Exact quotient by a constant in ``K[x]``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x = ring("x", QQ) >>> R.dup_exquo_ground(x**2 + 2, QQ(2)) 1/2*x**2 + 1 rI)rJexquorBs rdup_exquo_groundrR`s9  566 &' )QWWR^ )) )s2c l|s t|||S|dz }|Dcgc]}t||||c}Scc}w)z Exact quotient by a constant in ``K[X]``. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x,y = ring("x,y", QQ) >>> R.dmp_exquo_ground(x**2*y + 2*x, QQ(2)) 1/2*x**2*y + x r)rRdmp_exquo_groundrFs rrTrTvs? 1a(( AA56 8r b!Q * 88 8rGc0|s|S||jg|zzS)z Efficiently multiply ``f`` by ``x**n`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_lshift(x**2 + 1, 2) x**4 + x**2 r.rrrs r dup_lshiftrWs  AFF8A:~r c|d| S)a Efficiently divide ``f`` by ``x**n`` in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_rshift(x**4 + x**2, 2) x**2 + 1 >>> R.dup_rshift(x**4 + x**2 + 2, 2) x**2 + 1 NrArVs r dup_rshiftrYs Sqb6Mr cJ|Dcgc]}|j|c}Scc}w)z Make all coefficients positive in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_abs(x**2 - 1) x**2 + 1 )absrrcoeffs rdup_absr^s () *eQUU5\ ** *s ch|s t||S|dz }|Dcgc]}t|||c}Scc}w)z Make all coefficients positive in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_abs(x**2*y - x) x**2*y + x r)r^dmp_absrr$rr%r/s rr`r`9 q!} AA)* ,2WRA  ,, ,/c.|Dcgc]}| c}Scc}w)z Negate a polynomial in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_neg(x**2 - 1) -x**2 + 1 rAr\s rdup_negres"# $eV $$ $s ch|s t||S|dz }|Dcgc]}t|||c}Scc}w)z Negate a polynomial in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_neg(x**2*y - x) -x**2*y + x r)rer+ras rr+r+rbrccP|s|S|s|St|}t|}||k(r+tt||Dcgc] \}}||z c}}St||z }||kDr |d|||d}}n |d|||d}}|t||Dcgc] \}}||z c}}zScc}}wcc}}w)z Add dense polynomials in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_add(x**2 - 1, x - 2) x**2 + x - 3 N)rrzipr[ rgrdfdgabkhs rdup_addrqs   AB AB RxSAY8TQ1q5899 RL 7Ra5!AB%qARa5!AB%qAs1ay2tq!QU22293s B B"c |s t|||St||}|dkr|St||}|dkr|S|dz }||k(r5tt||Dcgc]\}}t ||||c}}|St ||z } ||kDr |d| || d}} n |d| || d}} | t||Dcgc]\}}t ||||c}}zScc}}wcc}}w)z Add dense polynomials in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_add(x**2 + y, x**2*y + x) x**2*y + x**2 + x + y rrN)rqrr rhr"r[ rrjr$rrkrlr%rmrnrorps rr"r"$s q!Q Aq B Av Aq B Av AA Rx3q!9F41a71aA.FJJ RL 7Ra5!AB%qARa5!AB%qASAY@TQWQ1a(@@@GAs C -Ccx|s t||S|s|St|}t|}||k(r+tt||Dcgc] \}}||z  c}}St ||z }||kDr |d|||d}}nt|d||||d}}|t||Dcgc] \}}||z  c}}zScc}}wcc}}w)z Subtract dense polynomials in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_sub(x**2 - 1, x - 2) x**2 - x + 1 N)rerrrhr[ris rdup_subruNs q!}  AB AB RxSAY8TQ1q5899 RL 7Ra5!AB%qA1Ra5!$aeqAs1ay2tq!QU22293s B0 B6c |s t|||St||}|dkr t|||St||}|dkr|S|dz }||k(r5tt ||Dcgc]\}}t ||||c}}|St ||z } ||kDr |d| || d}} nt|d| |||| d}} | t ||Dcgc]\}}t ||||c}}zScc}}wcc}}w)z Subtract dense polynomials in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_sub(x**2 + y, x**2*y + x) -x**2*y + x**2 - x + y rrN)rurr+r rhr*r[rss rr*r*qs  q!Q Aq B Avq!Q Aq B Av AA Rx3q!9F41a71aA.FJJ RL 7Ra5!AB%qA1Ra5!Q'12qASAY@TQWQ1a(@@@GAs C! C'c2t|t||||S)z Returns ``f + g*h`` where ``f, g, h`` are in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_add_mul(x**2 - 1, x - 2, x + 2) 2*x**2 - 5 )rqdup_mulrrjrprs r dup_add_mulrz 1gaA& **r c 6t|t||||||S)z Returns ``f + g*h`` where ``f, g, h`` are in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_add_mul(x**2 + y, x, x + 2) 2*x**2 + 2*x + y )r"r2rrjrpr$rs r dmp_add_mulr~  1gaAq)1a 00r c2t|t||||S)z Returns ``f - g*h`` where ``f, g, h`` are in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_sub_mul(x**2 - 1, x - 2, x + 2) 3 )rurxrys r dup_sub_mulrr{r c 6t|t||||||S)z Returns ``f - g*h`` where ``f, g, h`` are in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_sub_mul(x**2 + y, x, x + 2) -2*x + y )r*r2r}s r dmp_sub_mulrrr c H||k(r t||S|r|sgSt|}t|}t||dz}|dks |js}g}t d||zdzD][}|j }t td||z t ||dzD]} ||| ||| z zz }|j|]t|S|dz} t|d| |t|d| |} } tt|| ||| |} tt|| ||| |}t| | |t| ||}}tt| | |t| |||}t|t||||}tt|t|| ||t|d| z||S)z Multiply dense polynomials in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_mul(x - 2, x + 2) x**2 - 4 rdr)dup_sqrrmaxis_ExactrangerminappendrrrYrxrqrurW)rrjrrkrlrrprr]jn2flglfhghlohimids rrxrxs Avq!} ! AB AB B aA3wajj q"r'A+& AFFE3q!b&>3r1:>: '1aAh& ' HHUO  | T1aQ'1aQ)?B  !RA.A 6  !RA.A 6R#WRQ%7Bgb"a('"b!*>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_mul(x*y + 1, x) x**2*y + x rr) rxdmp_sqrrrr rrr"r2rr ) rrjr$rrkrlrpr%rr]rs rr2r2s q!QAvq!Q Aq B Av Aq B Av q1uqA 1b2gk " s1a"f~s2qzA~6 HAE71Q41q51a#@!QGE H   Q?r czt|dz g}}tdd|zdzD]}|j}td||z }t ||}||z dz}||dzzdz }t||dzD]} ||| ||| z zz }||z }|dzr||dz} || dzz }|j |t |S)z Square dense polynomials in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_sqr(x**2 + 1) x**4 + 2*x**2 + 1 rrr)rrrrrrr) rrrkrprrjminjmaxrrelems rrrCs FQJB 1adQh  FF1a"f~1bz 4K!Oa1f}q tTAX& A 1aAh A  Q q5TAX;D qLA  '* Q<r c |s t||St||}|dkr|Sg|dz }}tdd|zdzD]}t|}t d||z }t ||} | |z dz} || dzzdz } t|| dzD]%} t |t|| ||| z ||||}'t||d||}| dzr!t|| dz||} t || ||}|j|t||S)z Square dense polynomials in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_sqr(x**2 + x*y + y**2) x**4 + 2*x**3*y + 3*x**2*y**2 + 2*x*y**3 + y**4 rrr) rrrr rrr"r2rErrr ) rr$rrkrpr%rrrrrrrs rrrks7 q!} Aq B Av q1uqA 1adQh  QK1a"f~1bz 4K!Oa1f}q tTAX& @A71Q41q51a8!Q?A @ 1adAq ) q51TAX;1-D4A&A  '* Q?r c|s |jgS|dkr td|dk(s|r||jgk(r|S|jg} |dz|}}|dzrt|||}|s |St||}+)z Raise ``f`` to the ``n``-th power in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_pow(x - 2, 3) x**3 - 6*x**2 + 12*x - 8 r+Cannot raise polynomial to a negative powerrr)one ValueErrorrxr)rrrrjrs rdup_powrs w1uFGGAvQ!w, A !tQ1 q51a A H AqM r c|s t|||S|s t||S|dkr td|dk(st||s t |||r|St||} |dz|}}|dzrt ||||}|s |St |||}-)z Raise ``f`` to the ``n``-th power in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_pow(x*y + 1, 3) x**3*y**3 + 3*x**2*y**2 + 3*x*y + 1 rrrr)rr rr r r2r)rrr$rrjrs rdmp_powrs q!Q q!}1uFGGAvAq!Yq!Q%71 A !tQ1 q51a#A H Aq!  r ct|}t|}g||}}}|s td||kr||fS||z dz}t||} t||} ||z |dz }} t|| |} t | | | |}t|| |} t || | |}t | ||}|t|}}||krn||ks t|||| |z}t|||}t|||}||fS)z Polynomial pseudo-division in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_pdiv(x**2 + 1, 2*x - 4) (2*x + 4, 20) rIr)rrJrrCrr0rur)rrjrrkrlqrdrNlc_glc_rrQRG_drrs rdup_pdivrs% AB AB1b"qA  566 b!t  R! A !Q>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_prem(x**2 + 1, 2*x - 4) 20 rIr)rrJrrCr0rur)rrjrrkrlrrrrrrrrrs rdup_premrs AB AB rrA  566 b R! A !Q>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_pquo(x**2 - 1, 2*x - 2) 2*x + 2 >>> R.dup_pquo(x**2 + 1, 2*x - 4) 2*x + 4 r)rrrjrs rdup_pquorJs" Aq! Q r cBt|||\}}|s|St||)a\ Polynomial pseudo-quotient in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_pexquo(x**2 - 1, 2*x - 2) 2*x + 2 >>> R.dup_pexquo(x**2 + 1, 2*x - 4) Traceback (most recent call last): ... ExactQuotientFailed: [2, -4] does not divide [1, 0, 1] )rrrrjrrrs r dup_pexquor^s+& Aq! DAq !!Q''r c>|s t|||St||}t||}|dkr tdt|||}}}||kr||fS||z dz} t ||} t ||} ||z | dz } } t || d||} t | | | ||}t || d||}t || | ||}t||||}|t||}}||krn||ks t|||t| | |dz |}t ||d||}t ||d||}||fS)z Polynomial pseudo-division in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_pdiv(x**2 + x*y, 2*x + 2) (2*x + 2*y - 2, -4*y + 4) rrIr) rrrJr rr3r&r*rr)rrjr$rrkrlrrrrrrrrrrrrs rdmp_pdivrysi 1a  Aq B Aq B Av 566{Ar"qA Bw!t  R! A !Q>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_prem(x**2 + x*y, 2*x + 2) -4*y + 4 rrIr)rrrJrr3r*rr)rrjr$rrkrlrrrrrrrrrrs rdmp_premrs 1a  Aq B Aq B Av 566 rrA Bw R! A !Q>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = x**2 + x*y >>> g = 2*x + 2*y >>> h = 2*x + 2 >>> R.dmp_pquo(f, g) 2*x >>> R.dmp_pquo(f, h) 2*x + 2*y - 2 r)rrrjr$rs rdmp_pquors* Aq!Q  ""r cXt||||\}}t||r|St||)a Polynomial pseudo-quotient in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = x**2 + x*y >>> g = 2*x + 2*y >>> h = 2*x + 2 >>> R.dmp_pexquo(f, g) 2*x >>> R.dmp_pexquo(f, h) Traceback (most recent call last): ... ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []] )rr rrrjr$rrrs r dmp_pexquors4. Aq!Q DAq!Q!!Q''r ct|}t|}g||}}}|s td||kr||fSt||} t||} | |zr ||fS|j| |} ||z } t || | |}t || | |} t || |}|t|}} ||kr ||fS|| ks t|||)z Univariate division with remainder over a ring. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_rr_div(x**2 + 1, 2*x - 4) (0, x**2 + 1) rI)rrJrrQrr0rurrrjrrkrlrrrrrrrrprs r dup_rr_divrs AB AB1b"qA  566 b!t !Q>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_rr_div(x**2 + x*y, 2*x + 2) (0, x**2 + x*y) rrIr) rrrJr r dmp_rr_divr r&r3r*rrrjr$rrkrlrrrrr%rrrrrprs rrrM0 !Q"" Aq B Aq B Av 566{Ar"qA Bw!t QlAE!D a|$a+1!Q  a4K G Aq!Q ' Aq!Q ' Aq!Q jA&R 7  a4Ks(*1a3 3% r ct|}t|}g||}}}|s td||kr||fSt||} t||} |j| |} ||z } t || | |}t || | |} t || |}|t|}} ||kr ||fS|| k(r/|js#t|dd}t|}||kr ||fS|| ks t|||)z Polynomial division with remainder over a field. Examples ======== >>> from sympy.polys import ring, QQ >>> R, x = ring("x", QQ) >>> R.dup_ff_div(x**2 + 1, 2*x - 4) (1/2*x + 1, 5) rIrN) rrJrrQrr0rurrrrs r dup_ff_divrs AB AB1b"qA  566 b!t !Q>> from sympy.polys import ring, QQ >>> R, x,y = ring("x,y", QQ) >>> R.dmp_ff_div(x**2 + x*y, 2*x + 2) (1/2*x + 1/2*y - 1/2, -y + 1) rrIr) rrrJr r dmp_ff_divr r&r3r*rrs rrrrr cN|jr t|||St|||S)a. Polynomial division with remainder in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x = ring("x", ZZ) >>> R.dup_div(x**2 + 1, 2*x - 4) (0, x**2 + 1) >>> R, x = ring("x", QQ) >>> R.dup_div(x**2 + 1, 2*x - 4) (1/2*x + 1, 5) )rKrrrs rdup_divrs)$ zz!Q""!Q""r c"t|||dS)a Returns polynomial remainder in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x = ring("x", ZZ) >>> R.dup_rem(x**2 + 1, 2*x - 4) x**2 + 1 >>> R, x = ring("x", QQ) >>> R.dup_rem(x**2 + 1, 2*x - 4) 5 rrrs rdup_remr$ 1a A r c"t|||dS)a Returns exact polynomial quotient in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x = ring("x", ZZ) >>> R.dup_quo(x**2 + 1, 2*x - 4) 0 >>> R, x = ring("x", QQ) >>> R.dup_quo(x**2 + 1, 2*x - 4) 1/2*x + 1 rrrs rdup_quorrr cBt|||\}}|s|St||)aW Returns polynomial quotient in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_exquo(x**2 - 1, x - 1) x + 1 >>> R.dup_exquo(x**2 + 1, 2*x - 4) Traceback (most recent call last): ... ExactQuotientFailed: [2, -4] does not divide [1, 0, 1] )rrrs r dup_exquor-s+& 1a DAq !!Q''r cR|jrt||||St||||S)aK Polynomial division with remainder in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_div(x**2 + x*y, 2*x + 2) (0, x**2 + x*y) >>> R, x,y = ring("x,y", QQ) >>> R.dmp_div(x**2 + x*y, 2*x + 2) (1/2*x + 1/2*y - 1/2, -y + 1) )rKrrrs rdmp_divrHs-$ zz!Q1%%!Q1%%r c$t||||dS)a) Returns polynomial remainder in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_rem(x**2 + x*y, 2*x + 2) x**2 + x*y >>> R, x,y = ring("x,y", QQ) >>> R.dmp_rem(x**2 + x*y, 2*x + 2) -y + 1 rrrs rdmp_remr`$ 1aA q !!r c$t||||dS)a2 Returns exact polynomial quotient in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ, QQ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_quo(x**2 + x*y, 2*x + 2) 0 >>> R, x,y = ring("x,y", QQ) >>> R.dmp_quo(x**2 + x*y, 2*x + 2) 1/2*x + 1/2*y - 1/2 rrrs rdmp_quorurr cXt||||\}}t||r|St||)a Returns polynomial quotient in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = x**2 + x*y >>> g = x + y >>> h = 2*x + 2 >>> R.dmp_exquo(f, g) x >>> R.dmp_exquo(f, h) Traceback (most recent call last): ... ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []] )rr rrs r dmp_exquors4. 1aA DAq!Q!!Q''r cH|s |jStt||S)z Returns maximum norm of a polynomial in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_max_norm(-x**2 + 2*x - 3) 3 )rrr^rrs r dup_max_normr! vv 71a=!!r cV|s t|S|dz tfd|DS)z Returns maximum norm of a polynomial in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_max_norm(2*x*y - x - 3) 3 rc38K|]}t|ywN) dmp_max_norm.0rrr%s r zdmp_max_norm..s0|Aq!$0)rrrr$rr%s `@rrrs/ Aq!! AA 0a0 00r cH|s |jStt||S)z Returns l1 norm of a polynomial in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_l1_norm(2*x**3 - 3*x**2 + 1) 6 )rsumr^rs r dup_l1_normrrr cV|s t|S|dz tfd|DS)z Returns l1 norm of a polynomial in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_l1_norm(2*x*y - x - 3) 6 rc38K|]}t|ywr) dmp_l1_normrs rrzdmp_l1_norm..s/{1a#/r)rrrs `@rrrs/ 1a   AA /Q/ //r cZt|Dcgc]}|dz c}|jScc}w)z Returns squared l2 norm of a polynomial in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_l2_norm_squared(2*x**3 - 3*x**2 + 1) 14 r)rrr\s rdup_l2_norm_squaredrs' a(Uq(!&& 11(s (cV|s t|S|dz tfd|DS)z Returns squared l2 norm of a polynomial in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_l2_norm_squared(2*x*y - x - 3) 14 rc38K|]}t|ywr)dmp_l2_norm_squaredrs rrz&dmp_l2_norm_squared..!s7"1a+7r)rrrs `@rrrs/ "1a(( AA 7Q7 77r c\|s |jgS|d}|ddD]}t|||}|S)z Multiply together several polynomials in ``K[x]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x = ring("x", ZZ) >>> R.dup_expand([x**2 - 1, x, 2]) 2*x**3 - 2*x rrN)rrx)polysrrrjs r dup_expandr$sE w aA 12Y Aq!  Hr c\|s t||S|d}|ddD]}t||||}|S)z Multiply together several polynomials in ``K[X]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> R.dmp_expand([x**2 + y**2, x + 1]) x**3 + x**2 + x*y**2 + y**2 rrN)r r2)rr$rrrjs r dmp_expandr=sH q!} aA 12Y  Aq!Q   Hr N)R__doc__sympy.polys.densebasicrrrrrrr r r r r rrsympy.polys.polyerrorsrrrr&r(r,r0r3r6r:r=r?rCrErMrOrRrTrWrYr^r`rer+rqr"rur*rzr~rrrxr2rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrAr rrs{KS2:@D2:@D3(I6$":"$":"&(7,':74*,9,(&+"-,%"-, 3F'AT 3F'AT+"1"+"1"63r(V%P-`" J% P2j*)Z ((66r0'f#0(>.b2j1h2j#0**(6&0"*"*(>"(1,"(0,2"8, 2 r