I want to replace a function with either one or two functions and also combine their arguments.
Say I have an original expression
expr = u[i + 1] r[i] r[i-1]
Then I want to to replace u[i]
with g[i+1] f[i-1]
in such a way that expr
becomes
g[i+2] f[i] r[i] r[i-1]
If I were to feed in f[i+1]
, then I would like to replace u[i]
with f[i+1]
so expr
becomes f[i+2] r[i] r[i-1]
.
I tried using pure functions by saying
q[h_] := expr /. {u -> Function[x, h[x]]};
but this didn't work, instead just putting (h[x])[i+1] r[i] r[i-1]
when I enter a function h[x]
.
The expression expr
is a simple example, so I don't want to separate them into functions and arguments by hand.
u[i]
withg[i+1] f[i-1]
soexpr
becomesg[i+2] u[i] r[i] r[i-1]
. I would read "I want to replaceu[i]
withg[i+1] f[i-1]
" to mean that the result should beg[i+2] f[i] r[i] r[i-1]
. Is that right? $\endgroup$