The second law of quantum thermodynamics as an equality

We investigate the connection between recent results in quantum thermodynamics and fluctuation relations by adopting a fully quantum mechanical description of thermodynamics. By including a work system whose energy is allowed to fluctuate, we derive a set of equalities which all thermodynamical transitions have to satisfy. This extends the condition for maps to be Gibbs-preserving to the case of fluctuating work, providing a more general characterisation of maps commonly used in the information theoretic approach to thermodynamics. For final states, block diagonal in the energy basis, this set of equalities are necessary and sufficient conditions for a thermodynamical state transition to be possible. The conditions serves as a parent equation which can be used to derive a number of results. These include writing the second law of thermodynamics as an equality featuring a fine-grained notion of the free energy. It also yields a generalisation of the Jarzynski fluctuation theorem which holds for arbitrary initial states, and under the most general manipulations allowed by the laws of quantum mechanics. Furthermore, we show that each of these relations can be seen as the quasi-classical limit of three fully quantum identities. This allows us to consider the free energy as an operator, and allows one to obtain more general and fully quantum fluctuation relations from the information theoretic approach to quantum thermodynamics.


I. INTRODUCTION
The second law of thermodynamics governs what state transformations are possible regardless of the details of the interactions. As such, it is arguably the law of physics with the broadest applicability, relevant for situations as varied as subatomic collisions, star formation, biological processes, steam engines, molecular motors and cosmology. For a system which could be placed in contact with a thermal reservoir at temperature T , the second law can be expressed as an inequality of the form where the free energy is F (ρ) = tr Hρ − T S(ρ), the entropy is S(ρ) = − s P (s) log P (s), with P (s) the probability that the system has energy level |s , H is the Hamiltonian of the system, and w is the average work done by the system when it transitions from ρ to ρ . The free energy is a scalar, and can be thought of as an average quantity. Here, we will see that by thinking of the free energy as an operator or random variable, one can derive a much stronger classical version of the second law which is an equality e β(f s −fs+w) = 1 (2) in terms of a fine-grained free energy that can be considered as a random variable occurring with probability P (s) and whose average value is the ordinary scalar free energy F = f s . Here, initial energy levels are given by E s = tr |s s|H, while the energy levels E s correspond to the final Hamiltonian H . Although the term −T log P (s) is not defined for P (s) = 0, all its moments are. We will see that this equality version of the second law can be thought of as a simple consequence of a much stronger family of equalities and quantum identities. We will also see that if we Taylor expand the exponential in the above equality, we obtain not only the standard inequality version of the second law, but in addition, an infinite set of higher order inequalities. These can be thought of as corrections to the standard inequality.
This second law equality is valid for transitions between any two states as long as the initial state is diagonal in the energy eigenbasis, and when work is considered as the change in energy of some work system or weight. As such, although it is a greatly strengthened form of the second law, it is of a more classical nature, reminiscent of the fluctuation theorems of Jarzynski [1] and Crooks [2] where it is required that a measurement is performed on the initial and final state. We are however, not only able to get a more general classical version of the Jarzynski fluctuation theorem, valid for any initial state, but we are also able to derive two fully quantum identities which reduce in the classical limit to these classical generalisations of the Jarzynski equation and the second law.
What's more, even our classical fluctuation theorems are derived from a fully quantum mechanical point of view, and are thus valid for any quantum process. Previous derivations, assumed a particular form of Markovian classical trajectories (e.g. assuming a Langevin equation or classical trajectory in the context of classical stochastic thermodynamics) [2][3][4][5][6][7][8]. A quantum mechanical derivation of the standard Jarzynski equation has been done in numerous works [9][10][11][12][13][14], but in these one is usually limited to initial thermal states, and also must resort to energy measurements on the system in order to define work. A derivation of fluctuation theorems for classical trajectories between arbitrary initial and final states has been performed in the case of erasure and a degenerate Hamiltonian [8]. A derivation with arbitrary initial and final states was also undertaken in [15], for a family of maps which go slightly beyond the classical case.
Here, we adopt a fully general and quantum mechanical treatment and derive a fully quantum identity, which reduces to the generalised fluctuation relation e β(w−fs) = Z S (4) when the initial state is diagonal in the energy eigenbasis. We call such states, i.e. those that satisfy [ρ S , H S ] = 0, quasi-classical states, and the above fluctuation relation is valid for arbitrary initial and final states of this form and for any quantum thermodynamical process. When the initial state is thermal, we further have e −βfs = Z S for all s which gives Jarzynski's equation in its usual form Our two quantum identities, which reduce to the equality version of the second law and the generalisation of the Jarzynski equation valid for arbitrary initial quasiclassical states, can be considered as two independent children of a third, more powerful, quantum identity where ρ W is the initial state of the weight system, 1 S is the identity on the system S of interest, Γ SW is the completely positive trace preserving map acting on the joint state of system and weight which gives its evolution, and we define, as in [16] (but with opposite sign convention), J H (ρ) = e β 2 H ρ e β 2 H . This parent identity can easily be used to derive a fully quantum, general Jarzynski Equation for arbitrary states (Result 3 in Section III). When the input is quasiclassical, it reduces to our generalised Jarzynski Equation for arbitrary initial quasi-classical states. Likewise, the parent identity gives a fully quantum version of the second law equality, Result 2 in Section III, which reduces to the equality version of the second law when the initial state is quasi-classical. Now, it is natural to ask what the parent identity, Eq. (6), reduces to for quasi-classical states. While Eq. (6) must necessarily be fulfilled by all thermodynamical processes on quantum states, on quasi-classical states it leads to the following necessary and sufficient condition for transition probabilities to be realizable through thermal processes: for all s , where P (s , w|s) is the conditional probability of the final state having energy levels E s , and work w being done by the system, given that the initial state had energy level E s . This turns out to be the extension of an important equation from the resource theoretic approach to quantum thermodynamics which finds its origin in ideas from quantum information theory ). An overarching idea behind the information theoretic approach is to precisely define what one means by thermodynamics, and thus consider which possible interactions are allowed between a system, a heat bath, and a work storage device, while systematically accounting for all possible resources used in the process. This leads to a definition of thermodynamics known as Thermal Operations (TO) [17,22,46]. This, and its catalytic version [24], represent the most an experimenter can possibly do when manipulating a system without access to a reservoir of coherence (although one can easily include a coherence reservoir as an ancilla as in [21,28,32]). It is thus the appropriate class of operations for deriving limitations such as a second law. However, they can be realised by very coarse grained control of the system, and thus also represent achievable thermodynamical operations [42].
They also include the allowed class of operations considered in fluctuation theorems, which include arbitrary unitaries on system and bath. We explain this inclusion in Appendix A. Thermal Operations are thus broad enough to encompass commonly considered definitions of thermodynamics (see [21] for further discussion on this point), including those used in the context of fluctuation relations.
Eq. (7) turns out to completely characterise thermodynamics in the case of fluctuating work. In information theory, an important class of maps are those which satisfy the doubly-stochastic condition, i.e. preservation of the maximally mixed state. In thermodynamics, when there is no work system, any operation must instead preserve the Gibbs state. Equation 7 is an extension of this condition to the case where there is a work system which is allowed to fluctuate. Taking Eq. (7) with w = T log Z S Z S gives the Gibbs-preserving condition derived in [17,46]. We will show that Eq. (7) provides a necessary and sufficient condition for thermodynamical transitions between states which are diagonal in the energy eigenbasis, and as a result is a necessary and sufficient condition for work fluctuations. Using a generalisation of a theorem of Hardy, Littlewood, and Polya [47], the condition of Gibbs-preservation was shown in [48] to be equivalent to the set of thermodynamical second laws which have recently been proven to be necessary and sufficient condition for quantum thermodynamical state transformations [22] (c.f. [47]), the so-called thermo-majorization criteria [22,49]. The latter are conditions on the initial probabilities P (s) and final probabilities P (s ) under which one state can be transformed into another.
Previously, in the resource theory approach, the work storage system had to be taken to be part of the system of interest [22]. Using this technique, one can compute the minimal amount of deterministic work required to make a state transformation [22] using thermo-majorization. One can also consider fluctuating or probabilistic work from the resource theoretic perspective, but thus far, only average work has been computed [21,26]. Unresolved, thus far, has been the question of how the information theoretic paradigm fits in with the fluctuation theorem approach. Some further insights have been obtained in attempting to link the information theoretic approach with the fluctuation theorem approach [36,50,51], however, how the two paradigms fit together has remained an open question.
Here, we see that one can incorporate fluctuating work explicitly in the resource theoretic approach through Eqs. (6) and (7). These serve to bring the field of fluctuation theorems fully into the domain of the information and resource theoretic approach. This is possible because the class of operations which are allowed in the fluctuation theorem paradigm lies within Thermal Operations. The latter approach is also able to incorporate not only fluctuations of work, but also of states [52,53], and we here aim to extend its use to further physically motivated situations.
Finally, it is interesting to compare the power of the relations presented here, with the Jarzynski and Crooks' relations. We do this for one of the simplest examples, the process of Landauer erasure [54], where a bit in an unknown state is erased to the 0 state. Since the initial state is thermal, one can apply the Jarzynski equality in its standard form. However, even in this simple case, we find that the new equalities proven here give more information than the standard Jarzynski and Crooks, in part because one has an independent equality for each possible final energy state. One finds a number of additional insights. Namely, (i) that one needs very large work fluctuations that grow exponentially as the probability that the erasure fails decreases -the more perfect we demand our erasure to be, the larger the work fluctuations; (ii) it is impossible to even probabilistically extract work in a perfect erasure process; and (iii) that the optimal average work cost for perfect erasure of T log 2 is only achieved when the work fluctuations associated with successful erasure tend to zero. While these facts are known for protocols that are thermodynamically reversible, we know of no proof that they hold for arbitrary protocols. This simple application is discussed in the Conclusion.
The remainder of the paper is structured as follows: in Section II we define what we consider to be thermodynamics -namely the set of Thermal Operations in the presence of fluctuating work. This involves three simple conditions on the type of operations which can be performed and we find some general constraints they need to obey. In Section III we introduce the three fully quantum thermodynamic identities and prove them. In Section IV we show that in the case of states which are diagonal in their energy eigenbasis, these quantum identities each reduce to the equality version of the second law, a generalisation of the Jarzynski equation, and the extension of the Gibbs-preservation condition to the case of fluctu-ating work. In Section V we discuss the implications of our results on determining conditions for state transformations to be possible. In Section VI we show that in the case of the initial state being diagonal in the energy basis and the final state being arbitrary, the quantum identities reduce to constraints on the expectation values of certain operators with a clear physical interpretation. Related work: While this research was nearing completion, [16] appeared on the arXiv. There, a fully quantum Crooks-type identity was derived. This gives a constraint on the quantum state of the weight depending on both the evolution and the time-reversed evolution. As our constraints are on both the system and weight, the two results appear to complement each other without overlap. We relate the two results by proving a quantum analog of the Crooks relation, of similar form to that in [16] but applying not just to the weight, but to the system and weight. This is done in Section VII. Some of the other results there can be derived in our framework as well.

II. THERMAL OPERATIONS WITH FLUCTUATING WORK
First, let us characterise the type of process/operation that we consider, and show that they are suitably general and implementable to encompass what is commonly considered to be thermodynamics. Our setting consists of a system with Hamiltonian H S , a bath with Hamiltonian H B initially in the thermal state ρ B = 1 Z B e −βH B , and an ideal weight with Hamiltonian H W = R dx x|x x|, where the orthonormal basis {|x , ∀ x ∈ R} represents the position of the weight. The operations we consider will allow for the Hamiltonian to change as we shall see in Subsection II A. Any joint transformation of system, bath and weight is represented by a Completely Positive Trace Preserving (CPTP) map Γ SBW . We only consider maps Γ SBW satisfying the following conditions: Unitary on all systems: It has an (CPTP) inverse Γ −1 SBW , which implies unitarity: Here ∆ W is the generator of the translations in the weight and canonically conjugate to the position of the weight H W , that is [∆ W , H W ] = i. Note that these constraints allow for processes that exploit the coherence of the weight, as in [26,55]. We expand on how this in Appendix A, where we show that such coherence can allow us to implement arbitrary unitaries on system and bath. Both unitarity and energy conservation are fundamental laws of nature, so imposing them is a necessary assumption. Any process which appears to violate energy conservation in the above sense is in fact energy conserving, one is merely tracing out or ignoring a system which is taking or giving up energy. For example, turning on an interaction Hamiltonian between system, bath and weight can be done via a coherent ancilla as demonstrated in [21]. One can generate other couplings between the three systems via the unitary U . Imposing energy conservation on the systems considered, thus ensures that all sources of energy are properly accounted for. Note that while we require that the total process is unitary on the systems, weight and bath, the operation on system and weight alone will usually not be.
The last condition, independence of the weight position, implies that the reduced map on system and bath Γ SB is a mixture of unitaries (Result 1 in [55]). Hence the transformation can never decrease the entropy of system and bath, which guarantees that the weight is not used as a resource or as an entropy sink. Independence of the position of the weight can be thought of as a definition of work [26] and is used in both the information theoretic and fluctuation theorem approaches. In the latter case, the assumption is implicit, since the amount of work is taken to be the difference in energy between the initial and final system/bath. In other words, work is taken to be a change in energy of either the work system (explicit), or change in energy of the system-bath (implicitly). Conservation of energy ensures that the implicit and explicit paradigms are equivalent. Work then is the change in energy of the work system, and does not depend on how much energy is currently stored there, hence the unitary must commute with its translations. In the Appendix, we discuss the connection between different paradigms in more detail, and in particular, show that Thermal Operations is sufficiently general to include the the paradigms typically considered in the context of fluctuation relations.

A. Thermal operations with non-constant Hamiltonian
Thermal operations are general enough to include the case where the initial Hamiltonian of the system H S is different than the final one H S . This is done by including an additional qubit system X which plays the role of a switch (as in [22]). Now the total Hamiltonian is and energy conservation reads [V, H] = 0, where V is the global unitary when we include the switch. We impose that the initial state of the switch is |0 X and the global unitary V performs the switching for any ρ SBW . This implies where U andŨ are unitaries on system, bath and weight. The condition [V, H] = 0 implies Therefore, the reduced map on system, bath and weight can be written as where the unitary U does not necessarily commute with H S +H B +H W nor H S +H B +H W but satisfies Eq. (11).

III. IDENTITIES FOR QUANTUM THERMAL OPERATIONS
In this section we derive some fully quantum equalities for Thermal Operations with fluctuating work. In the next section we shall provide the physical meaning of these equalities. Thus far, from the information theoretic perspective, some quantum constraints on state transformations are known i.e. constraints on transformations of the coherences over energy levels [24,[28][29][30][31][32], but none of these constraints apply in the case of fluctuating work. On the other hand, in the fluctuation theorem approach, no quantum relations are known -one always assumes that the initial and final states are measured in the energy eigenbasis, thus one is only considering transitions between quasi-classical states.
In what follows we are mostly interested in the joint dynamics of system and weight, which is described by the CPTP map It is convenient to define the CP (but not TP) map whose inverse is Using Eqs. (11) and (12) we obtain As mentioned in the previous section, it was proven in [55] that the condition [U, ∆ W ] = 0 implies tr W U (1 SB ⊗ ρ W ) U † = 1 SB for any state ρ W . Proceeding similarly as in Eq. (16) we obtain We thus have: Result 1 (Quantum Gibbs-stochastic). If Γ SW is a thermal operation, then This is a quantum extension of the Gibbs-preservation condition presented in [17,46]. The result generalises that in [17,46], not only because it includes work, but also because it is fully quantum. The details of the quasiclassical generalization to the case of fluctuating work are provided in Section IV.
Next, we use the identities J −1 T ln ρ (ρ) = 1 and tr S [J T ln ρ (1)] = 1, which hold for any full-rank state ρ. In the case where the initial state ρ S is not full rank, we can take the limit of a full-rank state. Now, applying J T ln ρ S and taking the trace over S on both sides of Eq. (18) we obtain: Result 2 (Quantum Second Law Equality). If Γ SW is a thermal operation, then, for every pair of initial states ρ S , ρ W , we have where is the final state of the system.
The above result is a quantum generalization of the second law equality, which we will describe in Section IV. Now, applying J −1 H S and taking the trace over S on both sides of Eq. (18) we obtain a quantum generalization of the Jarzynski inequality for general initial states: Result 3 (Quantum Jarzynski Equality). If Γ SW is a thermal operation then 21) for every pair of initial states ρ S , ρ W .

IV. IDENTITIES FOR CLASSICAL THERMAL OPERATIONS
We will now go from the fully quantum identities, to ones which are applicable for quasi-classical states (i.e. those considered in fluctuation theorems). We thus consider the case where there is an eigenbasis |s for H S and an eigenbasis |s for H S such that Γ SW (|s s| ⊗ |0 0|) = s ,w P (s , w)|s s | ⊗ |w w| , (22) where |w are eigenstates of H W . Note that when H S or H S are degenerate, they could have other eigenbases not satisfying the above. We say that Γ SW is a process which acts on quasi-classical states. Also, the "independence of the position of the weight" allows us to choose its initial state to be |0 without loss of generality. If we denote by E s and E s the eigenvalues corresponding to |s and |s , then we can write J H S (|s s|) = e βEs |s s| and J H S (|s s |) = e βE s |s s |.
When Eq. (22) holds, we can represent the thermal operation Γ SW by the stochastic matrix The if direction is proven as follows. Let us consider a bath with infinite volume in a thermal state at inverse temperature β. Without loss of generality, the energy origin of the bath can be chosen such that E β = 0. This and the fact that its heat capacity is infinite (due to the infinite volume) implies that the density of states Ω(E) is proportional to e βE . Due to energy conservation and invariance of the position of the weight, the joint map of system, bath and weight can be characterised by a map on system and bath π : (s, b) → (s , b ) where (s, b) and (s , b ) label pairs of system and bath energy levels. We construct the map π from the given P (s , w|s) in the following way. When the system makes the transition s → s , a fraction P (s , w = E − E + E s − E s |s) of the bath states with energy E are mapped to bath states with energy E , for all values of E. Using the fact that the number of states with energy E is Ω(E) = A e βE (for some constant A), we will now show that π is a permutation.
The number of (final) states in the set {(s , b ) : E b = E } is Ω(E ). And the number of (initial) states (s, b) that are mapped to this set is where in the last line we have used Eq. (24). Therefore, it is possible to construct a permutation with the mentioned requirements.
Note that Result 4 gives a necessary and sufficient condition that Thermal Operations with a fluctuating weight must satisfy for transformations between quasi-classical states, while the fully quantum Result 1 is a necessary condition. This last point can be seen by considering an operation that is Gibbs preserving on the system and acts as 1 W on the weight. This clearly satisfies Eq. (18), yet since Gibbs preserving operations are a larger class of operations that Thermal Operations [56], it need not be a Thermal Operation.
The above is an extension of the Gibbs preservation condition [17,46] to the case where thermodynamical work is included. When the Hamiltonian of the system does not change, setting w = 0 in Result 4 reproduces the aforementioned result. We discuss the implications of this condition on state transformations in the next section.
In a similar fashion to the previous section, we can write the quasi-classical version of Result 2 as s ,s,w P (s , w|s) e β(f s −fs+w) P (s) = 1 , where we define the fine-grained free energies In a more compact form:

Result 5 (Classical Second Law Equality).
A process on quasi-classical states that acts unitarily on the total system, conserves energy and is independent of the position of the weight satisfies e β(f s −fs+w) = 1 .
This result follows simply by using Eq. (23) in Result 2 or directly from Result 4. Due to the convexity of the exponential, this equality implies the standard second law But Eq. (28) is stronger, since it implies the following infinite list of inequalities where N can be any odd number. Note that Eq. (29) is the N = 1 case. One can think of Eq. (30) as providing higher order corrections to the standard second law inequality. All the other inequalities have information about the joint fluctuations of f s , f s and w. To prove Eq. (30) we just note that the residue of the Taylor expansion of the exponential function to any odd order is always negative. Next we proceed as in Result 5, and obtain the classical version of Result 3. Once again, this can be done either by substituting Eq. (23) into Result 3 or proceeding directly from Result 4.
Result 6 (Classical Jarzynski Equality). A process on quasi-classical states that acts unitarily on the total system, conserves energy and is independent of the position of the weight satisfies e β(w−fs) = Z S .
Note that this version of the Jarzynski equation is valid for any initial state of the system, encoded in the finegrained free energy f s . For the particular case where the initial state is thermal, we have e −βfs = Z S for all s, which implies the standard Jarzynski Equality

V. IMPLICATIONS FOR CONDITIONS ON STATE TRANSFORMATIONS
Result 4, the extension of the Gibbs preserving condition to the case of fluctuating work, is a restriction on what maps are possible in thermodynamics. The Gibbs preserving condition, is likewise a generalisation of the condition for a map to be bistochastic (i.e. preserve the maximally mixed state). This is recovered when the initial and final Hamiltonians of the system are trivial H S = H S = 0, and we set w = 0 in Result 4.
For the case of bistochastic maps Λ, the condition on the map is equivalent to a condition on what state transformations are possible. Namely, for two states ρ and ρ , ρ = Λ (ρ) if and only if ρ is majorised by ρ [57]. The majorisation condition is as follows. For eigenvalues of ρ and ρ arranged in non-increasing order and denoted by λ s , λ s , we say that ρ is majorised by ρ if and only if k s=1 λ s ≥ k s=1 λ s ∀k. For non-trivial Hamiltonians such that H S = H S (but still setting w = 0), Thermal Operations preserve the associated Gibbs state rather than the maximally mixed state. For such sets of allowed operations thermomajorisation provides a set of conditions that relate initial states to achievable final states (see Figure 1). These can be considered as a refinement of the second law of thermodynamics, since they constrain the states to which some initial state can evolve under the laws of thermodynamics.
In the case of fluctuating work (no longer requiring that w = 0), one can now ask whether it is possible to relate the condition on allowed maps given by Result 4 to a condition akin to thermo-majorisation on the achievable states and work distributions. A simple, and fairly common case is where the values of work that occur are labeled by s and s and of the form w ss = α s − γ s . These can be readily related to the Gibbs-preservation condition of [17,46] (note that processes such as Level Transformations as discussed in the Appendix are examples of such transformations). For such work distributions, P (s , w ss |s) is a thermal operation if and only if P (s |s) ≡ P (s , w ss |s) satisfy the Gibbs-preservation condition of [17,46] but with the energy levels of the initial and final systems redefined so that the initial energy levels are E s +γ s and the final are E s +α s . Determining whether it is possible to convert a state ρ into a state σ while extracting work of the form w ss = α s − γ s can be done using the thermo-majorization diagrams introduced in [22] as shown in Fig. 1. Indeed, when α s = −E s and γ s = −E s , the problem reduces to the question of whether ρ majorises σ.

VI. CLASSICAL-QUANTUM IDENTITIES
In classical physics no problem arises from writing joint expectations of observables for the initial and final states of an evolution. For example, this is done in Results 4-6. In general, quantum theory does not allow for this, because a measurement on the initial state will disturb it, and then no longer will it be the initial state. However, in the case where the measurement is non-disturbing on the initial state, the joint expectation is well-defined, independently of the measurement on the final state.
In what follows we analyze this case, by imposing that both the system and weight are initially quasi-classical. We do not impose any constraint on the final state, but define its dephased version by This dephasing CPTP map projects ρ S onto the subspace of Hermitian matrices that commute with H S . If ρ S = s P (s)|s s| is the spectral decomposition of the initial state, and |x is an eigenstate of H W , then Es|s s|, its thermo-majorization diagram (see [22] for more details) is formed by first relabeling the pairs of occupation probabilities and energy levels so that p1e βE 1 ≥ p2e βE 2 ≥ · · · ≥ pne βEn and then plotting the points k s=1 e −βEs , k s=1 ps n k=1 , joining them together to form a concave curve. The figure shows examples for a qubit. In the absence of a work storage system, (ρ, HS) can be transformed into (σ, HS) using a thermal operation if and only if the curve associated with ρ is never below that of σ. In this example, the curve of ρ crosses that of σ so the transformation is not possible. When all values in a work distribution have the form w ss = α s − γs, the existence of a thermal operation mapping a quasi-classical state a ρ to quasi-classical state σ while producing such a work distribution can be determined by considering the curves associated with ρ, n s=1 (Es + γs) |s s| and σ, n s=1 (Es + αs) |s s| . In this example, the curve associated with ρ and {γs} lies above that of σ and {αs} so the transformation from ρ to σ is possible with respect to this work distribution. By adjusting γs and αs so that both curves are straight lines that overlap, one can make the average work of the transformation equal to the change in free energy and the transformation becomes reversible.
The following definitions of the free energy operator are used below If in the derivation of Result 2 we multiply Eq. (18) by J T ln ∆ρ S instead of J T ln ρ S , we obtain where we have used that ∆[ρ S ] = ρ S . Again, independence from the position of the weight allows us to choose ρ W = |0 0|. This enables us to write the above equality as s e −βfs P (s) tr SW e β(F S +H W ) Γ SW (|s s|⊗|0 0|) = 1 (38) or, equivalently: Result 7 (Classical-Quantum Second Law Equality). Consider a process that acts unitarily on the total system, conserves energy and is independent of the position of the weight . If the initial states of system and weight commute with the corresponding Hamiltonians, then e βF S e βW e −βF S = 1 .
In the same way we have:

VII. A QUANTUM CROOKS RELATION
Here we use our techniques to prove a fully quantum version of the Crooks relation, which is related to that proven in [16] but on the weight and system. We also derive a classical version directly from our generalised Gibbs-stochastic condition and without the need to assume micro-reversibility.
In relation to the map defined in Eq. (13), we can also define the associated backwards CPTP map associated: Like any CP map, this can be written in Kraus form The dual of a map is defined as A bit of algebra shows that from which it follows: Result 9. The forward and backward maps, respectively Γ SW and Θ SW , are related via This shows that the dual map is analogous to the transpose map that appears in various results of quantum information theory [58,59]. Note that using the classical version of generalised Gibbs-stochasity, Result 4, we can define the map P back (s, −w|s ) = P (s , w|s) e β(E s −Es+w) .
One can check that constraint in Eq. (24) applied to P (s , w|s) is equivalent to the normalization of P back (s, −w|s ), and the normalization of P (s , w|s) is equivalent to constraint in Eq. (24) applied to P back (s, −w|s ). This constraint implies that P back (s, w|s ) is a thermal operation, hence, there is a global unitary generating this transformation. It can also be seen that one can use the unitary that is the inverse of the one that generates P (s , w|s) (although other unitaries may also generate the same dynamics on system and weight). P back (s, −w|s ) is thus the microscopic reverse of P (s , w|s). Indeed, by defining the probability of obtaining work w in going from energy level s to s when the initial state is thermal by p forward (w, s , s) = P (s , w|s)e −βEs /Z S for the forward process and p back (−w, s , s) = P back (s , −w|s)e −βE s /Z S for the reverse, we obtain a Crooks relation without needing to assume micro-reversibility, which is the starting assumption of [2, 60]. One can take p back (−w, s, s ) to the RHS of Eq. (47) and then sum over s and/or s to obtain the more standard Crooks relation but Eq. (47) is clearly stronger.

VIII. CONCLUSION
In this paper we considered thermodynamical operations between a system, a thermal bath and a weight from which one can extract work in a probabilistic way. From a small set of physically motivated assumptions one can show that these operations obey an identity on arbitrary states from which a number of new, or more general equalities can easily be found. The equalities are both of a fully quantum and of a classical nature. One of these, the second law as an equality, is of a much stronger form than the standard second law. For example, the saturation of the second-law inequality implies w = f s − f s for all s, s .
This regime is called thermodynamically reversible, and provides the optimal consumption or extraction of work when we take its average w as the figure of merit. Outside of the thermodynamically reversible regime, violations of for individual realizations of the process (s, s , w) can occur. Defining the excess random variable v = f s −f s +w, allows us to write Eq. (28) as e βv = 1 .
Recalling that the exponential function gives more weight to the positive fluctuations as compared with the negative ones, we conclude that, outside of the thermodynamically reversible regime, the negative fluctuations of v must be larger and/or more frequent than the positive ones. In other words: the violation of the second law is more rare than its satisfaction. This asymmetry is also articulated by the infinite list of bounds for the moments of v given in Eq. (30). Note that the Gibbs-stochastic condition of Eq. (7) gives more information than the Jarzynski equation or second law equality as the number of constraints it imposes is given by the dimension of the final system. In fact, each condition can be thought of as a separate second law equality -a situation which parallels the fact that one has many second laws for individual systems [22,24]. This is related to the fact that in the case with no weight, Gibbs-stochasity is equivalent to these additional second laws given by thermo-majorisation [48].
As a concrete and simple example of these conditions, let us take the case of Landauer erasure [54]. We consider a qubit with H S = 0 that is initially in the maximally mixed state and which we want to map to the |0 state. Recalling that a positive work value represents a yield, while a negative work value is a cost, we consider a process such that −w 0 is the work cost when erasing |0 → |0 , and −w 1 the work cost if the transition |1 → |0 occurs. We allow for an imperfect process and imagine that this erasure process happens with probability 1 − , while with probability we have an error and either |0 → |1 with work yieldw 0 or |1 → |1 with work yieldw 1 . We call such a process deterministic, because w is determined by the particular transition.
For this scenario, the the Generalised Gibbs-stochastic condition, Eq. (7), gives two conditions e βwo + e βw1 = 1/(1 − ) (53) e βwo + e βw1 = 1/ We immediately see that to obtain perfect erasure, → 0, then when the erasure fails there must be work fluctuations which scale like −T log . Such a work gain happens rarely, but precludes perfect erasure, and is related to the third law proven in [55] and is discussed in detail in [61].
In the limit of perfect erasure we illustrate the work fluctuations in Fig. 2. We easily see that the minimal As a simple example of the second law equality, one can think of single qubit erasure. In the limit of perfect erasure, the 2nd law equality reads in this case e βw 0 + e βw 1 = 1, and the average work spent is w = 1 2 (w0 + w1). In the figure, we show the tradeoff between w0 and w for such perfect erasure. The optimal work value for erasure is the usual Landauer cost at w0 = w1 = −T log 2. As seen in Eq. (53), perfect or near-perfect erasure requires the work cost to fluctuate arbitrarily.
average work cost of erasure, T log 2, is obtained when the work fluctuations associated with successful erasure are minimal. We also see that no work, not even probabilistically, can be obtained in such a deterministic process. Since Eq. (7) is not only necessary but also sufficient, we can achieve these work distributions just through the very simple operations described in [42]. Through this example, one sees that the identities proven here can lead to new insights in thermodynamics, particularly with respect to work fluctuations and their quantum aspects.
for all E ∈ R. If we translate this equation to Fourier space using we obtain The solutions of this differential equation are where V C is arbitrary. Finally, we impose unitarity U CW U † CW = 1 CW . That is Using the linear independence of e iE∆ W we obtain for all E ∈ R. If we translate this equation to Fourier space using Eq. (A4) we get An equivalent form can be obtained by using the eigen-projectors of H C = dE E P E and H C = dE E P E . That is If the spectra of H C and H C are discrete, H C = c E c |c c| and H C = c E c |c, c, |, then we can write the above as We stress that there is no constraint on V C . This type of unitary was used in the context of thermodynamics in [21,28]. The above result allows one to obtain an explicit form for the effective map on system-bath (after tracing out the weight) By noting that t|ρ W |t is a probability distribution, we see that the reduced map on system and bath Γ SB is a mixture of unitaries (Result 1 in [55]). Hence the transformation can never decrease the entropy of system and bath, which guarantees that one cannot pump entropy into the weight, which would be a form of cheating. Eq. (A13) also implies that, if the initial state of the weight ρ W is an eigenstate of ∆ W , then the mixture of unitaries only has one term, so that Result 10. If the weight is in a maximally coherent state, that is, an eigenstate of ∆ W with eigenvalue t , the effect on system and bath is an arbitrary unitary and V SB is as defined in Lemma 1.
Proof. In the particular case where of Eq. (A13) where ρ W = |t t | is an eigenstate of of ∆ W so that ∆ W |t = t |t , the integral is then That is, even though this effective map involves tracing out the weight, the result on system-bath is unitary. In addition, this unitary is totally unconstrained, and in particular, it need not be energy-conserving. A typical form for this unitary is T exp [ dt H SB (t)], where T is the time-order operator.
In summary, thermal operations with fluctuating work can simulate general unitary transformation which do not preserve energy. Hence, statements such as Results 1, 2 and 3 that apply to the first type also apply to the second type. This way we include the operations of the usual derivations of Tasaki-Crooks fluctuation theorems [9,11], where arbitrary unitaries on system and bath are allowed.
We now outline how one may derive the analogue of fluctuation relations such as Result 6 in this case, given any unitary dynamics, or mixtures of them. There, the work extracted from system and bath is quantified by measuring their energy before and after the transformation, such that the work takes the form of the random variable E − E, where E is a system+bath energy associated with projector P E . The conditional distribution P (E |E) = tr S [P E Γ SB (P E ρ SB P E )] plays the key role. It is known that if the map Γ SB is unital (as guaranteed by Eq. (A13)), then the matrix P (E |E) is doubly-stochastic, and the Jarzynski equality holds, as Other relations, such as the 2nd law equality or Crooks theorem, can be derived analogously too. Essentially, the double-stochasticity of P (E |E) plays the role of Eq. (7) in the derivations of the fluctuation theorems. Eq. (A17) works independently of the state of the weight. In particular, it can be a coherent state |t , which will make the reduced map on the system unitary. Hence, the average of the work extracted from system and bath can be equivalently expressed in terms of: (i) measurements on their energy or (ii) shifts in the weight.
An important caveat of the results of this section is that they require the weight to be in a coherent state |t . While exactly attaining this state is physically impossible, arbitrarily good approximations are possible in principle, allowing for the implementation of maps arbitrarily close to unitary. Here we are showing that when one wants to implement arbitrary unitaries, coherence (understood as a thermodynamical resource) is needed. However, as we have already noted in Section IV in the main text, implementing a unitary which merely maps energy eigenstates to energy eigenstates, requires no such coherence.
Finally, in a different direction, there is a further set of operations that we can include within our framework, and in particular in Result 4. A large part of the literature on resource-theoretic approaches to thermodynamics has been built around a set of operations consisting of sequences of transformations of the energy levels (with an associated work cost), and thermalizations between system and bath. Examples of this are [23,27,42]. On one hand, the thermalization processes are those for which the work cost vanishes, and consist of a stochastic process (possibly between only two levels) for which we have the following constraint s P (s |s) e β(E s −Es) = 1 , which is a particular case of Eq. 7 when we take w = 0 (note that for such thermalization processes the system Hamiltonian remains unchanged). The level transformation processes, on the other hand, consist of a change of Hamiltonian that leaves the populations of the energy levels invariant (ρ, H S ) → (ρ, H S ). Hence, these correspond to stochastic matrices of the form P (s , w|s) = δ s,s δ Es−E s ,w . It can be easily seen that a process like this satisfies Eq. (24). The values of the work distribution that occur in this process are given by the difference between initial and final energy levels, as expected.