First of all, don't call this post_process
; that's a reserved function which Cadabra will call after every manipulation step.
To do this, you need to somehow indicate where you want the 'argument' of the operator to go, otherwise a \partial_{\mu\nu}
not acting on anything will be replaced with zero before it even makes it to the function. Try something like the code below:
import cdb.core.manip as manip
\partial{#}::PartialDerivative;
def appop(ex, op):
t1=manip.get_lhs(ex)
t2=manip.get_rhs(ex)
o1:= @(op);
o2:= @(op);
for arg in o1:
if arg.name=='#':
arg.replace(t1)
for arg in o2:
if arg.name=='#':
arg.replace(t2)
ex.top().replace( $@(o1) = @(o2)$ )
return ex
You can then do
ex:= A = B;
appop(ex, $\partial_{\mu\nu}{#}$);
to get the result
$$\partial_{\mu\nu}{A} = \partial_{\mu\nu}{B}$$
You may want to add some error checking code for when you feed it a single expression, not an equation.