def gcdex_diophantine(a, b, c):
    """
    Extended Euclidean Algorithm, Diophantine version.

    Given a, b in K[x] and c in (a, b), the ideal generated by a and b,
    return (s, t) such that s*a + t*b == c and either s == 0 or s.degree()
    < b.degree().
    """
    s, g = a.half_gcdex(b)
    q = c.exquo(g)
    s = q * s
    if not s.is_zero and b.degree() >= b.degree():
        q, s = s.div(b)
    t = (c - s * a).exquo(b)
    return s, t
