# [Maxima] substituting function in diff

David Webb david.webb at noc.soton.ac.uk
Thu Jul 16 03:51:04 CDT 2009

```> I dunno. I can't really recommend using inpart or other part-hacking
functions.
> How could anyone (for example, yourself next week or next year)
> figure out what is the intended effect of substinpart(foo(bar), baz, x, y,
z) ??
>
> I'll recommend subst, funmake, op / args, and buildq instead.

The trouble is that I have to keep count.  With a term like:
z^2*(d/dz)wv(x,y,z,t),
I want to replace each z and wv by a separate fourier expansion with a
different set of indices.  Thus in the above equation, the z's need to be
transferred to functions ht(kx,ky,t) and the wv's to the corresponding
function with wavenumbers all with separate sets of indices.  Thus the above
becomes

ht(kx1,ky1,t)*exp(i*(kx1*x+ky1*y))*
ht(kx2,ky2,t)*exp(i*(kx2*x+ky2*y))*
wv(kx3,ky3,t)*exp(i*(kx3*x+ky3*y))*(d/dz)cosh(k3*(z+H))/cosh(k3*H)

where: k3 = sqrt(kx3*kx3+ky3+ky3) and H is fixed.  I would also like to
include an integral from -infinity to +infinity over kx1, kx2, ky1, ... .
However that is asking too much for the moment as I read that the resulting
delta functions are not fully supported by maxima.  So for the moment I am
treating the integral as implicit.

Given the requirement, I have tried to write a well commented function to
carry out the substitution, keeping track of the indices, for expressions
containing many terms like the one above and some including d/dx's and
d/dy's.  I have had a quick look at the functions you suggest. I could use
op, args and funmake with only minor changes as I only use the simplest forms
of inpart and substinpart:
operator : inpart(old_expression, 0),
...
new_expression : substinpart(new_function, old_expression, 1),
However for such cases I am not sure what is gained.

There may be a more elegant method using buildq - I am not into macros but