On Thu, Dec 3, 2015 at 12:37 PM, Francesco Bonazzi
<[email protected]> wrote:
>
>
> On Thursday, 3 December 2015 17:40:47 UTC+1, Aaron Meurer wrote:
>>
>> On Thu, Dec 3, 2015 at 5:48 AM, Francesco Bonazzi
>> <[email protected]> wrote:
>> >  I mean, I think there are two options:
>> >
>> > make .subs( ) aware of wildcards.
>>
>> How would this be different from replace then? I'm -1. We should be
>> more distinct between the difference between things like xreplace,
>> subs, and replace. What if I literally want to replace a Wild in an
>> expression with something else?
>
>
> Well, subs( ) could be the mathematically sensitive matcher, .replace( ) the
> structural one. I don't see any reason why any of them should not support
> wildcards.
>
> Maybe a syntax live .subs( ... , wilds=(list of symbols to use as wilds ...
> )) would avoid the problem of matching a Wild, though I don't believe
> there's an urgent need to match wildcards.
>
>>
>>
>> > make .replace( ) match subexpressions (alternatively, a parameter
>> > subexpression=True/False)
>>
>> How would it work though?
>>
>
> The example in the other thread would work, or maybe:
>
> In [12]: expr = x + y + 3
>
> In [13]: expr.subs(x+1, z)
> Out[13]: y + z + 2
>
> In [14]: expr.replace(x+1, z)
> Out[14]: x + y + 3
>
> In [15]: expr.subs(x+3, z)
> Out[15]: y + z
>
> In [16]: expr.replace(x+3, z)
> Out[16]: x + y + 3
>
>
> The way I see it, I'd prefer the last expression (output 16) to return y +
> z, because Add(x, 3) should match the subexpression in Add(x, y, 3).
>
> On the other hand, Add(x, 1) should not match Add(y, x, 3), because (x, 1)
> is not a subset of (x, y, 3).
>
> I think this would still qualify as a structural matcher, except for the
> awareness of associativity and commutativity. This is the way Mathematica
> does it, and it works pretty well.

I mean how would it work internally? Right now replace just iterates
all subexpressions (via .args) and replaces the ones that match.  You
could make it so that Add(x, y, z) iterates subexpressions like (x, y,
z, x + y, x + 3, y + 3, x + y + 3), but that gets combinatorially
inefficient fast.

Aaron Meurer

>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/9777e4d8-f941-4cfa-9a69-01b8ee2041b4%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 [email protected].
To post to this group, send email to [email protected].
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%3D6K718geF1vYYGEY4TWsJeikOUXiF9yJeQx1qj_CmHVhSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to