'Remove unnecessary generators from ``f``.
Examples
>>> from sympy import Poly
>>> from sympy.abc import a, b, c, d, x
>>> Poly(a + x, a, b, c, d, x).exclude()
Poly(a + x, a, x, domain=\'ZZ\')'

def exclude(f):

    (J, new) = f.rep.exclude()
    gens = []
    for j in range(len(f.gens)):
        if (j not in J):
            gens.append(f.gens[j])
    return f.per(new, gens=gens)
