On Sunday, September 22, 2013 5:20:14 AM UTC+2, Angus Griffith wrote:
>
> In this case I think it's roughly equivalent to the Mathematica pattern (a 
> and b are optional and must be 'free of' x)
>
> I'm more familiar with Mathematica's pattern matching than SymPy's, but to 
> summarize what I perceive as the the major differences:
>
>    - In Mathematica you can build up a pattern object and apply 
>    conditions to the pattern as a whole.
>    
> Consider the example pattern 'a_. + b_ /; FreeQ[a + b x, x]'. That is, 'a' 
> is optional, 'b' is required but we have the condition that a + b x can't 
> be an expression in x. This would match '1/x', 'z + 1/x', 'Unevaluated[z + 
> 0]', '-1 + x' etc. I'm not sure if such a thing is possible in SymPy.
>
>
>    - Mathematica has the concept of a repeated patterns. Could this be 
>    added to SymPy?. (E.g. Repeated 
>    http://reference.wolfram.com/mathematica/ref/Repeated.html)
>
> e.g. '{{_Real, _Real}..}' which matches a list of pairs of real numbers. 
> Related to this is patterns for matching sequences (E.g. 
> BlankSequence 
> http://reference.wolfram.com/mathematica/ref/BlankSequence.html) 
>
>
>    - Mathematica has a variety of Test functions, designed for putting 
>    constraints on patterns. About half way down this guide: 
>    
> http://reference.wolfram.com/mathematica/tutorial/PuttingConstraintsOnPatterns.html
>
> Mathematica pattern matching feels more mature and more natural than 
> Sympy's. Part of this is the abundance of documentation on Mathematica's 
> patterns. Patterns really feel like first class citizens in Mathematica and 
> are used extensively internally (every MMA function has a pattern), while 
> in SymPy they feel a little bolted on.
>

It is true that Mathematica's pattern matching is much more powerful than 
Sympy's, but a workaround for that could be using Sympy's pattern matching 
with if conditions and loops. I think it's not that complicated to write an 
unoptimized algorithm in Sympy, the main problem is performance.

The RUBI integration code has around 4200 pattern matching rules, that is a 
lot. I believe that Mathematica has a very efficient pattern matching 
algorithm that can rule out in advance some non-matching rules. Besides, 
it's probably optimized in C.

I don't think that a loop around 4200 rules would be a good idea in Sympy, 
but some attempts to improve that can be made, for instance if in an 
expression there are no sin( ) functions, all rules with sin( ) can be 
discarded. I believe that an efficient pattern matching would require the 
construction of a supportive data structure to address the code to a subset 
of correct rules (discarding without even trying many incorrect one).

How is it implemented in Mathics?

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to