# Derivation of 1st law of thermodynamics using microcanonical ensemble

In the book Statistical Physics of Particles by M. Kardar, the author shows the connection between the microcanonical ensemble and thermodynamics deriving the zeroth, 1st and 2nd laws. In the paragraph right before eq. $$(4.7)$$ it is stated the following:

The first law: we next inquire about the variations of $$S(E,\mathbf{x})$$ with $$\mathbf{x}$$, by changing the coordinates reversibly by $$\delta\mathbf{x}$$. This results in doing work on the system by an amount $$\delta W = J \cdot \delta \mathbf{x}$$, which changes the internal energy to $$E +\mathbf{J}\cdot \delta \mathbf{x}$$ The first-order change in entropy is given by $$\delta S(E, \mathbf{x}) = S(E +J\cdot \delta \mathbf{x}, \mathbf{x}+ \delta \mathbf{x}) - S(E, \mathbf{x}) = \left(\frac{\partial S}{\partial E} \mathbf{J} + \frac{\partial S}{\partial \mathbf{x}} \right)\delta \mathbf{x} \tag {4.8}$$ This change will occur spontaneously, taking the system into a more probable state, unless the quantity in brackets is zero. Using Eq. $$(4.7)$$ ($$\partial S/ \partial E = 1/T$$), this allows us to identify the derivatives $$\frac{\partial S}{\partial x_i} |_{E, x_{j\ne i}} = - \frac{J_i}{T}.\tag{4.9}$$ Having thus identified all variations of $$S$$, we have $$d S(E, \mathbf{x})= \frac{dE}{T} - \frac{\mathbf{J} \cdot d \mathbf{x}}{T} \implies dE = TdS + \mathbf{J} \cdot d \mathbf{x}$$ allowing us to identify the heat input $$\delta Q = TdS$$.

What I don't understand is that if the author derived equation $$(4.9)$$ from the assumption that there's no heat (isolated system) and that the change $$\delta \mathbf{x}$$ is reversible, how can he just substitute this equation in the differential of entropy for a generic case (which allows flow of heat)?

The way I see this is the following: So, $$S$$ is a function of $$E$$ and $$\mathbf x$$. To get an expression for the differential of entropy $$S$$, one needs to know $$\frac{\partial S}{\partial E} |_{\mathbf x}$$ and $$\frac{\partial S}{\partial x_i} |_{E, x_{j\ne i}}$$. The former is $$1/T$$, and the latter is found out via the calculation shown.
Now, it does not matter how we calculate $$\frac{\partial S}{\partial x_i} |_{E, x_{j\ne i}}$$ since it is not something that depends on the path. It is simply the infinitesimal change in entropy (which is a state function) divided by an infinitesimal change in the coordinate $$x_i$$ (a state variable). Moreover, what we get after the calculation is indeed consistent with this fact as $$- \frac{J_i}{T}$$ is a state function.