let fold p f a e = List.fold_left (fun acc m -> let q = coefficient_of_mono m and x = variable_of_mono m in if p q x then f q x acc else acc) e (nonconstant_monomials_of a)