This is a general problem. The pattern matcher is going to have to be
smart enough to recognize things like this, especially for cases that
simplify automatically. We should think about how to tackle this.
One idea is to have a set of rules where automatic simplification is
known to take place for certain inputs, for instance, (a*b)**x ->
a**x*b**x (happens if a and b are numbers, maybe in other cases as
well I'm not sure). Then each pattern should run through the rules and
generate a new pattern. For instance, (b*log(x))**n would generate
b**n*log(x)**n. The rules are then run recursively on this pattern,
and so on. I think the sympy.strategies module would be a good fit for
this. Then instead of a single pattern you have a list of patterns,
and if any match an expression the expression matches. This way, the
expression matching itself can be naive and deal only with the
structural form of the expression, and be separated from the
mathematical rules.
That's just one idea. There may be other ways to handle this as well.
Aaron Meurer
>
https://groups.google.com/d/msgid/sympy/cbf027df-b0b8-468d-a2de-97d2bb4099d7%40googlegroups.com.