THE SCIENCE OF
COMPLEXITY

LET'S START

Author
Maxime Dherbécourt
26 August 2025
25 minutes read
On a summer night, you lie in a field looking at fireflies lighting up the sky. At first, their flashes seem random, erratic. But wait long enough, and you see magic happening: these tiny lanterns start to pulse in unison, creating waves of light that ripple through the darkness.
Not far from here, school of fishes swim through the seas with a similar grace. Each fish moves independently, yet together they form fluid, coordinated pattern, almost like a dance.
And back in your own hands, even a simple magnet carries these mysteries: countless atoms inside cooperate to create a single, unified magnetism.
What ties these scenes together? How does order emerge, where we only expect disorder to happen? This, is the story I want to tell you.
But there's also a second story, one just as important: how theory itself is built. We often picture scientists as people who know every answer there is. In reality, theory is a slow and complex process: you build a model, test it against the world, find where it fails, and refine it again. It takes time, patience, and imagination. So let yourself be guided along this article, ask yourself questions when proposed to, and step by step you'll discover how science is crafted.
By the end of this journey, you won't just see magnets, fireflies, and fishes differently. You will see patterns, and most importantly, know why they happen. You'll also see how theorists, and especially physicists, think, and why their work often unfolds in small, steady steps rather than sudden leaps.
And without any longer introduction, let's begin.

From the physics of magnetism...

What is a magnet?

Before diving into the science of complexity, let's start by exploring a simple yet fascinating example: magnets. You will see that this example is not only interesting in itself, but also serves as a perfect introduction.
Question
What is a magnet? Really, try to give a definition.
Your first instinct might be something like
Open quote
A magnet is an object with a north and a south pole that attracts or repels other magnets.
Close quote
Magnets attraction and repulsion
Here below is the first interactive simulation of this article.
Use the slider to change the distance between the magnets, and release it to see the effect. You can also click on a magnet to change its orientation.
Loading simulation....

Separation

Question
But let's ask again: What is a magnet, really?
I'm not sure about you, but I find this definition a bit unsatisfactory. Moreover, this definition doesn't explain some properties:
  • Do you know that, when you cut a magnet in half, you don't end up with a positive half and a negative half? Instead, you get two smaller magnets, each with its own positive and negative pole. Why is that?
  • Have you noticed that when a magnet gets hot, it stops working? Why does this happen?
In this first part, we'll explore all of these. As you'll see, the explanation is more subtle than it might appear, and it will lead us into some fascinating concepts in physics.

Zooming into matter

Zooming on a magnet
Let's try to discover the secrets of a magnet by zooming in to uncover what lies inside. Use the slider below to zoom in and out.

A simple magnet with a positive and negative pole.

Zoom

Question
So... are atoms really tiny magnets?
I mean... sort of! In fact, there are two different sources of magnetism in an atom:
  • Each electron has a property called spin. Imagine it as a tiny arrow attached to the electron, pointing in a certain direction ... although the electron doesn't literally spin. This arrow is then capable of producing its own magnetism, just like a tiny magnet.
  • Electrons also move around the nucleus. Since a moving electric charge creates magnetism (this is what's called induction), this motion also contributes to the atom's overall magnetism.
In short, let's simplify and think of atoms as tiny arrow-shaped magnets. The tip of the arrow points to the north, and the tail points to the south.
Now, a magnet contains an enormous number of atoms... and even more electrons! So the real question is
Question
How do all these tiny arrows end up working together? Shouldn't they just point in random directions, canceling each other out? And this is where the magic starts.
Magnets Interaction
Try to change the orientation of the central atom's spin using the slider below, and see how the other spins react.
Loading simulation....

Rotation

As you can see, atom's spins prefer to point in the same direction as their neighbors.
For more informations...

A deeper look

To understand why, we need to dip into the realm of quantum physics. At very small scales, particules are not just tiny balls: they are described by a mathematical object called a wave function. Think of it as a sort of fuzzy cloud that represents the probability of finding the particle at a certain place. Like water waves, two wave functions can interfere, combining to form bigger waves or canceling each other out.
Since electrons all carry the same negative charge, they repel each other. In a solid, the Pauli exclusion principle forces their wave functions into certain arrangements. In some cases, the lowest-energy state occurs when neighboring spins are aligned. This effect is called the exchange interactions. It is not a new "fundamental" force, but rather a consequence of the wave nature of particles and their interactions.
Theorist Corner
Ok, that's a lot to take in. Let's put on our theorist hat. How could we summarise what we have learnt so far, simplifying as much as possible, without loosing the essence of the physics behind?
Try to think about it a bit. These parts are the real challenge of this article!
Let's strip this down to its essence. A magnet consists of many atoms arranged in a regular pattern.
  • Suppose we have N atoms, that we identify using the letter j that runs from 1 to N.
  • To simplify, we model each atom as a single arrow pointing in a given direction. We call this the atom's spin, and write it as S_j.
  • Let's make it even simpler: Suppose each arrow can only point up that we write as S_j =\,+1, or down where S_j =\,-1.
  • Finally, we describe the evolution of our system over time by saying that each spin prefers to align with its nearest neighbors.
For more informations...

Energy minimization

In physics, a core principle is that systems tend to minimize their energy. In our case, the energy of a given atom j can be written asE_j = - J \sum_{j'\ \in\ \mathrm{neighbors\ of\ } j} S_j\, S_{j'},where J is a positive constant that represents the strength of the interaction between neighboring arrows. From this relation, if S_j and S_{j'} are aligned (both +1 or both -1), the energy is negative, meaning that this configuration is better for the system. If they are opposite, the energy is positive. This means that, as we wanted, the system prefers to align the spins.
In quantum mechanics, energy minimization is a fundamental principle. Instead of talking about the total energy E of the system, we use the letter H and call it the Hamiltonian. Here, it is the sum of the energies of all the atoms in the system:H = - J \sum_{j=1}^N \sum_{j'\, \in\, \mathrm{neighbors\ of\ } j} S_j\, S_{j'}.
Question
But how do we actually measure the magnetism of a magnet?
For this, we need to define the total magnetization that we write as M, which is what we usually mean when we talk about how strong a magnet is and in which direction it is pointing. It is simply the average of all the spins' orientations, a sort of average arrow, defined asM = \frac{1}{N} \sum_{j=1}^N S_j.
Note
The division by N keeps M between +1 and -1, making it easy to interpret. Again, the tip of the arrow points to the north, and the tail points to the south.
And... voilà! We can now summarize our model into a simple algorithm:
  1. Pick a random atom j anywhere in the grid.
  2. Consider flipping its arrow, but don't actually do it yet. First, check how this change would affect the system.
    • If the flip increases alignment with neighbors, accept it.
    • If it decreases alignment, reject it.
  3. Repeat many times.
Magnets simulation
This is a simulation of the model we just built. It shows a grid of arrows, each representing an atom's spin. A red arrow represents a spin pointing up (S_j =\,+1), while a blue arrow represents a spin pointing down (S_j =\,-1).
Finally, the big arrow on the side represents the total magnetization M of the system, which is the average of all the spins' orientations. The bigger it is, the stronger the magnet.
Nice, we have our model... or do we really? Let's look at our checklist of what we wanted to simulate:
  • North and south poles. - The magnetization, represented by the big arrow.
  • Attraction and repulsion between magnets. - If we had another magnet, their big arrows would tend to align together.
  • Cutting a magnet in two. - Each half still has its own big arrow, so each is still a magnet.
  • Magnets stop working when hot.
Shoot! We still have one thing to explain.
Question
Why does heating destroy magnetism?
Theorist Corner
That's how theory works!
You build a model, see where it matches reality, and then notice where it doesn't. You then try to fix the model by adding new elements that you think will help.
So here's your challenge: How would you add temperature to our model? What effect would it have on each arrow?

The crucial role of temperature

Temperature, that we will write using the letter T, can be thought of as shaking the arrows. In this article, we will call it, more generally, noise. The higher the temperature, the more the spins jostle.
In our model, to include temperature, we imagine the system evolving according to the following steps:
  1. Pick a random atom j anywhere in the grid.
  2. Consider flipping its arrow, but don't actually do it yet. First, check how this change would affect the system.
    • If the flip increases alignment with neighbors, accept it.
    • If it decreases alignment, don't reject it outright. Instead, generate a random number that depends on T. At higher temperatures, this number is more likely to be large. If the random number exceeds a threshold, accept it. This represents the effect of thermal fluctuations that can sometimes overcome the alignment.
  3. Repeat many times.
Note
These algorithms are called Monte-Carlo simulations, powerful methods in physics.
Enough theory! Let's see what happens with temperature in practice.
Ising Model
The implementation of the above algorithm.
Try to change the temperature using the slider below.

Temperature

That's better! At high temperature, the arrows are jumbled, and the total magnetization is zero as before. However, below a certain critical temperature, the arrows suddenly align, and the total magnetization becomes large: we have a magnet!
Note
We also observe patches of aligned spins below this critical value. These patches are called magnetic domains, and are a key feature of real magnets. Our model even made a new prediction that is experimentally found!
Now, let's try to better characterize what's happening. To do this, we will measure the total magnetization more precisely for different temperatures and plot it on a graph.
Magnetization temperature variation
Try clicking on the graph to see how the magnets internal structure changes and how the total magnetization varies with temperature.
We observe what we saw earlier: there is a sudden change in the magnetization starting from a certain critical temperature:
  • Below, the magnet is ordered, and M \simeq \pm 1. This means that the arrows are aligned, and the magnet works.
  • Above, it is disordered, and M \simeq 0. This means that the arrows are jumbled, and the magnet doesn't work.
This process is called a phase transition, and it is a fundamental concept in physics. Here, it explains why magnets stop working when overheated: the thermal fluctuations become so strong that they win compared to the alignment of the arrows, leading to a disordered state and killing the magnetism.
Note
The model we used here is called the Ising model. Despite its simplicity, it is a cornerstone of statistical physics and complexity science. A lot of research has been and continues to be conducted on this model and its variants.
There are a lot of phase transitions in nature, as we will see in the rest of this article: You even know one! It occurs while boiling water: At 100°C, when the water abruptly changes from liquid to a gas.
To finish this first part, let me insist again on what we just saw. Magnets are made of countless atoms, each with its own tiny magnetic arrow that we call spin.
A priori, we expected that these arrows would point in random directions, canceling each other out. However, this is only what happens at high temperature. Below a certain temperature, the atoms' spins suddenly start to cooperate and work together, aligning themselves in the same direction and as a result producing what we usually call magnets. This sudden change is called a phase transition and is a fundamental concept in physics.

Temperature

We saw that even with constant noise, a collective order can emerge. This is a key idea in the science of complexity:
Open quote
Simple rules at the scale of a few individuals can give rise to rich and complex organizational patterns at large scales.
Close quote

...through the synchronized flashing of fireflies...

Fireflies?

Question
Did you ever see fireflies flashing in the night? If so, did you notice anything special about them?
If you did, you might have noticed that their light seems to blink in a synchronized manner, almost like a dance.
What if I told you that, using just a very slightly modified version of what we just saw, we can explain this synchronized flashing of fireflies?

Extending the Ising model

Theorist Corner
So far, we saw how to describe magnets using the Ising model.
But I just told you that using a generalization of this model, we could also describe fireflies. Try to think about how we could do this.
Let's first talk about the Ising model, again. Trust me on this. A core approximation that we did was to consider the spins of every atoms (their tiny arrows) only either pointing up or down, that is S_j = \pm 1. However, in real life, spins are not limited to just two values: they can point in any direction.
Note
Here, we represent 2D spins to simplify the simulations, but the model can be extended to 3D spins.
To simplify a bit, instead of talking about vectors, we describe each atom by an angle to, let's say, the horizontal axis. Therefore, instead of using \color{electron}{S}_j to describe the atom j, we use the angle \color{electron}{\theta}_j. What is nice about this, is that now this angle is no longer just \pi/2 (up where S_j =\,+1) or -\pi/2 (down where S_j =\,-1), but can take any value in between, making it continuous.
We can now rewrite our earlier algorithm as the equation\frac{\mathrm{d}\color{electron}{\theta}_j}{\mathrm{d}t} = \color{coupling}{K} \sum_{j' \mathrm{\ that\ are}\atop \mathrm{\ neighbors\ of\ } j} \sin(\color{electron}{\theta}_{j'} - \color{electron}{\theta}_j).Let's break this down:
  • The notation \mathrm{d}\color{electron}{\theta}_j/\mathrm{d}t means that we are looking at how the angle of j changes over time.
  • The term \sin(\color{electron}{\theta}_{j'} - \color{electron}{\theta}_j) tells us about the interactions:
    • If the angle of j is larger than the angle of j' (j is ahead of j'), the sinus is negative, so \color{electron}{\theta}_j will tend to decrease: j will try to slow down for j'.
    • Conversely, if the angle of j is lower compared to the one of j' (j is behind j'), the sinus is positive, so \color{electron}{\theta}_j will tend to increase: j will try to catch up with j'.
  • The positive interaction strength constant \color{coupling}{K} measures how strongly the neighbors influence each other. If K is large, the arrows will tend to align more quickly than if it's small.
2D Ising Model
Here below is the simulation of this 2D Ising model, where each atom is represented as an arrow. Try to change the interaction strength K using the slider, and see what happens.

   Interaction

And... I think that we forgot about our last, and most important, ingredient!
Question
Where is the temperature?
To add it, we can simply add a term in \sqrt{\color{temperature}{T}} times a factor \eta(t). This \eta(t) term will randomly change the angle of each atom at each time t, simulating the effect of thermal fluctuation.
For more informations...

Temperature dependence

The fact that we took the square root of the temperature is a bit technical, but it is a common way to model thermal fluctuations in physics. These types of equations are called stochastic spin dynamics, and here more particularly, the Langevin-Landau-Gilbert equation.
So our final equation becomes the so-called XY model\frac{\mathrm{d}\color{electron}{\theta}_j}{\mathrm{d}t} = \color{coupling}{K} \sum_{j' \mathrm{\ that\ are}\atop \mathrm{\ neighbors\ of\ } j} \sin(\color{electron}{\theta}_{j'} - \color{electron}{\theta}_j) + \eta(t) \sqrt{\color{temperature}{T}}.
XY Model
The same model as before, but now with the temperature T. Try to play with these two sliders. Now, the arrows should be moving around.

Temperature

   Interaction

As I don't want to go into too much detail in this article, let's continue by finally talking about... fireflies!
For more informations...

BKT transition

The main difference with the previous 1D Ising model is that the XY model has a continuous symmetry, meaning that the arrows can point in any direction, not just up or down.
A mathematical theorem known as the Mermin-Wagner theorem, explains why this continuous symmetry is important:
  • For 3D spins, we recover a phase transition pretty similar to the Ising one.
  • For 2D spins, however, a new phase transition appears, called the Berezinski-Kosterlitz-Thouless (BKT) transition, which is a bit more subtle than the one we saw in the Ising model. It is no longer a simple change from ordered to disordered, but rather a change in the nature of the order itself.

The synchronisation of fireflies

Theorist Corner
That's very nice, but what does it have to do with fireflies?
Let's start by thinking about it for a bit.
First let's change our perspective a little. Instead of thinking of a firefly as a complex organism, we can think of it as a little arrow that constantly rotates. When it is, let's say, pointing up, the firefly flashes.
So now, synchronisation of flashes of fireflies can be seen as if the little arrows of the fireflies are trying to align with each other... And this is exactly what the XY model describes!
Note
Biologically, fireflies try to mimic the flashing rate of their neighbors. This occurs to be a strategy to maximize the chances of finding a mate, or reduce predation risk: a predator seeing a whole group of flashing fireflies might be confused, and not be able to focus on a single one.
One Firefly
One firefly is represented by a rotating arrow. When the arrow is up, it flashes.
Try to change the noise T using the slider to see how much the arrow is shaken around.

Noise

We can then use the same model as for magnetism, with a slight change of perspective:
  • Fireflies are not atoms arranged in a regular grid. They can freely move in all directions. Moreover, a neighbor of a firefly is now described as any other firefly that is close enough to it.
  • The noise T, previously represented how much the arrows were shaken around due to temperature fluctuations. Now, this noise describes how much the fireflies are independent.
  • The interaction strength K now describes how strongly a given firefly wants to align with its neighbors.
And... that's it! Just a change of interpretation, nothing more.
Fireflies Synchronisation
Here is the simulation of the fireflies described by our model.
You can change the noise and the interaction strength using the two sliders, and tick the box to show the individual arrows of each firefly.

Interaction

        Noise

Question
Hum... why are they never flashing?
Oops! We forgot to add in our equation that each little arrow now rotates continuously over time. We write the speed of the rotation of each firefly as \color{electron}{\omega}_j. So let's add this to our model that becomes\frac{\mathrm{d}\color{electron}{\theta}_j}{\mathrm{d}t} = \color{electron}{\omega}_j + \color{coupling}{K} \sum_{j' \mathrm{\ that\ are}\atop \mathrm{\ neighbors\ of\ } j} \sin(\color{electron}{\theta}_{j'} - \color{electron}{\theta}_j) + \eta(t) \sqrt{\color{temperature}{T}}.
Note
Here, we took the frequency \omega_j of each firefly from a Gaussian distribution.
Fireflies Synchronisation
The same as before, but now with the intrinsic rotation of each firefly activated.
Try to play with the interaction strength slider and see what happens!

Interaction

        Noise

Note
In this simulation, the constant displacement of each firefly isn't relevant. I just added it to make the simulation more visually appealing.
If you paid attention, you just saw that the fireflies start to flash in unison when the interaction strength is large enough. However, below a certain threshold, they suddenly stop synchronizing and flash independently. Does this remind you of something? Again, a phase transition!
Theorist Corner
So now, how do we characterize this?
How do we know when the fireflies are synchronized or not?
The first thing that we can do is put each arrow on one big circle, to see how they are distributed.
Order parameter
The same simulation as before, but we now only draw the arrows of each firefly on a circle. This allows us to see how the arrows are distributed.
Try to change the interaction strength using the slider.

Interaction

        Noise

To measure the amount of synchronisation, we can use the same idea as before and define a sort of mean arrow. The length of the arrow now tells us how synchronized the fireflies are: if it is close to 1, they are all flashing in unison. However, if it is closer to 0, they are flashing independently.
For more informations...

Mathematical definition

Mathematically, we can define this mean arrow as a complex number \color{electron}{R} \mathrm{e}^{\mathrm{i}\Phi}, where R is the length of the arrow and \Phi is its angle\color{electron}{R} \mathrm{e}^{\mathrm{i}\Phi} = \frac{1}{N} \sum_{j=1}^N e^{\mathrm{i} \color{electron}{\theta}_j}.
So why not simply take the average of the angles? Because angles are periodic, meaning that if we take the average of two angles that are close to 0 and 2\pi, we would get something close to \pi, which is not what we want. Instead, we use complex numbers to represent the angles, which allows us to take into account this periodic nature.
Order parameter
Same as before, but now we also draw the mean arrow in white that represents the amount of synchronisation.

Interaction

        Noise

Then, you guessed it, let's measure this synchronisation amount (the length of the mean arrow) for different values of the interaction strength.
Note
You can also do this for the noise, but will see that it is not as interesting. Here, the main parameter that drives the phase transition, the order parameter, is the interaction strength.
Synchronisation measurement
Try clicking on the graph to see how the fireflies synchronisation amount changes varies with the interaction strength.
Again, what you see is what we observed earlier. There is a sudden change in the synchronisation amount at a certain interaction strength. Below this value, the fireflies are not synchronized, while above it, they flash in unison.
What we observe is then another... phase transition! You guessed it.
Note
This model, called the Kuramoto model, can also be used to describe many other systems, such as neurons firing in the brain, or even the synchronisation of power grids.
Let's recap what we have learned so far. Magnets, fireflies, neurons, power grids... all these systems can be described by a very similar model. And they all exhibit something called a phase transition for a certain parameter (temperature, interaction strength, etc.) which consist of a sudden change in their behavior.
To finish with this article, let's take a look at one last example, which is for me the most visually striking one, fishes.

...to the coordinated swimming of fishes

Fish schools

Let me start by telling you that fishes and fireflies are the... same thing!
Question
Wait, what? I'm not really sure about that...
Okay, not really, I agree. Still, let's look at their similarities. In nature, fishes in oceans often travel in schools, meaning that they move together in a coordinated manner.
Theorist Corner
Now, you guessed it, how can we modify our previous model to describe this behavior?
And how can we characterize the schooliness of fishes?

The Vicsek model

Let's start by recalling what the two previous models were about. Each atom's spin or firefly was an arrow that wanted to align with its neighbors. It however also had to fight against noise that randomly changed its orientation. Note that in the Kuramoto model, these arrows were also constantly rotating.
Reinterpreting these models, we introduce the Vicsek model:
  • The arrows are no longer spins of atoms or fireflies, but rather fishes, and they do no longer rotate anymore over time. The head of the arrow is the fish head, and the tail is... its tail.
  • The fishes can move freely in space.
  • The noise again represents how much the arrows is shaken around, that is how much the fishes are independent.
  • The interaction strength is now how strongly a given fish wants to align with its neighbors.
Finally, the equation that describes how the angle \color{electron}{\theta}_j of a given fish j evolves over time is\frac{\mathrm{d}\color{electron}{\theta}_j}{\mathrm{d}t} = \color{coupling}{K} \sum_{j' \mathrm{\ that\ are}\atop \mathrm{\ neighbors\ of\ } j} \sin(\color{electron}{\theta}_{j'} - \color{electron}{\theta}_j) + \eta(t) \sqrt{\color{temperature}{T}}.
Note
Note how we only changed our view again, and that the equation stayed (almost) exactly the same!
For more informations...

Velocity and position update

The way we handle the movement of the fishes is a bit more complex than just updating their angle. At each time, we first update each \color{electron}{\theta}_j of every fish, and then update their position \color{magnet}{\mathbf{r}}_j, according to the relation\color{magnet}{\mathbf{r}}_j(t + \Delta t) = \color{magnet}{\mathbf{r}}_j(t) + v_0 \Delta t \left( \cos \color{electron}{\theta}_j(t),\, \sin \color{electron}{\theta}_j(t) \right),where we assume that each fish swims at a constant speed v_0. Without entering into too many details, this update scheme is very typical in simulations. It is called the Euler method, and can be directly derived from Newton's laws of motion.
Fish schools
Here is a simulation of the Vicsek model. You can change the interaction strength and noise using the sliders. You can also toggle the display of the internal structure of the fishes (the arrows) using the checkbox.

Interaction

        Noise

Theorist Corner
Time from your last job of the day! Try to change the interaction strength and see how it affects the behavior of the fish school. How could we characterize this effect more precisely?

Characterizing the schooliness of fishes

As you can see, the fishes start to swim in a coordinated manner when the interaction strength is above a certain threshold. To characterize this flocking behavior, we can take a look at the average direction of the fishes, the same way as before.
We again define a mean arrow following the same procedure that we already did two times! The length of the arrow now tells us how coordinated the fishes are:
  • If the length is close to one, they are all swimming in the same direction.
  • If the length is close to zero, they are swimming independently.
Finally, you know the deal, let's plot how this order parameter evolves as a function of the interaction strength.
Note
We could also plot it as a function of the noise strength: the two values are directly related!
What we observe is a sudden change in the coordination amount at a certain amount of interaction strength... again! Above this threshold, fishes swim in a coordinated manner, while below it, they swim independently... again!
This, is a phase transition... again! With just a slightly different model, but with a new physical interpretation, how awesome is that? Alright, we could go on with other variations or model applications, but I think you get the point: it's time to wrap up this article.

Conclusion

In this article, we explored three different examples of systems in nature: magnets, fireflies and fishes. A priori, these systems are very different and do not have much in common. Every individual in a system should behave in a completely independent manner, and should have its own specific rules and behavior.
However, if we vary a given parameter (temperature, interactions, noise), we observe that below (or above) a certain value, the individuals behave independently, while above (or below), they coordinate with each other. This common phenomenon is what we call a phase transition. It is a universal behavior that is found everywhere in nature, with magnets, fireflies, fishes, birds, herds of animals, and even humans!
And what we did in this article is pretty impressive! Using a common set of rules and a common mathematical model, we were able to explain very different behaviors of very different systems by very similar mechanisms. This is the power of theoretical physics!
I also hope that you understand a bit more the scientific method and especially how theorists work, as it is often a gray zone for many: they build models for a given phenomenon, test them, try to understand the results, see where they match reality... and then notice where they don't! They then try to modify their model to better fit reality, and explore other phenomena that could be explained by their model. This never-ending process is what takes lots of time, but it is also what leads to a deeper understanding of the world around us.

Sources

Thank you for reading this article! I hope you enjoyed it and learned something new, please share it online or to some friends!
If you want to see more content like this, sneak peeks of my work, tutorials or behind the scenes content, you can consider supporting me on my Patreon. And if you have any question, suggestion or feedback, feel free to reach out to me using the form below or on the Patreon.