[7/24]: rework assumptions to use FactRules (hash)
commitb0f9dd27e3c9447e0119e79d72434f92f8c15c6a
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Fri, 25 Jul 2008 18:03:06 +0000 (25 22:03 +0400)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Fri, 25 Jul 2008 18:03:06 +0000 (25 22:03 +0400)
treee559feb5539c519bc33b358a9b8d93f309a10ed3
parent8bf95bf21b5e2ec3b0b14b9933a3ccaa81ee3432
[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>
sympy/core/assumptions.py
sympy/core/basic.py
sympy/core/tests/test_assumptions.py