o
    &ôjB…  ã                   @   sT  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d„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Z d"d#„ Z!d$d%„ Z"d&d'„ Z#d(d)„ Z$d*d+„ Z%d,d-„ Z&d.d/„ Z'd0d1„ Z(d2d3„ Z)d4d5„ Z*d6d7„ Z+d8d9„ Z,d:d;„ Z-d<d=„ Z.d>d?„ Z/d@dA„ Z0dBdC„ Z1dDdE„ Z2dFdG„ Z3dHdI„ Z4dJdK„ Z5dLdM„ Z6dNdO„ Z7dPdQ„ Z8dRdS„ Z9dTdU„ Z:dVdW„ Z;dXdY„ Z<dZd[„ Z=d\d]„ Z>d^d_„ Z?d`da„ Z@dbdc„ ZAddde„ ZBdfdg„ ZCdhdi„ ZDdjdk„ ZEdldm„ ZFdndo„ ZGdpdq„ ZHdrds„ ZIdtdu„ ZJdvdw„ ZKdxdy„ ZLdzd{„ ZMd|d}„ ZNd~d„ ZOd€d�„ ZPd‚dƒ„ ZQd„S )…zEArithmetics 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                 C   s’   |s| S t | ƒ}|| d }||d kr#t| d | g| dd…  ƒS ||kr4|g|jg||   |  S | d|… | | | g | |d d…  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Úm© r   úg/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/sympy/polys/densearith.pyÚdup_add_term   s   *r   c                 C   sÀ   |s	t | |||ƒS |d }t||ƒr| S t| ƒ}|| d }||d kr7tt| d |||ƒg| dd…  |ƒS ||krH|gt|| ||ƒ |  S | d|… t| | |||ƒg | |d d…  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   r   r   r   Údmp_add_term+   s   
&0r#   c                 C   s”   |s| S t | ƒ}|| d }||d kr#t| d | g| dd…  ƒS ||kr5| g|jg||   |  S | d|… | | | g | |d d…  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   r   r   r   Údup_sub_termM   s   *r$   c                 C   sÊ   |s
t | | ||ƒS |d }t||ƒr| S t| ƒ}|| d }||d kr8tt| d |||ƒg| dd…  |ƒS ||krMt|||ƒgt|| ||ƒ |  S | d|… t| | |||ƒg | |d d…  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    r   r   r   Údmp_sub_termj   s   
&"0r'   c                    s*   ˆ r| sg S ‡ fdd„| D ƒ|j g|  S )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

    c                    ó   g | ]}|ˆ  ‘qS r   r   ©Ú.0Úcf©r   r   r   Ú
<listcomp>�   ó    z dup_mul_term.<locals>.<listcomp>©r   )r   r   r   r   r   r,   r   Údup_mul_termŒ   s   r0   c                    s\   |s	t | ˆ|ˆ ƒS |d ‰t| |ƒr| S tˆˆƒrt|ƒS ‡ ‡‡fdd„| D ƒt|ˆˆ ƒ S )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   c                    ó   g | ]	}t |ˆˆˆ ƒ‘qS r   )Údmp_mulr)   ©r   r   r"   r   r   r-   ¸   ó    z dmp_mul_term.<locals>.<listcomp>)r0   r	   r
   r   )r   r   r   r!   r   r   r3   r   Údmp_mul_term    s   

"r5   c                 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   r   r   r   Údup_add_ground»   ó   r8   c                 C   ó   t | t||d ƒ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   r   r   r   Údmp_add_groundÌ   ó   r<   c                 C   r6   )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$   r7   r   r   r   Údup_sub_groundÝ   r9   r>   c                 C   r:   )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   r;   r   r   r   Údmp_sub_groundî   r=   r?   c                    s   ˆ r| sg S ‡ fdd„| D ƒS )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

    c                    r(   r   r   r)   r,   r   r   r-     r.   z"dup_mul_ground.<locals>.<listcomp>r   r7   r   r,   r   Údup_mul_groundÿ   s   r@   c                    ó.   |st | ˆˆ ƒS |d ‰‡ ‡‡fdd„| D ƒS )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   c                    r1   r   )Údmp_mul_groundr)   r3   r   r   r-   &  r4   z"dmp_mul_ground.<locals>.<listcomp>)r@   r;   r   r3   r   rB     ó   rB   c                    s@   ˆst dƒ‚| s
| S ˆ jr‡ ‡fdd„| D ƒS ‡fdd„| D ƒS )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 divisionc                    ó   g | ]}ˆ   |ˆ¡‘qS r   )Úquor)   ©r   r   r   r   r-   A  ó    z"dup_quo_ground.<locals>.<listcomp>c                    s   g | ]}|ˆ  ‘qS r   r   r)   r,   r   r   r-   C  r.   )ÚZeroDivisionErrorÚis_Fieldr7   r   rG   r   Údup_quo_ground)  s   rK   c                    rA   )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   c                    r1   r   )Údmp_quo_groundr)   r3   r   r   r-   ]  r4   z"dmp_quo_ground.<locals>.<listcomp>)rK   r;   r   r3   r   rL   F  s   rL   c                    s(   ˆst dƒ‚| s
| S ‡ ‡fdd„| D ƒS )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

    rD   c                    rE   r   )Úexquor)   rG   r   r   r-   s  rH   z$dup_exquo_ground.<locals>.<listcomp>)rI   r7   r   rG   r   Údup_exquo_ground`  s
   rN   c                    rA   )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   c                    r1   r   )Údmp_exquo_groundr)   r3   r   r   r-   ‰  r4   z$dmp_exquo_ground.<locals>.<listcomp>)rN   r;   r   r3   r   rO   v  rC   rO   c                 C   s   | s| S | |j g|  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   r   r   r   Ú
dup_lshiftŒ  s   rQ   c                 C   s   | 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

    Nr   rP   r   r   r   Ú
dup_rshift   s   rR   c                    s   ‡ fdd„| D ƒS )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

    c                    s   g | ]}ˆ   |¡‘qS r   )Úabs©r*   Úcoeff©r   r   r   r-   Á  s    zdup_abs.<locals>.<listcomp>r   ©r   r   r   rV   r   Údup_abs³  s   rX   c                    ó*   |st | ˆ ƒS |d ‰‡ ‡fdd„| D ƒS )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   c                    ó   g | ]}t |ˆˆ ƒ‘qS r   )Údmp_absr)   ©r   r"   r   r   r-   ×  rH   zdmp_abs.<locals>.<listcomp>)rX   ©r   r!   r   r   r\   r   r[   Ä  ó   
r[   c                 C   s   dd„ | D ƒS )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

    c                 S   s   g | ]}| ‘qS r   r   rT   r   r   r   r-   è  s    zdup_neg.<locals>.<listcomp>r   rW   r   r   r   Údup_negÚ  r9   r_   c                    rY   )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   c                    rZ   r   )r&   r)   r\   r   r   r-   þ  rH   zdmp_neg.<locals>.<listcomp>)r_   r]   r   r\   r   r&   ë  r^   r&   c                 C   s¢   | s|S |s| S t | ƒ}t |ƒ}||kr tdd„ t| |ƒD ƒƒS t|| ƒ}||kr8| d|… | |d… }} n|d|… ||d… }}|dd„ t| |ƒD ƒ S )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

    c                 S   ó   g | ]\}}|| ‘qS r   r   ©r*   ÚaÚbr   r   r   r-     rH   zdup_add.<locals>.<listcomp>Nc                 S   r`   r   r   ra   r   r   r   r-   !  rH   )r   r   ÚziprS   ©r   Úgr   ÚdfÚdgÚkÚhr   r   r   Údup_add  s   rk   c                    sÔ   |st | |ˆ ƒS t| |ƒ}|dk r|S t||ƒ}|dk r| S |d ‰||kr6t‡ ‡fdd„t| |ƒD ƒ|ƒS t|| ƒ}||krN| d|… | |d… }} n|d|… ||d… }}|‡ ‡fdd„t| |ƒD ƒ S )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   c                    ó   g | ]\}}t ||ˆˆ ƒ‘qS r   ©r   ra   r\   r   r   r-   B  ó    zdmp_add.<locals>.<listcomp>Nc                    rl   r   rm   ra   r\   r   r   r-   K  rn   )rk   r   r   rd   rS   ©r   rf   r!   r   rg   rh   ri   rj   r   r\   r   r   $  s    

 r   c                 C   s®   | st ||ƒS |s| S t| ƒ}t|ƒ}||kr#tdd„ t| |ƒD ƒƒS t|| ƒ}||kr;| d|… | |d… }} nt |d|… |ƒ||d… }}|dd„ t| |ƒD ƒ S )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

    c                 S   ó   g | ]\}}|| ‘qS r   r   ra   r   r   r   r-   e  rH   zdup_sub.<locals>.<listcomp>Nc                 S   rp   r   r   ra   r   r   r   r-   n  rH   )r_   r   r   rd   rS   re   r   r   r   Údup_subN  s   
 rq   c                    sä   |st | |ˆ ƒS t| |ƒ}|dk rt||ˆ ƒS t||ƒ}|dk r"| S |d ‰||kr:t‡ ‡fdd„t| |ƒD ƒ|ƒS t|| ƒ}||krR| d|… | |d… }} nt|d|… |ˆ ƒ||d… }}|‡ ‡fdd„t| |ƒD ƒ S )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   c                    rl   r   ©r%   ra   r\   r   r   r-   �  rn   zdmp_sub.<locals>.<listcomp>Nc                    rl   r   rr   ra   r\   r   r   r-   ˜  rn   )rq   r   r&   r   rd   rS   ro   r   r\   r   r%   q  s    

 "r%   c                 C   ó   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

    )rk   Údup_mul©r   rf   rj   r   r   r   r   Údup_add_mul›  ó   rv   c                 C   ó   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   rf   rj   r!   r   r   r   r   Údmp_add_mul¬  ó   rz   c                 C   rs   )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

    )rq   rt   ru   r   r   r   Údup_sub_mul½  rw   r|   c                 C   rx   )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   ry   r   r   r   Údmp_sub_mulÎ  r{   r}   c                 C   s~  | |kr	t | |ƒS | r|sg S t| ƒ}t|ƒ}t||ƒd }|dk s%|js]g }td|| d ƒD ](}|j}ttd|| ƒt||ƒd ƒD ]}	|| |	 |||	   7 }qD| |¡ q0t|ƒS |d }
t	| d|
|ƒt	|d|
|ƒ}}t
t	| |
||ƒ|
|ƒ}t
t	||
||ƒ|
|ƒ}t|||ƒt|||ƒ}}tt|||ƒt|||ƒ|ƒ}t|t|||ƒ|ƒ}tt|t||
|ƒ|ƒt|d|
 |ƒ|ƒ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Úis_ExactÚranger   ÚminÚappendr   r   rR   rt   rk   rq   rQ   )r   rf   r   rg   rh   r   rj   r   rU   ÚjÚn2ÚflÚglÚfhÚghÚloÚhiÚmidr   r   r   rt   ß  s2   
"ÿrt   c              	   C   sÚ   |st | ||ƒS | |krt| ||ƒS t| |ƒ}|dk r| S t||ƒ}|dk r(|S g |d }}td|| d ƒD ]/}t|ƒ}	ttd|| ƒt||ƒd ƒD ]}
t|	t| |
 |||
  ||ƒ||ƒ}	qM| 	|	¡ q8t
||ƒ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   )rt   Údmp_sqrr   rƒ   r
   r�   r„   r   r2   r…   r   )r   rf   r!   r   rg   rh   rj   r"   r   rU   r†   r   r   r   r2     s"   

"&
r2   c                 C   sÊ   t | ƒd g }}tdd| d ƒD ]N}|j}td|| ƒ}t||ƒ}|| d }||d  d }t||d ƒD ]}	|| |	 | ||	   7 }q8||7 }|d@ r[| |d  }
||
d 7 }| |¡ q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   rg   rj   r   r   ÚjminÚjmaxr   r†   Úelemr   r   r   r€   C  s   
r€   c              	   C   s  |st | |ƒS t| |ƒ}|dk r| S g |d }}tdd| d ƒD ]_}t|ƒ}td|| ƒ}t||ƒ}	|	| d }
||
d  d }	t||	d ƒD ]}t|t| | | ||  ||ƒ||ƒ}qIt||dƒ||ƒ}|
d@ r|t	| |	d  ||ƒ}t||||ƒ}| 
|¡ q"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   rB   r�   r…   r   )r   r!   r   rg   rj   r"   r   r   r�   r‘   r   r†   r’   r   r   r   r�   k  s(   


&
r�   c                 C   sz   |s|j gS |dk rtdƒ‚|dks| r| |j gkr| S |j g}	 |d |}}|d r7t|| |ƒ}|s7	 |S t| |ƒ} q!)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   Tr   )ÚoneÚ
ValueErrorrt   r€   )r   r   r   rf   r   r   r   r   Údup_pow›  s    
þ÷r–   c                 C   s˜   |st | ||ƒS |st||ƒS |dk rtdƒ‚|dks&t| |ƒs&t| ||ƒr(| S t||ƒ}	 |d |}}|d@ rEt|| ||ƒ}|sE	 |S t| ||ƒ} q.)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   Tr   )r–   r   r•   r	   r   r2   r�   )r   r   r!   r   rf   r   r   r   r   Údmp_powÀ  s$   

þ÷r—   c                 C   s  t | ƒ}t |ƒ}g | |}}}|stdƒ‚||k r||fS || d }t||ƒ}		 t||ƒ}
|| |d }}t||	|ƒ}t||
||ƒ}t||	|ƒ}t||
||ƒ}t|||ƒ}|t |ƒ}}||k rdn||k snt| ||ƒ‚q*|	| }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)

    rD   r   )r   rI   r   r@   r   r0   rq   r   )r   rf   r   rg   rh   ÚqÚrÚdrÚNÚlc_gÚlc_rr†   ÚQÚRÚGÚ_drr   r   r   r   Údup_pdivè  s6   

ðr¢   c                 C   sÊ   t | ƒ}t |ƒ}| |}}|stdƒ‚||k r|S || d }t||ƒ}	 t||ƒ}	|| |d }
}t|||ƒ}t||	|
|ƒ}t|||ƒ}|t |ƒ}}||k rRn||k s\t| ||ƒ‚q%t||| |ƒ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

    rD   r   )r   rI   r   r@   r0   rq   r   )r   rf   r   rg   rh   r™   rš   r›   rœ   r�   r†   rŸ   r    r¡   r   r   r   Údup_prem  s,   


ór£   c                 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   rf   r   r   r   r   Údup_pquoJ  s   r¦   c                 C   ó"   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   rf   r   r˜   r™   r   r   r   Ú
dup_pexquo^  ó   
r©   c                 C   sD  |st | ||ƒS t| |ƒ}t||ƒ}|dk rtdƒ‚t|ƒ| |}}}||k r,||fS || d }	t||ƒ}
	 t||ƒ}|| |	d }}	t||
d||ƒ}t|||||ƒ}t||
d||ƒ}t|||||ƒ}t||||ƒ}|t||ƒ}}||k rzn||k s„t| ||ƒ‚q8t	|
|	|d |ƒ}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   rD   r   )
r¢   r   rI   r
   r   r5   r#   r%   r   r—   )r   rf   r!   r   rg   rh   r˜   r™   rš   r›   rœ   r�   r†   rž   rŸ   r    r¡   r   r   r   r   Údmp_pdivy  s:   



ðr«   c                 C   sþ   |st | ||ƒS t| |ƒ}t||ƒ}|dk rtdƒ‚| |}}||k r%|S || d }t||ƒ}		 t||ƒ}
|| |d }}t||	d||ƒ}t||
|||ƒ}t||||ƒ}|t||ƒ}}||k rcn||k smt| ||ƒ‚q1t|	||d |ƒ}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   rD   r   )r£   r   rI   r   r5   r%   r   r—   )r   rf   r!   r   rg   rh   r™   rš   r›   rœ   r�   r†   rŸ   r    r¡   r   r   r   r   Údmp_prem²  s2   




ór¬   c                 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   rf   r!   r   r   r   r   Údmp_pquoå  s   r¯   c                 C   ó*   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   rf   r!   r   r˜   r™   r   r   r   Ú
dmp_pexquoý  ó   

r²   c                 C   sÖ   t | ƒ}t |ƒ}g | |}}}|stdƒ‚||k r||fS t||ƒ}	 t||ƒ}	|	| r2	 ||fS | |	|¡}
|| }t||
||ƒ}t||
||ƒ}t|||ƒ}|t |ƒ}}||k r`	 ||fS ||k sjt| ||ƒ‚q$)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)

    rD   )r   rI   r   rM   r   r0   rq   r   ©r   rf   r   rg   rh   r˜   r™   rš   rœ   r�   r   r†   rj   r¡   r   r   r   Ú
dup_rr_div  s2   

òýîrµ   c                 C   ó  |st | ||ƒS t| |ƒ}t||ƒ}|dk rtdƒ‚t|ƒ| |}}}||k r,||fS t||ƒ|d }	}
	 t||ƒ}t||	|
|ƒ\}}t||
ƒsO	 ||fS || }t|||||ƒ}t|||||ƒ}t	||||ƒ}|t||ƒ}}||k r{	 ||fS ||k s…t
| ||ƒ‚q7)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   rD   r   )rµ   r   rI   r
   r   Ú
dmp_rr_divr	   r#   r5   r%   r   ©r   rf   r!   r   rg   rh   r˜   r™   rš   rœ   r"   r�   r   rŸ   r†   rj   r¡   r   r   r   r·   M  ó6   



óýîr·   c                 C   sþ   t | ƒ}t |ƒ}g | |}}}|stdƒ‚||k r||fS t||ƒ}	 t||ƒ}	| |	|¡}
|| }t||
||ƒ}t||
||ƒ}t|||ƒ}|t |ƒ}}||k rW	 ||fS ||krt|jstt|dd… ƒ}t |ƒ}||k rs	 ||fS n
||k s~t	| ||ƒ‚q$)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)

    rD   Tr   N)
r   rI   r   rM   r   r0   rq   r‚   r   r   r´   r   r   r   Ú
dup_ff_div‚  s:   


÷ûërº   c                 C   r¶   )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   rD   r   )rº   r   rI   r
   r   Ú
dmp_ff_divr	   r#   r5   r%   r   r¸   r   r   r   r»   ¶  r¹   r»   c                 C   s   |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)

    )rJ   rº   rµ   r¥   r   r   r   Údup_divë  s   r¼   c                 C   r¤   )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¥   r   r   r   Údup_rem  ó   r¾   c                 C   r¤   )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¥   r   r   r   Údup_quo  r¿   rÀ   c                 C   r§   )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¨   r   r   r   Ú	dup_exquo-  rª   rÁ   c                 C   s"   |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)

    )rJ   r»   r·   r®   r   r   r   Údmp_divH  s   rÂ   c                 C   r­   )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®   r   r   r   Údmp_rem`  ó   rÄ   c                 C   r­   )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®   r   r   r   Údmp_quou  rÅ   rÆ   c                 C   r°   )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±   r   r   r   Ú	dmp_exquoŠ  r³   rÇ   c                 C   ó   | 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�   rX   rW   r   r   r   Údup_max_norm©  ó   rÉ   c                    ó.   |st | ˆ ƒS |d ‰t‡ ‡fdd„| D ƒƒS )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   c                 3   ó   � | ]	}t |ˆˆ ƒV  qd S ©N)Údmp_max_norm©r*   r   r\   r   r   Ú	<genexpr>Ð  ó   € zdmp_max_norm.<locals>.<genexpr>)rÉ   r�   r]   r   r\   r   rÎ   ½  ó   
rÎ   c                 C   rÈ   )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   ÚsumrX   rW   r   r   r   Údup_l1_normÓ  rÊ   rÔ   c                    rË   )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   c                 3   rÌ   rÍ   )Údmp_l1_normrÏ   r\   r   r   rÐ   ú  rÑ   zdmp_l1_norm.<locals>.<genexpr>)rÔ   rÓ   r]   r   r\   r   rÕ   ç  rÒ   rÕ   c                 C   s   t dd„ | D ƒ|jƒS )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

    c                 S   s   g | ]}|d  ‘qS )r   r   rT   r   r   r   r-     r.   z'dup_l2_norm_squared.<locals>.<listcomp>)rÓ   r   rW   r   r   r   Údup_l2_norm_squaredý  s   rÖ   c                    rË   )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   c                 3   rÌ   rÍ   )Údmp_l2_norm_squaredrÏ   r\   r   r   rÐ   !  rÑ   z&dmp_l2_norm_squared.<locals>.<genexpr>)rÖ   rÓ   r]   r   r\   r   r×     rÒ   r×   c                 C   s6   | s|j gS | d }| dd… D ]}t|||ƒ}q|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”   rt   )Úpolysr   r   rf   r   r   r   Ú
dup_expand$  s   rÙ   c                 C   s:   | st ||ƒS | d }| dd… D ]	}t||||ƒ}q|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   rf   r   r   r   Ú
dmp_expand=  s   
rÚ   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   r5   r8   r<   r>   r?   r@   rB   rK   rL   rN   rO   rQ   rR   rX   r[   r_   r&   rk   r   rq   r%   rv   rz   r|   r}   rt   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Ú   r   r   r   r   Ú<module>   s†    <""#*#*9+(0%(5-931545