You can just do `return x not in coeff.free_symbol`