# Does the chain rule need to account for derivatives as test functions?

I have a functional $$\Omega[n,v] = \int \omega \mathrm{d}\boldsymbol{r}$$ with $$\omega\left(n(\boldsymbol{r},\boldsymbol{R}),v(\boldsymbol{r},\boldsymbol{R})\right)$$ (where $$n$$ and $$v$$ are functions depending on position in space) and want to calculate the partial derivative with respect to some other vector $$\boldsymbol{R}$$. I want to know if it is ok to write:

$$\frac{\mathrm{d} \Omega}{\mathrm{d}\boldsymbol{R}} = \int \frac{\delta \Omega}{\delta n}\nabla_\boldsymbol{R} n~\mathrm{d}\boldsymbol{r}+\int \frac{\delta \Omega}{\delta v}\nabla_\boldsymbol{R}v~\mathrm{d}\boldsymbol{r}$$

(where $$\frac{\delta \Omega}{\delta n}$$ represent functional derivatives).

I think this should be correct, but I cannot find a proper derivation, can someone help me with that or present a derivation?

If one uses the intuitive chain rule one gets a different result. We can convert the above expression and then compare to the conventional chain rule:

$$\frac{\mathrm{d} \Omega}{\mathrm{d}\boldsymbol{R}} = \int \frac{\delta}{\delta n}\left[\int \omega \mathrm{d}\boldsymbol{r}\right] \nabla_\boldsymbol{R}n ~\mathrm{d}\boldsymbol{r}+ \int \frac{\delta}{\delta v}\left[\int \omega \mathrm{d}\boldsymbol{r}\right]\nabla_\boldsymbol{R}v ~ \mathrm{d}\boldsymbol{r} = \int \left(\frac{\partial \omega}{\partial n}-\nabla\cdot \frac{\partial \omega}{\partial \nabla n}\right)\nabla_\boldsymbol{R}n ~ \mathrm{d}\boldsymbol{r}+\int \left(\frac{\partial \omega}{\partial v}-\nabla\cdot \frac{\partial \omega}{\partial \nabla v}\right)\nabla_\boldsymbol{R}v ~ \mathrm{d}\boldsymbol{r}\\=\int \frac{\partial \omega}{\partial n}\nabla_\boldsymbol{R}n ~ \mathrm{d}\boldsymbol{r}+\int \frac{\partial \omega}{\partial v}\nabla_\boldsymbol{R}v ~ \mathrm{d}\boldsymbol{r} \underbrace{- \int \left(\nabla\cdot \frac{\partial \omega}{\partial \nabla n}\right)\nabla_\boldsymbol{R}n ~ \mathrm{d}\boldsymbol{r}-\int \left(\nabla\cdot \frac{\partial \omega}{\partial \nabla v}\right)\nabla_\boldsymbol{R}v ~ \mathrm{d}\boldsymbol{r}}_{additional~terms}\\=\int \frac{\partial \omega}{\partial n}\nabla_\boldsymbol{R}n ~ \mathrm{d}\boldsymbol{r}+\int \frac{\partial \omega}{\partial v}\nabla_\boldsymbol{R}v ~ \mathrm{d}\boldsymbol{r} \underbrace{+ \int \frac{\partial \omega}{\partial \nabla n}\nabla_\boldsymbol{R} (\nabla n)~ \mathrm{d}\boldsymbol{r}+\int \frac{\partial \omega}{\partial \nabla v}\nabla_\boldsymbol{R} (\nabla v)~ \mathrm{d}\boldsymbol{r}}_{additional~terms}$$

Where in the last step, I threw away the surface terms, which is valid in my case.

Do I understand it correctly, that if $$\omega$$ is also a function of $$\nabla n$$ and $$\nabla v$$, we necessarily have to include the $$additional~terms$$, so the conventional chain rule does not work, since the gradients are also considered as test functions?

Edit: we actual want the total derivative of $$\Omega$$ with respect to the nuclear positions not the partial derivative!

$f(x) = \underbrace{x^2}_{g(x)}+\underbrace{2x}_{g'(x)} = g(x)+g'(x)$
$\frac{\mathrm{d} f}{\mathrm{d}x} = \frac{\partial f}{\partial g}\frac{\partial g}{\partial x}+\frac{\partial f}{\partial g'}\frac{\partial g'}{\partial x} = 2x+2$