# Entropy as a Functor #### Manojna Namuduri #### Adjoint School 2022 <style> .comment { color: red; } </style> ## Motivation Our goal in this blog post is to break down Lawvere's approach to finding thermodynamic entropy functions, as described in his 1984 [article](https://conservancy.umn.edu/items/cf80dfdc-5fb3-4641-872e-d9ea5df14930) _State Categories, Closed Categories, and the Existence of Semi-Continuous Entropy Functions_. We first think of a category, representative of a thermodynamic system, where the objects are states of the system and the morphisms are processes which start in the domain state and end in the codomain state. Then we consider functors into the real numbers that assign *entropies* to states and *entropy supplies* to processes. ## What is entropy? The concept of entropy has its roots in classical thermodynamics, but has much more general utility as a quantification of disorder or uncertainty in a system. The following section will provide some useful intuitions, but you should feel free to skip it if you are already familiar with entropy. In order to understand entropy, let's first think of a billiards table. We choose the initial energy supplied by a player breaking the triangle of arranged billiards balls as our macroscopic property of interest for the system. Let's also assume that this *internal energy* is conserved as the system evolves. [Here](https://www.myphysicslab.com/engine2D/billiards-en.html?SHOW_ENERGY%3Dtrue%3BRANDOM_SEED%3D402294262%3BELASTICITY%3D1%3BRUNNING%3Dfalse%3BFIRING%3Dtrue%3BX_Y_GRAPH_LINE.Y_VARIABLE%3D5%3BX_Y_GRAPH_LINE.GRAPH_COLOR%3Dblack%3BDAMPING%3D0%3B) is a simulation of such a setup. In statistical mechanics, macrostates of a system are defined by its macroscopic properties when the system attains internal equilibrium, wherein there are no net flows of matter or energy. On the other hand, there are microstates, which are points in the *phase space* of a thermodynamic system. For example, a microstate of the billiards table may be specified by the instantaneous position and velocity vectors of each ball on the table. Many such configurations have the same energy, however, and are described by the same macrostate. The concept of equilibrium is important because it allows us to make the assumption that is the fundamental postulate of statistical mechanics: > An isolated system in equilibrium is equally likely to occupy any of its accessible microstates. From a dynamical perspective, when the system equilibriates, the energy is uniformly distributed throughout; the initial condition has been totally scrambled. If we fixed the energy but varied the initial condition - we can imagine arranging the billiard balls into a circle instead of a triangle to begin with, [like so](https://www.myphysicslab.com/engine2D/billiards-en.html?SHOW_ENERGY%3Dtrue%3BRANDOM_SEED%3D2751990320%3BELASTICITY%3D1%3BRUNNING%3Dfalse%3BFIRING%3Dtrue%3BX_Y_GRAPH_LINE.Y_VARIABLE%3D5%3BX_Y_GRAPH_LINE.GRAPH_COLOR%3Dblack%3BDAMPING%3D0%3BBALL4_X_POSITION%3D2.126725047620707%3BBALL4_Y_POSITION%3D0.10069930069930155%3BBALL5_X_POSITION%3D1.5560956769913374%3BBALL5_Y_POSITION%3D1.0864160839160841%3BBALL6_X_POSITION%3D1.6903614112570702%3BBALL6_Y_POSITION%3D-0.8850174825174828%3BBALL2_X_POSITION%3D0.4339918944397242%3BBALL2_Y_POSITION%3D1.0227797202797206%3BBALL3_X_POSITION%3D0.618607279055109%3BBALL3_Y_POSITION%3D-0.9892132867132868%3B) - the trajectory of the system would certainly be different at first, but over time we'd see some coarse-grained behaviors that are universal for systems of that macrostate. One example might be the distribution that describes the number of balls present on the left half of the billiards table at any given point in time. The entropy is a function of state, which means that it's possible to define it based on the specifications of the macrostate. In the thermostatic view, entropy is perhaps best understood as an extensive quantity that describes the volume of the system's explorable phase space for a certain macrostate. The equilibriation of the billiards table illustrates the second law of thermodynamics. > The entropy of an isolated system cannot decrease over time; at equilibrium, a system's entropy is maximized under the condition of fixed internal energy. After the initial break, entropy temporarily increases. As more collisions happen and energy spreads from one ball to the entire system, each ball can assume an increasingly wide range of instantaneous positions and velocities, constrained only by the total energy of the system. The volume of the phase space grows as more microstates become accessible. Then, entropy stops increasing at equilibrium. The equilibrium velocity distribution of billiards balls, assuming that energy is conserved, looks Gaussian. This suggests that all the balls are moving at similar velocities. They continue to move at similar velocities because elastic (as opposed to sticky) collisions of same-mass, similar-velocity objects result in pretty much equal and opposite exit velocities. Because of conservation of momentum, we know that the sum of entry velocities will be equal to the sum of exit velocities, so we can reasonably infer that the Gaussian of equilibrium velocities persists over time. The volume of the phase space is fixed according to the system's internal energy because at equilibrium, all the balls on the table behave in similar ways. Intuitively, we understand the second law's suggestion that things spread out. It's much easier to make a mess than it is to clean it up. ![](https://lh3.googleusercontent.com/UdlB56MA7JS0Vp23kOx2v6gFL3qTrTRAz9guE2Pkvtb3o1KLbBSSfCfCDd_HX7ScfJ7tihm29eLPz4MiLVsFSti2f7mvjE3cI5tLIIkX6iewsY5cLp572A82fxFArbjyCEutOPFVmYisyuP1pg) What happens when the system is not isolated, though? So far we have discussed entropy as a quantity associated to a state of a system in equilibrium, but systems may interact with their surroundings and with other systems. What does it mean to associate a change in entropy to a process, which introduces some sort of flux into or out of a system? Let's remove the assumption of energy conservation on the billiards table. In the real world, all the balls eventually stop moving after the initial break, as demonstrated by [this instatiation](https://www.myphysicslab.com/engine2D/billiards-en.html?SHOW_ENERGY%3Dtrue%3BRANDOM_SEED%3D722726994%3BELASTICITY%3D0.8%3BRUNNING%3Dfalse%3BFIRING%3Dtrue%3BX_Y_GRAPH_LINE.Y_VARIABLE%3D5%3BX_Y_GRAPH_LINE.GRAPH_COLOR%3Dblack%3BDAMPING%3D0%3B) of the simulation. This is due to the dissipation of energy through effects like heat produced by the friction of the balls against the felt of the table and sounds from all the collisions happening. This energy can no longer be "useful" in the system because it has been lost as entropy to the environment. Processes with dissipation - equivalently, those that have resulted in an entropy increase for the system **and/or** its surroundings - are known as *irreversible*. On the other hand, *reversible* processes do not increase the total entropy of the system **and** its surroundings. In thermodynamics, the infinitesimal change in a system's entropy is defined as $d S = \frac{\delta Q }{T}$, where $\delta Q$ is the amount of heat supplied during a reversible process leading from the initial state of a system to the final state, and $T$ is the temperature of the system when the increment of heat is absorbed. Since entropy is a function of state, change in entropy of a system is path-independent; it'll be the same for any process between the same initial and final states, regardless of whether it's reversible or not. In reversible processes, the entropy change of the system and the entropy change of the surroundings are equal and opposite, such that the total entropy of the system and its surroundings stays constant. For irreversible processes, $dS_{sys}+dS_{surr}>0$. The entropy change of the surroundings varies according to the chosen process, as long as the overall entropy change is positive. Reversible processes are really an idealization that describe how thermodynamic systems perform at maximum efficiency (read: no dissipation), which doesn't happen in the real world. We can recognize our billiards table example as a crude approximation of an [ideal gas](http://hyperphysics.phy-astr.gsu.edu/hbase/Kinetic/idegas.html) in a tank. Let's put two mechanisms in place to allow our ideal gas tank to interact with its environment: an interface between the tank and an infinite heat bath at fixed temperature, and a mechanical piston whose movements modulate the amount of volume available for the ideal gas to occupy. There are two fluxes at play here: heat and work. Heat will flow until the system reaches *thermal equilibrium* with its environment, in which case the temperatures of the system and environment will be the same. Similarly, work will flow until *mechanical equilibrium* is attained, at the point where the system and its environment have the same pressure. In order to analyze a classical system such as this, we might look at the thermodynamic identity, which generally encapsulates the relationship between macroscopic properties $U$ internal energy, $S$ entropy, $V$ volume, $T$ temperature, and $P$ pressure. $$dU = TdS-PdV$$ Rearranging the thermodynamic definition for an increment of entropy, we can define the heat received by the system as $\delta Q = TdS$. The work $W$ is the amount of mechanical energy transferred into the system from the surroundings. Work is done on the system if the volume decreases; an increment of work is defined as $\delta W = -PdV$. These definitions allow us to rewrite the thermodynamic identity as the first law of thermodynamics: $$dU = \delta Q+\delta W$$ > The change in internal energy of a closed system (assuming no transfer of matter), is the sum of the heat transferred into and the mechanical work done on the system. The first law also includes a statement about conservation of energy: when initially isolated subsystems are combined, the internal energy of the new system must be the same as the sum of internal energies of the original subsystems. A thermodynamic cycle consists of several processes in sequence, such that the system returns to its initial state after completing the cycle. Each process results in a flux of heat and/or work into or out of the system. One classic example of a thermodynamic cycle is the [Carnot engine](https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Supplemental_Modules_(Physical_and_Theoretical_Chemistry)/Thermodynamics/Thermodynamic_Cycles/Carnot_Cycle), which is the most efficient heat engine that is theoretically possible. The Clausius theorem states that the entropy of an external reservoir cannot decrease if a system with which it exchanges heat is performing a thermodynamic cycle. In the following statement, $\delta Q$ is the amount of heat received by the system, $T_{surr}$ is the temperature of the external reservoir, and $\Delta S_{surr}$ is the change in entropy of the reservoir. $$(-\Delta S_{surr} = \oint \frac{\delta Q}{T_{surr}}) \leq 0 $$ The change in a system's entropy over a thermodynamic cycle is always zero since the initial and final state are the same. In a reversible cycle, the entropy changes of the system and the surroundings are equal and opposite, so equality of the Clausius theorem holds. In this case, the system and the surroundings could *both* be performing thermodynamic cycles. On the other hand, for an irreversible cycle, only the system is performing a thermodynamic cycle and the entropy change of the surroundings is always strictly positive. The more irreversible the process, the greater the entropy change. This aligns with the expectation for a dissipative process that the overall change of entropy in the system and surroundings is positive. In Lawvere's framework, $-\Delta S_{surr}$ is identified as the entropy supply of a process. In identifying the optimal (read: least dissipative with respect to the surroundings) paths between chosen system states, we are able to constrain the entropy of those states. ## The phase space category Assume we have a category that represents the phase space of a thermodynamic system. We'll call it $X$, where the objects of the category are macrostates and the morphisms are processes, trajectories in phase space leading from one macrostate to another. A process generates entropy when it has a negative entropy supply value, which is the case when the entropy of the surroundings has increased. On the other hand, an entropy-consuming process results in more ordered surroundings and has a positive entropy supply value. Such a category, paired with functors that appropriately assign entropies to states and entropy supplies to processes, might be used to optimize thermodynamic systems by considering paths through the phase space that minimize the system's entropy production. ## Entropy supply Lawvere assumes that there is given a [functor](https://ncatlab.org/nlab/show/functor) $s: X \rightarrow \overline R$ from the phase space category to the additive monoid of extended reals. Shortly, $\overline{R}$ is a category with a single object, where the morphisms are elements of the extended reals $[-\infty, \infty]$ and composition of morphisms is given by addition. Because there is only one object in $\overline R$ , $\forall x, y \in \text{ob}(X). s(x)=s(y)$. This functor is not appropriate for assigning entropies to macrostates of $\text{ob}(X)$, which makes sense because entropy supplies, which are changes in entropy, should only apply to processes in $\text{ar}(X)$. When checking preservation of identity morphisms, we find $\forall x \in \text{ob}(X). s({id}_x)={id}_{s(x)}$. The sole identity morphism in $\overline R$ is the arrow labeled $0$. The condition then becomes $\forall x \in \text{ob}(X). s({id}_x)=0$; the identity morphisms represent the system being "frozen" in the same macrostate and supply $0$ entropy. Now investigating the preservation of composition, we have for any composable morphisms $(f:x \rightarrow y), (g: y \rightarrow z) \in \text{ar}(X)$, $s(g) + s(f) = s(g \circ f)$. This is to say that entropy supply is additive; the entropy supply of two composed processes is equal to the sum of the entropy supplied by the individual processes. At this point, we have been given a phase space category $X$ and entropy supplies for the morphisms of $X$. We will need to learn a little bit about enriched category theory to be able to assign entropies to states, however. ## Monoidal categories [Monoidal categories]((https://ncatlab.org/nlab/show/monoidal+category)) are necessary for enriched category theory, so we will briefly review them. A monoidal category $\mathcal{V}$ is equipped with a *tensor product*, denoted $\otimes$, which is a functor from the [product category](https://ncatlab.org/nlab/show/product+category) of $\mathcal{V}$ with itself to $\mathcal{V}$. Any object tensored with the category's unit object, denoted $I$, maps to itself. We give a few examples of monoidal categories below. ### Example 1: $\text{Set}$ Let $(\mathcal{V}, \otimes, I)$ be $(\text{Set}, \times, \{\ast\})$ where $\times$ is the Cartesian product and $\{\ast\}$ is the singleton set. --- ### Example 2: $\text{Bool}$ For our second example of a monoidal category, we let $(\mathcal{V}, \otimes, I)$ be $(\text{Bool}, \wedge, 1)$. The category $\boldsymbol{\text{Bool}}$, short for Boolean, is also a [poset]((https://ncatlab.org/nlab/show/partial+order)). It has two objects, which we call $0$ (the bit value corresponding to the truth value $\text{False}$) and $1$ (the bit value corresponding to the truth value $\text{True}$), and a morphism indicating the binary comparison relation $\leq$. Drawing these objects and morphisms: <img style="display: block; margin-left: auto; margin-right: auto; width: 100px" src="https://github.com/lia-approves/act2022_adjoint-school/blob/master/boolcat.png?raw=true" alt=""/> The monoidal product in $\text{Bool}$, denoted by $\wedge$, is multiplication on bit values or, equivalently, the $\text{AND}$ operation on truth values. --- ### Example 3: Poset of non-negative extended reals Consider the monoidal category where $(\mathcal{V}, \otimes, I)$ is $(\mathcal{D}, +, 0)$, where $\mathcal{D} = ([0, \infty], <)$ is a poset. Recall that every poset is a category. This specific poset has as objects all real numbers from $0$ to positive infinity inclusive, where for $a,b \in [0,\infty]$, a morphism from $a$ to $b$ is present iff $a < b$. The monoidal product is just the addition of two reals. Note that the monoidal product preserves the partial order; if $a < a'$ and $b < b'$, then $a+b < a'+b'$. ## Enriched categories There are two perspectives in category theory. One view focuses on morphisms, which have a domain and a codomain. Another view is that every pair of objects in a category has a *hom-set*, the set of all morphisms between the objects. *Enriched categories* are more in line with this second view, except instead of hom-sets, which are objects in the category $\text{Set}$, we define *hom-objects* that belong to some monoidal category. Let $(\mathcal{V}, \otimes, I)$ denote the category over which we are enriching, which must be monoidal. A $\mathcal{V}$-category is something that is enriched over $\mathcal{V}$. However, this name is a scam; $\mathcal{V}$-categories are not categories in general. For a $\mathcal V$-category $\mathcal C$, the [underlying ordinary category](https://ncatlab.org/nlab/show/underlying+ordinary+category) $\mathcal C_0$ has the same objects as $\mathcal C$ and hom-sets defined by: $$\mathcal C_0(x, y) = \mathcal{V} (I, \mathcal C(x, y))$$ That is to say, the set of morphisms between $x$ and $y$ in the underlying ordinary category $\mathcal C_0$ is given by the set of morphisms in $\mathcal V$ between the unit object and the hom-object $\mathcal C(x, y)$. (By the notation $\text{ob}(\mathcal{X})$ and $\text{ar}(\mathcal{X})$, we mean, respectively, the collection of objects and the collection of morphisms in a category $\mathcal{X}$.) A $\mathcal{V}$-category $\mathcal C$ consists of: - a collection of objects $\text{ob}(\mathcal{C}) = \text{ob}(\mathcal{C}_0)$ - $\forall x,y \in \text{ob}(\mathcal{C}$). $\mathcal{C}(x,y) \in$ $\text{ob}(\mathcal{V}$) The hom-object $\mathcal{C}(x,y)$ is an object in $\mathcal{V}$ corresponding to the hom-set of morphisms between objects $x$ and $y$ in the underlying ordinary category $\mathcal C_0$. - $\forall x,y,z \in \text{ob}(\mathcal{C}). (\circ_{xyz} : \mathcal{C}(y,z) \otimes \mathcal{C}(x,y) \rightarrow \mathcal{C}(x,z)) \in \text{ar}(\mathcal{V})$ The composition morphism $\circ_{xyz}$ is a morphism in $\mathcal{V}$. The tensor product of hom-objects $\mathcal{C}(x,y)$ and $\mathcal{C}(y,z)$ in $\mathcal{V}$ is analogous to the composition of morphisms in the corresponding underlying hom-sets $(f \in \mathcal{C}_0(x,y), g \in \mathcal{C}_0(y,z)) \mapsto g \circ f$. - $\forall x \in$ $\text{ob}(\mathcal{C}$).($j_x : I \rightarrow \mathcal{C}(x,x)) \in \text{ar}(\mathcal{V})$ $j_x$, called the identity [element](https://ncatlab.org/nlab/show/global+element), is a morphism in $\mathcal{V}$ that goes from the unit object in $\mathcal{V}$ to the hom-object corresponding to the hom-set that is endomorphisms of a single object of $\mathcal{C}_0$. The monoidal product and unit object in $\mathcal V$ provide the composition and identity morphisms in the $\mathcal V$-category. Composition in an enriched category must also satisfy the coherence conditions of associativity and unitality, as shown in the below diagrams, which are borrowed from [ncatlab](https://ncatlab.org/nlab/show/enriched+category). Note that associativity and unitality are automatically satisfied for any category enriched over $\text{Bool}$ or the real numbers. The commuting diagram for associativity, which employs the [associator](https://ncatlab.org/nlab/show/associator) $\alpha \in \text{ar}(\mathcal{V})$: <img style="display: block; margin-left: auto; margin-right: auto; width: 750px" src="https://github.com/lia-approves/act2022_adjoint-school/blob/master/enriched_associativity.png?raw=true" alt=""/> The commuting diagram for unitality, which employs the left and right [unitors](https://ncatlab.org/nlab/show/unitor) $l, r \in \text{ar}(\mathcal{V})$: <img style="display: block; margin-left: auto; margin-right: auto; width: 550px" src="https://github.com/lia-approves/act2022_adjoint-school/blob/master/enriched_unitality.png?raw=true" alt=""/> Enriched categories are useful because they give us additional information about our underlying ordinary category with respect to the enriching monoidal category. ### $\text{Set}$-categories (AKA categories) As the simplest example of an enriched category, consider the case where a category is enriched over $(\text{Set}, \times, \{\ast\})$. A $\text{Set}$-category $\mathcal C$ consists of: - hom-objects: $\forall x, y \in \text{ob}(\mathcal{C}$). $\mathcal{C}(x,y) \in \text{ob}(\text{Set}$) The hom-objects when $\text{Set}$ is the enriching category are precisely hom-sets. - composition morphisms: $\forall x,y,z \in \text{ob}(\mathcal{C}$). $(\circ_{xyz} : \mathcal{C}(y,z) \times \mathcal{C}(x,y) \rightarrow \mathcal{C}(x,z)) \in \text{ar}(\text{Set})$ - identity elements: $\forall x \in \text{ob}(\mathcal{C}). (j_x : \{\ast\} \rightarrow \mathcal{C}(x,x)) \in \text{ar}(\text{Set})$, which map $\ast \mapsto (id_x \in \mathcal{C}(x,x))$ The Cartesian product of hom-sets is associative, but we already knew that because composition of morphisms in the underlying original category is associative. Unitality also trivializes because in $\text{Set}$, the Cartesian product of any set $A$ with any singleton set is isomorphic to $A$; thus, pre-composition with $id_a$ or post-composition with $id_b$ of any morphism in $\mathcal{C}(a,b)$ leaves that morphism unchanged, which we also already knew. Therefore, what we call associativity and unitality for $\mathcal{C}$ enriched over $\text{Set}$ tell us no more than our standard notions of associativity and unitality of morphisms in $\mathcal{C}$. By enriching our category over $\text{Set}$, we do not gain any additional information about the underlying category. In other words, all categories are already enriched over $\text{Set}$. ### $\text{Bool}$-categories (AKA preorders) For our second example, we enrich over $(\mathcal{V}, \otimes, I) = (\text{Bool}, \wedge, 1)$ where $\wedge$ is multiplication on bits. A $\text{Bool}$-category has hom-objects in $\text{Bool}$ for any objects $x, y$ in the original category $\mathcal{C}$: $$\mathcal{C}(x,y) = \begin{cases} 1 \\ 0 \end{cases}$$ This means that there are two possibilities for the relationship between $x$ and $y$. Without loss of generality, and for reasons which will soon become clear, let us call this the $\leq$ relation because it is a relation with two possibilities: either $x \leq y$ or $x > y$: $$\mathcal{C}(x,y) = \begin{cases} 1 \ (\text{meaning } \ x \leq y) \\ 0 \ (\text{meaning } \ x > y)\end{cases}$$ The enrichment tells us two things about the hom-objects. First, consider our composition morphisms in $\text{Bool}$ of the form $$\mathcal{C}(y,z) \otimes \mathcal{C}(x,y) \rightarrow \mathcal{C}(x,z)$$ When we make the appropriate identifications from $\text{Bool}$ to the above equation, the resulting equation is $(y \leq z) \wedge (x \leq y) \implies (x \leq z)$, i.e. the $\leq$ relation on objects in $\mathcal{C}$ is *transitive*. We also get another condition from the identity elements in $\text{Bool}$. These morphisms are of the form $1 \rightarrow \mathcal{C}(x,x)$. Notice that in the previously given diagram of the two bit values and morphisms between them in $\text{Bool}$, all arrows starting from $1$ also end at $1$. Therefore, from examining the identity element morphisms in $\text{Bool}$, we conclude that $\mathcal{C}(x,x) = 1$ for all $x \in \text{Bool}$, i.e. the $\leq$ relation between any object in $\mathcal{C}$ with itself is *reflexive*. We have shown that when you unwrap the definition of a $\text{Bool}$-enriched category, what you get is precisely the definition of a [preorder](https://ncatlab.org/nlab/show/preorder); the ordering relation satisfies transitivity and reflexivity. ### Lawvere metric spaces Lawvere metric spaces, which are a generalization of typical [metric spaces](https://ncatlab.org/nlab/show/metric+space), are enriched over $\text{Lawv} = (\mathcal{D}^{op}, +, 0)$, where $\mathcal{D}^{op} = ([0, \infty], \geq)$ is a poset. (Notice that $\mathcal{D}^{op}$ is the same as the previously introduced poset $\mathcal{D}$, but has the opposite ordering relation, so all the morphisms from the original category have been reversed.) We can think of a hom-object $\mathcal{C}(x, y) \in \text{ob}(\text{Lawv})$ in a Lawvere metric space as an assignment of *distance* between objects $x, y$ in the original category $\mathcal{C}$. For example, if you imagine a directed graph where the nodes correspond to objects and the edges between them are weighted by distance, a distance of infinity could mean that no path exists between the source and target objects for the edge. Through enrichment, for each $x \in \text{ob}(\mathcal{C})$, we have a morphism in $\text{Lawv}$, $$j_x : I \rightarrow \mathcal{C}(x,x)$$ which becomes $$j_x : 0 \geq \mathcal{C}(x,x)$$ Because all hom-objects in $\text{Lawv}$ are $0$ or greater, we retrieve the condition that $\mathcal{C}(x,x) = 0$ for all $x \in \text{ob}(\mathcal{C})$; the distance from any object to itself is $0$. Substituting into the composition morphisms in $\text{Lawv}$ that exist for all $x, y, z \in \text{ob}(\mathcal{C})$ $$\circ_{xyz} :\mathcal{C}(y,z) \otimes \mathcal{C}(x,y) \rightarrow \mathcal{C}(x,z)$$ we also have that $$\circ_{xyz} :\mathcal{C}(y,z) + \mathcal{C}(x,y) \geq \mathcal{C}(x,z)$$ You may have seen this before as the [triangle inequality](https://en.wikipedia.org/wiki/Triangle_inequality#Metric_space), which says that the sum of lengths of two sides of a triangle must be at least as long as the third side. The triangle inequality is an important property of norms in vector spaces, which is why it makes sense to think of hom-objects of Lawvere metric spaces as distances. ### Closed categories and self-enrichment A monoidal category is also *closed* if it is *self-enriched*; intuitively, closure of a monoidal category means that there is a way to define "natural" hom-objects that are already objects of the category itself. We will be using the idea of [adjoint functors](https://ncatlab.org/nlab/show/adjoint+functor#definition) moving forward. The key notion to keep in mind is that adjointness of endofunctors of some category $\mathcal{V}$, written $L \dashv R$, means that for all $x, z \in \text{ob}(\mathcal{V})$, there is a [natural isomorphism](https://ncatlab.org/nlab/show/natural+isomorphism) between the hom-sets: $$\{L(x) \rightarrow z\} \simeq \{x \rightarrow R(z)\}$$ Two morphisms $f: L(x) \rightarrow z$ and $g: x \rightarrow R(z)$ that correspond under such a natural isomorphism are said to be *adjunct* to each other. Monoidal categories $(\mathcal{V}, \otimes, I)$ may have an [*internal hom*](https://ncatlab.org/nlab/show/internal+hom) bifunctor $[-,-]: \mathcal{V}^{\text{op}} \times \mathcal{V} \rightarrow \mathcal{V}$, such that for any $y \in \text{ob}(\mathcal{V})$, the following *tensor-hom adjunction* holds: $$(-\otimes y) \dashv [y, -]$$ which corresponds to the following isomorphism, natural in all variables $x,y, z \in \text{ob}(\mathcal{V{}})$: $$\mathcal{V}(x \otimes y, z) \simeq \mathcal{V}(x, [y, z])$$ If this adjunction, which asserts that the internal hom is right adjoint to the right-tensoring functor, holds for some definition of the internal hom, then the monoidal category is right-closed. If there is also an internal hom that can be defined to be right adjoint to the left-tensoring functor, then the category is biclosed. Symmetric monoidal categories are always biclosed. For any $x, y \in \text{ob}(\mathcal{V})$ we have an identity morphism on hom-objects in the self-enriched category: $$id_{[x, y]}: [x, y] \rightarrow [x, y]$$ The adjunct of such an identity morphism is called an *evaluation morphism*: $$\text{ev}_{[x, y]}: ([x, y] \otimes x) \rightarrow y$$ The form of these evaluation morphisms suggests that the adjointness of the tensor product and the internal hom works like the two functors "undoing" each other. What do the composition morphisms look like for closed categories? For every triple $x, y, z \in \text{ob}(\mathcal{V})$, there is a composition morphism in $\mathcal{V}$: $$\circ_{x, y, z}: \mathcal{V}(y, z) \otimes \mathcal{V}(x, y) \rightarrow \mathcal{V}(x, z) $$ By identifying the hom-sets with internal hom-objects, we find that such a composition morphism must belong to the hom-set $\mathcal{V}([y, z]\otimes[x, y], [x, z])$. Then, applying the tensor-hom adjunction, we know that this hom-set must be isomorphic to $\mathcal{V}(([y, z]\otimes[x,y])\otimes x, z)$. Using the evaluation and identity morphisms and associativity of the tensor product, we find that $ev_{[y, z]}\circ (id_{[y, z]} \otimes ev_{[x, y]})\circ \alpha_{[y, z], [x, y], x}$ is a morphism that belongs to this new hom-set; a composition morphism $\circ_{x, y, z}$ will be [adjunct](https://ncatlab.org/nlab/show/adjoint+functor#GeneralAdjunctsInTermsOfAdjunctionUnitCounit) to this morphism. Similarly, the identity element for each $x \in \text{ob}(\mathcal{V})$: $$j_x: I \rightarrow \mathcal{V}(x, x)$$ belongs to the hom-set $\mathcal{V}(I, [x, x])$, which is isomorphic to the hom-set $\mathcal{V}(I \otimes x, x)$ through the tensor-hom adjunction. The left unitor morphism belongs to the hom-set $\mathcal{V}(I \otimes x, x)$; its adjunct is the identity morphism for the given element. The most well-known example of a closed monoidal/self-enriched category is $(\text{Set}, \times, \{\ast\})$. The internal hom corresponding to the Cartesian monoidal product is given by the exponential object $Z^Y$, which denotes the set of all functions $Y \rightarrow Z$, which is itself an object of $\text{Set}$. There is a bijection between bivariate functions $f: (a, b) \mapsto c$ and their curried form as a sequence of single-variable functions $\overline{f}: a \mapsto (b \mapsto c)$, which corresponds to the natural isomorphism $\text{Set}(A \times B, C) \simeq \text{Set}(A, C^B)$. ## The extended reals In this blog post, we are interested in enriching over the *extended reals*, which will look somewhat similar to the earlier example on Lawvere metric spaces. Values of entropy and changes in entropy will live in the extended reals, and we will work to impose some physically-motivated constraints on thermodynamic processes and states. We will use the poset of extended reals equipped with addition as a tensor product, $(\mathcal{R}, +, 0)$. Here $\mathcal{R} = ([-\infty, \infty], \leq)$ is a poset, and thus also a category because all posets are categories. This monoidal category is also [strict](https://ncatlab.org/nlab/show/strict+monoidal+category) and [symmetric](https://ncatlab.org/nlab/show/symmetric+monoidal+category), owing to the fact that the tensor product operation of addition is commutative and associative, and that adding $0$ amounts to an identity operation. (A fun fact that we won't need here is that posets are also preorders, except posets have the additional axiom of antisymmetry, which ensures that the only isomorphisms in the category are identity morphisms. For this reason, the poset $\mathcal{R}$ can also be viewed as the $\text{Bool}$-enrichment of $[-\infty, \infty]$.) Note that $(\mathcal{R}, +, 0)$ is not to be confused with $\overline R$, the target category for the entropy supply functor. In $(\mathcal{R}, +, 0)$, the objects are the extended reals and in $\overline{R}$ the morphisms are the extended reals. Importantly, the poset of extended reals is a closed monoidal category. This gives rise to a natural self-enrichment structure upon its objects. The monoidal product functor here is addition, so the internal hom functor must be subtraction, which acts as $\mathcal{R}(x, y) = [x,y] = y - x$. We know this is an appropriate definition for the internal hom because subtraction is right adjoint to addition. For any elements of the extended reals $x, y, z \in \text{ob}(\mathcal{R})$, $$((x + y \leq z) \in \mathcal{R}(x \otimes y, z)) \iff ((x \leq z - y) \in \mathcal{R}(x, [y, z]))$$ For a triple of reals $x,y,z \in \text{ob}(\mathcal{R})$ the composition morphism $\circ_{xyz}:\mathcal{R}(y,z) \otimes \mathcal{R}(x,y) \rightarrow \mathcal{R}(x,z)$ becomes the morphism $(z-y)+(y-x) \leq (z-x)$ after making the appropriate identifications. After simplifying, this morphism becomes $(z-x) \leq (z-x)$. By applying the tensor-hom adjunction as in the previous section, we know that this morphism must be adjunct to a morphism $(z-y)+(y-x)+x \leq z$, which in turn simplifies to $z \leq z$. All of this tells us that adding or subtracting the same element from both sides of an inequality preserves the inequality. Meanwhile, the identity elements tell us that $\forall x \in \text{ob}(\mathcal{R})$, there is a morphism $0 \rightarrow \mathcal{R}(x,x)$, which means that $0 \leq (x - x)$, i.e., $0 \leq 0$. We know that this morphism must be adjunct to the left unitor morphism $l_x: 1 \otimes x \rightarrow x$, which becomes the morphism $0+x\leq x$, or more simply, $x \leq x$, in the enriched category. Intuitively, the identity elements hint towards additive inverses in the extended reals; for all finite $x$, adding $x$ and $-x$ gives $0$, which is the unit object. Now we ought to check how addition and subtraction work on positive and negative infinity. For any $x, y \in [-\infty, \infty]$, $x + y \leq \infty$, and thus by the adjunction, $x \leq \infty - y$. Letting $x$ be $\infty$, this states that $\infty \leq \infty - y$. For any value of $y$, then $\infty = \infty - y$. In particular, this means that $\infty -\infty = \infty$. We now apply the same reasoning for $-\infty$. For any $v, w \in [-\infty, \infty]$, $-\infty \leq v - w$, and thus $-\infty + w \leq v$. Letting $v$ be $-\infty$, this states that for any $w$, $-\infty + w \leq -\infty$. So for any value of $w$, $-\infty + w = -\infty$. In particular, this means that $-\infty + \infty = \infty +(-\infty) = -\infty$. This makes it clear that adding $-\infty$ and subtracting $\infty$ are not equivalent operations. ## Connecting phase space and entropy Now, starting from our phase space category $X$ and entropy supply functor $s$, we can begin our endeavor of finding a way to assign entropies to states. ### Entropy change of the system and surroundings Let's say a function $S$ is called a *naive entropy* for an entropy supply $s: X \rightarrow \overline{R}$ iff for all morphisms $(P: x \rightarrow y) \in \text{ar}(X)$ $$s(P) \leq S(y)-S(x)$$ The left hand side of the inequality is the entropy supplied by a process, which is the negative entropy change experienced by the surroundings during that process, and the right side is the difference in entropy between the system's final and initial states. If $S(y)-S(x)$ is negative, then the system is becoming more ordered. Then, due to the second law, the entropy of the surroundings must increase, which makes the entropy supply negative. As long as the magnitude of the entropy supply is greater than or equal to the magnitude of the change in entropy of the system, the statement holds. If $S(y)-S(x)$ is positive, then the system is becoming more disordered. In this case, the entropy of the surroundings can increase or decrease. If it increases, then the entropy supply is negative and the inequality holds. If it decreases, then the entropy supply is positive and the inequality holds as long as the magnitude of the entropy supply is less than or equal to the magnitude of the change in entropy of the system. In short, this function is a way to assert that the overall entropy of the system and its surroundings will never decrease. ### Selecting optimal paths Let's also define a function $M$ that calculates the entropy supply for the process that is minimally dissipative *with respect to the surroundings* between two given states $x, y \in \text{ob}(X)$: $$M(x, y) = \text{sup}\{s(P)|(P:x\rightarrow y) \in \text{ar}(X)\}$$ If there are no morphisms $f: x \rightarrow y \in \text{ar}(X)$, then the $\text{sup}$ will return $-\infty$, which we should interpret as signaling an impossible process. If the surroundings are becoming more disordered, then the entropy supply is negative. The supremum picks out the value closest to zero because this is the process that is minimally dissipative for the surroundings; this provides a negative lower bound on the entropy change between the states of the system. If the surroundings are becoming more ordered, then the entropy supply is positive. The supremum picks out the greatest value. In this case, the entropy supply is a positive lower bound on the entropy change between the states of the system. ### Enriched phase space Observe that the function $M$ takes two states from $\text{ob}(X)$ and maps them onto an extended real from $\text{ar}(\overline{R})$, almost like a hom-object, but not quite. We can then recognize that the morphisms of $\overline R$ are the same as the objects of $\mathcal R$, the poset of extended reals, and that in fact, the input of $\text{sup}$ is meant to be a poset. Addition, which was the composition operation in $\overline R$, corresponds to the tensor product in $\mathcal R$, and the identity morphism in $\overline R$, $0$, corresponds to the unit object in $\mathcal R$. So now we can say we have a new enriched category $M$ which is enriched over $(\mathcal{R}, +, 0)$ and which has the same objects as $X$. Because we are enriching over a poset, associativity and unitality are automatically satisfied. Its hom-objects $M(x, y)$ are entropy supply values for paths between $x, y \in \text{ob}(M)$ that are minimally dissipative with respect to the surroundings, and which bound the difference in entropy between states $x, y$. The identity elements are $\forall x \in ob(M). (id_x: 1_\mathcal{R} \rightarrow M(x, x) \in \text{ar}(\mathcal{R}))$, which reduces to $0 \leq M(x, x)$. Recall that identity morphisms on states do not supply entropy; $\forall x \in ob(M). s({id}_x)=0$. The supremum will always select these "freeze" processes against any endomorphic process that increases the entropy of the surroundings, and therefore has negative entropy supply. So then a hom-object for a state $M(x, x)$ must be either 0 or any positive entropy supply value corresponding to some process that reduces the entropy of the surroundings. But it turns out that we cannot have a positive entropy supply value for an endomorphism. The difference in entropy between a state and itself is always $0$, so $M(x, x) \leq (S(x)-S(x)=0)$, and the identity elements reduce to the statement that $M(x,x)=0$. Lawvere refers to this as the *naive Clausius property*. The composition morphisms for $M$ are defined as $\forall x, y, z \in ob(M)$ as $M(y, z) \bigotimes M(x, y) \rightarrow M(x, z)$. Making the appropriate identifications, this becomes the condition $M(y, z) + M(x, y) \leq M(x, z)$, which is the *reverse triangle inequality*. Because both sides of this inequality are entropy supplies of processes with the same domain and codomain, the whole inequality is bounded above by the entropy change between the initial and final system states $S(z)-S(x)$. In the case that $M(y, z) + M(x, y) = M(x, z)$, we can say that the least surroundings-wise dissipative process that takes the system from state $x$ to state $z$ supplies as much entropy as the composite of the least surroundings-wise dissipative processes that take the system from $x$ to $y$ and from $y$ to $z$. But in the case that $M(y, z) + M(x, y) < M(x, z)$, we know that there is some process that has a greater entropy supply than any composite process with the same domain and codomain. If $M(x, z) \leq 0$, there is some morphism $h: x \rightarrow z$ that generates as little entropy as possible in the surroundings. Then $M(y, z) + M(x, y)$ must necessarily be negative, but its magnitude will be greater, representing a more dissipative composite process. If $0 < M(x, z)$, there is some morphism $h: x \rightarrow z$ that leads to the most ordered surroundings possible. Then $M(y, z) + M(x, y)$, can correspond to any negative value, representing a composite process that increases the entropy of the surroundings, or a positive value that is less than $s(h)$, representing a composite process that is less efficient than $h$ at reducing the entropy of the surroundings. While entropy itself is a function of state, entropy supply is *path-dependent*. The composition condition for category $M$ basically says that a surroundings-wise optimal path that moves from states $x$ to $y$ and then $y$ to $z$ is at least as dissipative as a path directly from $x$ to $z$. ### Entropy functions At this point, we have two categories: $M$, our revamped phase space category, and $\mathcal R$, the poset of extended reals. We have shown that both of these categories can be considered to be enriched over $(\mathcal R, +, 0)$. So now we can define a class of *enriched functors* which will map objects and morphisms in $M$ to values in $\mathcal R$ corresponding, respectively, to entropies of states and entropy supplies of processes. For $C, D$ enriched over the same monoidal category $(\mathcal V, \otimes, I)$, a $\mathcal V$-functor $F: C \rightarrow D$ consists of: * a function between objects $F_0: \text{ob}(C) \rightarrow \text{ob}(D)$ * a collection of morphisms in the enriching category $\mathcal V$, $$\forall x, y \in \text{ob}(C).F_{x, y}:C(x, y)\rightarrow D(F_0(x), F_0(y))$$ An enriched functor, much like a typical functor, is a homomorphism between enriched categories, except that instead of mapping hom-sets to hom-sets, we think of morphisms between hom-objects, since both the source and target of the functor are enriched over the same category. Units and composition must be preserved, as illustrated in the diagrams below, which are borrowed from [ncatlab](https://ncatlab.org/nlab/show/enriched+functor#definition). The commuting diagram for respect for composition, which employs composition morphisms $(\circ_{x, y, z} \in \text{ar}(\mathcal{V}))$ for $\forall x, y, z \in \text{ob}(C)$: <img style="display: block; margin-left: auto; margin-right: auto; width: 750px" src="https://github.com/mnamuduri/categorytheory/blob/main/Screen%20Shot%202022-08-28%20at%2018.51.16.png?raw=true" alt=""/> The commuting diagram for respect for units, which employs the identity elements $j_x \in \text{ar}(\mathcal{V})$ for any object $x$ of $C$ or $D$: <img style="display: block; margin-left: auto; margin-right: auto; width: 550px" src="https://github.com/mnamuduri/categorytheory/blob/main/Screen%20Shot%202022-08-28%20at%2018.51.21.png?raw=true" alt=""/> Let's consider the $\mathcal{R}$-functor $S: M \rightarrow \mathcal{R}$, which has: * a function on objects $S: ob(M) \rightarrow \text{ob}(\mathcal{R})$, which computes entropies of states * a collection of morphisms belonging to $\text{ar}(\mathcal R)$, $$\forall x, y, \in ob(M).S_{x, y}: M(x, y)\rightarrow \mathcal{R}(S(x), S(y))$$ Because we are enriching over $\mathcal{R}$, a poset, preservation of units and composition automatically follow. Recalling that internal hom-objects of $\mathcal R$ are given by subtraction, the defining collection of morphisms can be rewritten as $\forall x, y \in \text{ob}(M).M(x, y)\leq S(y)-S(x)$. In doing so, we have recovered the naive entropy function we defined at the beginning of the section. The hom-objects $M(x,y)$ are calculated using the functor $s$, which is assumed to be given. If we fix a state $x_0 \in \text{ob}(M)$ and assign it $0$ entropy, then $\forall x \in \text{ob}(M)$ we can define $S$ as an *entropy function*: $$S(x)=M(x_0, x)$$ This definition used on the morphisms between hom-objects in the $\mathcal R$-functor gives $\forall x, y \in \text{ob}(M)$ the new morphisms $$M(x, y) \leq M(x_0, y)-M(x_0, x)$$ which are adjunct to the composition morphisms of $M$ on the same objects, $M(x_0, x) + M(x, y) \leq M(x_0, y)$. At this point, we can recognize that $S$ is a [*representable functor*](https://ncatlab.org/nlab/show/representable+functor). Based on our choice of representing object/zero-entropy state $x_0 \in \text{ob}(M)$, we have a family of functors $M(x_0, -): M \rightarrow \mathcal R$, any of which could work for the given phase space category and accompanying entropy supply functor. Our choice of representing object fixes the state whose entropy we compare against the entropy of every other state. If the entropy supply $s$ satisfies the naive Clausius property for the chosen representing object, $M(x_0, x_0)=0$, then $\forall x \in \text{ob}(M). (M(x_0, x) = S(x)) \leq -M(x, x_0)$. This condition allows us to relate the covariant functor $M(x_0, -)$ to its dual, the contravariant functor $M(-, x_0): M^\text{op} \rightarrow \mathcal R$, where $M^\text{op}$ has the same objects as $M$ but reversed morphisms. All of this gives us a general functorial framework for associating entropies to trajectories in a phase space. ## Conclusion The rest of Lawvere's 1984 article discusses how the topology of the phase space affects the properties of possible entropy supply functors, but this is beyond the scope of this blog post. The topology of the phase space is related to likelihoods of trajectories in the phase space; this information is encoded in the [action](https://en.wikipedia.org/wiki/Action_(physics)) of the physical system. During the pre-conference research week of Applied Category Theory 2022, we developed a humble example of Lawvere's functorial entropy framework. We defined a phase space category and and entropy supply functor for heat networks represented by open graphs. See our [slides](https://msp.cis.strath.ac.uk/act2022/slides/adjointschool_group1.pdf) for more details on this example.