EpistemicPhysics
All articles
Field note · Thermodynamics · Information

A coin, a magnet, and a learning machine

Follow a binary trial from coin flips into magnetic spins, Shannon compression, and neural gradient descent.

Picture three rooms situated along the same laboratory hallway.

In the first room, a statistician flips a fair coin repeatedly, logging the sequence of heads and tails in a notebook.

In the second room, a condensed matter physicist places a crystal of tiny magnetic dipoles inside a variable magnetic field, heating and cooling it in a thermal bath.

In the third room, a computer scientist trains a neural network on text, adjusting synaptic weights so the machine can predict whether an incoming sentence ends with a question mark.

At first glance, these three researchers seem to inhabit entirely separate scientific worlds. One is studying combinatorial chance, another is measuring thermodynamics, and the third is optimizing artificial intelligence.

Yet when I set their mathematical models side by side, an astonishing realization emerges: all three rooms are running the exact same equations. Each room investigates a binary event with two possible outcomes. Each room parameterizes that event using the hyperbolic rapidity coordinate of spacetime. And each room discovers that the curvature of its underlying potential is governed by Einstein’s relativistic Lorentz factor.

Let us walk through all three rooms together, following a single binary trial as it evolves from a counting puzzle into a thermodynamic magnet, an optimal data compressor, and an adaptive learning machine.

The three rooms: Coins, spins, and bits

Let us establish a universal mathematical notation for all three rooms.

Consider any elementary trial with two mutually exclusive outcomes, which we label positive (+1) and negative (−1).

Let p∈(0,1) denote the probability of the positive outcome, so that 1−p is the probability of the negative outcome.

In Epistemic Physics, we frequently switch between three complementary coordinates that describe this bias:

  1. The raw probability p∈(0,1).
  2. The centered epistemic velocity v∈(−1,1), which maps balance to the origin: v=2p−1=E[S], where S∈{−1,+1} is the discrete random outcome.
  3. The epistemic rapidity ρ∈(−∞,∞), which represents half the log-odds: ρ=12ln⁡(p1−p).

Inverting these definitions expresses probability and velocity in terms of rapidity:

p=eρeρ+e−ρ=11+e−2ρ,v=tanh⁡ρ.

Now recall the relativistic Lorentz factor γ(v)=1/1−v2. Using the fundamental hyperbolic identity 1−tanh2⁡ρ=1/cosh2⁡ρ:

γ=11−tanh2⁡ρ=cosh⁡ρ=eρ+e−ρ2.

Keep this hyperbolic cosine cosh⁡ρ in mind: it is the master key that unlocks every room in the laboratory.

Counting histories: Microstates and Shannon entropy

Let us step inside the first room, where our statistician is recording coin flips.

Suppose a notebook contains a summary of n trials, recording Y positive outcomes (heads) and N negative outcomes (tails), such that n=Y+N.

The summary records only the total counts, not the chronological sequence in which they arrived. How many distinct ordered histories (microstates) could have produced that exact summary?

This is the elementary binomial coefficient:

Ω(Y,N)=(nY)=n!Y!N!=n!Y!(n−Y)!.

Here the exclamation mark denotes the factorial (n!=n×(n−1)×⋯×1).

Notice how the number of compatible histories changes with balance:

  • If a sequence of six trials yields six heads and zero tails, there is only (66)=1 possible history: (+,+,+,+,+,+).
  • If the six trials split evenly into three heads and three tails, the number of compatible histories explodes to (63)=6×5×43×2×1=20 distinct orderings.

Balance opens up maximal combinatorial freedom.

When the number of recorded trials n becomes large, we can approximate the logarithm of the microstate count using Stirling’s asymptotic formula, ln⁡(k!)≈kln⁡k−k:

ln⁡Ω(Y,N)≈(nln⁡n−n)−(Yln⁡Y−Y)−(Nln⁡N−N)=nln⁡n−Yln⁡Y−Nln⁡N.

Divide both sides by n, and substitute the observed frequencies p=Y/n and 1−p=N/n:

1nln⁡Ω≈ln⁡n−Ynln⁡Y−Nnln⁡N=−Ynln⁡(Yn)−Nnln⁡(Nn).

This yields Claude Shannon’s famous binary entropy function, h(p):

1nln⁡Ω≈h(p)=−pln⁡p−(1−p)ln⁡(1−p).

Binary entropy measures the logarithmic volume of possible histories per trial. When natural logarithms are used, entropy is measured in nats; dividing by ln⁡2 converts the units into bits.

Entropy peaks at complete balance (p=1/2), where h(1/2)=ln⁡2≈0.693 nats=1.0 bit. At the boundaries (p→0 or p→1), entropy plunges to zero: a completely deterministic process produces zero surprise and permits only a single history.

The history cabinet

Make four histories from one notebook

Tap a head and a tail to swap them. Find 4 distinct orderings while preserving the notebook's totals.

The notebook always reads 3 H and 3 T

Choose an H, then a T. Their positions will trade.

Your history album · 1/20 slots

HHHTTT

There are 20 compatible histories in total. Album slots are a display limit, not a limit on possible histories.

Change the notebook and count all possible histories

Notebook size

0 heads6 headssame trial total

Exact log-count / trial

0.720 bits

Shannon limit / trial

1.000 bits
Ω=(nY),log2⁡Ω/n⟶H2(Y/n)

A Beta ledger for independent identically distributed trials retains counts, so all these orders yield the same final weights. Their tracelet order is still different. Exact finite log-count and the Shannon large-sample expression differ. An all-heads or all-tails notebook has only one history.

Thermal physics: The paramagnet in a heat bath

Now walk into the second room. Put away the coin, and inspect the physicist’s apparatus: a collection of non-interacting magnetic atoms (a paramagnet).

Each atom has an intrinsic magnetic dipole moment that can point in one of two directions along an applied magnetic field: spin up (s=+1) or spin down (s=−1).

An external magnetic field applies an energy bias ε. The energy of a spin state is:

Es=−εs.

If ε>0, pointing up is energetically favored (E+1=−ε), while pointing down is penalized (E−1=+ε).

The crystal sits inside a thermal reservoir at absolute temperature T>0. According to the Boltzmann distribution of statistical mechanics, the thermal probability of finding a dipole in state s is proportional to its Boltzmann factor e−Es/(kBT), where kB≈1.38×10−23 J/K is Boltzmann’s constant.

The sum of all state weights is the canonical partition function, denoted Z:

Z=∑s∈{−1,+1}e−Es/(kBT)=eε/(kBT)+e−ε/(kBT).

Now compare this formula with the rapidities from our first room!

Define the dimensionless physical rapidity as the ratio of magnetic field energy to thermal energy:

ρ=εkBT.

Substituting ρ into the partition function:

Z=eρ+e−ρ=2cosh⁡ρ.

Look at that: the physical partition function is twice the relativistic Lorentz factor!

The thermal probability of finding a spin pointing up is:

p=eε/(kBT)Z=eρeρ+e−ρ=11+e−2ρ.

The net magnetization (the average alignment per spin) is:

⟨s⟩=(+1)p+(−1)(1−p)=2p−1=tanh⁡ρ=v.

The magnetic alignment of a crystal is mathematically identical to the centered epistemic velocity of a coin!

When the temperature is high (kBT≫ε), thermal agitation dominates: rapidity vanishes (ρ→0), and the spins point up and down in equal numbers (v=0). When the temperature is low (kBT≪ε), the magnetic field freezes the dipoles into uniform alignment (ρ→∞,v→1).

Thermodynamic potentials: The Lorentz factor as curvature

In statistical physics, all thermodynamic properties of a system can be derived by differentiating a characteristic potential: the free energy, or its dimensionless counterpart, the log-partition function:

Λ(ρ)=ln⁡(Z2)=ln⁡cosh⁡ρ.

Let us differentiate this potential with respect to rapidity ρ:

The first derivative gives the expected velocity (magnetization):

Λ′(ρ)=ddρln⁡cosh⁡ρ=sinh⁡ρcosh⁡ρ=tanh⁡ρ=v.

The second derivative gives the response sensitivity (magnetic susceptibility, or variance):

Λ″(ρ)=ddρtanh⁡ρ=1−tanh2⁡ρ=1−v2=1γ2.

Look at that identity:

Λ″(ρ)=1γ2.

The curvature of the thermodynamic log-partition function is the inverse square of the Lorentz factor!

Near the balanced center (v=0,γ=1), the curvature is at its maximum (Λ″=1): a tiny increase in the applied field ρ produces a large, immediate change in alignment. Near saturation (|v|→1,γ→∞), the curvature vanishes: the spins are already pinned, and further field increases produce almost no change.

Now let us perform a Legendre transformation to switch perspectives. Instead of driving the system with an external force ρ, suppose we specify the internal state v and ask for the corresponding entropy cost.

Define the entropy deficit function Φ(v)=ln⁡2−h((1+v)/2), which measures how much order has been imposed relative to maximum entropy:

Φ(v)=vρ−Λ(ρ)=vartanh⁡(v)−ln⁡cosh⁡(artanh⁡v).

Differentiating Φ(v) with respect to velocity v:

Φ′(v)=ρ=artanh⁡(v).

Differentiating once more gives the stiffness (the resistance of the system to being displaced from balance):

Φ″(v)=ddvartanh⁡(v)=11−v2=γ2.

The two curvatures are exact reciprocal partners:

Λ″(ρ)×Φ″(v)=(1γ2)×(γ2)=1.

The curvature of order in state space is the relativistic Lorentz factor squared!

Where the system is easy to move in rapidity, it is flat in entropy deficit. Near the speed of light, the entropy deficit approaches the finite ceiling ln⁡2, while its slope and curvature climb toward infinity. The surprise is an infinitely steep edge to a finite hill: absolute certainty demands unbounded rapidity!

Optimal coding: Cross-entropy and the cost of being wrong

Now enter the third room. Here we meet the computer scientist, who is compressing data and training machine learning models.

Suppose the true environment produces positive outcomes with probability p. However, our observer or predictive model holds a subjective belief that positive outcomes occur with probability q.

According to Shannon’s source coding theorem, if an encoder designs an optimal prefix code tailored to an expected probability q, the ideal code length for an outcome that was expected with probability q is:

L=−ln⁡q nats=−log2⁡q bits.

Outcomes expected to be common are assigned short code words; outcomes expected to be rare receive long code words.

Now, what is the expected code length per trial when the true data source actually produces outcomes according to probability p?

This expected cost is the cross-entropy, C(p,q):

C(p,q)=−pln⁡q−(1−p)ln⁡(1−q).

We can decompose cross-entropy into two distinct components:

C(p,q)=h(p)+DKL(p∥q).

Here h(p)=−pln⁡p−(1−p)ln⁡(1−p) is the true binary entropy of the source: the unavoidable, irreducible randomness of the physical process itself.

The excess penalty, DKL(p∥q), is the Kullback-Leibler (KL) divergence, also called relative entropy:

DKL(p∥q)=pln⁡(pq)+(1−p)ln⁡(1−p1−q).

Look at what KL divergence measures: it is the informational tax you pay for using the wrong model of reality.

By Gibbs’ inequality, DKL(p∥q)≥0 always, with equality if and only if q=p.

The code kitchen

Pack a message with fewer wasted bits

Pick a prediction recipe for this source. Open its coding bill and see which part of the surprise you can remove.

Source 1 of 3

The source sends plus 80% of the time.

Free recipe mixing and the thermal connection p=11+e−2ρ,C(p,q)=H(p)+DKL(p‖q)

ρ is field energy divided by thermal energy in the two-state model. Costs here use base-two logs and are expected ideal code lengths for long independent blocks. There are no sampled trials or invented game points. The bars share one cost scale. Choosing a new recipe closes its bill until you inspect it.

Test this in the interactive lab above. Adjust the true probability p and the model’s prediction q. Watch how the total message length expands when the model’s expectations diverge from reality.

Let us see this in concrete numbers:

Suppose the world produces positive outcomes 90% of the time (p=0.90). The irreducible entropy of this source is:

h(0.90)=−(0.90)log2⁡(0.90)−(0.10)log2⁡(0.10)≈0.469 bits per trial.
  1. If the model knows the true distribution (q=0.90), its average description length is 0.469 bits. The penalty is zero.
  2. If the model is completely agnostic (q=0.50), it assigns 1 bit to every outcome. The penalty is DKL=1.000−0.469=0.531 bits wasted per trial.
  3. If the model is dogmatically wrong, predicting positive outcomes only 10% of the time (q=0.10), the expected code length leaps to: C(0.90,0.10)=−(0.90)log2⁡(0.10)−(0.10)log2⁡(0.90)≈3.005 bits per trial. The penalty is DKL≈3.005−0.469=2.536 bits wasted on every single observation!

Dogmatic misprediction is immensely expensive.

Gradient descent: How learning machines follow hyperbolic curves

How does an artificial neural network fix its mistakes?

Let the machine represent its prediction using its own internal rapidity parameter, η (eta):

η=12ln⁡(q1−q)⟹q=eηeη+e−η,vq=tanh⁡η.

Here η is an unconstrained parameter generated by the network’s final linear layer. It is half the usual binary logit z=ln⁡[q/(1−q)]: z=2η.

Now express the cross-entropy loss C(p,q) directly as a function of the model’s internal parameter η:

C(p,η)=−pln⁡(eηeη+e−η)−(1−p)ln⁡(e−ηeη+e−η).

Using elementary algebra:

C(p,η)=−p[η−ln⁡(2cosh⁡η)]−(1−p)[−η−ln⁡(2cosh⁡η)].

Combining terms:

C(p,η)=ln⁡(2cosh⁡η)−(2p−1)η=ln⁡(2cosh⁡η)−vη.

Look at that formula:

Cross-entropy loss in machine learning uses the same conjugate expression that builds the Legendre transform of a thermal paramagnet! The transform maximizes vη−ln⁡(2cosh⁡η) over η; minimizing its negative, our loss, gives h(p). At any prediction, the excess above that minimum is exactly the mismatch penalty DKL(p∥q).

Now compute the gradient of this loss with respect to the network’s parameter η:

∂C∂η=ddηln⁡(2cosh⁡η)−v=tanh⁡η−v=vq−v.

Look at how extraordinarily simple and elegant this gradient is:

∂C∂η=vq−v.

The learning force that drives gradient descent is simply the difference between the model’s predicted velocity vq and the environment’s true velocity v!

When the training data consists of individual discrete observations S∈{−1,+1}, the stochastic gradient on a single trial is:

g=vq−S.

If the network predicts vq=+0.80 and observes a positive trial (S=+1), the gradient is a small adjustment: g=0.80−1.00=−0.20.

If instead the network encounters an unexpected negative trial (S=−1), the gradient is a massive kick: g=0.80−(−1.00)=+1.80.

The machine takes a large stride in rapidity precisely when an observation strongly contradicts its prediction.

Rapidity steering

Steer a learner into the prediction gate

Choose the size of each learning step. Land within 0.01 extra bits per trial of the source. Big steps can cross the target.

Course 1 of 3 · Cross the track · step 0

Apricot learner

10.0%

Sky target

90%

The learner starts far from the target. How large a first step would you choose?

Inspect your route and the gradient rule
0: 10.0%
g=tanh⁡η−(2p−1),ηnext=η−λg

Current rapidity η = -1.099; gradient g = -1.600.

These are deterministic gradient steps against the source's expected outcome, rather than sampled trials or Beta evidence accumulation. The target measures excess expected log loss. A large gain can overshoot and need not reduce loss every time. Your route is capped at 30 steps; undo and replay remain available.

Spreading convictions: A physical lattice of learning minds

We have now traveled through all three rooms:

  • In the coin room, we discovered that microstate volume generates Shannon entropy h(p).
  • In the magnet room, we found that thermal partition functions Z=2cosh⁡ρ govern physical dipoles, with response sensitivity given by the inverse Lorentz factor Λ″=γ−2.
  • In the neural room, we showed that cross-entropy loss reproduces the exact same potential, driving gradient descent through the velocity error vq−v.

Now imagine combining all three rooms into a single physical system: a distributed lattice of learning agents.

Picture a two-dimensional grid where each node maintains an evidence notebook (α,β). Each node observes an incoming stream of noisy binary tracelets from its local environment, while communicating with its immediate neighbors.

When neighboring nodes disagree, the cross-entropy mismatch generates an informational shear force proportional to vi−vj. This force drives their internal rapidities toward consensus, exactly like the exchange interaction between magnetic spins in an Ising model:

  • At low informational temperature, the lattice exhibits spontaneous symmetry breaking: agents coalesce into vast, coherent domains of shared conviction.
  • At high temperature, random noise disrupts communication, dissolving the lattice into an uncommitted paramagnetic gas.
  • At the critical temperature, long-range correlations emerge: a single surprising observation at one corner can propagate like a phase wave across the entire collective network.

Such a world possesses three distinct physical stiffnesses:

  • Saturation stiffness: An element near certainty responds weakly to bias changes because its susceptibility vanishes (γ−2→0).
  • Inertial stiffness: A thick notebook with massive epistemic rest mass mE turns slowly because each incoming trial is divided by τ+1.
  • Information tension: A mismatched prediction incurs a steep cross-entropy cost, generating mechanical pressure to realign.

These are distinct physical mechanisms that we can place side by side and simulate.

Build the smallest toy version: two neighboring notebooks, a shared stream of binary events, and a coupling proportional to prediction mismatch. Watch whether agreement spreads like heat, travels like a wave, or freezes into competing domains.

Coins, magnets, and neural networks are not merely loose metaphors for one another. They are distinct physical manifestations of the same underlying information geometry. The equations have given us parts for a little physical world.

In our next excursion, we will follow this geometry into the cosmic fabric of spacetime in A universe written in two inks, where positive and negative evidence lay down the light cones of physical reality.