f # g



> Let f(x1,...,xn) and g(x1,...,xn) be polynomials in n variables.
> I'd like to define the operation f # g as follows: replace each xi
> in f be the corresponding partial derivative operator d/dxi and then
> apply the resulting differential operator f(d/dx1,...,d/dxn) to g.

Maxima doesn't support differential operators directly, but there is a
pretty easy way of doing this anyway.  Construct an expression which,
when evaluated, gives the result you want.  So for example, from

        x[1]^2 + x[1]*x[2]

you would construct

      diff(q,x[1],2) + diff(diff(q,x[2]),x[1]) )

assuming that you want to transform multiplication into composition of
operators and not into multiplication.  (q is a dummy variable)  There
is no reason to restrict the second argument to polynomials (unless
you want to do something clever and efficient).

Here is some code to do this using match operations.  Of course, this
will be slower than hand-coding in Lisp, but unless you are doing this
to extremely large expressions, or to lots of them, it probably
doesn't matter.

matchdeclare([ia,ib,ic,id],true)$

defrule(var_to_diff,       /* changes x[2]^2 => diff(q,xx[2],2) */
        x[ia]^ib,
        'diff(q,xx[ia],ib))$       /* use xx to avoid circular matching */ 

defrule(diff_mul,      /* changes diff(q,xx[2])*diff(q,xx[3]) =>
diff(diff(q,xx[2]),xx[3]) */
        'diff(q,xx[ia],ib)*'diff(q,xx[ic],id),
        'diff('diff(q,xx[ia],ib),xx[ic],id))$

defrule(rename_xx,xx[ia],x[ia])$ /* convert back from xx to x */

polydiff( p1, expr )  :=
    block( [subxx],
      sub: subst( expr, q, apply1( p1, var_to_diff, diff_mul, rename_xx ) ),
      ev(sub,diff) ) $

Example:

polydiff( x[1]^2 + x[2]^2 + x[3]^2, sin(x[1]*x[2])-sin(x[2]*x[3]));
 =>
 x[3]^2*sin(x[2]*x[3])
 +x[2]^2*sin(x[2]*x[3])
 -x[2]^2*sin(x[1]*x[2])
 -x[1]^2*sin(x[1]*x[2])

Hope this helps.

          -s