'Half extended Euclidean algorithm of ``f`` and ``g``.
Returns ``(s, h)`` such that ``h = gcd(f, g)`` and ``s*f = h (mod g)``.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x
>>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
>>> g = x**3 + x**2 - 4*x - 4
>>> Poly(f).half_gcdex(Poly(g))
(Poly(-1/5*x + 3/5, x, domain=\'QQ\'), Poly(x + 1, x, domain=\'QQ\'))'

def half_gcdex(f, g, auto=True):

    (dom, per, F, G) = f._unify(g)
    if (auto and dom.is_Ring):
        (F, G) = (F.to_field(), G.to_field())
    if hasattr(f.rep, 'half_gcdex'):
        (s, h) = F.half_gcdex(G)
    else:
        raise OperationNotSupported(f, 'half_gcdex')
    return (per(s), per(h))
