Hey folks,
I have a problem. I would like to be able to use a derivative operator inside an inactive sum to represent a mapping like this: $$ F(g(x_1,x_2,x_3)) = \sum_{i=1}^{3} \partial_{i} g(x_1,x_2,x_3) $$ where $\partial_{i} g = \frac{\partial g}{\partial x_i}$. The key thing here is that I would like to keep the sum inactive so I could manipulate the terms inside the sum and activate it later if needed. More specifically, I would like to be able to calculate a Gâteaux derivative of this functional like this: $$ \partial_{g} F(g; \psi) = \left[ \frac{\mathrm{d} }{\mathrm{d} t} F(g(x_1,x_2,x_3) + \epsilon \,\psi(x_1,x_2,x_3)) \right]_{\epsilon=0} $$
Ideally, I would like to be able to write this:
x = {x1, x2, x3};
expr = Inactive[Sum][D[p[k][x1, x3, x3], x[[k]]], {k, 1, 3}]
but it does not work, as it accuses:
Part::pkspec1: The expression k cannot be used as a part specification.
I then tried this
func[p_] :=
Inactive[Sum][
Inactive[D][p[k],(*function*)
Inactive[Part][x, k]],(*\[PartialD]/\[PartialD]x_k kept inert*){k,
1, 3}];
This works, but it does not allow for the Gâteaux derivative to work:
D[func[Function[i,
p[i] @@ x + \[Epsilon] \[Psi] @@ x KroneckerDelta[k,
1]]], \[Epsilon]] // InputForm
which yields:
Inactive[Sum][KroneckerDelta[1, k]*\[Psi][x1, x2, x3]*Inactive[D][1, Inactive[Part][{x1, x2, x3}, k]], {k, 1, 3}]
which is wrong. Since the derivative is inactive, the derivative with relation to $\epsilon$ doesn't really work here, as it assumes that $\phi$ is not related to {x1,x2,x3}[[k]], and then takes it out of the derivative.
The reason why I need this is for calculating the Gâteaux derivative of an Augmented Lagrangians for the Adjoint State Method for my research. Since I am dealing with PDEs with tensor notation, I would like to preserve the indices of the tensor notation all the way to the end of the calculations, and activate only then.
I think the way to go might be to define a function that acts as a derivative and somehow tell Mathematica how it interacts with other derivatives that might nest with it, and then make it turn into a normal derivative as soon as I activate it.
I wonder if any of you has any suggestions on how to proceed and lend me some help. I am attaching a notebook with some of my attempts but it is a little cluttered, I apologize in advance,
All the best,
Átila.