SymPy's default pattern matcher is not a structural one, i.e. it tries to 
match according to some mathematical rules. A structural pattern matcher 
would instead just match the structure of the expression-tree.

While it is necessary to have some mathematical awareness such as, give the 
wild *w*:

   - associativity awareness (i.e. f(a, b, c) = f(a, f(b, c)) and similar): 
   (a+b+c).match(a+w) ==> {w: b+c}
   - commutativity awareness:
   (a+b).match(w+a) ==> {w: b}
   - one-identity awareness (f is one-identical if f(x) = x for any x):
   x.match(Add(w, evaluate=False)) ==> {w: x}
   
These rules are also available in Wolfram Mathematica.

There are some results which come out as an attempt to apply some kind of 
equation solving:

In [20]: (x*y).match(x/w)
Out[20]: 
⎧   1⎫
⎨w: ─⎬
⎩   y⎭

That is, *Mul(x, y)* is matched to become *Mul(x, Pow(Mul(1, Pow(y, -1)), 
-1))* which is equivalent mathematically, but not structurally.

I would expect this result by calling:

In [29]: solve(Eq(x*y, x/w), w)
Out[29]: 
⎡1⎤
⎢─⎥
⎣y⎦

I was wondering, what are the pattern matching rules for this awareness? 
This goes beyond the three rules I pointed out hereabove. Technically, 
mathematical-aware patterns may yield infinite results as long as they are 
combined with equation solvers.

Wolfram Mathematica seems not to have any solver-awareness, that is, the 
previous pattern does not match:

In[12]:= (x y) /. x/w_ -> {w}
Out[12]= x y

It would be useful to keep SymPy's pattern matching rules as close as 
possible to those of Mathematica. I suggest to remove redundant results 
relying on solvers, or maybe add a parameter to the matcher to turn it off. 
What do you think?

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/10ad1141-ee19-44ad-bd6e-42c982af3da2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to