[7/24]: rework assumptions to use FactRules (hash)
As promised, rework Basic.__hash__ to properly account for assumptions.
The problem
-----------
issue #726 contains records about how our hash was unstable some time ago.
The gist of the problem was that Basic.__hash__ was taking ._assumptions into
account, and also ._assumptions were used like cache for knew know facts so its
content could change in time.
That's why e.g. the following sequence used to 'change' a2 hash:
x = Symbol("x")
y = Symbol("y")
a1 = x+y
a2 = y+x
a2.is_comparable
h1 = hash(a1)
h2 = hash(a2)
assert h1 == h2 # boom!
In
b1b0cd23c21a Ondrej just turned assumptions cache off, and this solved the
problem although also it slowed down runtime somewhat.
Now, as we are again caching the assumptions we have to properly account for
this effect.
In fact, what is also important is that say for this two objects:
Symbol('x', even=True)
Symbol('x', integer=True, odd=False)
Their hash be equal, and they themselve should be equal.
Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Ondrej Certik <ondrej@certik.cz>
Signed-off-by: Mateusz Paprocki <mattpap@gmail.com>