My idea was to put assumptions on Wild expressions. I guess using the
new assumptions system, the assumptions do not need to be, nor should
they be, actually tied to the symbols. This will also make it easy to
add assumptions about general expressions, not just Wilds (and make it
easier to do the sorts of things Angus was talking about). So
something like

expr = x + 2
a = Wild('a', exclude=[x])
expr.match(x + a, assumptions=Q.positive(a))

would work, but for

expr = x - 2

it would not match.

One could then specify arbitrary assumptions, and match would refuse
to return any result where the assumptions are False. Or you could add
a flag to make it even stronger: don't return a result unless the
assumptions are True (as opposed to None).

This may be far reaching and could be a bad idea, but I think we could
then extend the assumptions system to allow "assumptions" like
Q.free_of(a, x) to mean that a does not depend on x, or
Q.isinstance(a, Mul) to mean that a is a Mul.

The new assumptions system is still relatively weak and needs to be
integrated into SymPy better, so this would be a lofty goal. But
assuming we can unify the system, and get something like
https://code.google.com/p/sympy/issues/detail?id=3929, I think this
would be a nice way to specify things, much better (and more powerful)
than throwing a bunch of lambdas around.

Aaron Meurer

On Thu, Sep 26, 2013 at 3:01 PM, F. B. <[email protected]> wrote:
>
>
> On Thursday, September 26, 2013 8:39:28 PM UTC+2, Ondřej Čertík wrote:
>>
>> On Thu, Sep 26, 2013 at 11:45 AM, F. B. <[email protected]> wrote:
>> > What's your idea to include assumptions in pattern matching?
>> >
>> > I have some hypothetical uses:
>> >
>> > a = Wild('a', assumptions=[Q.is_positive])
>> > a = Wild('a'); a & Q.is_positive(a)
>> > expr.match(expr2, assumptions= ... )
>>
>> What difference would it make? It seems to me that "a" is just "a", no
>> matter what
>> assumptions are on it.
>
>
> Match expression with Wild "a" if the resulting expression is positive.
>
> That means, "a" matches "3" but not "-2".
>
> Should this assumption be specified in Wild, in the pattern matching
> expression, or in the .match( ) method? Or any other idea?
>
> --
> 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.

-- 
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