o
    oh0                     @   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 ZOdd ZPdd ZQdS )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   j/var/www/html/construction_image-detection-poc/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   sx  | |kr	t | |S | r|sg S t| }t|}t||d }|dk rZg }td|| d D ](}|j}ttd|| t||d D ]}	|| |	 |||	   7 }qA|| q-t|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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 st| ||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 st
| ||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   is_Exactr   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