You could read about unification,   unification with identity, 
associativity, etc.
You could add "solving" as a method of matching but probably you don't want
to use this routinely.  Maxima's matcher does a little of this and most 
people
find it surprising.

I think it would be unfortunate if you design another matcher without
reading what else has gone on.  Knowing Mathematica's matcher is a start, 
but
it is not everything.

Doing what Mathematica does, no more and no less would have the advantage 
of taking advantage
of the 40+ years of experience in designing pattern matchers, some of which 
are condensed into it.
There also appear to be some open-source implementations of much of it 
(MockMMA, and
also Mathics)

On the other hand  (a) Some of it is still controversial (b) Especially for 
a noivce It is hard to use efficiently (c) it is
intimately tied to the evaluation semantics of the rest of Mathematica, and 
you probably don't
want to eat the whole thing.


On Monday, September 1, 2014 4:28:45 AM UTC-7, F. B. wrote:
>
> 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/2ea9e76a-2f14-466d-b78d-e547dcf6f8e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to