'Returns GCD of ``a`` and ``b``.
This definition of GCD over fields allows to clear denominators
in `primitive()`.
>>> from sympy.polys.domains import QQ
>>> from sympy import S, gcd, primitive
>>> from sympy.abc import x
>>> QQ.gcd(QQ(2, 3), QQ(4, 9))
2/9
>>> gcd(S(2)/3, S(4)/9)
2/9
>>> primitive(2*x/3 + S(4)/9)
(2/9, 3*x + 2)'

def gcd(self, a, b):

    try:
        ring = self.get_ring()
    except DomainError:
        return self.one
    p = ring.gcd(self.numer(a), self.numer(b))
    q = ring.lcm(self.denom(a), self.denom(b))
    return (self.convert(p, ring) / q)
