You are testing for structural equivalence of the expression trees, not for mathematical equality. Check the SymPy tutorial http://docs.sympy.org/dev/gotchas.html