Include `math.sign`

I sort of explained this in another thread:

The issue is that == is what is used by dict and set so you have to choose between defining == in a way that makes the expressions efficiently hashable vs defining == as mathematical equality. SymPy chooses the hashable version but that means that == is not in the same semantic plane as < and > and the equality operator that corresponds to < is actually spelled as Eq(a, b) rather than a == b:

In [1]: e = log(sin(4)**2 + cos(4)**2)

In [2]: Eq(e, 0)
Out[2]: True

Note that if you want to use that reliably you have to spell it like

if Eq(e, 0) == True:

because bool(Eq(e, 0)) can blow up on you for some expressions.

The alternative choice that a == b be equivalent to Eq(a, b) would make == semiundecidable even for well-defined simple numeric expressions.

1 Like