Deriving the Boltzmann formula, defining temperature, and simulating liquid/vapor.
@SpectralCollective has the second part: https://youtu.be/yEcysu5xZH0
You can play with a simulation of this model here: https://vilas.us/simulations/liquidvapor/
These lessons are funded directly by viewers: https://3b1b.co/support
Home page: https://www.3blue1brown.com
Notes from Vilas:
1) This open problem is to prove the ergodicity of the deterministic dynamical systems that are used to model the molecule-level physics. A good example of such a dynamical system is the box with particles evolving according to Newton's laws with elastic collisions, like in the video.
2) This video assumes that all probability distributions are discrete, which is the case in the simulations. But one can also set up this formalism for systems with continuous state spaces. Again, a good example is particles in a box, which are not restricted to a lattice, which is only used for visualization purposes in this video.
3) Strictly speaking, these "derivatives" don't make sense since in our simulations the energy can only take on a discrete set of values. But a derivative is the right way to think about this, and is the correct notion in a limiting sense.
4) The factor of -T in the definition of the chemical potential is sort of a historical leftover, but including it has the convenient side effect of allowing the same Boltzmann formula to hold, with an energy function that depends on the chemical potential as well. It should also be noted that temperature must equalize in any situation where the chemical potential equalizes, since it is impossible for systems to exchange molecules without also exchanging energy.
5) This algorithm, where we only choose one pixel at a time, is called Glauber dynamics. There are multiple ways to parallelize it, but the method chosen in this video is to only update each pixel with a low probability at each call of the compute shader, to avoid (frequently) updating two neighboring pixels simultaneously. One could also alternate between updating the even or odd pixels at each step.
6) By "zooming out," what is meant, technically, is a renormalization operation whereby each 3x3 grid of pixels is replaced by just one pixel, which has a molecule exactly when 5 or more of the pixels in the 3x3 grid have molecules. But that is somewhat tough to simulate as the size has to increase by 9 at each step, so this video cheats a bit by just zooming out on a large simulation.
7) The "interesting behavior" referenced here is the fact that the interface between the up and down sections of the picture can be rescaled (as the size of the model goes to infinity) in a way that yields a universal random curve called Schramm-Loewner evolution. This family of random curves shows up in many seemingly-unrelated places in statistical mechanics and probability.
Chapter markers:
0:00 - What is phase change?
6:27 - The Boltzmann law and free energy
12:05 - A preliminary simulation
15:30 - Defining temperature
21:25 - Deriving the Boltzmann law
24:30 - Sampling with MCMC
28:30 - Chemical potential
33:20 - Interesting properties
This video made use of the following Creative Commons material:
https://commons.m.wikimedia.org/wiki/File:How_to_(nearly)_instantly_freeze_a_bottle_of_sparkling_water.ogv
https://commons.m.wikimedia.org/wiki/File:Blue_rotating_brain_animation.mpg
https://commons.m.wikimedia.org/wiki/File:7_Tesla_MRI_of_the_ex_vivo_human_brain_at_100_micron_resolution_(100_micron_MRI_acquired_FA25_coronal).webm
https://commons.m.wikimedia.org/wiki/File:Axonal_nerve_fibers_in_a_brain_-_the_neural_network_that_is_us.webm
Оглавление (8 сегментов)
What is phase change?
[Submit subtitle corrections at criblate. com] This is a video about phase transitions. Our main goal will be to study a simulation of a discretized fluid model, which has a phase transition as the parameters are varied. That's what you're looking at right now, and it's called the liquid vapor model. To understand how this simulation works, we'll need to introduce one of the most important formulas in physics, the Boltzmann formula. Then we'll see how you could build this simulation yourself, and we'll investigate some of the very interesting behavior that it exhibits. By the way, this video is part one in a two part series. The follow up is live now on the Spectral Collective channel. There we'll look at a simplified version of the liquid vapor model, which we can essentially completely understand using basic mathematics. Okay, so what is a phase transition? You might remember from a chemistry class that phase transitions are not chemical reactions. The molecules of ice are the same as those in water and steam. It's all H2O. The different phases of matter correspond to different ways in which the molecules interact with each other. For instance, in ice, the molecules are locked into a rigid structure and the interactions span long distances. In other words, if you push on one end of an ice cube, the other end moves. This doesn't happen for water, and it definitely doesn't happen for steam. There is still some semblance of long range interaction in water though, since ripples can travel pretty far. However, if you move one small region of steam a little bit, there is pretty much no effect on another distant location. You've probably seen a phase diagram like this one before. It tells you what phase of matter you'll observe if you have a bunch of H2O molecules at various temperatures and pressures. Crossing any of these lines between phases results in a phase transition. This is not something that happens suddenly in real time, as you probably know from waiting for water to boil. Instead, the phase of a system refers to its equilibrium behavior, which is what you see after the system has had enough time to settle down. The equilibrium behavior is determined by only a few parameters. In this case, temperature and pressure. And a phase transition is a discontinuity in the equilibrium behavior as a function of the parameters. Something you might not have seen before is that there are actually at least 19 different types of ice. But that's beyond the scope of this video. Also, at very high temperatures and pressures, there's something over here called a supercritical fluid, which varies continuously between liquid and gas. This means that by moving the parameters through this region, you can actually get steam from water without ever witnessing A phase transition. One of the main goals of this video is to introduce the liquid vapor model, which is a discretized model of a fluid in this region of the phase diagram. Here's what that looks like again. Each blue pixel on the screen represents a molecule, and each white pixel represents an empty space. We have a control panel here which also shows the phase diagram where we can set the values of two parameters which control the behavior of the simulation. T is the temperature, and you might be expecting pressure for the second parameter, but it turns out that pressure is a bit tricky to work with in a simulation like this, so we use a different parameter called the chemical potential instead. Instead of. Just to clarify this point, let me say that there's a nice correspondence between various pairs of thermodynamic observables, which I'll say more about later in the video. Temperature is paired up with energy, pressure volume, and chemical potential is the thing which is paired up with the molecule count or the number of molecules. We'll get into the details of this later, but for now, just know that if we have a system at a specific fixed temperature, then it turns out we have to allow the energy to vary slightly, and how it varies is determined by the specific temperature we set. In the same way, if we wanted a system at a specific pressure, we'd have to allow the volume to change. And this isn't so easy to do in a simulation like the one I'm showing you, since the state of this simulation is represented in my computer by an array of fixed size. Instead, we'll allow the number of molecules on the screen to change in a way that's controlled by this other parameter, the chemical potential. At high chemical potential, there will generally be more molecules on the screen, and vice versa. Increasing the number of molecules has a somewhat similar effect to decreasing the volume, since both of these increase the density of the molecules. And this is why the chemical potential is at least an okay, stand in for pressure. Now, although you might have some intuition for it, the temperature is actually a little bit more mysterious. It controls how important the energy is, and in our simulation, the energy corresponds to how clumped up the molecules are. We'll understand much more about this later, but for now, just notice that at high temperatures, having molecules clumped up next to each other doesn't matter so much, and randomness is the key factor. Instead, when we vary the chemical potential at high temperatures, the density of the molecules varies smoothly without a phase transition, and this is like the supercritical fluid region of our real phase diagram. But at low temperatures, once we cross a certain threshold, a phase transition begins to happen and the density goes from very low, like a gas, to very high, like a liquid, skipping all the intermediate values. Due to the nature of the simulation, the number of molecules on the screen still has to change gradually, and the phase transition doesn't happen all at once. But during the phase transition, every region of the picture is either mostly blue or mostly white, and there are no regions with intermediate density where the blue and white regions meet. We see well defined curves with shapes that can actually be described mathematically. There is so much to talk about in this one simulation and in this video. I want to introduce everything we need to really understand what's going on here. The main question at this point, which I didn't say much about yet, is how exactly does this simulation work? To answer this question, we'll need to talk about the most important formula in statistical the Boltzmann law.
The Boltzmann law and free energy
is a formula for a probability distribution telling us the probability of each configuration x of molecules. A first question you might have is why are we using randomness here at all? I want to first say that this is not the randomness that might come from quantum mechanics. Even if the universe is truly deterministic, using randomness to model systems with many particles can be extremely useful. To see why, let's start with a thought experiment. Suppose we have 20 particles in a box with given initial positions and velocities. This is called a microstate, since it contains all the information about the microscopic particles in the system. Lets suppose that these are perfectly spherical particles evolving according to Newton's laws of motion, colliding elastically with each other with no friction. Now let's suppose you close your eyes and take a 30 minute nap. What microstate will you observe when you wake up? You probably couldn't solve this problem by hand. Maybe you could do it if you had a computer. But even a computer will start to struggle if we increase the particle count. For instance, even this simulation with just 200 particles took my computer multiple hours to make. Even the most powerful computers we have could never solve this problem. If the number of particles was something like 10 billion or 10 to the power of 10. There are just too many calculations. And by the way, 10 billion isn't even close to the typical number of particles in anything we interact with. In just one teaspoon of water, the number of water molecules is around 10 to the 23rd power. To get a bit of a grasp on just how large this is. There are about that many teaspoons worth of water in the entire ocean. So clearly we're not going to be able to predict the exact location of every water molecule in a glass of water in order to determine the microstate. But we don't need to do that in order to know that it's water and not ice. I mean, people could tell the difference between water ice and steam far before anyone even knew that molecules existed. Since we can only see the large scale behavior or the macro state, we really only care about the overall statistics of the molecules rather than their individual behavior. This is the key motivation for the first main idea, which is approximating a deterministic microstate like this one by a random microstate. One perspective on this is that we are using randomness as a proxy for the fact that we don't know the true microstate. In other words, we're using randomness as a stand in for our own uncertainty. This is a subtle point, and in fact, it's still an open problem to prove mathematically that this approximation is a good one in general. But that's beyond the scope of this video. For now, we'll just accept the postulate of randomness because it works well in practice. But just saying that the microstate of a system is random doesn't tell the full picture. We need to know the distribution of the microstates. In other words, we need to know the probability that we see any particular microstate. It turns out that the probability of a microstate x is proportional to the exponential of the negation of the energy of the microstate over the temperature of the system. This is called the Boltzmann distribution, and understanding this is our first main task for this video. If you've seen this before, you might remember a factor of k in the denominator here. This is called Boltzmann's constant, and we'll just ignore it in this video. We can do this by choosing our units in such a way that the numerical value of k is equal to 1. Anyway, this formula actually already explains how phase transitions can arise as we vary the temperature. So, before we prove the Boltzmann formula itself, let's see how this works. First, states with higher energy have lower probability and vice versa. This agrees with the fact that nature likes to minimize energy. But this doesn't necessarily mean that we'll typically see a microstate with very low energy under the Boltzmann distribution. In order to understand which energy levels are more likely we also have to account for the number of microstates at a particular energy level. Lets use Omega E to denote the set of microstates with energy e. Since all of these microstates have the same probability, which is proportional to the exponential of minus E over T, the probability that we get a microstate in Omega E is proportional to this exponential factor times the size of Omega E. To put things on common footing, we can move the size of Omega E into the exponential by taking a logarithm. The logarithm of the size of Omega E is actually a very important quantity called the entropy of the system at energy level E, and we denote it by S. Keep in mind that in this context, the entropy S is actually a function of the energy E, although for now we'll just write it as S to keep the notation simple. From this formula, we can see that the most likely energy level is the one where minus E over t plus S is maximized. Since temperature is non negative, this is equivalent to minimizing E minus T times S. This important quantity is called the free energy. Let's take a minute to see how this minimization problem is solved. First, when the temperature is very low, changing the entropy doesn't change the free energy by much. So minimizing the free energy essentially amounts to minimizing the energy itself. At high temperatures, changes in entropy are much more important, and so the minimization of free energy is driven by maximizing the entropy instead. In summary, nature tries to minimize the free energy and at different temperatures this is done in different ways. This simple fact is ultimately what leads to the different phases of matter and the transitions between them.
A preliminary simulation
We can see this principle in action using our simulation. For now, let's consider a situation with a fixed number N of molecules represented by blue pixels. The molecules can move around from pixel to pixel inside of a box, but it's energetically favorable for them to be next to each other. This is inspired by real intermolecular interactions, which have a sort of sweet spot. Molecules really don't like to be too close, but they also far apart. We encode the fact that the molecules can't be too close by the fact that each pixel can contain at most 1. And we encode the fact that they don't like to be too far apart by giving each pair of molecules an energy of minus 1 if they are adjacent and 0 if they're not. Remember, lower energy is better. In other words, we can actually write the energy of a microstate explicitly as minus the number of pairs of molecules which are adjacent. Since having lower energy is good, I'll put a little green diamond between each pair of adjacent molecules so that the energy is exactly equal to the negative of the number of little green diamonds. You see. Note that we're totally ignoring kinetic energy here, so our model isn't exactly a realistic fluid simulation. But that's not the point. The main point of this model is to be as simple as possible while still exhibiting a phase transition. And at high and low temperatures, we can see two distinct behaviors emerging, which we call macrostates. At high temperatures, the molecules bounce around and mostly ignore one another, which is how molecules behave in a gas. So this is a gas macrostate. At low temperatures, though, the molecules start to clump up into a droplet. This is a liquid macrostate. The energy of a droplet is much lower since there are more pairs of adjacent molecules represented by green diamonds. But at the same time, the entropy is also lower since there are far fewer configurations that look like this. If you just chose a random configuration of N molecules in a box without considering the energy, there is basically no way that you'd choose a configuration that looks like a droplet. Instead, you get something gas, since there are just more microstates that look like this, although they have higher energy. But at low temperatures, when you're considering energy as an important factor, the higher energy gas configurations lose to the droplets. Notice that there are no macrostates with both low energy and high entropy. So when minimizing the free energy, our simulation can't just minimize energy and maximize entropy simultaneously. Instead, it has to choose which of these optimization tasks is more important, and that's determined by the temperature. I think this point that energy and entropy are in competition with each other, and that this competition is mediated by the temperature, is the main takeaway of this video. This is all a consequence of the formula for the Boltzmann distribution, where the probability of a particular microstate is proportional to the exponential of the negative of the energy of the microstate divided by the temperature of the system. But we still haven't seen exactly why this is the correct formula. So our next task will be to explain this. After that, we'll be ready to really understand what's going on in the simulations I've shown you so far. It will actually take us a few steps to get to this formula for the Boltzmann distribution, but bear with me, because along the way, we'll get a more precise Understanding of what temperature actually is
Defining temperature
lets first consider a completely isolated system. This system has no way to exchange energy with the outside world, and so every possible microstate of this system has the same energy. In fact, by the same reasoning, there's essentially no way to tell the possible microstates of this system apart in any meaningful way. In this situation, the only reasonable probability distribution on the microstates is the one where every possible microstate is equally likely. In other words, if the collection of microstates of an isolated system at fixed energy level E is called Omega E, then each possible microstate will be chosen with probability 1 over the size of Omega E, because all of the probabilities need to add up to one. This fact that in an isolated system at fixed energy E, all microstates are equally likely will come up a few more times during our derivation of the Boltzmann law. So keep this in mind. Now, what would happen if we have two isolated systems at different energies and then suddenly put them in contact, allowing energy to transfer from one system to the other? Well, one thing we know from experience is that after enough time, the temperatures of two things in contact with each other will equalize. But what is temperature actually? This fact that temperature equalizes when things are put into contact is essentially all we know about it. So let's try to figure out what quantity must equalize once the system has reached equilibrium. To do this, let's formalize things a bit. At any given instant, system one will have some energy, which we'll call E1, and system two will have energy E2. The total energy of the combined system is E1 plus E2, and that can't be changed. But energy can move back and forth between the two subsystems. So E1 can increase if E2 decreases by the same amount. We'll use DE to denote a small energy packet that could be transferred from one system to the other. These small energy packets will continuously be transferred back and forth randomly, and the system reaches equilibrium when there's no overall flow of energy packets from one system to the other. Or in other words, when both directions are equally likely. But what determines the chances that an energy packet will flow from one system to the other? Well, remember that the combined system is in isolation, so each microstate of the combined system is equally likely. This means that we need to understand the number of combined microstates of the combined system with various splits of the energy across the two subsystems. If there are more combined microstates with energy split E1, DE and E2DE than there are with energy split E1 and E2, then an energy packet DE will be more likely to flow from system 2 to system 1, simply because there are more possibilities for the energy to flow in this direction. Let's use Omega E1 E2 to denote the set of combined microstates with energy E1 in system one and energy E2 in system two. This is the same as the Cartesian product of the set of microstates of system 1 with energy E1 and 2 with energy E2. Since any combined microstate with the correct energy configuration is valid, and a combined microstate is the same thing as its two pieces combined. So we can consider a sort of combined entropy S12, which is the log of the size of omega E1 E2. And this is just the sum of the entropies of the two subsystems at their respective energies, which we'll denote by S1 and S2. Now, to determine if there are more combined microstates with energy split E1DE and E2DE, we should consider the change in this combined entropy, which we'll denote by ds12. If this change is positive, then the energy packet de will be more likely to flow from system 2 to system 1. Since the energy packet is very small, the change in combined entropy can be written in terms of the derivatives of the two entropies as functions of the energies of the two systems. Like this. Using the chain rule factoring out DE like this, we find that energy is more likely to flow from system 2 to system 1 as long as the derivative of S1 with respect to E1 is greater than the derivative of S2 with respect to E2. Similar reasoning shows that energy is more likely to flow in the opposite direction if the opposite inequality holds. Remember, equilibrium is reached when energy is equally likely to flow from either system to the other. This means that these two derivatives must be equal at equilibrium. And here it is. This is the quantity which equalizes when systems are brought into contact. Exactly what we were looking for. But is this temperature? Actually, not quite. We usually think that energy flows from a hotter system to a colder one. But we just saw that energy flows from the system with a lower value of this derivative to the system with the higher value. So the derivative of entropy with respect to energy is actually one over temperature. To get a better understanding for why this is the correct definition for temperature, let's just take a step back and review the math we just did. On a more intuitive level, generally increasing the Energy also increases the number of microstates available to the system. For instance, like we saw before, there are many more gas microstates than there are liquid microstates in our discretized simulation. But this increase is not consistent at high temperatures, when the derivative of entropy with respect to energy is small, adding or removing energy doesn't impact the number of microstates that much. On the other hand, at low temperatures, when this derivative is large, adding even a little bit of energy can increase the number of microstates by a lot. So when two systems are in contact to get more combined microstates, it makes sense for a high temperature system to donate energy to a low temperature system. And this is how we understand temperature intuitively.
Deriving the Boltzmann law
Now that we know what temperature is, we can derive the formula for the Boltzmann distribution of a system at fixed temperature T. But how can we control the temperature of our system? One way is to put it in contact with a huge reservoir of energy at that temperature, sometimes called a heat bath. Although it could also be cold. The temperatures will equalize between our system and the heat bath, but the temperature of the huge heat bath won't change by much at all. So the resulting temperature of our little system will essentially be set to the same temperature T as the heat bath. Now, we want to figure out the probability that we see a particular microstate, say X, when we just look at the little system. But again, the combined system of the heat bath plus the little system is isolated and has some fixed total energy, say E0. So each combined microstate is equally likely. Again, this means that the probability that we see a particular microstate X in the little system is proportional to the number of microstates of the heat bath that are compatible with X. Since the two systems can only exchange energy, a microstate of the heat bath is compatible with a microstate X of the little system exactly when it has the right energy, which is the total energy minus the energy of x. So the set of heat bath microstates compatible with X is the same as the set of microstates with this energy, which we can write using our Omega notation. This is the exponential of the entropy of the heat bath at this particular energy. Now remember, the heat bath is huge and can basically donate as much energy as the little system needs without changing temperature. In other words, for all relevant energy values, the derivative of the entropy of the heat bath with respect to its energy is a constant, which is one over the temperature. This means that the entropy of the heat bath at energy E 0 minus E is essentially the same as its entropy at energy E0 minus 1, t times E. Let's call the entropy of the heat bath at energy E0s0. Now, we can factor the exponential like this. Since the exponential of S0 is a constant which doesn't depend on X, we can just absorb that in our proportionality relation. And we find that the probability of X is proportional to the exponential of minus the energy of X over the temperature. Exactly what we wanted. This finishes the proof of Boltzmann's formula for the probability of microstates in a system at temperature T. This is the distribution that the simulation I've shown is sampling from. So far, we've been considering configurations where there are a fixed number of molecules and the energy of a microstate is the negative of the number of pairs of adjacent molecules, which we could also see visually as the number of green diamonds here. This mimics the fact that intermolecular forces have a sweet spot where molecules prefer to be relatively close to each other. So now we understand this distribution on some level. But just knowing the Boltzmann formula is not enough to actually sample from this distribution, at least not efficiently on a computer. The key reason for this is that there are exponentially
Sampling with MCMC
many different possible microstates. So even though we have a formula for the distribution which does allow us to implement some basic sampling procedure, like generating a uniform random number and choosing the microstate based on a division of the unit interval into bins, this kind of procedure will take an exponentially long time to run on a computer. So how are we getting the samples you're seeing on the screen right now? Well, you probably noticed that the simulation is continuously changing over time. So we're not just getting a sample from the Boltzmann distribution in one go. Instead, we're making a bunch of small, manageable random changes to the picture that eventually lead to a proper sample. You can think of this like shuffling cards. Each time you shuffle, a little bit of randomness is added, and eventually you get a roughly uniform distribution on the arrangements of cards. For this simulation, at each time step, we choose two pixels, and if there's a molecule in only one, we randomly decide whether or not to switch the position of the molecule from one pixel to the other. But how do we decide the probability of the swap? Here's where we use our formula for the Boltzmann distribution. Let's call the microstate we've currently got X and the microstate. With the molecules swapped X' by our formula we know that the ratio of these probabilities is exactly the exponential of the energy difference over the temperature. Here we're using the fact that the proportionality constant that's hidden in the Boltzmann formula is the same for both X and X'. So it cancels out and we actually get an equality here. Now, given that we've chosen this pair of pixels to potentially swap, we can only choose between X and X'. So given that we've only got two choices and we know the ratio of their probabilities, we can also find each probability individually because the probabilities have to add up to one. If you only have two choices and the ratio of their probabilities is Q, then the raw probability of the choice in the numerator is Q1Q. So this is the probability that we pick X', or in other words, the probability that we swap the molecules. And that's basically it. Repeating this one step is the entire algorithm. Now, it's important that the energy difference here can actually be calculated quite easily. This is because it only depends on the at most 8 pixels surrounding the two that we've chosen to potentially swap. So this algorithm can easily be run on a computer, and it's really not that complicated. I hope that by this point in the video, if you have some programming experience, you could make this simulation yourself. By the way, this algorithm is called Kawasaki Dynamics, and it's an example of a more general class of algorithms that go by the name of Markovchain Monte Carlo. One thing you might be wondering about is why don't we force the swap to happen between neighboring pixels? After all, that would be a more realistic choice, since we wouldn't have molecules teleporting all over the place. But as I mentioned before, this procedure shouldn't really be thought of as a simulation of real fluid dynamics. It's just a sort of random walk through the space of possible microstates. As it turns out, by running this random walk for long enough, we do end up getting a sample that's very close to the Boltzmann distribution, just like how when you shuffle a deck of cards enough, its distribution gets close to the uniform distribution on all arrangements. Actually, this also holds for the algorithm where we only swap neighboring pixels, but the number of steps it would take to get an accurate sample is much higher. This is similar to how there are multiple different ways to shuffle cards, but some are more efficient than others. With the algorithm I've presented here, which allows for teleportation, we can even look at a slightly Bigger simulation and we can see the change in behavior as the temperature changes again. At high temperatures we see a gaseous phase with high energy and entropy, while at low temperatures we see a liquid phase with low energy and entropy. Additionally, the phase transition doesn't happen all at once, especially when we're going from high temperature to low temperature, since it takes the molecules a while to clump up.
Chemical potential
Now, I promised a simulation which has a phase diagram similar to that of H2O in this region. But this is a two dimensional phase diagram and so far we've only got temperature as a parameter, meaning the model we've been considering so far could only have a one dimensional phase diagram. The other axis on the standard phase diagram is pressure, but we're actually going to use a different second parameter for this video. In the same way that temperature is defined as the thing which equalizes when systems are allowed to swap energy, pressure can be defined as the thing which equalizes when systems are also allowed to swap volume, maybe by using a moving wall between the systems. But in our simulation it might be a bit tough to expand and contract the container on the fly. Instead, we'll allow the number of molecules to change when two systems are brought into contact with a permeable wall which lets molecules through. The thing which equalizes is called the chemical potential. If you have some fancy setup with multiple different kinds of molecules, each kind of molecule will have its own associated chemical potential which will equalize when two systems are put into contact using a permeable wall, which only lets that type of molecule through. We only have one type of molecule though, so we'll only have one chemical potential which we'll call C. This is defined as minus T times the derivative of entropy S with respect to the number of molecules n. By the way, unlike the temperature, which is always non negative, the chemical potential could be any real number. Now, we'll place our small system in a huge heat bath at fixed temperature and fixed chemical potential, and allow our system to exchange energy and molecules with the heat bath. Using an argument similar to the one we used when deriving the formula for the Boltzmann distribution, we can see that the probability of any particular microstate of our small system is now proportional to the exponential of the negative of one over the temperature times the energy of the microstate plus the chemical potential over the temperature times the number of molecules in the microstate. This means that when the chemical potential is positive, microstates with more molecules are favored and vice versa. Another way to think about this is that we're redefining the energy function like this, so that it depends on the chemical potential and the molecule number as well. This way we still have the same Boltzmann formula as before. Allowing the number of molecules to change actually makes the simulation easier. Instead of choosing two pixels and possibly swapping a molecule from one to the other, we can just choose one pixel and randomly decide to add or remove a molecule. What this means is that each pixel can make its own decisions, and these decisions can actually be somewhat parallelized, meaning that this simulation can be run on the gpu. So we can increase the size of the simulation by a lot, and we can change the temperature and the chemical potential on the fly in real time. Now let's explore the phase diagram for this model, which describes the behavior as a function of T and C. This simulation is more spatially homogeneous than the one with fixed molecule count, so the density of molecules gives a decent large scale characterization. In other words, our phase diagram will be a function telling us the density of molecules for each value of the parameters T and C. At high temperatures, changing the chemical potential makes the density change smoothly. So the phase diagram looks something like this over here. This is the supercritical fluid phase, which interpolates smoothly between liquid and gas. When the chemical potential is greater than minus 2, changing the temperature also makes the density change smoothly. And we can fill in this corner of the diagram identifying the liquid phase. The density also changes smoothly with T when C is less than minus 2, which is the gas phase. And so the overall phase diagram looks like this. As promised, this looks like the phase diagram of H2O in this region, with a phase transition line between a liquid phase and a gas phase, as well as a region of supercritical fluid. To me, this is pretty amazing. After all, the model we're working with is almost nothing like the real world, where molecules have non trivial shapes and can move around freely in three dimensions, where kinetic energy is relevant at all, and where the intermolecular energy is much more complicated than just it's good when molecules are next to each other. Still, with all of these simplifications, we can recover behavior that is qualitatively similar to something in the real world. This is an example of the principle of universality, which is the idea that most specific details of a model shouldn't actually be too important. Universality posits that there are usually only a few fundamental microscopic rules that you need in order to see the same macroscopic behavior, at least qualitatively. This is maybe the Second and final key point of this video. But before we wrap things up, I want to talk a bit more about some
Interesting properties
of the interesting behavior we can observe in this model, as well as some connections to other models you might have heard of. First, you probably noticed these shapes expanding as we cross the line of phase transition. Since the density can't change smoothly as a function of the chemical potential, these droplets or bubbles need to form so that locally it always looks like either a liquid or a gas. As we change the temperature, the shape of the droplets changes as well. And this is simply due to the fact that we're working on a square lattice of pixels. At very low temperatures, the droplets really feel the shape of the lattice and become square themselves, while at higher but still subcritical temperatures, they look more round. It's actually possible to calculate the shape of these bubbles as a function of temperature. Look up the wolf shape if you want to learn more. You might have also noticed that we actually have to cross the phase transition line by a decent amount in order to see the droplets appearing and the phase transition happening in real time. If we instead only just barely cross the line from the gas to the liquid phase, you'll see that the system actually remains in the gas phase. This is because the phase transition actually needs to happen through the droplets we just discussed. If we artificially insert a big enough droplet, then it will slowly grow and fill up the whole simulation. But without this kickstart, the droplets that arise naturally in the gas won't get big enough to start this reaction, even though the liquid macrostate is the true phase at these parameters. Instead, they're overwhelmed by the gas around them and shrink back down as soon as they form. They just can't get big enough to be stable like the one we inserted artificially. This phenomenon is known as metastability, where the system remains in the wrong macrostate for a very long time if there's no external impulse, like our artificial insertion of a droplet. You might have seen something like this in real life, where water can be cooled slightly below its freezing point, but doesn't actually turn into ice until some external impulse starts a freezing chain reaction. Now let's take a look at the behavior of the model exactly at the critical point, the end of the phase transition line. The behavior here is somewhat unlike at any other point in the phase diagram. At the critical point, the molecules form strange fractal like structures, and there's a self similarity to the model at criticality, meaning that it looks essentially the same, no matter how much you zoom out. This doesn't happen away from the critical point anywhere except for the critical point. When you zoom out, the model becomes more and more homogeneous. At slightly higher temperatures, it becomes homogeneous with density 1/2. And at slightly lower either 1 or 0. The critical point is the only point where scaling the model doesn't seem to change anything. And this mysterious behavior sparks a lot of interesting ideas, including the critical brain hypothesis, which hypothesizes that brains are in some sense at criticality with the self similarity and multiscale structure, allowing for long range impulses and intercommunication in the brain without it being overwhelmed by electrical activity. But that is far beyond the scope of this video. Something slightly more accessible, which you might have heard of before, is the Ising model. This is a model of a magnet which consists of a bunch of tiny magnetic elements arranged in a grid, each of which is pointing either up or down. Neighboring elements would like to be aligned with each other, and there's an external field which also influences each element individually. If this simulation looks familiar, that's because it's exactly the same model as the fluid we've been looking at this whole time. Just identify a molecule with up and an empty space with down. Under this identification, we need to reinterpret the chemical potential as an external magnetic field over the whole magnet. In this particular simulation, I'm also imposing boundary conditions where the left border of the simulation is fixed to be up and the right border down. These are called dobrushin boundary conditions, and they lead to very interesting behavior, especially at the critical point, which is what we're looking at right now with this magnetic interpretation. Something interesting also happens if we allow the magnets to not just point up or down, but to point in any direction. For now, let's just let them point in any direction in two dimensional space, which I'll parameterize by a color wheel. Then we get a truly different model which actually doesn't have the same type of phase transition anymore, at least not in two dimensions. The fact that the direction of the magnet can change smoothly means that the elements will never end up all pointing in the same direction, even at very low temperatures. Instead, as we decrease the temperature, we see a new phenomenon where the color varies smoothly, except for at a few points where all the colors meet. These are called vortices, and they come in two different orientations depending on the direction in which the colors change around the vortex. Interestingly, these vortices behave somewhat like positively and negatively charged particles, and they interact with something like an electrical force, with vortices of opposite types attracting each other and a repulsive force between vortices of the same type of this is called the XY model. If you are curious and want to learn more, all of these models can also be considered in three dimensions, or even higher, or on other strange non euclidean geometries. Even in just three dimensions, our simple liquid vapor model is not as well understood as we might like. For instance, in two dimensions it's known that the temperature at the critical point is exactly one over two times log of one plus the square root of two. But in three dimensions there's no such formula yet, only numerical approximation, and it's unclear if there will ever be a formula. Unfortunately, performing rigorous mathematical analysis on a more realistic model of H2O in three dimensions is simply out of the question. Something like that would have to incorporate the electromagnetic asymmetry of the molecules and allow them to move and rotate freely in space. So far, most techniques we have to solve things exactly are restricted to two dimensions, and adding all these extra details would certainly not make anything easier. For all of these reasons, we'll probably never have a precise mathematical description of H2O that allows us to prove things like the fact that the melting point of ice is 273kelvin. Rather than despair at this fact, we can, as mathematicians recognize that such a question is not really mathematical in nature to begin with. In math we prefer to simplify things as much as we can while still retaining core features. This helps us gain a better conceptual understanding of which mechanisms are the most fundamental to the observed behavior. In the second video, which is live now on Spectral Collective, we'll do exactly that. There we'll simplify the liquid vapor model from this video even more, to the point where we can essentially completely understand it in a rigorous way using basic mathematics. I find the fact that we can do this without completely destroying the phase diagram really amazing. And in the second video we'll see exactly how the different phases arise and what makes a phase transition happen mathematically. I hope to see you there.