I wanted to ask a question about implicit differentiation in partial differentiation.
When I was at school, I remember partial differentiation as something like this:
When you have a function composed of $x$ and $y$'s and you run into a $y$ term, differentiate with respect to $y$ and multiply by $\frac{dy}{dx}$ i.e. $$\frac{d}{dx} = \frac{d}{dy} \times \frac{dy}{dx}$$
Now, I read a problem on the Physics section yesterday afternoon that is relevant to my Chemistry course and I couldn't work it out.
If I have the equation
\begin{aligned} \frac{F\left(N_{A}, N_{B}\right)}{k T}=& N_{A} \ln \left(\frac{N_{A}}{N}\right)+N_{B} \ln \left(\frac{N_{B}}{N}\right) \\ &+\left(\frac{z w_{A A}}{2 k T}\right) N_{A}+\left(\frac{z w_{B B}}{2 k T}\right) N_{B}+\chi_{A B} \frac{N_{A} N_{B}}{N} \end{aligned}
I can get a quantity called the Chemical potential $\mu_{A}$ by differentiating the above equation with respect to $N_A$ while keeping $N_B$ and $T$ constant.
$$\mu_{A}=\left(\frac{\partial F} {\partial N_{A}}\right)_{T, N_{B}}$$
(The above equation is called the Free Energy Equation)
$N$ is the total number of molecules in the system, $N_A$ and $N_B$ are the number of molecules of A and B respectively. $N$ is not constant. They are related quite simply as via the sum:
$$N = N_A + N_B$$
which makes sense.
This equation also shows us that a small change in $N_A$ will also yield a small change in $N$ hence why $N$ is not constant, as mentioned above.
So I wanted to get from this equation, $\mu_{A}$
$$\frac{\mu_{A}}{k T}=\left[\frac{\partial}{\partial N_{A}}\left(\frac{F}{k T}\right)\right]_{T, N_{B}}$$
which makes sense.
The result given from the book (page 7), however, confused me. They gave the result as
$$=\ln \left(\frac{N_{A}}{N}\right)+1-\frac{N_{A}}{N}-\frac{N_{B}}{N}+\frac{z w_{A A}}{2 k T}+\chi_{A B} \frac{\left(N_{A}+N_{B}\right) N_{B}-N_{A} N_{B}}{\left(N_{A}+N_{B}\right)^{2}}$$
and only the last two terms made sense.
The OP asked where the terms
$$-\frac{N_{A}}{N}-\frac{N_{B}}{N}$$
came from and the answer given was as follows:
You missed the $N$ in the logarithm. Since $N_{B}$ is kept constant while changing $N_{A}$, the total number of particles $N=N_{A}+N_{B}$ changes as well. The missing term is $$\dfrac{\partial N}{\partial N_{A}}\dfrac{\partial}{\partial N}\left[N_{A}\ln\left(\dfrac{N_{A}}{N}\right)+N_{B}\ln\left(\dfrac{N_{B}}{N}\right)\right]=-\dfrac{N_{A}}{N}-\dfrac{N_{B}}{N}$$
and in the comments the value of $\dfrac{\partial N}{\partial N_{A}}$ was clarified to be $1$, again using the equation $N = N_A + N_B$. I understood this step.
but I then thought, if that was the case, how did the terms $$\ln \left(\frac{N_{A}}{N}\right)+1$$ arise then?
My original thought, similar to the OP was to differentiate:
$$\dfrac{\partial}{\partial N_{A}}\left[N_{A}\ln\left(\dfrac{N_{A}}{N}\right)+N_{B}\ln\left(\dfrac{N_{B}}{N}\right)\right]$$
but as explained, this assumed $N$ was constant, which it is not.
How are the terms $$\ln \left(\frac{N_{A}}{N}\right)+1$$
yielded by this application of implicit differentiation, if $\dfrac{\partial N}{\partial N_{A}} = 1$ using $\dfrac{\partial N}{\partial N_{A}}\dfrac{\partial}{\partial N}$?
We want to compute \begin{aligned} \frac{\partial }{\partial N_A}\left( N_{A} \ln \left(\frac{N_{A}}{N}\right)+N_{B} \ln \left(\frac{N_{B}}{N}\right) +\left(\frac{z w_{A A}}{2 k T}\right) N_{A}+\left(\frac{z w_{B B}}{2 k T}\right) N_{B}+\chi_{A B} \frac{N_{A} N_{B}}{N}\right) \end{aligned}
First note that $$\frac{\partial N }{\partial N_A}= \frac{\partial}{\partial N_A}(N_A+N_B)=1+0=1$$
Now, let's compute partial derivative term by term.
\begin{align}\frac{\partial}{\partial N_A}\left(N_A\ln \left( \frac{N_A}{N}\right) \right) &= \left( \frac{\partial N_A}{\partial N_A}\right) \ln \left( \frac{N_A}{N}\right) + N_A \frac{\partial }{\partial N_A}\left( \ln \left( \frac{N_A}{N}\right)\right)\\ &= \ln \left( \frac{N_A}{N}\right) + N_A \frac{\partial }{\partial N_A}\left( \ln N_A - \ln N \right) \\ &=\ln \left( \frac{N_A}{N}\right)+ N_A (\frac1{N_A}-\frac1N \frac{\partial N}{\partial N_A})\\ &= \ln \left( \frac{N_A}{N}\right)+1-\frac{N_A}{N}\tag{1}\end{align}
where in the first line I have used product rule; in the second line, I have used a logarithm identity; in the third line, I used chain rule.
\begin{align}\frac{\partial}{\partial N_A}\left(N_B\ln \left( \frac{N_B}{N}\right) \right) &= \frac{\partial}{\partial N_A}\left(N_B(\ln \left( N_B)- \ln(N)\right) \right)\\ &= N_B(-\frac1N \frac{\partial N}{\partial N_A})\\ &=- \frac{N_B}{N}\tag{2}\end{align}
\begin{align}\frac{\partial}{\partial N_A}\left(\left(\frac{zw_{AA}}{2kT}\right)N_A\right) =\left(\frac{zw_{AA}}{2kT}\right)\tag{3}\end{align}
\begin{align}\frac{\partial}{\partial N_A}\left(\left(\frac{zw_{BB}}{2kT}\right)N_B\right) =0\tag{4}\end{align}
\begin{align}\frac{\partial}{\partial N_A}\left(\chi_{AB}N_B\left(\frac{N_A}{N}\right)\right) &= \chi_{AB}N_B\left(\frac{N-N_A \frac{\partial}{\partial N_A}N}{N^2} \right) \\&=\chi_{AB}\left(\frac{N_B}{N}\right)^2\tag{5}\end{align}
We just have to sum these terms up to get the result. Equation $(1)$ is of particular interest to you.