[00:00] [Submit subtitle corrections at criblate.com] Our main goal will be to study a simulation of a discretized fluid model, [00:13] 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. [00:28] 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. [00:40] The follow up is live now on the Spectral Collective channel. which we can essentially completely understand using basic mathematics. [00:53] You might remember from a chemistry class that The molecules of ice are the same as those in water and steam. [01:05] The different phases of matter correspond to different For instance, in ice, the molecules are locked into a rigid structure and the interactions span long distances. [01:21] 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, [01:33] However, if you move one small region of steam a little bit, there is pretty much no effect on another distant location. [01:45] 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. [02:00] as you probably know from waiting for water to boil. which is what you see after the system has had enough time to settle down. [02:14] In this case, temperature and pressure. equilibrium behavior as a function of the parameters. [02:27] there are actually at least 19 different types of ice. But that's beyond the scope of this video. there's something over here called a supercritical fluid, [02:41] This means that by moving the parameters through this region, you can actually get steam from water without ever witnessing A phase transition. which is a discretized model of a fluid [02:57] Here's what that looks like again. and each white pixel represents an empty space. We have a control panel here which also shows the phase diagram where we can [03:12] 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, [03:26] 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. [03:41] Temperature is paired up with energy, pressure is paired up with volume, and chemical potential is the thing which is paired up with the molecule count or the We'll get into the details of this later, but for now, [03:54] just know that if we have a system at a specific fixed temperature, and how it varies is determined by the specific temperature we set. [04:06] 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 [04:20] 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, [04:34] 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. [04:50] 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. [05:04] 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. the density of the molecules varies smoothly without a phase transition, [05:21] and this is like the supercritical fluid region of our real phase diagram. a phase transition begins to happen and the density goes from very low, [05:35] like a gas, to very high, like a liquid, skipping all the intermediate values. has to change gradually, and the phase transition doesn't happen all at once. [05:50] 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. [06:07] I want to introduce everything we need to really understand what's going on here. is how exactly does this simulation work? [06:21] most important formula in statistical the Boltzmann law. telling us the probability of each configuration x of molecules. [06:37] A first question you might have is why are we using randomness here at all? that might come from quantum mechanics. Even if the universe is truly deterministic, using randomness [06:50] to model systems with many particles can be extremely useful. Suppose we have 20 particles in a box with given initial positions and velocities. [07:02] 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. [07:17] Now let's suppose you close your eyes and take a 30 minute nap. What microstate will you observe when you wake up? Maybe you could do it if you had a computer. [07:29] But even a computer will start to struggle if we increase the particle count. particles took my computer multiple hours to make. If the number of particles was something like 10 billion or 10 to the power of 10. [07:47] And by the way, 10 billion isn't even close to the In just one teaspoon of water, the number of water To get a bit of a grasp on just how large this is. [08:04] 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. [08:16] I mean, people could tell the difference between water ice and steam far before anyone even knew that molecules existed. we really only care about the overall statistics of the molecules rather than their [08:33] This is the key motivation for the first main idea, which is approximating a deterministic microstate like this one by a random microstate. [08:45] 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. prove mathematically that this approximation is a good one in general. [09:03] 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. [09:16] 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 [09:28] of the negation of the energy of the microstate over over the temperature of the system. 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. [09:44] This is called Boltzmann's constant, and we'll just ignore it in this video. way that the numerical value of k is equal to 1. phase transitions can arise as we vary the temperature. [10:00] 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. [10:14] 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. [10:28] Lets use Omega E to denote the set of microstates with energy e. 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 [10:43] 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 [10:57] 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. [11:12] 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. [11:26] Let's take a minute to see how this minimization problem is solved. the entropy doesn't change the free energy by much. [11:39] 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. [11:54] at different temperatures this is done in different ways. phases of matter and the transitions between them. [12:07] 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, [12:21] 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 don't like to be too far apart. [12:35] 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. [12:49] In other words, we can actually write the energy of a microstate explicitly as minus the number of pairs of molecules which are adjacent. between each pair of adjacent molecules so that the energy is [13:06] You see. so our model isn't exactly a realistic fluid simulation. The main point of this model is to be as simple as [13:21] And at high and low temperatures, we can see two distinct behaviors emerging, At high temperatures, the molecules bounce around and mostly ignore one another, [13:34] So this is a gas macrostate. At low temperatures, though, the molecules start to clump up into a droplet. The energy of a droplet is much lower since there are more [13:49] pairs of adjacent molecules represented by green diamonds. there are far fewer configurations that look like this. box without considering the energy, there is basically no way [14:05] that you'd choose a configuration that looks like a droplet. since there are just more microstates that look like this, But at low temperatures, when you're considering energy as an important factor, [14:21] Notice that there are no macrostates with both low energy and high entropy. just minimize energy and maximize entropy simultaneously. [14:37] and that's determined by the temperature. I think this point that energy and entropy are in competition with each other, is the main takeaway of this video. [14:53] 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. [15:06] But we still haven't seen exactly why this is the correct formula. After that, we'll be ready to really understand what's going on in the simulations I've shown you so far. [15:19] It will actually take us a few steps to get to this formula for the Boltzmann we'll get a more precise Understanding of what temperature actually is, lets first consider a completely isolated system. [15:34] and so every possible microstate of this system has the same energy. the possible microstates of this system apart in any meaningful way. [15:49] 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 [16:02] 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. all microstates are equally likely will come up a few more times during our derivation [16:20] 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? [16:34] the temperatures of two things in contact with each other will equalize. This fact that temperature equalizes when things are [16:48] So let's try to figure out what quantity must To do this, let's formalize things a bit. which we'll call E1, and system two will have energy E2. [17:06] 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. [17:20] could be transferred from one system to the other. These small energy packets will continuously be transferred back and forth randomly, of energy packets from one system to the other. [17:36] Or in other words, when both directions are equally likely. packet will flow from one system to the other? so each microstate of the combined system is equally likely. [17:52] 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, [18:05] 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. [18:21] 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 [18:35] 1 with energy E1 and the set of microstates of system 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. [18:48] which is the log of the size of omega E1 E2. at their respective energies, which we'll denote by S1 and S2. [19:03] 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 [19:18] will be more likely to flow from system 2 to system 1. entropy can be written in terms of the derivatives of the two entropies as functions of the energies of the two systems. [19:31] 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 [19:44] Similar reasoning shows that energy is more likely to flow Remember, equilibrium is reached when energy is [19:56] This means that these two derivatives must be equal at equilibrium. This is the quantity which equalizes when systems are brought into contact. [20:08] But is this temperature? We usually think that energy flows from a hotter system to a colder one. value of this derivative to the system with the higher value. [20:26] So the derivative of entropy with respect to energy is actually one over temperature. let's just take a step back and review the math we just did. [20:38] 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 [20:51] than there are liquid microstates in our discretized simulation. when the derivative of entropy with respect to energy is small, adding or removing energy doesn't impact the number of microstates that much. [21:07] adding even a little bit of energy can increase the number of microstates by a lot. it makes sense for a high temperature system to donate energy to a low temperature [21:23] And this is how we understand temperature intuitively. for the Boltzmann distribution of a system at fixed temperature T. [21:35] One way is to put it in contact with a huge reservoir of energy at that temperature, The temperatures will equalize between our system and the heat bath, [21:49] but the temperature of the huge heat bath won't change by much at all. 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, [22:04] But again, the combined system of the heat bath plus the little system is isolated and has some fixed total energy, say E0. Again, this means that the probability that we see a particular [22:21] of microstates of the heat bath that are compatible with X. a microstate of the heat bath is compatible with a microstate X of the [22:35] 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. [22:49] This is the exponential of the entropy of the heat bath at this particular energy. energy as the little system needs without changing temperature. [23:02] the derivative of the entropy of the heat bath with respect to its energy is a constant, This means that the entropy of the heat bath at energy E 0 minus [23:17] 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. Since the exponential of S0 is a constant which doesn't depend on X, [23:35] And we find that the probability of X is proportional to the Exactly what we wanted. [23:47] This finishes the proof of Boltzmann's formula for the probability distribution that the simulation I've shown is sampling from. So far, we've been considering configurations where there are a fixed number of [24:02] 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 This mimics the fact that intermolecular forces have a sweet spot [24:15] where molecules prefer to be relatively close to each other. But just knowing the Boltzmann formula is not enough to actually sample from this distribution, at least not efficiently on a computer. [24:29] 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 [24:42] 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? [24:55] 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. changes to the picture that eventually lead to a proper sample. [25:10] Each time you shuffle, a little bit of randomness is added, and eventually you get a roughly uniform distribution on the arrangements of cards. and if there's a molecule in only one, we randomly decide whether [25:27] or not to switch the position of the molecule from one pixel to the other. Here's where we use our formula for the Boltzmann distribution. [25:39] 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. [25:52] 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, [26:07] So given that we've only got two choices and we know the ratio of their probabilities, probabilities have to add up to one. [26:19] 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. the probability that we swap the molecules. [26:34] Repeating this one step is the entire algorithm. here can actually be calculated quite easily. [26:46] 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. [26:58] I hope that by this point in the video, if you have some programming experience, 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 [27:11] One thing you might be wondering about is why don't we After all, that would be a more realistic choice, since we wouldn't have molecules teleporting all over the place. [27:25] be thought of as a simulation of real fluid dynamics. It's just a sort of random walk through the space of possible microstates. we do end up getting a sample that's very close to the Boltzmann distribution, [27:40] 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. [27:55] 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 [28:08] 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. [28:20] especially when we're going from high temperature to low temperature, since it takes the molecules a while to clump up. diagram similar to that of H2O in this region. [28:36] got temperature as a parameter, meaning the model we've been considering so far could only have a one dimensional phase diagram. but we're actually going to use a different second parameter for this video. [28:54] 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 [29:08] But in our simulation it might be a bit tough to 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. [29:23] The thing which equalizes is called the chemical potential. If you have some fancy setup with multiple different kinds of molecules, which will equalize when two systems are put into contact using a permeable wall, [29:38] 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 [29:51] 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 [30:06] chemical potential, and allow our system to exchange energy and molecules with the heat Using an argument similar to the one we used when deriving the formula for the microstate of our small system is now proportional to the exponential of the [30:22] negative of one over the temperature times the energy of the microstate plus the microstate. microstates with more molecules are favored and vice versa. [30:38] 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. [30:51] 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. [31:03] What this means is that each pixel can make its own decisions, meaning that this simulation can be run on the gpu. and we can change the temperature and the chemical potential on the fly in real time. [31:23] 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. [31:39] 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. [31:51] This is the supercritical fluid phase, which interpolates smoothly between liquid and gas. changing the temperature also makes the density change smoothly. [32:06] 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, And so the overall phase diagram looks like this. [32:20] with a phase transition line between a liquid phase and a gas phase, To me, this is pretty amazing. [32:33] 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 [32:45] much more complicated than just it's good when molecules are next to each other. that is qualitatively similar to something in the real world. which is the idea that most specific details of a model shouldn't actually [33:03] 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. [33:15] This is maybe the Second and final key point of this video. of the interesting behavior we can observe in this model, as well as some connections to other models you might have heard of. [33:30] as we cross the line of phase transition. Since the density can't change smoothly as a function of the chemical potential, always looks like either a liquid or a gas. [33:45] 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 [33:58] they look more round. of these bubbles as a function of temperature. Look up the wolf shape if you want to learn more. [34:12] 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, [34:25] This is because the phase transition actually needs If we artificially insert a big enough droplet, But without this kickstart, the droplets that arise naturally in [34:42] even though the liquid macrostate is the true phase at these parameters. 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. [34:58] remains in the wrong macrostate for a very long time if there's no external impulse, You might have seen something like this in real life, [35:10] but doesn't actually turn into ice until some external impulse starts a freezing chain reaction. the end of the phase transition line. [35:27] 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, meaning that it looks essentially the same, no matter how much you zoom out. [35:44] 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. [35:56] And at slightly lower temperatures, it becomes homogeneous with density either 1 or 0. the model doesn't seem to change anything. including the critical brain hypothesis, which hypothesizes that brains are in some [36:15] sense at criticality with the self similarity and multiscale structure, allowing for long range impulses and intercommunication in the brain without it being But that is far beyond the scope of this video. [36:31] Something slightly more accessible, which you might have heard of before, 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. [36:44] and there's an external field which also influences each element individually. the same model as the fluid we've been looking at this whole time. [36:58] Just identify a molecule with up and an empty space with down. potential as an external magnetic field over the whole magnet. [37:10] 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 is fixed to be down. and they lead to very interesting behavior, especially at the critical point, [37:27] 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, For now, let's just let them point in any direction in two dimensional space, [37:41] 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 [37:56] 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. [38:09] depending on the direction in which the colors change around the vortex. Interestingly, these vortices behave somewhat like positively and negatively [38:21] 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. [38:34] 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. [38:46] model is not as well understood as we might like. point is exactly one over two times log of one plus the square root of two. [39:00] only numerical approximation, and it's unclear if there will ever be a formula. realistic model of H2O in three dimensions is simply out of the question. [39:16] 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, [39:28] and adding all these extra details would certainly not make anything easier. For all of these reasons, we'll probably never have a precise like the fact that the melting point of ice is 273kelvin. [39:44] Rather than despair at this fact, we can, as mathematicians recognize that such a question is not really mathematical in nature to begin with. we can while still retaining core features. [39:58] 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. to the point where we can essentially completely understand it in a rigorous way using [40:17] I find the fact that we can do this without completely And in the second video we'll see exactly how the different phases arise and what makes a phase transition happen mathematically. [40:31] I hope to see you there.