I spent a few days calculating the first three derivatives of a very nasty function of the form
$f(n_a,n_b, \tau_a,\tau_b, \nabla n_t)$
where $n_t=n_a+n_b$ in $\nabla n_t$.
I need this derivative for part of a code that I am writing for my work and now it turns out I need to transform all the derivatives that I have to derivatives in terms of $n_t$, $n_s=n_a-n_b$, $\tau_t=\tau_a+\tau_b$, $\tau_s=\tau_a-\tau_b$ and $(\nabla n_t)^2$, i.e. the first three derivatives of
$f(n_t, n_s, (\nabla n_t)^2, \tau_t, \tau_s)$.
The conversion for $n_t,n_s$ and $\tau_t,\tau_s$ should be analogous. I know that I need to apply the chain rule but the point where I'm lost is that all of them depend on two variables ($a and b$).
For instance:
$\frac{dy}{du}=\frac{dx}{du}\cdot \frac{dy}{dx}$ for the first derivative
and $\frac{d^2y}{du^2}=\frac{d^2x}{du^2}\cdot\frac{dy}{dx}+(\frac{dx}{du})^2\cdot \frac{d^2y}{dx^2}$ for the second derivative conversion.
If I take a look at the first derivative conversion and let $y=f$ and $u=n_t$ and $x=n_a$ then I have:
$\frac{df}{dn_t}=\frac{dn_a}{dn_t}\cdot \frac{df}{dn_a}$.
I can express $n_\uparrow$ as $n_\uparrow=\frac{1}{2}(n_t+n_s)$ and thus $\frac{dn_\uparrow}{dn_t}=\frac{1}{2}$.
Since I already know $\frac{df}{dn_a}$ that would give me: $\frac{df}{dn_t}=\frac{1}{2}\cdot \frac{df}{dn_a}$
But I can do the same for $n_b$ and would get the same result. I know this is wrong, so I guess my question is how do I the derivatives conversion when there is more than one variable involved?
$\textbf{EDIT:}$
I found that for two variables the chain rule is as follows:
$\frac{\partial f}{\partial u}=\frac{\partial x}{\partial u}\cdot \frac{\partial f}{\partial x}+\frac{\partial y}{\partial u}\cdot \frac{\partial f}{\partial y}$
which is simple enough for $n_a,n_b,\tau_a$ and $\tau_b$. And since $\nabla n_t=\sqrt{(\nabla n_t)^2}$ that would give me:
$\frac{\partial f}{\partial (\nabla n_t)^2}=\frac{\partial \nabla n_t}{\partial (\nabla n_t)^2}\cdot \frac{\partial f}{\partial \nabla n_t}=\frac{\partial f}{\partial \nabla n_t}\cdot \frac{1}{2\nabla n_t}$?