My guess is that it's an issue with floating point accuracy. Unless you are testing floating point numbers directly, I would suggest making all values in the expressions rational. To accurately test floating point numbers, you generally have to check that the difference is below some small epsilon (like 1e-15), which can be annoying if they appear throughout an expression.
Aaron Meurer On Mon, May 23, 2016 at 3:58 PM, Alexander Lindsay <[email protected]> wrote: > Hi all, > > I am working on a pull request. When writing tests for the PR, I keep > encountering false comparisons when the expressions I'm comparing appear to > be the exact same. Example shown below: > > In[80]: %paste > result = manualintegrate(x**(3/2) * log(x), x) > desired_result = 0.4*x**2.5*log(x) - 0.16*x**2.5 > print(result) > print(desired_result) > print(result == desired_result) > assert result == desired_result > ## -- End pasted text -- > 0.4*x**2.5*log(x) - 0.16*x**2.5 > 0.4*x**2.5*log(x) - 0.16*x**2.5 > False > Traceback (most recent call last): > File > "/home/lindsayad/miniconda2/envs/python3SympyDev/lib/python3.5/site-packages/IPython/core/interactiveshell.py", > line 2885, in run_code > exec(code_obj, self.user_global_ns, self.user_ns) > File "<ipython-input-80-5bc67a132f24>", line 6, in <module> > assert result == desired_result > AssertionError > > Any suggestions on how to make these comparisons work? > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/942dfeea-3dc8-4655-817a-ecdaa0589299%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6Jz0NC8YNLb%3DWtNcEier3O71XJAr%3Dnb_w7GMT85jOfgZg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
