This test, btw, would succeed for `x**2*f(x)**2` so you aren't doing what you think you are doing. This is where python is great...don't try to test your logic here amongst everything else. Write a little test function that you can feed expressions to and see if it gives the output you expect. When it works, that code then goes here.