I checked ```F, opt = poly_from_expr(cancel(simplify(f)), f.gens[0])``` for ```f = (x**2*(cos(x)**2+sin(x)**2 - 1) + x ``` and it evaluates to the correct answer which is 1.

> Please don't guess. Please try to understand the current code first.

I did not guess brother. I just convinced you that the code in master gives no different answer. But it works fine in SymPy live (online SymPy)