+
    i2t                        R t ^ RIHtHtHtHtHtHtHtH	t	H
t
HtHtHtHtHtHtHtHtHtHt ^ RIHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t) ^ RI*H+t+H,t, ^ RI-H.t/H0t1 R t2R t3R t4R t5R	 t6R
 t7R t8R t9R t:R t;R t<R t=R t>R t?R t@R tAR tBR tCR tDR tER tFR tGR tHR tIR tJR tKR tLR  tMR! tNR" tOR# tPR$ tQR% tRR& tSR' tTR( tUR) tVR* tWR+ tXR, tYR- tZR. t[R/ t\R0 t]R7R2 lt^R3 t_R7R4 lt`R5 taR6 tbR1# )8zHAdvanced tools for dense recursive polynomials in ``K[x]`` or ``K[X]``. )dup_add_termdmp_add_term
dup_lshiftdup_adddmp_adddup_subdmp_subdup_muldmp_muldup_sqrdup_divdup_remdmp_remdup_mul_grounddmp_mul_grounddup_quo_grounddmp_quo_grounddup_exquo_grounddmp_exquo_ground)	dup_strip	dmp_stripdup_convertdmp_convert
dup_degree
dmp_degreedmp_to_dictdmp_from_dictdup_LCdmp_LCdmp_ground_LCdup_TCdmp_TCdmp_zero
dmp_ground
dmp_zero_pdup_to_raw_dictdup_from_raw_dict	dmp_zerosdmp_include)MultivariatePolynomialErrorDomainError)ceillog2c           
     <   V^ 8:  g	   V '       g   V # VP                   .V,          p\        \        V 4      4       F^  w  rEV^,           p\        ^V4       F  pWdV,           ^,           ,          pK  	  VP	                  ^ VP                  WR! V4      4      4       K`  	  V# )z
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

)zero	enumeratereversedrangeinsertexquo)fmKgicnjs   &&&     v/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/polys/densetools.pydup_integrater=   '   s      	AvQ	

A(1+&Eq!AQNA  	
AGGAqt$% ' H    c           
     z   V'       g   \        WV4      # V^ 8:  g   \        W4      '       d   V # \        W^,
          V4      V^,
          rT\        \	        V 4      4       FY  w  rgV^,           p\        ^V4       F  p	WV	,           ^,           ,          pK  	  VP                  ^ \        Ws! V4      WS4      4       K[  	  V# )z
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

)r=   r$   r'   r/   r0   r1   r2   r   )
r4   r5   ur6   r7   vr8   r9   r:   r;   s
   &&&&      r<   dmp_integraterB   G   s      Q1%%AvA!!QAq!1q5q(1+&Eq!AQNA  	
N1adA12 ' Hr>   c                    W48X  d   \        WW%4      # V^,
          V^,           r6\        V  Uu. uF  p\        WqWcWE4      NK  	  upV4      # u upi )z.Recursive helper for :func:`dmp_integrate_in`.)rB   r   _rec_integrate_inr7   r5   rA   r8   r;   r6   wr9   s   &&&&&&  r<   rD   rD   j   sL    vQ1((q5!a%qAGAq(qQ:AGKKG   Ac                ^    V^ 8  g   W#8  d   \        RW23,          4      h\        WV^ W$4      # )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

z(0 <= j <= u expected, got u = %d, j = %d)
IndexErrorrD   r4   r5   r;   r@   r6   s   &&&&&r<   dmp_integrate_inrK   t   s3      	1uCqfLMMQ1a..r>   c                   V^ 8:  d   V # \        V 4      pW18  d   . # . pV^8X  d6   V RV)   F*  pVP                  V! V4      V,          4       V^,          pK,  	  M_V RV)   FU  pTp\        V^,
          W1,
          R4       F  pWg,          pK  	  VP                  V! V4      V,          4       V^,          pKW  	  \        V4      # )z
``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

N)r   appendr1   r   )r4   r5   r6   r:   derivcoeffkr8   s   &&&     r<   dup_diffrR      s      	Av1Au	EAvsVELL1e$FA  sVEA1q5!%, - LL1e$FA  Ur>   c           	        V'       g   \        WV4      # V^ 8:  d   V # \        W4      pWA8  d   \        V4      # . V^,
          reV^8X  d9   V RV)   F-  pVP                  \	        Ws! V4      Wc4      4       V^,          pK/  	  MbV RV)   FX  pTp\        V^,
          WA,
          R4       F  p	W,          pK  	  VP                  \	        Ws! V4      Wc4      4       V^,          pKZ  	  \        WR4      # )a  
``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

NrM   )rR   r   r"   rN   r   r1   r   )
r4   r5   r@   r6   r:   rO   rA   rP   rQ   r8   s
   &&&&      r<   dmp_diffrT      s    $ a  Av1Au{1q51AvsVELLqtQ:;FA  sVEA1q5!%, - LLqtQ:;FA  Ur>   c                    W48X  d   \        WW%4      # V^,
          V^,           r6\        V  Uu. uF  p\        WqWcWE4      NK  	  upV4      # u upi )z)Recursive helper for :func:`dmp_diff_in`.)rT   r   _rec_diff_inrE   s   &&&&&&  r<   rV   rV      K    va##q5!a%qqBq!|A!5qBAFFBrG   c                ^    V^ 8  g   W#8  d   \        RV: RV: 24      h\        WV^ W$4      # )a'  
``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


0 <= j <=  expected, got )rI   rV   rJ   s   &&&&&r<   dmp_diff_inr[      0    $ 	1uAqABBaA))r>   c                    V'       g   VP                  \        W4      4      # VP                  pV  F  pW1,          pW4,          pK  	  V# )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    r.   )r4   ar6   resultr9   s   &&&  r<   dup_evalra     sB     yy&&VVF  Mr>   c                    V'       g   \        WV4      # V'       g   \        W4      # \        W4      V^,
          rTV R,           F  p\        WAWS4      p\	        WFWS4      pK  	  V# )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

   NN)ra   r!   r   r   r   )r4   r_   r@   r6   r`   rA   rP   s   &&&&   r<   dmp_evalre      s_     a  a|qa!eA210-  Mr>   c                    W48X  d   \        WW%4      # V^,
          V^,           r2\        V  Uu. uF  p\        WaW#WE4      NK  	  upV4      # u upi )z)Recursive helper for :func:`dmp_eval_in`.)re   r   _rec_eval_in)r7   r_   rA   r8   r;   r6   r9   s   &&&&&& r<   rg   rg   =  rW   rG   c                ^    V^ 8  g   W#8  d   \        RV: RV: 24      h\        WV^ W$4      # )a  
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

rY   rZ   )rI   rg   )r4   r_   r;   r@   r6   s   &&&&&r<   dmp_eval_inri   G  r\   r>   c           
        W8X  d   \        WR,          V4      # V  Uu. uF  p\        WQ^,           W#V4      NK  	  ppW\        V4      ,
          ^,           8  d   V# \        WbV) V,           ^,
          ,          V4      # u upi )z+Recursive helper for :func:`dmp_eval_tail`.rM   )ra   _rec_eval_taillen)r7   r8   Ar@   r6   r9   hs   &&&&&  r<   rk   rk   _  sp    vR5!$$9:<AnQAqQ/<3q6zA~HA!a!}a00 =s   A>c                    V'       g   V # \        W4      '       d   \        V\        V4      ,
          4      # \        V ^ WV4      pV\        V4      ^,
          8X  d   V# \	        WB\        V4      ,
          4      # )z
Evaluate a polynomial at ``x_j = a_j, ...`` in ``K[X]``.

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_tail(f, [2])
7*x + 4
>>> R.dmp_eval_tail(f, [2, 2])
18

)r$   r"   rl   rk   r   )r4   rm   r@   r6   es   &&&& r<   dmp_eval_tailrq   l  sa    $ !CF
##q!Q1%ACFQJAJ''r>   c                    WE8X  d   \        \        WW64      W#V4      # V^,
          V^,           rC\        V  Uu. uF  p\        WqW#WEV4      NK  	  upV4      # u upi )z+Recursive helper for :func:`dmp_diff_eval`.)re   rT   r   _rec_diff_eval)r7   r5   r_   rA   r8   r;   r6   r9   s   &&&&&&& r<   rs   rs     sV    vq,aA66q5!a%qAGAq~aA!:AGKKGs   Ac           	         W48  d   \        RV: RV: RV: 24      hV'       g   \        \        WWE4      W$V4      # \        WW$^ W54      # )a1  
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 < rZ   )rI   re   rT   rs   )r4   r5   r_   r;   r@   r6   s   &&&&&&r<   dmp_diff_eval_inrv     sE    $ 	uQ1EFFq,aA66!a..r>   c                   VP                   '       dL   . pV  FB  pWA,          pWA^,          8  d   VP                  WA,
          4       K1  VP                  V4       KD  	  M[VP                  '       d3   \        V4      pV  Uu. uF  qB! \        V4      V,          4      NK  	  ppMV  Uu. uF  qDV,          NK  	  pp\	        V4      # u upi u upi )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_ZZrN   is_FiniteFieldintr   )r4   pr6   r7   r9   pis   &&&   r<   	dup_truncr}     s     	wwwAA6z  
			V&')aaAna) Q!eeQ Q<	 * s   ? C&C	c                h    \        V  Uu. uF  p\        WAV^,
          V4      NK  	  upV4      # u upi )a  
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   r   )r4   r{   r@   r6   r9   s   &&&& r<   	dmp_truncr     s0    " ;1wqQUA.;Q??;s   /c                    V'       g   \        WV4      # V^,
          p\        V  Uu. uF  p\        WQWC4      NK  	  upV4      # u upi )z
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   dmp_ground_trunc)r4   r{   r@   r6   rA   r9   s   &&&&  r<   r   r     sD      q!!	AAQ@Q'a3Q@!DD@s   Ac                v    V '       g   V # \        W4      pVP                  V4      '       d   V # \        WV4      # )a  
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

)r   is_oner   )r4   r6   lcs   && r<   	dup_monicr     s4    $ 	Bxx||q))r>   c                    V'       g   \        W4      # \        W4      '       d   V # \        WV4      pVP                  V4      '       d   V # \	        WW4      # )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

)r   r$   r   r   r   )r4   r@   r6   r   s   &&& r<   dmp_ground_monicr     sL    , !	qQ	Bxx||q,,r>   c                    ^ RI Hp V '       g   VP                  # VP                  pW8X  d   V  F  pVP                  W44      pK  	  V# V  F.  pVP                  W44      pVP	                  V4      '       g   K-   V# 	  V# )a  
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

QQ)sympy.polys.domainsr   r.   gcdr   )r4   r6   r   contr9   s   &&   r<   dup_contentr   ?  st    , 'vv66DwA55>D  K A55>Dxx~~K  Kr>   c           	     r   ^ RI Hp V'       g   \        W4      # \        W4      '       d   VP                  # VP                  V^,
          rTW#8X  d(   V  F  pVP                  V\        WeV4      4      pK!  	  V# V  F9  pVP                  V\        WeV4      4      pVP                  V4      '       g   K8   V# 	  V# )a-  
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

r   )r   r   r   r$   r.   r   dmp_ground_contentr   )r4   r@   r6   r   r   rA   r9   s   &&&    r<   r   r   i  s    , '1  !vvffa!e!wA551!:;D  K A551!:;Dxx~~K  Kr>   c                    V '       g   VP                   V 3# \        W4      pVP                  V4      '       d   W 3# V\        WV4      3# )a@  
Compute content and the primitive form 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_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)

)r.   r   r   r   )r4   r6   r   s   && r<   dup_primitiver     sE    , vvqyqDxx~~w^AQ///r>   c                    V'       g   \        W4      # \        W4      '       d   VP                  V 3# \        WV4      pVP	                  V4      '       d   W03# V\        WW4      3# )af  
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)

)r   r$   r.   r   r   r   )r4   r@   r6   r   s   &&& r<   dmp_ground_primitiver     s]    , Q""!vvqyaA&Dxx~~w^AQ222r>   c                    \        W4      p\        W4      pVP                  W44      pVP                  V4      '       g   \        WV4      p \        WV4      pWPV3# )z
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)

)r   r   r   r   )r4   r7   r6   fcgcr   s   &&&   r<   dup_extractr     sT     
Q	B	Q	B
%%-C88C==11%11%19r>   c                    \        WV4      p\        WV4      pVP                  WE4      pVP                  V4      '       g   \        WW#4      p \        WW#4      pW`V3# )z
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)

)r   r   r   r   )r4   r7   r@   r6   r   r   r   s   &&&&   r<   dmp_ground_extractr     sX     
A!	$B	A!	$B
%%-C88C==11(11(19r>   c                   VP                   '       g%   VP                  '       g   \        RV,          4      h\        ^4      p\        ^4      pV '       g   W#3# VP                  VP
                  ..VP                  .. ..p\        V ^ ,          ^4      pV R,           F)  p\        WT^V4      p\        V\        V^4      ^ ^V4      pK+  	  \        V4      pVP                  4        F^  w  rV^,          p	V	'       g   \        W%^V4      pK%  V	^8X  d   \        W5^V4      pK;  V	^8X  d   \        W%^V4      pKQ  \        W5^V4      pK`  	  W#3# )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 %src   )rx   is_QQr*   r"   oner.   r#   r
   r   r%   itemsr   r   )
r4   r6   f1f2r7   rn   r9   HrQ   r5   s
   &&        r<   dup_real_imagr     s&   & 7771777WZ[[\\	!B	!Bv55!&&/	aeeWbM*A1Q4ArUUA!QJq!,aA6  	A	E1%B!V1%B!V1%B1%B  6Mr>   c                z    \        V 4      p \        \        V 4      ^,
          RR4       F  pW,          ) W&   K  	  V # )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

rM   )listr1   rl   )r4   r6   r8   s   && r<   
dup_mirrorr   C  s:     	QA3q6A:r2&u ' Hr>   c                    \        V 4      \        V 4      ^,
          TrCp \        V^,
          RR4       F  pW@V,          ,          WA,          uW&   pK  	  V # )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

rM   r   rl   r1   )r4   r_   r6   r:   br8   s   &&&   r<   	dup_scaler   Y  sN     1gs1vz1!A1q5"b!aD&!#a " Hr>   c                    \        V 4      \        V 4      ^,
          r0\        V^ R4       F>  p\        ^ V4       F+  pW^,           ;;,          WV,          ,          ,          uu&   K-  	  K@  	  V # )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

rM   r   )r4   r_   r6   r:   r8   r;   s   &&&   r<   	dup_shiftr   o  sV     7CFQJq1a_q!A!eHA$H   Hr>   c           	     *   V'       g   \        W^ ,          V4      # \        W4      '       d   V # V^ ,          VR,          rT\        V4      '       d%   V  Uu. uF  p\        WeV^,
          V4      NK  	  p pM\	        V 4      p V'       d~   \        V 4      ^,
          p\        V^ R4       FZ  p\        ^ V4       FG  p	\        W	,          WB^,
          V4      p
\        W	^,           ,          W^,
          V4      W	^,           &   KI  	  K\  	  \        W4      # u upi )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
rc   rM   )
r   r$   any	dmp_shiftr   rl   r1   r   r   r   )r4   r_   r@   r6   a0a1r9   r:   r8   r;   afjs   &&&&       r<   r   r     s    & aD!$$!qT1R5
2ww0131iqsA&3G	FQJq!RA1a[$QT2sA6"1U8SA#q9a% ! !
 Q? 4s   Dc                d   V '       g   . # \        V 4      ^,
          pV ^ ,          .VP                  ..re\        ^ V4       F%  pVP                  \	        VR,          W#4      4       K'  	  \        V R,          VR,          4       F)  w  r\	        WQV4      p\        W(V4      p\        WRV4      pK+  	  V# )z
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

rc   rM   )rl   r   r1   rN   r	   zipr   r   )	r4   r{   qr6   r:   rn   Qr8   r9   s	   &&&&     r<   dup_transformr     s     	A
AaD6QUUG9q1a[	2%&  AbE1R5!A!1#A! "
 Hr>   c           	         \        V4      ^8:  d!   \        \        V \        W4      V4      .4      # V '       g   . # V ^ ,          .pV R,           F  p\	        W1V4      p\        W4^ V4      pK  	  V# )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

rc   )rl   r   ra   r   r	   r   )r4   r7   r6   rn   r9   s   &&&  r<   dup_composer     sn     1v{(1fQlA6788		
1ArUUA!q!$  Hr>   c                    V'       g   \        WV4      # \        W4      '       d   V # V ^ ,          .pV R,           F  p\        WAW#4      p\        WE^ W#4      pK  	  V# )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

rc   )r   r$   r
   r   )r4   r7   r@   r6   rn   r9   s   &&&&  r<   dmp_composer     s`     1##!	
1ArUUA!q!'  Hr>   c                   \        V 4      ^,
          p\        W4      p\        V 4      p WP                  /pW1,          p\	        ^V4       F  pVP
                  p\	        ^ V4       Fo  p	W9,           V,
          V 9   g   K  W,
          V9   g   K(  WV	,           V,
          ,          WQV	,
          ,          rWWi,          ,
          V
,          V,          ,          pKq  	  VP                  WV,          V,          4      WQV,
          &   K  	  \        WR4      # )+Helper function for :func:`_dup_decompose`.)rl   r   r%   r   r1   r.   quor&   )r4   sr6   r:   r   r7   rr8   rP   r;   r   r   s   &&&         r<   _dup_right_decomposer   
  s    A
A	BA
UUA	A1a[q!A519>5A:1uqy\1U8!#gr\"_$E  55!B'a%  Q""r>   c                    / ^ rCV '       d9   \        WV4      w  rV\        V4      ^ 8  d   R# \        Wb4      W4&   YT^,           r@K@  \        W24      # )r   N)r   r   r   r&   )r4   rn   r6   r7   r8   r   r   s   &&&    r<   _dup_left_decomposer   &  sH    qq
qQa=1!<AD!eqQ""r>   c                    \        V 4      ^,
          p\        ^V4       F9  pW#,          ^ 8w  d   K  \        WV4      pVf   K$  \        WV4      pVf   K6  WT3u # 	  R# )z*Helper function for :func:`dup_decompose`.N)rl   r1   r   r   )r4   r6   dfr   rn   r7   s   &&    r<   _dup_decomposer   6  sY    	Q!B1b\6Q; q)=#A!,A}t  r>   c                \    . p \        W4      pVe   Vw  rV.V,           pK    T .T,           # )a  
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   )r4   r6   Fr`   rn   s   &&   r<   dup_decomposer   I  s=    H 	A
%DAaA37Nr>   c                    VP                   '       g   VP                  '       d   \        WV4      # VP                  '       d   \	        WV4      # \        R4      h)aI  
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_GaussianRingis_GaussianField_dmp_alg_inject_gaussianis_Algebraic_dmp_alg_inject_algr*   )r4   r@   r6   s   &&&r<   dmp_alg_injectr   {  sJ    , 	A...'a00	
"1++OPPr>   c                .   \        W4      / r0V P                  4        FD  w  rEVP                  VP                  rvV'       d   WcRV,           &   V'       g   K9  WsRV,           &   KF  	  \	        W1^,           VP
                  4      pW^,           VP
                  3# )+Helper function for :func:`dmp_alg_inject`.)    )rd   )r   r   xyr   dom)	r4   r@   r6   rn   f_monomr7   r   r   r   s	   &&&      r<   r   r     sw    qbqggi
ssACC1 !dWn1 !dWn   	aQ&A!eQUU?r>   c                   \        W4      / r0V P                  4        F6  w  rEVP                  4       P                  4        F  w  rgWsWd,           &   K  	  K8  	  \        W1^,           VP                  4      pW^,           VP                  3# )r   )r   r   to_dictr   r   )	r4   r@   r6   rn   r   r7   g_monomr9   r   s	   &&&      r<   r   r     sn    qbqggi
))+++-JG#$g  .   	aQ&A!eQUU?r>   c           
         ^RI Hp \        WV4      w  rEpVP                  P	                  4       p\        V\        \        ^V^,           4      4      ^ V4      pV! WHWV4      # )a#  
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

)dmp_resultant)euclidtoolsr   r   modto_listr(   r   r1   )	r4   r@   r6   r   r   rA   K2p_aP_As	   &&&      r<   dmp_liftr     sR    ( +aA&HA"
%%--/C
c4aQ0!R
8C''r>   c                B  a V3R lpSP                   '       g%   SP                  '       g   SP                  '       d   SP                  pEMSP                  '       d    SP
                  P                  '       d   TpMSP                  '       g   SP                  '       d   \        SP                  4      ^8X  d   SP                  P                   '       g/   SP                  P                  '       g   SP                  '       dJ   SP                  ^ ,          P                  '       d'   SP                  ^ ,          P                  '       d   TpM\        RS,          4      hSP                  ^ rTV  F,  pV! Wd,          4      '       d
   V^,          pV'       g   K*  TpK.  	  V# )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

c                 R   < V '       g   R # \        SP                  V 4      ^ 8  4      # )F)boolto_sympy)r_   r6   s   &r<   is_negative_sympy.dup_sign_variations.<locals>.is_negative_sympy  s#     

1)**r>   z-sign variation counting not supported over %s)rx   r   is_RRis_negativeis_AlgebraicFieldextis_comparableis_PolynomialRingis_FractionFieldrl   symbolsr   is_transcendentalr*   r.   )r4   r6   r   r   prevrQ   rP   s   &f     r<   dup_sign_variationsr     s   
+  	www!'''QWWWmm	
			!4!4!4'!"4"4"4#aii.A:M55;;;!%%+++)<)<)<
))A,
(
(
(QYYq\-G-G-G (IAMNNffa!uz""FA5D  Hr>   Nc           
        Vf&   VP                   '       d   VP                  4       pMTpVP                  pV  F#  pVP                  WAP	                  V4      4      pK%  	  VP                  V4      '       d   V'       g   W@3# V\        WV4      3# V  Uu. uF8  qQP                  V4      VP                  WAP	                  V4      4      ,          NK:  	  p pV'       g   V\        WV4      3# W@3# u upi )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_Ringget_ringr   lcmdenomr   r   numerr   )r4   K0K1r^   commonr9   s   &&&&  r<   dup_clear_denomsr     s    $ 
zBBVVF,  
yy9;qb111 ;<<!Q!RVVFHHQK0	0	0!A<{1"---y 	=s   >C,c           
         VP                   pV'       g,   V  F#  pVP                  WBP                  V4      4      pK%  	  V# V^,
          pV  F  pVP                  V\        WVW#4      4      pK!  	  V# )z.Recursive helper for :func:`dmp_clear_denoms`.)r   r   r   _rec_clear_denoms)r7   rA   r   r   r   r9   rF   s   &&&&   r<   r   r   8  si    VVFAVVFHHQK0F  M EAVVF$5aB$CDF  Mr>   c                   V'       g   \        WW4R7      # Vf&   VP                  '       d   VP                  4       pMTp\        WW#4      pVP	                  V4      '       g   \        WW4      p V'       g   WP3# V\        WW#4      3# )a*  
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^   )r   r   r   r   r   r   r   )r4   r@   r   r   r^   r   s   &&&&& r<   dmp_clear_denomsr  H  sy    $ r;;	zBBqR,F99V1a,y{1000r>   c                   VP                  \        W4      4      .pVP                  VP                  VP                  .p\	        \        \        V4      4      4      p\        ^V^,           4       FW  p\        W2! ^4      V4      p\        V \        W24      V4      p\        \        WxV4      WB4      p\        V\        V4      V4      pKY  	  V# )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

)revertr    r   r.   rz   _ceil_log2r1   r   r	   r   r   r   r   r   )	r4   r:   r6   r7   rn   Nr8   r_   r   s	   &&&      r<   
dup_revertr  n  s    ( 
&,	 A	
AE%(OA1a!e_1adA&Awq}a(GA!$a+q*Q-+	  Hr>   c                @    V'       g   \        WV4      # \        W4      h)z
Compute ``f**(-1)`` mod ``x**n`` using Newton iteration.

Examples
========

>>> from sympy.polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)

)r  r)   )r4   r7   r@   r6   s   &&&&r<   
dmp_revertr
    s     !"")!//r>   )NF)c__doc__sympy.polys.densearithr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   sympy.polys.densebasicr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   sympy.polys.polyerrorsr)   r*   mathr+   r  r,   r  r=   rB   rD   rK   rR   rT   rV   r[   ra   re   rg   ri   rk   rq   rs   rv   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
   r>   r<   <module>r     s\   N          
 .@ FL/,(V,^G*04:G*0
1(@L/4D@(E0*:!-H'T*Z0B!3H441h,,.(V>::#8# &/dQ< 
(<4n*Z #1LD0r>   