Our simulated gas is a two dimensional hard disk gas. Each molecule is
considered to have the same mass, and to collide elastically with each other
and any walls. The molecules do not rotate. The *x* and *y* positions and
momenta are stored in one array, and the coordinates of the end points of
each wall in another. Information about the state of the gas and demon is
saved in arrays and eventually saved on disk. The program is structured as
follows:

- Initialize variables
- Load coordinates and initial molecule positions and velocities
- Update gas for a specified number of collisions
- Calculation of the time of next collision
- Calculate when the demon makes its next observation
- Update of the positions to the time of next collision or observation
- Update of the momenta of any colliding molecules
- Perform demon's operation
- Calculate of the entropy of the system

- Save the entropy, final state, and demon's memory

The initialization of variables and loading of walls and molecule positions and velocities is self-explanatory. After the program has loaded the required information, the system is updated for a number of collisions specified by the user. Instead of updating the system in even time increments, which would have to be very small, the time increment over which the program steps is determined by the time until the next collision or the time until the next demon operation, whichever comes next. This is done by determining the time at which each molecule collides with each other molecule and each wall. Since the molecules are free when not colliding, there are general equations for the times of collision in each case, so the program can calculate these times very exactly (see appendix A; the geometry of a molecule-molecule collision is shown in Figure 6.). In cases where, for example, molecules do not collide with each other at all, the equation results in a complex or negative collision time. If the demon is scheduled to perform an action before the time of next collision, the state of the system is updated to that time instead.

If no collisions or demon operations occur between two times, and , in this interval the position of each molecule can be calculated exactly,

so that it is unnecessary to increment the model with smaller time steps. At the time of the next collision or demon operation, new momenta can be calculated using conservation of energy, linear momentum, and angular momentum. General expressions for the new momenta are derived in Appendix B. When the demon makes an observation, the result is recorded and the doors are moved appropriately.

At each demon operation, the entropy of the gas is calculated. The entropy of the gas is calculated by adding the individual entropies if each chamber. The tunnel is included in the chamber to which it is open.

The entropies of a gas of *N* molecules confined to an area *A* and having a
total energy *E* is calculated using the equation

where is . is Boltzmann's constant, which is set to so that the units of entropy will be in bits, the most easily calculated informational entropy units. This equation for entropy assumes that the molecules are not distinguished, which holds for this demon-gas system. The equation is only valid when the gas in the chamber is at equilibrium.

The entropy of the demon is not calculated by the program while it runs. Instead, the memory of the demon recorded on disk. Unlike the earlier analytically solved cases, the memory of the demon is not completely random. The time between the demon's observations of the gas is sufficiently small that there is some correlation between the observations, so the formula

where *n* is the number of bits of memory the demon used, will significantly
over-estimate the entropy of the demon.

A more accurate estimation can be made if the correlations are taken into account. If we treat the string of bits as if it were a Markov chain, we can take into account the correlation between each bit and the one following it. The correlation between neighboring bits can be determined by counting the number of occurrences of each pair of bits. For example, if the string we are examining is

then there are 7 occurrences of pairs of 0's followed by 0's, while there are only 3 occurrences of 0's followed by 1's. Each bit gives some information about the bit that follows it. By calculating how much information 1 and 0 gives, and how many 1's and 0's there are, the average information per bit can be calculated. If one knows this and the total number of bits in the message, the information content of the string can be calculated. By the noiseless coding theorem[1], one knows that this is approximately the length of the smallest string into which the string can be compressed. This method still only estimates the information content, since the demon's memory contains long-range correlations.

Mon Jun 16 13:53:44 EDT 1997