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) Davide. Il giorno sab 19 set 2020 alle ore 21:46 David Bailey <d...@dbailey.co.uk> ha scritto: > Dear All, > > I was hoping to use SymPy patterns to perform a transformation equivalent > to this Mathematica code: > > f[a + 2*b + c] /. f[x_] -> g[x] > > g[a + 2 b + c] > > I.e. I wanted to replace calls to the (undefined) function f with calls to > the function g with the same arguments. > > I tried the following, with f and g set up as undefined functions: > > patt=Wild("p1") > > f(a+2*b+c).subs(f(patt),g(patt)) > > f(a + 2*b + c) > > Is there a way to do this? > > 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 sympy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/87d22d50-3fd2-101e-7dc2-ad90843b06ca%40dbailey.co.uk > <https://groups.google.com/d/msgid/sympy/87d22d50-3fd2-101e-7dc2-ad90843b06ca%40dbailey.co.uk?utm_medium=email&utm_source=footer> > . > -- 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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAO%3D1Z0-fM%3DxYuTAdX9KhtMWdbp9tR2aiMahQXDe2mSUWT8uR%2Bg%40mail.gmail.com.