
    MZd<                        d Z ddlmZmZmZmZmZmZmZm	Z	m
Z
mZmZmZmZ ddlmZmZ d Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d  Z.d! Z/d" Z0d# Z1d$ Z2d% Z3d& Z4d' Z5d( Z6d) Z7d* Z8d+ Z9d, Z:d- Z;d. Z<d/ Z=d0 Z>d1 Z?d2 Z@d3 ZAd4 ZBd5 ZCd6 ZDd7 ZEd8 ZFd9 ZGd: ZHd; ZId< ZJd= ZKd> ZLd? ZMd@ ZNdA ZOdB ZPdC ZQyD)EzEArithmetics for dense recursive polynomials in ``K[x]`` or ``K[X]``.     )	dup_slicedup_LCdmp_LC
dup_degree
dmp_degree	dup_strip	dmp_strip
dmp_zero_pdmp_zero	dmp_one_pdmp_one
dmp_ground	dmp_zeros)ExactQuotientFailedPolynomialDivisionFailedc                     |s| S t        |       }||z
  dz
  }||dz
  k(  rt        | d   |z   g| dd z         S ||k\  r|g|j                  g||z
  z  z   | z   S | d| | |   |z   gz   | |dz   d z   S )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

       r   Nlenr   zerofciKnms         8/usr/lib/python3/dist-packages/sympy/polys/densearith.pydup_add_termr      s     AA	A	AAEz!A$(ae+,,63!&&1q5))A--Ra5AaD1H:%!a%&	11    c                 <   |st        | |||      S |dz
  }t        ||      r| S t        |       }||z
  dz
  }||dz
  k(  r"t        t	        | d   |||      g| dd z   |      S ||k\  r|gt        ||z
  ||      z   | z   S | d| t	        | |   |||      gz   | |dz   d z   S )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

    r   r   N)r   r
   r   r	   dmp_addr   r   r   r   ur   vr   r   s           r   dmp_add_termr&   +   s     Aq!Q''	AA!QAA	A	AAEz'!A$1a01AabE91==631q5!Q//!33Ra5GAaD!Q233aAi??r    c                     |s| S t        |       }||z
  dz
  }||dz
  k(  rt        | d   |z
  g| dd z         S ||k\  r| g|j                  g||z
  z  z   | z   S | d| | |   |z
  gz   | |dz   d z   S )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

    r   r   Nr   r   s         r   dup_sub_termr(   M   s     AA	A	AAEz!A$(ae+,,6B4166(AE**Q..Ra5AaD1H:%!a%&	11r    c                 T   |st        | | ||      S |dz
  }t        ||      r| S t        |       }||z
  dz
  }||dz
  k(  r"t        t	        | d   |||      g| dd z   |      S ||k\  r"t        |||      gt        ||z
  ||      z   | z   S | d| t	        | |   |||      gz   | |dz   d z   S )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

    r   r   N)r   r
   r   r	   dmp_subdmp_negr   r#   s           r   dmp_sub_termr,   j   s     Ar1a((	AA!QAA	A	AAEz'!A$1a01AabE91==6Aq!$%	!a%A(>>BBRa5GAaD!Q233aAi??r    c                 `    |r| sg S | D cg c]  }||z  	 c}|j                   g|z  z   S c c}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   )r   r   r   r   cfs        r   dup_mul_termr0      s5     A	"#%Ba%
22%s   +c           	          |st        | |||      S |dz
  }t        | |      r| S t        ||      rt        |      S | D cg c]  }t        ||||       c}t	        |||      z   S c c}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   )r0   r
   r   dmp_mulr   )r   r   r   r$   r   r%   r/   s          r   dmp_mul_termr3      sq     Aq!Q''	AA!Q!Q{013"Q1%3i1a6HHH3s   A%c                     t        | |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   )r   r   r   r   s      r   dup_add_groundr6           1a##r    c                 :    t        | t        ||dz
        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

    r   r   )r&   r   r   r   r$   r   s       r   dmp_add_groundr:      "     :aQ/Aq99r    c                     t        | |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(   r5   s      r   dup_sub_groundr=      r7   r    c                 :    t        | t        ||dz
        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

    r   r   )r,   r   r9   s       r   dmp_sub_groundr?      r;   r    c                 >    |r| sg S | D cg c]  }||z  	 c}S c c}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

     r   r   r   r/   s       r   dup_mul_groundrC      s&     A	"#%Ba%%%s   c           	      l    |st        | ||      S |dz
  }| D cg c]  }t        ||||       c}S c c}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   )rC   dmp_mul_groundr   r   r$   r   r%   r/   s         r   rE   rE     s>     aA&&	AA346R^B1a(666   1c                     |st        d      | s| S |j                  r | D cg c]  }|j                  ||       c}S | D cg c]  }||z  	 c}S c c}w c c}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)ZeroDivisionErroris_FieldquorB   s       r   dup_quo_groundrM   )  sZ    $  566zz()+"r1++#$&Rq&& ,&s   AAc           	      l    |st        | ||      S |dz
  }| D cg c]  }t        ||||       c}S c c}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   )rM   dmp_quo_groundrF   s         r   rO   rO   F  s>    $ aA&&	AA346R^B1a(666rG   c                 n    |st        d      | s| S | D cg c]  }|j                  ||       c}S c c}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   )rJ   exquorB   s       r   dup_exquo_groundrR   `  s9      566&')QWWR^)))s   2c           	      l    |st        | ||      S |dz
  }| D cg c]  }t        ||||       c}S c c}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   )rR   dmp_exquo_groundrF   s         r   rT   rT   v  s?     1a((	AA568rb!Q*888rG   c                 0    | s| S | |j                   g|z  z   S )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.   r   r   r   s      r   
dup_lshiftrW     s      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

    NrA   rV   s      r   
dup_rshiftrY     s      Sqb6Mr    c                 J    | D cg c]  }|j                  |       c}S c c}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

    )absr   r   coeffs      r   dup_absr^     s      ()*eQUU5\***s    c                 h    |st        | |      S |dz
  }| D cg c]  }t        |||       c}S c c}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_absr   r$   r   r%   r/   s        r   r`   r`     9     q!}	AA)*,2WRA,,,   /c                 .    | D cg c]  }|  c}S c c}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

    rA   r\   s      r   dup_negre     s     "#$eV$$$s   
c                 h    |st        | |      S |dz
  }| D cg c]  }t        |||       c}S c c}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   )re   r+   ra   s        r   r+   r+     rb   rc   c                 P   | s|S |s| S t        |       }t        |      }||k(  r+t        t        | |      D cg c]
  \  }}||z    c}}      S t        ||z
        }||kD  r| d| | |d } }n
|d| ||d }}|t        | |      D cg c]
  \  }}||z    c}}z   S c c}}w c c}}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)r   r   zipr[   	r   gr   dfdgabkhs	            r   dup_addrq     s     	AB	AB	RxSAY8TQ1q5899RL7Ra5!AB%qARa5!AB%qAs1ay2tq!QU222 9 3s   B
B"c                    |st        | ||      S t        | |      }|dk  r|S t        ||      }|dk  r| S |dz
  }||k(  r5t        t        | |      D cg c]  \  }}t	        ||||       c}}|      S t        ||z
        }	||kD  r| d|	 | |	d } }
n
|d|	 ||	d }}
|
t        | |      D cg c]  \  }}t	        ||||       c}}z   S c c}}w c c}}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

    r   r   N)rq   r   r	   rh   r"   r[   r   rj   r$   r   rk   rl   r%   rm   rn   ro   rp   s              r   r"   r"   $  s     q!Q	Aq	B	Av	Aq	B	Av	AA	Rx3q!9F41a71aA.FJJRL7Ra5!AB%qARa5!AB%qASAY@TQWQ1a(@@@ G As   C
-Cc                 x   | st        ||      S |s| S t        |       }t        |      }||k(  r+t        t        | |      D cg c]
  \  }}||z
   c}}      S t	        ||z
        }||kD  r| d| | |d } }nt        |d| |      ||d }}|t        | |      D cg c]
  \  }}||z
   c}}z   S c c}}w c c}}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)re   r   r   rh   r[   ri   s	            r   dup_subru   N  s     q!}	AB	AB	RxSAY8TQ1q5899RL7Ra5!AB%qA1Ra5!$aeqAs1ay2tq!QU222 9 3s   B0
B6c                    |st        | ||      S t        | |      }|dk  rt        |||      S t        ||      }|dk  r| S |dz
  }||k(  r5t        t	        | |      D cg c]  \  }}t        ||||       c}}|      S t        ||z
        }	||kD  r| d|	 | |	d } }
nt        |d|	 ||      ||	d }}
|
t	        | |      D cg c]  \  }}t        ||||       c}}z   S c c}}w c c}}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

    r   r   N)ru   r   r+   r	   rh   r*   r[   rs   s              r   r*   r*   q  s    q!Q	Aq	B	Avq!Q	Aq	B	Av	AA	Rx3q!9F41a71aA.FJJRL7Ra5!AB%qA1Ra5!Q'12qASAY@TQWQ1a(@@@ G As   C!
C'c                 2    t        | 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

    )rq   dup_mulr   rj   rp   r   s       r   dup_add_mulrz          1gaA&**r    c           	      6    t        | 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"   r2   r   rj   rp   r$   r   s        r   dmp_add_mulr~           1gaAq)1a00r    c                 2    t        | 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

    )ru   rx   ry   s       r   dup_sub_mulr     r{   r    c           	      6    t        | 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*   r2   r}   s        r   dmp_sub_mulr     r   r    c           
      0   | |k(  rt        | |      S | r|sg S t        |       }t        |      }t        ||      dz   }|dk  r}g }t        d||z   dz         D ][  }|j                  }t        t        d||z
        t        ||      dz         D ]  }	|| |	   |||	z
     z  z  } |j                  |       ] t        |      S |dz  }
t        | d|
|      t        |d|
|      }}t        t        | |
||      |
|      }t        t        ||
||      |
|      }t        |||      t        |||      }}t        t        |||      t        |||      |      }t        |t        |||      |      }t        t        |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

    r   d   r      )dup_sqrr   maxranger   minappendr   r   rY   rx   rq   ru   rW   )r   rj   r   rk   rl   r   rp   r   r]   jn2flglfhghlohimids                     r   rx   rx     s    	Avq!}!		AB	ABBaA3wq"r'A+& 	AFFE3q!b&>3r1:>: '1aAh&' HHUO	 |
 T1aQ'1aQ)?B	!RA.A6	!RA.A6R#WRQ%7Bgb"a('"b!*<a@c72r1-q1wr:c2q#91=!"adA.3 	3r    c                    |st        | ||      S | |k(  rt        | ||      S t        | |      }|dk  r| S t        ||      }|dk  r|S g |dz
  }}t        d||z   dz         D ]l  }t	        |      }	t        t        d||z
        t        ||      dz         D ]%  }
t        |	t        | |
   |||
z
     ||      ||      }	' |j                  |	       n t        ||      S )z
    Multiply dense polynomials in ``K[X]``.

    Examples
    ========

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

    >>> R.dmp_mul(x*y + 1, x)
    x**2*y + x

    r   r   )rx   dmp_sqrr   r   r   r   r   r"   r2   r   r	   )r   rj   r$   r   rk   rl   rp   r%   r   r]   r   s              r   r2   r2     s     q!QAvq!Q	Aq	B	Av	Aq	B	Avq1uqA1b2gk" s1a"f~s2qzA~6 	HAE71Q41q51a#@!QGE	H 	
 Q?r    c                 z   t        |       dz
  g }}t        dd|z  dz         D ]  }|j                  }t        d||z
        }t	        ||      }||z
  dz   }||dz  z   dz
  }t        ||dz         D ]  }	|| |	   | ||	z
     z  z  } ||z  }|dz  r| |dz      }
||
dz  z  }|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

    r   r   r   )r   r   r   r   r   r   r   )r   r   rk   rp   r   r   jminjmaxr   r   elems              r   r   r   C  s     FQJB1adQh FF1a"f~1bz4K!Oa1f}q tTAX& 	A1aAhA	 	
Qq5TAX;DqLA	'* Q<r    c                    |st        | |      S t        | |      }|dk  r| S g |dz
  }}t        dd|z  dz         D ]  }t        |      }t	        d||z
        }t        ||      }	|	|z
  dz   }
||
dz  z   dz
  }	t        ||	dz         D ]%  }t        |t        | |   | ||z
     ||      ||      }' t        | |d      ||      }|
dz  r!t        | |	dz      ||      }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

    r   r   r   )r   r   r   r   r   r   r"   r2   rE   r   r   r	   )r   r$   r   rk   rp   r%   r   r   r   r   r   r   r   s                r   r   r   k  s7    q!}	Aq	B	Avq1uqA1adQh QK1a"f~1bz4K!Oa1f}q tTAX& 	@A71Q41q51a8!Q?A	@ 1adAq)q51TAX;1-D4A&A	'* Q?r    c                     |s|j                   gS |dk  rt        d      |dk(  s| r| |j                   gk(  r| S |j                   g}	 |dz  |}}|dz  rt        || |      }|s	 |S t        | |      } +)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 powerr   r   )one
ValueErrorrx   r   )r   r   r   rj   r   s        r   dup_powr     s     w1uFGGAvQ!w,	
A
!tQ1q51a A H AqM r    c                    |st        | ||      S |st        ||      S |dk  rt        d      |dk(  st        | |      st	        | ||      r| S t        ||      }	 |dz  |}}|dz  rt        || ||      }|s	 |S t        | ||      } -)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

    r   r   r   r   )r   r   r   r
   r   r2   r   )r   r   r$   r   rj   r   s         r   dmp_powr     s     q!Qq!}1uFGGAvAq!Yq!Q%71A
!tQ1q51a#A H Aq! r    c                    t        |       }t        |      }g | |}}}|st        d      ||k  r||fS ||z
  dz   }t        ||      }		 t        ||      }
||z
  |dz
  }}t        ||	|      }t	        ||
||      }t        ||	|      }t        ||
||      }t        |||      }|t        |      }}||k  rn||k  st        | ||      |	|z  }t        |||      }t        |||      }||fS )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)

    rI   r   )r   rJ   r   rC   r   r0   ru   r   )r   rj   r   rk   rl   qrdrNlc_glc_rr   QRG_drr   s                    r   dup_pdivr     s%    
AB	AB1b"qA 566	b!t
R!A!Q<D
a|BwA11dA&D!Q'1dA&D!Q'Aq!jmR7s(*1a33! $ 	aAq!QAq!QAa4Kr    c                 p   t        |       }t        |      }| |}}|st        d      ||k  r|S ||z
  dz   }t        ||      }	 t        ||      }	||z
  |dz
  }}
t        |||      }t	        ||	|
|      }t        |||      }|t        |      }}||k  rn||k  st        | ||      dt        |||z  |      S )z
    Polynomial pseudo-remainder in ``K[x]``.

    Examples
    ========

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

    >>> R.dup_prem(x**2 + 1, 2*x - 4)
    20

    rI   r   )r   rJ   r   rC   r0   ru   r   )r   rj   r   rk   rl   r   r   r   r   r   r   r   r   r   s                 r   dup_premr     s     
AB	ABrrA 566	b
R!A!Q<D
a|BwA11dA&D!Q'Aq!jmR7s(*1a33  !T1Wa((r    c                 "    t        | ||      d   S )a   
    Polynomial exact pseudo-quotient in ``K[X]``.

    Examples
    ========

    >>> 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   )r   r   rj   r   s      r   dup_pquor   J  s    " Aq!Qr    c                 B    t        | ||      \  }}|s|S t        | |      )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]

    )r   r   r   rj   r   r   r   s        r   
dup_pexquor   ^  s+    & Aq!DAq!!Q''r    c                 >   |st        | ||      S t        | |      }t        ||      }|dk  rt        d      t        |      | |}}}||k  r||fS ||z
  dz   }	t	        ||      }
	 t	        ||      }||z
  |	dz
  }	}t        ||
d||      }t        |||||      }t        ||
d||      }t        |||||      }t        ||||      }|t        ||      }}||k  rn||k  st        | ||      t        |
|	|dz
  |      }t        ||d||      }t        ||d||      }||fS )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)

    r   rI   r   )
r   r   rJ   r   r   r3   r&   r*   r   r   )r   rj   r$   r   rk   rl   r   r   r   r   r   r   r   r   r   r   r   r   s                     r   dmp_pdivr   y  si    1a  	Aq	B	Aq	B	Av 566{Ar"qA	Bw!t
R!A!Q<D
a|BwA1D!Q*D!Q*D!Q*D!Q*Aq!QjA&R7s(*1a33! $ 	aQ"AQ1a#AQ1a#Aa4Kr    c                    |st        | ||      S t        | |      }t        ||      }|dk  rt        d      | |}}||k  r|S ||z
  dz   }t        ||      }		 t        ||      }
||z
  |dz
  }}t	        ||	d||      }t	        ||
|||      }t        ||||      }|t        ||      }}||k  rn||k  st        | ||      it        |	||dz
  |      }t	        ||d||      S )z
    Polynomial pseudo-remainder in ``K[X]``.

    Examples
    ========

    >>> 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

    r   rI   r   )r   r   rJ   r   r3   r*   r   r   )r   rj   r$   r   rk   rl   r   r   r   r   r   r   r   r   r   r   s                   r   dmp_premr     s    1a  	Aq	B	Aq	B	Av 566rrA	Bw
R!A!Q<D
a|BwA1D!Q*D!Q*Aq!QjA&R7s(*1a33  	aQ"A1aA&&r    c                 $    t        | |||      d   S )a.  
    Polynomial exact 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_pquo(f, g)
    2*x

    >>> R.dmp_pquo(f, h)
    2*x + 2*y - 2

    r   )r   r   rj   r$   r   s       r   dmp_pquor     s    * Aq!Q""r    c                 X    t        | |||      \  }}t        ||      r|S t        | |      )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], []]

    )r   r
   r   r   rj   r$   r   r   r   s         r   
dmp_pexquor     s4    . Aq!QDAq!Q!!Q''r    c                    t        |       }t        |      }g | |}}}|st        d      ||k  r||fS t        ||      }	 t        ||      }	|	|z  r	 ||fS |j                  |	|      }
||z
  }t	        ||
||      }t        ||
||      }t        |||      }|t        |      }}||k  r	 ||fS ||k  s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   )r   rJ   r   rQ   r   r0   ru   r   r   rj   r   rk   rl   r   r   r   r   r   r   r   rp   r   s                 r   
dup_rr_divr     s     
AB	AB1b"qA 566	b!t!Q<D
a|$;  a4K GGD$GAq!$Aq!$Aq!jmR7 a4K s(*1a33% r    c                    |st        | ||      S t        | |      }t        ||      }|dk  rt        d      t        |      | |}}}||k  r||fS t	        ||      |dz
  }
}		 t	        ||      }t        ||	|
|      \  }}t        ||
      s	 ||fS ||z
  }t        |||||      }t        |||||      }t        ||||      }|t        ||      }}||k  r	 ||fS ||k  st        | ||      )z
    Multivariate division with remainder over a ring.

    Examples
    ========

    >>> 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)

    r   rI   r   )r   r   rJ   r   r   
dmp_rr_divr
   r&   r3   r*   r   r   rj   r$   r   rk   rl   r   r   r   r   r%   r   r   r   r   rp   r   s                    r   r   r   M  0    !Q""	Aq	B	Aq	B	Av 566{Ar"qA	Bw!tQlAE!D
a|$a+1!Q a4K GAq!Q'Aq!Q'Aq!QjA&R7 a4K s(*1a33% r    c                    t        |       }t        |      }g | |}}}|st        d      ||k  r||fS t        ||      }	 t        ||      }	|j                  |	|      }
||z
  }t	        ||
||      }t        ||
||      }t        |||      }|t        |      }}||k  r	 ||fS ||k(  r/|j                  s#t        |dd       }t        |      }||k  r	 ||fS ||k  s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)

    rI   r   N)
r   rJ   r   rQ   r   r0   ru   is_Exactr   r   r   s                 r   
dup_ff_divr     s    
AB	AB1b"qA 566	b!t!Q<D
a|GGD$GAq!$Aq!$Aq!jmR7 a4K 3Yqzz!AB% AABBw a4K s(*1a33+ r    c                    |st        | ||      S t        | |      }t        ||      }|dk  rt        d      t        |      | |}}}||k  r||fS t	        ||      |dz
  }
}		 t	        ||      }t        ||	|
|      \  }}t        ||
      s	 ||fS ||z
  }t        |||||      }t        |||||      }t        ||||      }|t        ||      }}||k  r	 ||fS ||k  st        | ||      )z
    Polynomial division with remainder over a field.

    Examples
    ========

    >>> 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)

    r   rI   r   )r   r   rJ   r   r   
dmp_ff_divr
   r&   r3   r*   r   r   s                    r   r   r     r   r    c                 N    |j                   rt        | ||      S t        | ||      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)

    )rK   r   r   r   s      r   dup_divr     s)    $ 	zz!Q""!Q""r    c                 "    t        | ||      d   S )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

    r   r   r   s      r   dup_remr         $ 1aAr    c                 "    t        | ||      d   S )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

    r   r   r   s      r   dup_quor     r   r    c                 B    t        | ||      \  }}|s|S t        | |      )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]

    )r   r   r   s        r   	dup_exquor   -  s+    & 1aDAq!!Q''r    c                 R    |j                   rt        | |||      S t        | |||      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)

    )rK   r   r   r   s       r   dmp_divr   H  s-    $ 	zz!Q1%%!Q1%%r    c                 $    t        | |||      d   S )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

    r   r   r   s       r   dmp_remr   `      $ 1aAq!!r    c                 $    t        | |||      d   S )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

    r   r   r   s       r   dmp_quor   u  r   r    c                 X    t        | |||      \  }}t        ||      r|S t        | |      )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], []]

    )r   r
   r   r   s         r   	dmp_exquor     s4    . 1aADAq!Q!!Q''r    c                 H    | s|j                   S t        t        | |            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

    )r   r   r^   r   r   s     r   dup_max_normr     !     vv71a=!!r    c           
      z    |st        | |      S |dz
  }t        | D cg c]  }t        |||       c}      S c c}w )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

    r   )r   r   dmp_max_normr   r$   r   r%   r   s        r   r   r     s?     Aq!!	AA31aA&3443   8c                 H    | s|j                   S t        t        | |            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

    )r   sumr^   r   s     r   dup_l1_normr     r   r    c           
      z    |st        | |      S |dz
  }t        | D cg c]  }t        |||       c}      S c c}w )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

    r   )r   r   dmp_l1_normr   s        r   r   r     s?     1a  	AAq2!Q1%2332r   c                 Z    t        | D cg c]  }|dz  	 c}|j                        S c c}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   )r   r   r\   s      r   dup_l2_norm_squaredr     s'     a(Uq(!&&11(s   (c           
      z    |st        | |      S |dz
  }t        | D cg c]  }t        |||       c}      S c c}w )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

    r   )r   r   dmp_l2_norm_squaredr   s        r   r   r     s@     "1a((	AAq:!$Q1-:;;:r   c                 \    | s|j                   gS | d   }| dd D ]  }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

    r   r   N)r   rx   )polysr   r   rj   s       r   
dup_expandr   $  sE     waA12Y Aq! Hr    c                 \    | st        ||      S | d   }| dd D ]  }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

    r   r   N)r   r2   )r   r$   r   r   rj   s        r   
dmp_expandr   =  sH     q!}aA12Y  Aq!Q  Hr    N)R__doc__sympy.polys.densebasicr   r   r   r   r   r   r	   r
   r   r   r   r   r   sympy.polys.polyerrorsr   r   r   r&   r(   r,   r0   r3   r6   r:   r=   r?   rC   rE   rM   rO   rR   rT   rW   rY   r^   r`   re   r+   rq   r"   ru   r*   rz   r~   r   r   rx   r2   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   rA   r    r   <module>r      s{   K    S2:@D2:@D3(I6$":"$":"&(7,':74*,9,(&+"-,%"-, 3F'AT 3F'AT+"1"+"1"63r(V%P-`"J%P2j*)Z ((66r0'f#0(>.b2j1h2j#0**(6&0"*"*(>"(5,"(4,2"<,2r    