I would like to match a pattern to an expression in such a way that returns all possible matchings. Using SymPy I can match my pattern to my expression in a single arbitrarily selected way. How can I use pattern matching to obtain the entire set (up to arbitrary renamings)
Currently I can do this
>>> p, q = Wild('p'), Wild('q')
>>> x, y, z = symbols('x,y,z')
>>> (p+q).matches(x+y+z)
{p: y + z, q: x}
I want to do this
>>> (p+q).allmatches(x+y+z)
{{p: x, q: y + z}, {p: y, q: x + z}, {p: z, q: x + y}}
Note that each possible partitioning is represented. I would be willing to implement this myself. What are standard algorithms for pattern matching that produce all possible matches?