Theory of complexity: a gentle introduction

Reality is complex: please note that in the previous sentence complex has a very specific meaning; let’s just investigate a little more about it.

Image for post
Image for post
Photo by H Shaw on Unsplash


There is no general analytical solution to the three-body problem given by simple algebraic expressions and integrals: that is there is no compact way of represent the positions of the bodies.

Having an analytical solution would allow to forecast any future position of the bodies directly and precisely, furthermore it would also allow to “invert” the calculation letting us to answer, precisely, to the question “Where would the three bodies should be at time t₀ to meet here in such position in time tₙ?”

Image for post
Image for post
Three bodies subject to the gravitation laws, where they will end up?

Just to have a taste of how fast complexity arises consider that the Two-body problem does actually have an analytic solution that can be used to calculate the position of the two bodies starting from the initial conditions.

Other examples of problems where complexity arises are the following:

  • Cellular automata
  • Interactions within the terrestrial crust to forecast earthquakes
  • Weather forecast
  • Ecosystems in general, social systems and economical systems in details, for example
  • The complex interactions between our organs

You might instinctively see a pattern here: the more components are involved and the largest is the variety of interactions and relations between such elements, the more the complexity of the system is. In previous example just going from two bodies to three bodies makes things complex. Another characteristic of complex systems is that they usually present an emergent behavior: a complex behavior that cannot be forecast and that has not been forced by any of the laws the systems obey to.

Emergent behaviors

A nice example of this emergent behavior is displayed in the following video (you can play with the code from this repository on github)

Simulated flocks of birds aggregate in one single flock as an emergent behavior

In the video you can see a bunch some sort of simulated birds, birdoids, boids for short, or generally speaking, agents. Each of the agent obey to simple rules (you can read more here where the general idea was described):

1. Collision Avoidance: avoid collisions with nearby flockmates

2. Velocity Matching: attempt to match velocity with nearby flockmates

3. Flock Centering: attempt to stay close to nearby flockmates

The rules are simple, each of the agent take a decision by its limited awareness of the boids around it. There is no central coordination, there is not even a proper communication between the boids: they just keep an eye on the few flockmates that are around.

The emergent behavior is that soon or later scattered boids will end up in one single flock: the single flock will emerge even if it is not encoded in any of the rules followed by the boids.


So we have that boids are a complex system, that cannot be represented in a compact form, so it cannot be studied analytically, it is a form of n-body system, so even more complex than the three-body problem described above; we cannot analyze it but we can efficiently simulate it and by simulate I mean you can impose initial condition and check how it evolves.

Simulations are a powerful and effective tool to tackle complexity, they allow to wrap our mind around problems that you cannot state as equations, they enable you to check how your problems scale up when tens of components (agents, cars, planets etc…) are involved.

For example with Netlogo you can simulate the n-bodies problem, right into your browser

Image for post
Image for post
A 16-bodies problem running right in your browser


In conclusion, complexity is right behind the corner in a wide range of useful, interesting, funny, problems. A stimulating way to tackle the complexity is to setting up a simulation where you will be allowed to inspect your problem and forecast about how it scales and behave.


  1. Reynolds, Craig (1987). Flocks, herds and schools: A distributed behavioral model. SIGGRAPH ’87: Proceedings of the 14th Annual Conference on Computer Graphics and Interactive Techniques. Association for Computing Machinery. pp. 25–34.

Written by

Data Masseur, Distributed Systems Sculptor, and Scalability Evangelist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store