Sierpinski’s Triangle

Zach Wolpe
Analytics Vidhya
Published in
3 min readNov 24, 2019

Why Triangles will Change you see the World

Sierpinski’s triangle is an algorithm that demonstrates an interesting property of randomness (Python).

The key takeaway is that a seemingly complex pattern emerges from an extremely simple — partially random — pattern.

What other complex structures could be broken down into such a simple mechanism?

The Algorithm

The Sierpinski’s triangle works with 3 points, however, other interest patterns can emerge with more (K) points. Below are the steps to the algorithm.

Here are the steps for the 3 (and K) dimensional case:

  1. Randomly place K points on the plane.
  2. Pick a RANDOM location point on the plane to set as the current ‘focal point’
  3. Select one of the K nodes at RANDOM
  4. Compute & mark the half-way point (Euclidean distance) between the focal point & the selected node
  5. Set the marked point as the new focal point
  6. Repeat steps 3-to-5 many times (10'000+)

Philosophy

Intuitively, we do not expect anything miraculous or interesting to arise from this random pattern. However, when we run the algorithm the stunning results bring about 2 questions:

Complexity & Emergence

  • what other processes (fractals, organic/biological systems, etc) can be derived from emergent complexity? (see my article on elementary cellular automata)

Mathematical Simplicity

  • Linked to the beforementioned, where else in nature, society, industry or elsewhere can we fully describe the complex systems with simple algorithms? Algorithms far simpler than the system’s apparent constituents.

Randomness

  • Intuitively it is strange how such a structured system is derived from a set of rules governed by random events. This, in a non-trivial way, begs questions about the nature of deterministic systems & their relationship with stochastic processes.

Implementation

Let's implement the algorithm in Python.

K=3 nodes

3 Randomly placed nodes

Execute the algorithm, as stated above

Visualize the results

Sierpinski’s Triangle: emergent from randomness

Yes, that appeared through our randomizing algorithm. This type of pattern is called a Sierpinski Triangle and is an example of a fractal (a pattern that repeats itself indefinitely).

Extending the implementation to K nodes

We can write an algorithm that dynamically changes, allowing for any number of input nodes to be specified,

Execute the K node function, change the variable ‘points’ and run the code to see the newly generated patterns.

K=4 nodes

Barnsley's Fern

A more complex example of an algorithm that depends on randomness and produces marvelous results is ‘Barnley’s Fern’.

Essentially we have 6 starting points, forming 2 triangles, and move between the points with some known probability — again calculating and marking midpoints in the same manner. A full description is available here.

Barnsley’s Fern

Conclusion

Perhaps these emergent, complex, random, fractal sequences can open your mind to new thought mechanisms.

Both challenging your preconceived intuition about the relationship between randomness & determinism, & opening your mind to ideas of complexity & emergent phenomena.

--

--