# Why partial w/respect to $\phi$ of d'Alembertian of $\phi$ = 0?

Why is $$\frac{\partial }{\partial \phi}(\frac{\partial^2 \phi}{\partial x^2})$$ = 0?

I'm happy to read an article, but I don't know what keywords to search on.

Background: Apologies if this is a math question. The setup is physics and not sure if it's correct.

A text lists an example as $$L=\frac{1}{2}(\partial _{\mu}\phi)^{2}-\frac{1}{2}m^{2}\phi^{2}$$ and then asks for $$\frac{\partial L}{\partial \phi}$$. It lists the answer as $$-m^{2}\phi$$. The left-hand side of the equation, the d'Alembertian I believe, must have a derivative of 0, giving us the answer as the derivative of the right-hand side ($$\frac{\partial }{\partial \phi}(\frac{1}{2}m^{2}\phi^{2}=-m^{2}\phi)$$).

Why is the derivative of the d'Alembertian = 0? Expanding, it seems $$\frac{\partial }{\partial \phi}\frac{1}{2}(\frac{\partial^2 \phi}{\partial x_{0}^2}-\frac{\partial^2 \phi}{\partial x_{1}^2}-\frac{\partial^2 \phi}{\partial x_{2}^2}-\frac{\partial^2 \phi}{\partial x_{3}^2})=0$$.

Of course, the partial of a constant, or a variable that is not being differentiated with respect to, is 0. However, it seems to me all the terms depend on $$\phi$$, which is what we are differentiating with respect to. It probably has something to do with the chain rule of a first derivative applied to a second derivative, but I'm not clear how the chain rule works in that case. Further, I don't know what to search on.

Any help much appreciated!

TL;DR: The arguments of the Lagrangian density $${\cal L}$$ are independent$$^1$$.

This is for notational reasons easiest to explain for point mechanics, but it generalizes straightforwardly to field theory. In point mechanics, the Lagrangian $$(q,v,t)\mapsto L(q,v,t)$$ is a function of its independent arguments $$(q,v,t)$$. In particular, for sufficiently smooth $$L$$, it makes sense to differentiate $$L$$ partially wrt. to a single argument, keeping the other arguments constant. This is explained in detail in this related Phys.SE post.

$$^1$$ OP asks about second partial derivatives in title, but OP's Lagrangian density depends only on first partial derivatives, as is normally the case, so we will in this answer only discuss first partial derivatives for simplicity, but the story generalizes straightforwardly to higher-order partial derivatives.
Here the "partial" derivatives are really functional derivatives and should be written as (you don't lose anything except good notation to write the $$\delta$$ as $$\partial$$) : $$\frac{\delta}{\delta \phi} \qquad \textrm{ and } \qquad \frac{\delta }{\delta (\partial_{\mu} \phi)}$$ They are defined so that $$\frac{\delta \phi (x')}{\delta \phi(x)} = \delta^{D}(x - x') \textrm{ and } \qquad \frac{\delta (\partial_{\mu} \phi(x))}{\delta (\partial_{\nu} \phi(x'))} = \delta^{D}(x - x') \delta_\mu^{\nu}.$$ The variables $$\phi(x)$$ and $$\partial_{\mu}\phi(x)$$ are declared to be treated as independent from the perspective of the functional derivatives.
The analogy in point particle mechanics is for Lagrangians of the type $$L = \int dt' \left[ \frac{1}{2} \dot{x}^2 - \frac{1}{2}kx^{2}\right],$$ for example, where the conjugate momentum is defined to be $$p(t) = \frac{\delta L}{\delta (\dot{x}(t))} = m\dot{x}(t)$$, in which derivative we treated $$\dot{x}$$ and $$x$$ as independent in the sense that the derivative $$\frac{\delta}{\delta \dot{x}}$$ ignores all instances of $$x$$ without dots.