classifying polynomials by degree and terms