Looking for ways to calculate functional derivatives in Mathematica, I found this question. The answer by Jens points to a documented application of DiracDelta
exactly for this purpose. The documentation suggests
\[ScriptCapitalD][functional_, f_[y_]] :=
Assuming[Element[y, Reals],
Limit[((functional /.
f :> Function[x, f[x] + ε DiracDelta[x - y]]) -
functional)/ε, ε -> 0]]
However, this implementation as well the other answers to that question are very limited in scope. As pointed out in the comments, they fail for an example as simple as $\delta G[f(x)]/\delta f(y)$ (or as code \[ScriptCapitalD][G[f[x]], f[y]]
), which should output
$$G^\prime[f(x)] \, \delta(x-y).$$
In my case I'd like to compute functional derivatives of the form
$$\frac{\delta^n \, \Gamma[\rho(\varphi)]}{\delta \varphi_{i_1}(p_1) \dots \delta \varphi_{i_n}(p_n)},$$
where $\rho(\varphi) = \frac{1}{2} \sum_{i = 1}^n \varphi_i^2$ is a regular function of the $\varphi_i$, $i \in \{1,\dots,n\}$.
Is there a way to equip Mathematica with the ability to calculate such derivatives with justifiable effort?
\[ScriptCapitalD][f_[x_], f_[y_]]
, along with linearity, Leibniz, and chain rules? $\endgroup$