{"action":"created","issue":{"url":"https://api.github.com/repos/sympy/sympy/issues/9263","labels_url":"https://api.github.com/repos/sympy/sympy/issues/9263/labels{/name}","comments_url":"https://api.github.com/repos/sympy/sympy/issues/9263/comments","events_url":"https://api.github.com/repos/sympy/sympy/issues/9263/events","html_url":"https://github.com/sympy/sympy/issues/9263","id":66918600,"number":9263,"title":"Expression incorrectly evaluated","user":{"login":"proy87","id":8571708,"avatar_url":"https://avatars.githubusercontent.com/u/8571708?v=3","gravatar_id":"","url":"https://api.github.com/users/proy87","html_url":"https://github.com/proy87","followers_url":"https://api.github.com/users/proy87/followers","following_url":"https://api.github.com/users/proy87/following{/other_user}","gists_url":"https://api.github.com/users/proy87/gists{/gist_id}","starred_url":"https://api.github.com/users/proy87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/proy87/subscriptions","organizations_url":"https://api.github.com/users/proy87/orgs","repos_url":"https://api.github.com/users/proy87/repos","events_url":"https://api.github.com/users/proy87/events{/privacy}","received_events_url":"https://api.github.com/users/proy87/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-04-07T15:39:16Z","updated_at":"2015-04-12T18:34:04Z","closed_at":"2015-04-12T18:00:55Z","body":"```\r\n>>> (-12 + (-2 + 2*sqrt(2))**2 + 8*sqrt(2)) == 0  # returns False\r\n>>> (-12 + (-2 + 2*sqrt(2))**2 + 8*sqrt(2)).evalf() # gives -1*10^(-126)\r\n```\r\n\r\nShould be 0.\r\n"},"comment":{"url":"https://api.github.com/repos/sympy/sympy/issues/comments/92098729","html_url":"https://github.com/sympy/sympy/issues/9263#issuecomment-92098729","issue_url":"https://api.github.com/repos/sympy/sympy/issues/9263","id":92098729,"user":{"login":"asmeurer","id":71486,"avatar_url":"https://avatars.githubusercontent.com/u/71486?v=3","gravatar_id":"","url":"https://api.github.com/users/asmeurer","html_url":"https://github.com/asmeurer","followers_url":"https://api.github.com/users/asmeurer/followers","following_url":"https://api.github.com/users/asmeurer/following{/other_user}","gists_url":"https://api.github.com/users/asmeurer/gists{/gist_id}","starred_url":"https://api.github.com/users/asmeurer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asmeurer/subscriptions","organizations_url":"https://api.github.com/users/asmeurer/orgs","repos_url":"https://api.github.com/users/asmeurer/repos","events_url":"https://api.github.com/users/asmeurer/events{/privacy}","received_events_url":"https://api.github.com/users/asmeurer/received_events","type":"User","site_admin":false},"created_at":"2015-04-12T18:34:04Z","updated_at":"2015-04-12T18:34:04Z","body":"@skirpichev please stop being disrespectful to people. Now. \r\n\r\n@proy87 the behavior of `==` is described at http://docs.sympy.org/latest/tutorial/gotchas.html#equals-signs. This is done because structural equality is used far more often than mathematical equality, and also mathematical equality is typically very expensive to calculate and in general [impossible](https://en.wikipedia.org/wiki/Richardson%27s_theorem). To calculate mathematical equality to 0 it's best to use `simplify()` on the expression and see if it reduces to 0. \r\n\r\nAs for evalf, floating point numbers are inexact, and so they won't give exactly zero for zero equivalent expressions quite often. This is due to very fundamentally difficult issues with the way floating point numbers are (you can read https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html and http://perso.ens-lyon.fr/jean-michel.muller/Intro-to-TMD.htm to get a taste of why this is). A simpler answer is that if you get a very small number, say smaller than the precision (`10**15` by default in SymPy), you can assume that it is probably zero. Using `evalf(chop=True)` will automatically replace small floating point numbers with 0. "}}