[10/24] rework assumptions.py to use FactRules (assume typeinfo)
The problem
-----------
if we have an expression, say
s = 1 + pi
its ._assumptions may evolve in time, e.g. if we'll ask
s.is_positive -> True (it asks evalf)
it will add 'positive' to ._assumptions.
Now let's look at Basic._eval_expand_trig, I quote:
def _eval_expand_trig(self, *args):
...
terms = [ term._eval_expand_trig(*args) for term in sargs ]
return self.__class__(*terms, **self._assumptions)
b = a.expand(trig=True)
It seems it wants to create an object of the same class (self.__class__) and
with the same assumptions (self._assumptions)
Now the problem is that if even original s assumptions are empty, at expanded
instance creation time there sit 'positive' as well.
So expand will return *different* object with *different* starting assumptions
compared to what s had on its creation time, and btw do you remember
assumptions affect hash?
So hash(a) will be != hash(b) and this is bad!
To overcome this I introduce .assumptions0 property and .new() method.
- assumptions0 is used to obtain typinfo assumptions, and
- new -- to spawn new instance of self + assumptions0 typinfo applied.
Alos, failing test that demonstrates the problem is attached. We'll switch the
whole SymPy to .new and .assumptions0, and this will cure the problem and make
the test pass.
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>