Fix ((x**3+x**2+x)**2).expand() and add a test

Fixes #51.

Benchmarks unaffected, except expand1, which is a little bit slower.