On Fri, Jul 18, 2014 at 6:38 AM, F. B. <franz.bona...@gmail.com> wrote:
>
>
> On Friday, July 18, 2014 5:05:37 AM UTC+2, Ondřej Čertík wrote:
>>
>>
>> > This is also the sort of thing that would benefit from a performant
>> > core.
>> > We would write patterns in SymPy and then match them using some C++
>> > matching
>> > system.  This is likely a purely structural operation and so shouldn't
>> > require any of the Python logic code.  The patterns would probably
>> > translate
>> > well between SymPy and CSymPy.
>>
>> Yes, that's precisely what I had in mind. I want to implement this in
>> SymPy first, to get the algorithm right (and also that we have it in
>> SymPy) and then once a working algorithm is shown to do the job, nail
>> the speed in C++ with CSymPy, as an option for people that need speed.
>>
>
> I wrote a draft about a possible new pattern matching API on SymPy's wiki,
> though I have a better idea about it now. I will rewrite that wiki page soon
> or later, in any case my API suggestion is to create a Wild class and use
> nested methods (that was actually suggested by Joachim). That is, a possible
> example:
>
>>>> w = Wild('w')
>>>> w1 = w.is_integer().is_odd().filter(lambda x: True if x<100 else False)

This syntactic sugar is nice, but a bit limiting. I would rather just
use a logic expression, using the new assumptions. This would be
Q.integer & Q.odd & (w < 100). Note that in this case, we can actually
see the w < 100 part symbolically, and potentially do some
manipulation with it.  But the other advantage is that you can really
represent any kind of logical expression, not just a conjunction of
atomic assumptions. For example, how would you represent negation of a
fact with your idea?

Of course, the syntax isn't very important, because you can easily
swap out different syntaxes, or even support more than one.

>
> In this case, w would match everything, while w1 would match only odd
> integers less than 100. The advantage of this API is that it can be easily
> implemented in C++, and can also be easily defined to cover almost all of
> Mathematica's wildcard patterns.
>
> Concerning the implementation, there are already open-source project
> implementing Mathematica's pattern matching system (e.g. Mathics or
> MockMMA). I had a look at Mathics, it is not optimized at all. Its predicate
> dispatch is just a long list of matching rules associated with the head node
> of the expression being matched.
>
> Pattern rules form a partially ordered set, some rules should have priority
> over other rules, while having no clearly definite order over some other
> rules. I believe that this order should be extended in order to form a
> strictly totally ordered set of pattern rules (as similar as possible to the
> way Mathematica does it).
>
> In any case, I don't think that the first version of a new pattern matcher
> really needs to be optimized from its birth, we could just start by
> implementing a simple list-based algorithm, a nice API, writing tests and
> benchmark tools, porting RUBI to SymPy. After this first step is
> accomplished, reasoning about more efficient algorithms could start.

Yes, the first iteration should be as simple as possible, so that we
can just see that it works, and get an idea of what it actually looks
like.

Aaron Meurer

>
> In any case, the integrator algorithm is not the only one that could benefit
> from a predicate dispatching mechanism, it could also be used to make the
> code more readable and more maintainable for the equation solvers, ODE
> solvers, limits, and much else.
>
> --
> 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/7a4155ac-507c-4a58-99b5-aec9bf827b5a%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAKgW%3D6%2Bdq3N9FnjobrjWrW48PE%3DuJyR1jnWQ3MgjmTomtJQShA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to