Fix for w1.match(w2+w3) (#992)
AssocOp._matches_commutative was not accounting properly for already matched
Wilds, so e.g. in this example the following was happening:
Symbol Wild
(w2+w3).matches(x) (w2+w3).matches(w1)
(x +w3).matches(x) (w1+w3).matches(w1)
( w3).matches(0) (w1+w3).matches(w1)
... (infinite recursion)
--> {w2: x, w3: 0)
So I've added appropriate checks so that already matched Wild go away from the
pattern for sure -- this now works:
(w2+w3).matches(w1)
(w1+w3).matches(w1)
( w3).matches(0)
--> {w2: w1, w3: 0)
----
One .matches() doctest had to be reworked because .matches() is an internal
function and should accept only already sympified objects.
Also, this fixes original problem in #922, and we'll add appropriate tests in
the next patch.
Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Ondrej Certik <ondrej@certik.cz>