Fix for w1.match(w2+w3) (#992)
commit8df7084edbc301dd6371b5dc2e4b5fe989458ed3
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Thu, 7 Aug 2008 09:48:52 +0000 (7 13:48 +0400)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Thu, 7 Aug 2008 09:48:52 +0000 (7 13:48 +0400)
tree2101c3431a30e8eb345ac9a6387a49cc72ae6638
parent14941a018346aab6c29a8445ebdbaa3aa2177ac9
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>
sympy/core/basic.py
sympy/core/operations.py
sympy/core/tests/test_match.py