

def dmp_cancel(f, g, u, K, include=True):
    '\n    Cancel common factors in a rational function `f/g`.\n\n    Examples\n    ========\n\n    >>> from sympy.polys import ring, ZZ\n    >>> R, x,y = ring("x,y", ZZ)\n\n    >>> R.dmp_cancel(2*x**2 - 2, x**2 - 2*x + 1)\n    (2*x + 2, x - 1)\n\n    '
    K0 = None
    if (K.has_Field and K.has_assoc_Ring):
        (K0, K) = (K, K.get_ring())
        (cq, f) = dmp_clear_denoms(f, p_neg, K0, K, convert=True)
        (cp, g) = dmp_clear_denoms(g, u, K0, K, convert=True)
    else:
        (cp, cq) = (K.one, K.one)
    (_, p, q) = dmp_inner_gcd(f, g, u, K)
    if (K0 is not None):
        (_, cp, cq) = K.cofactors(cp, cq)
        p = dmp_convert(p, u, K, K0)
        q = dmp_convert(q, u, K, K0)
        K = K0
    p_neg = K.is_negative(dmp_ground_LC(p, u, K))
    q_neg = K.is_negative(dmp_ground_LC(q, u, K))
    if (p_neg and q_neg):
        (p, q) = (dmp_neg(p, u, K), dmp_neg(q, u, K))
    elif p_neg:
        (cp, p) = ((- cp), dmp_neg(p, u, K))
    elif q_neg:
        (cp, q) = ((- cp), dmp_neg(q, u, K))
    if (not include):
        return (cp, cq, p, q)
    p = dmp_mul_ground(p, cp, u, K)
    q = dmp_mul_ground(q, cq, u, K)
    return (p, q)

dataset/ETHPy150Open sympy/sympy/sympy/polys/euclidtools.py dmp_cancel/VarMisuse@65/218 `u`->`p_neg`