# 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.

# Complexity

Complexity theory has been inspired by some famous problems that come to the attention of the scientific community in the final decades of ‘800. One famous instance of such a family of problems is the Three-body problem: let pick three *bodies* in space (planets, satellites, etc…); we know that they are subject to the gravitational laws; to simplify things let consider them far away from each other object, so we can suppose that gravitational laws are applied just to them three; given the initial positions and velocities of such bodies we want calculate their positions in any successive moment in time.

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ₙ?”

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)

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.

# Simulations

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

# Conclusion

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.

# References

- 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.