(f, g, K)
return q, r
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)
Polynomial pseudo-division in ``K[x]``.
Polynomial pseudo - division in K [ x ] .
def dup_pdiv(f, g, K):
    """
    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)

    """
    df = dup_degree(f)
    dg = dup_degree(g)

    q, r, dr = [], f, df

    if not g:
        raise ZeroDivisionError("polynomial division")
    elif df < dg:
        return q, r

    N = df - dg + 1
    lc_g = dup_LC(g, K)

    while True:
        lc_r = dup_LC(r, K)
        j, N = dr - dg, N - 1

        Q = dup_mul_ground(q, lc_g, K)
        q = dup_add_term(Q, lc_r, j, K)

        R = dup_mul_ground(r, lc_g, K)
        G = dup_mul_term(g, lc_r, j, K)
        r = dup_sub(R, G, K)

        _dr, dr = dr, dup_degree(r)

        if dr < dg:
            break
        elif not (dr < _dr):
            raise PolynomialDivisionFailed(f, g, K)

    c = lc_g**N

    q = dup_mul_ground(q, c, K)
    r = dup_mul_ground(r, c, K)

    return q, r
def dup_pdiv ( f , g , K ) : df = dup_degree ( f ) dg = dup_degree ( g ) q , r , dr = [ ] , f , df if not g : raise ZeroDivisionError ( "polynomial division" ) elif df < dg : return q , r N = df - dg + 1 lc_g = dup_LC ( g , K ) while True : lc_r = dup_LC ( r , K ) j , N = dr - dg , N - 1 Q = dup_mul_ground ( q , lc_g , K ) q = dup_add_term ( Q , lc_r , j , K ) R = dup_mul_ground ( r , lc_g , K ) G = dup_mul_term ( g , lc_r , j , K ) r = dup_sub ( R , G , K ) _dr , dr = dr , dup_degree ( r ) if dr < dg : break elif not ( dr < _dr ) : raise PolynomialDivisionFailed ( f , g , K ) c = lc_g ** N q = dup_mul_ground ( q , c , K ) r = dup_mul_ground ( r , c , K ) return q , r