'Return ``True`` if ``Poly(f, *gens)`` retains ground domain.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x, y, z
>>> Poly(x*y + 1, x, y, z).has_only_gens(x, y)
True
>>> Poly(x*y + z, x, y, z).has_only_gens(x, y)
False'

def has_only_gens(f, *gens):

    indices = set()
    for gen in gens:
        try:
            index = f.gens.index(gen)
        except ValueError:
            raise GeneratorsError(("%s    doesn't    have    %s    as    generator" % (f, gen)))
        else:
            indices.add(index)
    for monom in f.monoms():
        for (i, elt) in enumerate(monom):
            if ((i not in indices) and elt):
                return False
    return True
