Comment #25 on issue 1337 by mattpap: find all instances in an expression
http://code.google.com/p/sympy/issues/detail?id=1337

subs() and replace() have different semantics. Both get two arguments, but

1. subs() gets a Basic instance, tries to find all its occurrences in an expression and replace them exactly with another Basic instance.

2. replace() gets some kind of pattern or query and replaces all found instances with an explicit instance or an instances generated by a function (possibly also by Lambda).

Example (with find()):

In [1]: a = Wild('a')

In [2]: (x*sin(2*x)).subs(sin(a), cos(2*x))
Out[2]: x⋅sin(2⋅x)

In [3]: (x*sin(2*x)).find(sin(a))
Out[3]: set(sin(2⋅x))

([3] would read (x*sin(2*x)).replace(sin(a), lambda expr: cos(expr.args)), or it could be even more intelligent, e.g. e.replace(sin(a), cos) with sub-expression matched by 'a' put into cos(...)).

If we can somehow distinguish expressions with are patterns from real patterns in subs() then we can think about putting replace()'s functionality in subs(). However, even in this case, I think that two functions will be beneficial, especially when we take into consideration new proposed features to subs(), like exact=True.

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to