In 1968, a Hungarian botanist named Aristid Lindenmayer developed a grammarbased system to model the growth patterns of plants.
A Lindenmayer system, or LSystem, can be used to model the morphology of a variety of organisms and to generate selfsimilar fractal patterns.
As described by Benoit Mandelbrot, a fractal is “a rough or fragmented geometric shape that can be split into parts, each of which is (at least approximately) a reducedsize copy of the whole”.
Each part of a fractal is a reducedsize copy of the whole. ^{1}
It is clear that fractals’ geometry has a recursive nature, repeating itself in a selfsimilar way.
An Lsystem can be used to define fractals because at its core there is the idea of replacing parts of the whole using a set of replacing rules. It allows for obtaining complex fractals by applying recursion.
An Lsystem consists of:
 An alphabet composed of symbols that can be used to make strings.
For example, with the alphabet “AB”, any string in the Lsystem can only include these two characters.  An axiom consisting of a string (made of symbols from the alphabet). It is the initial state of the system.
For example, with the alphabet “AB”, some possible axioms are “A”, “ABB”, or “BAB”.  Rules: a collection of production rules that, when applied to each symbol, generates other strings. A rule is made of a predecessor and a successor.
For example, the rule “BB > ABA” replaces the occurrences of “BB” with “ABA”.
What does it look like in action?
A simple example
Let’s begin with a simple Lsystem: the original Lindenmayer’s Lsystem for modeling the growth of algae.
It is defined by:
Alphabet: A B
Axiom: A
Rules: (A → AB), (B → A)
We label the axiom as Generation 0, and consider each application of the rules as a new generation. By iteratively applying the rules to each generation we get:
Generation 0: A
Generation 1: AB
Generation 2: ABA
Generation 3: ABAAB
Generation 4: ABAABABA
...and so on...
How can we use this? Well, we can replace each letter of the alphabet with an action, meaning that we can visually represent the fractal by using drawing instructions.
However, we are not going to draw fractals here, as we are interested in hearing them instead.
An example with music
We are going to generate music using the Minor Pentatonic scale. We need to define the Lsystem first:
Alphabet: 1 2 3 4 5
Axiom: 1
Rules: (1 → 52), (2 → 13), (3 > 24), (4 > 35), (5 > 41)
The alphabet is composed by the scale degrees, the axiom is the first degree of the scale, and the rules replace each note with the previous and the next scale degrees.
The first five generations are:
Generation 0: 1
Generation 1: 52
Generation 2: 4113
Generation 3: 35525224
Generation 4: 2441411341131335
Generation 5: 13353552355252243552522452242441
If we start playing from C4, here is how this Lsystem sounds:
Generation 0
Generation 1
Generation 2
Generation 3
Generation 4
Generation 5
They don’t sound like memorable tunes, but the rules can be anything so it is a matter of tuning the system with better rules.
For example, more sophisticated rules could include the control of rhythm, awareness of phrases, and anything else you can think of.
I hope you found this interesting. See you in the next post!

Picture from The Nature of Code ↩