Derivation of entropy, I don't understand the relation $ \frac{\partial S_2}{\partial E_1} = -\frac{\partial S_2}{\partial E_2} $ My course guide gives the following derivation for change in entropy w.r.t. energy, where I don't understand a step:
\begin{align}
E & = E_1 + E_2 \\
S & = S_1 + S_2 \\
S(E,E_1 ) & = S_1 (E_1) + S_2(E-E_1)
\end{align}
Then the question is asked, which $E_1$ the new S wouldn't change. I don't truly understand what the premise is of this question. But I understand that it is a maximum, thus you can find it with setting a derivative to zero as follows:
$$\frac{\partial S}{\partial E_1} = 0 =\frac{\partial S_1}{\partial E_1} + \frac{\partial S_2 }{\partial E_1}   \tag{ chain rule}$$
Then the guide just says: "Use the following relation". I don't get how to find this relation?
$$ \frac{\partial S_2}{\partial E_1}  = -\frac{\partial S_2}{\partial E_2} $$
Where then this follows:
$$ \frac{\partial S_1}{\partial E_1}  = \frac{\partial S_2}{\partial E_2} $$
Central question:
$$ \frac{\partial S_2}{\partial E_1}  = -\frac{\partial S_2}{\partial E_2} $$
How to find this. When I differentiate $S$ to $E_2$ I just get:
$$\frac{\partial S}{\partial E_2} = 0 =\frac{\partial S_1}{\partial E_2} + \frac{\partial S_2 }{\partial E_2}   \tag{ chain rule}$$
 A: It's not unreasonable to be confused about this.  Let's say you have a function $f$ of one variable and $f'$ is its derivative.  Then we have
$$\frac{d}{dx} f(c-x) = \color{red}{-}f'(c-x)$$
via the chain rule.  If we have a function $g$ of two variables, then we might similarly write
$$\frac{\partial}{\partial x} g(c-x,y) = \color{red}{-} \big(\partial_1 g\big)(c-x,y)$$
where $\partial_1g$ is the function obtained by differentiating $g$ with respect to its first entry. It is extremely common to simply call $\partial_1 g$ the same thing as $\frac{\partial g}{\partial x}$, but that only works when we assume that $x$ is the thing which we plug into the first slot of $g$.  When that isn't the case - e.g. here - that notation is bad in my opinion.

In our case, we have the following expression:
$$S(E,E_1) := S_1(E_1) + S_2(E - E_1)$$
$S_1(\epsilon)$ is the entropy of the first system when it has energy $\epsilon$.  $S_2(\epsilon)$ is the entropy of the second system when it has energy $\epsilon$.  $S(E,E_1)$ is the entropy of both systems together when they have total energy $E$, and when the first system has energy $E_1$ (so the second system has energy $E_2= E-E_1$).
If we wish to maximize this with respect to $E_1$, we would differentiate and set the result to zero:
$$\frac{d}{dE_1} \big(S_1(E_1) + S_2(E-E_1)\big) = S_1'(E_1) \color{red}{-} S_2'(E-E_1) = 0$$
$$\implies S_1'(E_1) = S_2'(\underbrace{E-E_1}_{=E_2})$$
This is what your course guide is trying to say.
A: In my opinion the notation is very bad. $S_2$ is a function of a single variable (at least in this context here) and it simply does not make sense to compute partial derivatives with respect to two different energy variables. However, we can define a function:
$$\mathscr S := S_2 \circ Q_E \quad , $$
with $Q_E: E_1 \mapsto E-E_1 $ and hence $\mathscr S(E_1) = S_2(E-E_1)  = S_2(E_2)\quad .$
By the chain rule, we thus obtain
$$\mathscr S^\prime (E_1) = - S_2^\prime(E_2) \quad , $$
where prime denotes the derivative.
So what this all means it that on the one hand, you have the entropy of system $2$ as a function of the energy of this system, namely $S_2$ and on the other hand you have the very same entropy as a function of the energy of system $1$, namely $\mathscr S$. Let me stress that while both yield the same physical quantity, i.e. the entropy of system $2$, these are different functions, explaining my comment at the beginning.
I guess in your case it is meant that
\begin{align}
\frac{\partial S_2}{\partial E_1} (E_1) &:= \mathscr S^\prime (E_1) \\
\frac{\partial S_2}{\partial E_2} (E_2) &:=S_2^\prime(E_2) \quad .
\end{align}
A: The point is that $E$ is fixed, so that if you raise $E_1$ by some amount $\delta x$ you have to lower $E_2$ by the exact same amount $\delta x$. This means that $E_1$ and $E_2$ can not be varied arbitrarily, but must always change like this
$$
E_1 \to E_1 + \delta x
$$
$$
E_2 \to E_2 - \delta x
$$
This is reflected in the signs of the derivative because the derivative is:
$$
\frac{df}{dx} = \lim_{\delta x \to 0}\frac{f(x+\delta x) - f(x)}{\delta x}
=\lim_{\delta x \to 0}\frac{f(x) - f(x-\delta x)}{\delta x}\;.
$$
We can also multiply the above equation by $-1$ to see that:
$$
-\frac{df}{dx} = \lim_{\delta x \to 0}\frac{f(x-\delta x) - f(x)}{\delta x}\;.
$$
Finally, we can drop the limits above and rearrange to see that:
$$
f(x+\delta x) \approx f(x)+\frac{df}{dx}\delta x 
$$
$$
f(x-\delta x) \approx f(x)-\frac{df}{dx}\delta x \;,
$$
where the approximation is exact as $\delta x$ goes to zero.
The total entropy $S_1(E_1) + S_2(E_2)$ is to be maximized subject to the above constraint (i.e., that the variation in $E_1$ is always the opposite of the variation in $E_2$).
At the maximum the first order variation in the total entropy $\delta S$ must be zero. As $E_1$ changes to $E_1+\delta x$, we have that the total entropy $S$ changes like:
$$
S\to S+\delta S = S_1(E_1 + \delta x) + S_2(E_2 - \delta x)
$$
$$
\approx S_1(E_1)+\frac{dS_1}{dE_1}\delta x + S_2(E_2) - \frac{dS_2}{dE_2}\delta x
$$
$$
\approx S + \delta x (\frac{dS_1}{dE_1}- \frac{dS_2}{dE_2})
$$
Or, to first order in $\delta x$:
$$
\delta S = \delta x(\frac{dS_1}{dE_1} - \frac{dS_2}{dE_2})
$$
The first order variation with $\delta x$ is zero at the maximum, so the maximum entropy condition is:
$$
\frac{dS_1}{dE_1} - \frac{dS_2}{dE_2} = 0
$$
Or, rearranging:
$$
\frac{dS_1}{dE_1} = \frac{dS_2}{dE_2}
$$
