Oh, I think I get it now.  `replace(w*(2*x+3)` starts at the bottom of the 
expression tree.  So at first it's not looking to replace expressions, it's 
looking to replace atoms.

Now I'm wondering if it would make sense for an `if` statement inserted 
into the logic to ensure that `w*(2*x+3)` doesn't match an atom.  Because 
it seems like that would never be desirable, and basically makes 
(non-repeated) multiplication by Wild objects useless...




On Friday, March 20, 2015 at 12:50:00 PM UTC-4, Mike Boyle wrote:
>
>
> I think we should make it so that cos(4*x + 6).replace(2*x + 3, u) works. 
>>
>
> That would be nice.  Also, Francesco's wildcard replacement looks buggy. 
>  The `4*x` apparently matches twice, once for 4 and once for x:
> In [1]: u = symbols('u')
>
> In [2]: w = Wild('w')
>
> In [3]: cos(4*x+6).replace(w*(2*x+3), u*w, map=True)
> Out[3]: 
>
> ⎛   ⎛     2              ⎞                                      ⎞
> ⎜   ⎜  4⋅u ⋅x       6⋅u  ⎟  ⎧     4⋅u         6⋅u         u⋅x  ⎫⎟
> ⎜cos⎜────────── + ───────⎟, ⎨4: ───────, 6: ───────, x: ───────⎬⎟
> ⎜   ⎜         2   2⋅x + 3⎟  ⎩   2⋅x + 3     2⋅x + 3     2⋅x + 3⎭⎟
> ⎝   ⎝(2⋅x + 3)           ⎠                                      ⎠
>
>
> This seems to contradict the documentation's claims that "changes made are 
> targeted only once" and "changes are not made twice".  I thought maybe I 
> just misunderstood the `simultaneous` flag, but that makes things even 
> worse.  Or am I misunderstanding that?
>

-- 
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/b3d0dd5c-47c0-4d49-91ef-4b77721725ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to