On 19/09/2020 20:50, Davide Sandona' wrote:
Hello David,
in Sympy there are three substitution methods:
1. subs: it is the most generic.
2. xreplace: it only replace the exact expression you provide.
3. replace: this is the most powerful, as it allows for "pattern
matching operations".
In your case, I would do something like this:
f, g = symbols("f, g", cls=Function)
a, b, c = symbols("a:c")
expr = f(a + 2 * b + c)
expr.replace(f, g)
Thanks for that quick response! Unfortunately I don't think your
solution really generalises. I mean suppose I wanted to replace
f(anything) by g(5*anything**2)
(again that would be easy in Mathematica - the transformation would be
f[x_] -> g[5*x^2] )
I mean, clearly those patterns are there to solve problems like that,
and I can't figure out how to use them effectively.
David
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/686c98db-97f4-bea7-7ee0-0fe220164a70%40dbailey.co.uk.