

def dmp_inner_subresultants(f, g, u, K):
    '\n    Subresultant PRS algorithm in `K[X]`.\n\n    Examples\n    ========\n\n    >>> from sympy.polys import ring, ZZ\n    >>> R, x,y = ring("x,y", ZZ)\n\n    >>> f = 3*x**2*y - y**3 - 4\n    >>> g = x**2 + x*y**3 - 9\n\n    >>> a = 3*x*y**4 + y**3 - 27*y + 4\n    >>> b = -3*y**10 - 12*y**7 + y**6 - 54*y**4 + 8*y**3 + 729*y**2 - 216*y + 16\n\n    >>> prs = [f, g, a, b]\n    >>> sres = [[1], [1], [3, 0, 0, 0, 0], [-3, 0, 0, -12, 1, 0, -54, 8, 729, -216, 16]]\n\n    >>> R.dmp_inner_subresultants(f, g) == (prs, sres)\n    True\n\n    '
    if (not u):
        return dup_inner_subresultants(f, g, K)
    n = dmp_degree(f, u)
    m = dmp_degree(g, u)
    if (n < m):
        (f, g) = (g, f)
        (n, m) = (m, n)
    if dmp_zero_p(f, u):
        return ([], [])
    v = (u - 1)
    if dmp_zero_p(g, u):
        return ([f], [dmp_ground(K.one, v)])
    R = [f, g]
    d = (n - m)
    b = dmp_pow(dmp_ground((- K.one), v), (d + 1), v, K)
    h = dmp_prem(f, g, u, K)
    h = dmp_mul_term(h, b, 0, u, K)
    lc = dmp_LC(g, K)
    c = dmp_pow(lc, d, v, K)
    S = [dmp_ground(K.one, v), c]
    c = dmp_neg(c, v, K)
    while (not dmp_zero_p(h, u)):
        k = dmp_degree(h, u)
        R.append(h)
        (f, g, m, d) = (g, h, k, (m - k))
        b = dmp_mul(dmp_neg(lc, v, K), dmp_pow(c, d, v, K), v, K)
        h = dmp_prem(f, g, u, K)
        h = [dmp_quo(ch, b, v, K) for ch in h]
        lc = dmp_LC(g, K)
        if (d > 1):
            p = dmp_pow(dmp_neg(lc, v, K), d, v, K)
            q = dmp_pow(c, (d - 1), v, K)
            c = dmp_quo(p, q, v, K)
        else:
            c = dmp_neg(lc, v, K)
        S.append(dmp_neg(c, v, K))
    return (R, S)

dataset/ETHPy150Open sympy/sympy/sympy/polys/euclidtools.py dmp_inner_subresultants/original