Why according to python -a(b+c) != a(-b-c)?

Viewed 69

I was coding on python (Anaconda) and while working with sympy I noticed this issue:

import sympy as sym

a = sym.Symbol('a')

b = sym.Symbol('b')

c = sym.Symbol('c')

-a*(b+c) == a*(-b-c)

Out[190]: False

Why is this happening?

Picture of my code

1 Answers

I believe it may have to do with how Sympy treats the overloads for the Symbol object.

Your statement is comparing two object references.

It looks like you're just doing math and comparing values, but that's not what's going on under the hood. Look at the gotchas.

Related