def dup_half_gcdex(f, g, K):
    if not K.has_Field:
        raise DomainError("can't compute half extended GCD over %s" % K)

    a, b = [K.one], []

    while g:
        q, r = dup_div(f, g, K)
        f, g = g, r
        a, b = b, dup_sub_mul(a, q, b, K)

    a = dup_quo_ground(a, dup_LC(f, K), K)
    f = dup_monic(f, K)

    return a, f
Half extended Euclidean algorithm in `F[x]`.
dataset/ETHPy150Open sympy/sympy/sympy/polys/euclidtools.py/dup_half_gcdex