Lsystem
An Lsystem or Lindenmayer system is a parallel rewriting system and a type of formal grammar. An Lsystem consists of an alphabet of symbols that can be used to make strings, a collection of production rules that expand each symbol into some larger string of symbols, an initial "axiom" string from which to begin construction, and a mechanism for translating the generated strings into geometric structures. Lsystems were introduced and developed in 1968 by Aristid Lindenmayer, a Hungarian theoretical biologist and botanist at the University of Utrecht. Lindenmayer used Lsystems to describe the behaviour of plant cells and to model the growth processes of plant development. Lsystems have also been used to model the morphology of a variety of organisms^{[1]} and can be used to generate selfsimilar fractals such as iterated function systems.
Origins
As a biologist, Lindenmayer worked with yeast and filamentous fungi and studied the growth patterns of various types of algae, such as the cyanobacteria Anabaena catenula. Originally the Lsystems were devised to provide a formal description of the development of such simple multicellular organisms, and to illustrate the neighbourhood relationships between plant cells. Later on, this system was extended to describe higher plants and complex branching structures.
Lsystem structure
The recursive nature of the Lsystem rules leads to selfsimilarity and thereby, fractallike forms are easy to describe with an Lsystem. Plant models and naturallooking organic forms are easy to define, as by increasing the recursion level the form slowly 'grows' and becomes more complex. Lindenmayer systems are also popular in the generation of artificial life.
Lsystem grammars are very similar to the semiThue grammar (see Chomsky hierarchy). Lsystems are now commonly known as parametric L systems, defined as a tuple
 G = (V, ω, P),
where
 V (the alphabet) is a set of symbols containing both elements that can be replaced (variables) and those which cannot be replaced ("constants" or "terminals")
 ω (start, axiom or initiator) is a string of symbols from V defining the initial state of the system
 P is a set of production rules or productions defining the way variables can be replaced with combinations of constants and other variables. A production consists of two strings, the predecessor and the successor. For any symbol A which is a member of the set V which does not appear on the left hand side of a production in P, the identity production A → A is assumed; these symbols are called constants or terminals. (See Law of identity).
The rules of the Lsystem grammar are applied iteratively starting from the initial state. As many rules as possible are applied simultaneously, per iteration. The fact that each iteration employs as many rules as possible differentiates an Lsystem from a formal language generated by a formal grammar, which applies only one rule per iteration. If the production rules were to be applied only one at a time, one would quite simply generate a language, rather than an Lsystem. Thus, Lsystems are strict subsets of languages.
An Lsystem is contextfree if each production rule refers only to an individual symbol and not to its neighbours. Contextfree Lsystems are thus specified by a contextfree grammar. If a rule depends not only on a single symbol but also on its neighbours, it is termed a contextsensitive Lsystem.
If there is exactly one production for each symbol, then the Lsystem is said to be deterministic (a deterministic contextfree Lsystem is popularly called a D0L system). If there are several, and each is chosen with a certain probability during each iteration, then it is a stochastic Lsystem.
Using Lsystems for generating graphical images requires that the symbols in the model refer to elements of a drawing on the computer screen. For example, the program Fractint uses turtle graphics (similar to those in the Logo programming language) to produce screen images. It interprets each constant in an Lsystem model as a turtle command.
Examples of Lsystems
Example 1: Algae
Lindenmayer's original Lsystem for modelling the growth of algae.
 variables : A B
 constants : none
 axiom : A
 rules : (A → AB), (B → A)
which produces:
 n = 0 : A
 n = 1 : AB
 n = 2 : ABA
 n = 3 : ABAAB
 n = 4 : ABAABABA
 n = 5 : ABAABABAABAAB
 n = 6 : ABAABABAABAABABAABABA
 n = 7 : ABAABABAABAABABAABABAABAABABAABAAB
Example 1: Algae, explained
n=0: A start (axiom/initiator) / \ n=1: A B the initial single A spawned into AB by rule (A → AB), rule (B → A) couldn't be applied / \ n=2: A B A former string AB with all rules applied, A spawned into AB again, former B turned into A /  \ n=3: A B A A B note all A's producing a copy of themselves in the first place, then a B, which turns ... /  \ \ \ n=4: A B A A B A B A ... into an A one generation later, starting to spawn/repeat/recurse then
The result is the sequence of Fibonacci words. If we count the length of each string, we obtain the famous Fibonacci sequence of numbers (skipping the first 1, due to our choice of axiom):
 1 2 3 5 8 13 21 34 55 89 ...
For each string, if we count the kth position from the left end of the string, the value is determined by whether a multiple of the golden ratio falls within the interval . The ratio of A to B likewise converges to the golden mean.
This example yields the same result (in terms of the length of each string, not the sequence of As and Bs) if the rule (A → AB) is replaced with (A → BA), except that the strings are mirrored.
This sequence is a locally catenative sequence because , where is the nth generation.
Example 2: Pythagoras tree
 variables : 0, 1
 constants: [, ]
 axiom : 0
 rules : (1 → 11), (0 → 1[0]0)
The shape is built by recursively feeding the axiom through the production rules. Each character of the input string is checked against the rule list to determine which character or string to replace it with in the output string. In this example, a '1' in the input string becomes '11' in the output string, while '[' remains the same. Applying this to the axiom of '0', we get:
axiom:  0 
1st recursion:  1[0]0 
2nd recursion:  11[1[0]0]1[0]0 
3rd recursion:  1111[11[1[0]0]1[0]0]11[1[0]0]1[0]0 
… 
We can see that this string quickly grows in size and complexity. This string can be drawn as an image by using turtle graphics, where each symbol is assigned a graphical operation for the turtle to perform. For example, in the sample above, the turtle may be given the following instructions:
 0: draw a line segment ending in a leaf
 1: draw a line segment
 [: push position and angle, turn left 45 degrees
 ]: pop position and angle, turn right 45 degrees
The push and pop refer to a LIFO stack (more technical grammar would have separate symbols for "push position" and "turn left"). When the turtle interpretation encounters a '[', the current position and angle are saved, and are then restored when the interpretation encounters a ']'. If multiple values have been "pushed," then a "pop" restores the most recently saved values. Applying the graphical rules listed above to the earlier recursion, we get:

Example 3: Cantor set
 variables : A B
 constants : none
 start : A {starting character string}
 rules : (A → ABA), (B → BBB)
Let A mean "draw forward" and B mean "move forward".
This produces the famous Cantor's fractal set on a real straight line R.
Example 4: Koch curve
A variant of the Koch curve which uses only right angles.
 variables : F
 constants : + −
 start : F
 rules : (F → F+F−F−F+F)
Here, F means "draw forward", + means "turn left 90°", and − means "turn right 90°" (see turtle graphics).
 n = 0:
 F
 n = 1:
 F+F−F−F+F
 n = 2:
 F+F−F−F+F + F+F−F−F+F − F+F−F−F+F − F+F−F−F+F + F+F−F−F+F
 n = 3:
 F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F +
 F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F −
 F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F −
 F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F +
 F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F
Example 5: Sierpinski triangle
The Sierpinski triangle drawn using an Lsystem.
 variables : F G
 constants : + −
 start : F−G−G
 rules : (F → F−G+F+G−F), (G → GG)
 angle : 120°
Here, F and G both mean "draw forward", + means "turn left by angle", and − means "turn right by angle".
 n = 2
 n = 4
 n = 6
It is also possible to approximate the Sierpinski triangle using a Sierpiński arrowhead curve Lsystem.
 variables : A B
 constants : + −
 start : A
 rules : (A → +B−A−B+), (B → −A+B+A−)
 angle : 60°
Here, A and B both mean "draw forward", + means "turn left by angle", and − means "turn right by angle" (see turtle graphics).
Example 6: Dragon curve
The dragon curve drawn using an Lsystem.
 variables : X Y
 constants : F + −
 start : FX
 rules : (X → X+YF+), (Y → −FX−Y)
 angle : 90°
Here, F means "draw forward", − means "turn left 90°", and + means "turn right 90°". X and Y do not correspond to any drawing action and are only used to control the evolution of the curve.
Example 7: Fractal plant
 variables : X F
 constants : + − [ ]
 start : X
 rules : (X → F−[[X]+X]+F[+FX]−X), (F → FF)
 angle : 25°
Here, F means "draw forward", − means "turn left 25°", and + means "turn right 25°". X does not correspond to any drawing action and is used to control the evolution of the curve. The square bracket "[" corresponds to saving the current values for position and angle, which are restored when the corresponding "]" is executed.
Variations
A number of elaborations on this basic Lsystem technique have been developed which can be used in conjunction with each other. Among these are stochastic grammars, context sensitive grammars, and parametric grammars.
Stochastic grammars
The grammar model we have discussed thus far has been deterministic—that is, given any symbol in the grammar's alphabet, there has been exactly one production rule, which is always chosen, and always performs the same conversion. One alternative is to specify more than one production rule for a symbol, giving each a probability of occurring. For example, in the grammar of Example 2, we could change the rule for rewriting "0" from:
 0 → 1[0]0
to a probabilistic rule:
 0 (0.5) → 1[0]0
 0 (0.5) → 0
Under this production, whenever a "0" is encountered during string rewriting, there would be a 50% chance it would behave as previously described, and a 50% chance it would not change during production. When a stochastic grammar is used in an evolutionary context, it is advisable to incorporate a random seed into the genotype, so that the stochastic properties of the image remain constant between generations.
Context sensitive grammars
A context sensitive production rule looks not only at the symbol it is modifying, but the symbols on the string appearing before and after it. For instance, the production rule:
 b < a > c → aa
transforms "a" to "aa", but only If the "a" occurs between a "b" and a "c" in the input string:
 …bac…
As with stochastic productions, there are multiple productions to handle symbols in different contexts. If no production rule can be found for a given context, the identity production is assumed, and the symbol does not change on transformation. If contextsensitive and contextfree productions both exist within the same grammar, the contextsensitive production is assumed to take precedence when it is applicable.
Parametric grammars
In a parametric grammar, each symbol in the alphabet has a parameter list associated with it. A symbol coupled with its parameter list is called a module, and a string in a parametric grammar is a series of modules. An example string might be:
 a(0,1)[b(0,0)]a(1,2)
The parameters can be used by the drawing functions, and also by the production rules. The production rules can use the parameters in two ways: first, in a conditional statement determining whether the rule will apply, and second, the production rule can modify the actual parameters. For example, look at:
 a(x,y) : x == 0 → a(1, y+1)b(2,3)
The module a(x,y) undergoes transformation under this production rule if the conditional x=0 is met. For example, a(0,2) would undergo transformation, and a(1,2) would not.
In the transformation portion of the production rule, the parameters as well as entire modules can be affected. In the above example, the module b(x,y) is added to the string, with initial parameters (2,3). Also, the parameters of the already existing module are transformed. Under the above production rule,
 a(0,2)
Becomes
 a(1,3)b(2,3)
as the "x" parameter of a(x,y) is explicitly transformed to a "1" and the "y" parameter of a is incremented by one.
Parametric grammars allow line lengths and branching angles to be determined by the grammar, rather than the turtle interpretation methods. Also, if age is given as a parameter for a module, rules can change depending on the age of a plant segment, allowing animations of the entire lifecycle of the tree to be created.
Open problems
There are many open problems involving studies of Lsystems. For example:
 Characterisation of all the deterministic contextfree Lsystems which are locally catenative. (A complete solution is known only in the case where there are only two variables). ^{[2]}
 Given a structure, find an Lsystem that can produce that structure.
Types of Lsystems
Lsystems on the real line R:
Wellknown Lsystems on a plane R^{2} are:
 spacefilling curves (Hilbert curve, Peano's curves, Dekking's church, kolams),
 median spacefilling curves (Lévy C curve, HarterHeighway dragon curve, DavisKnuth terdragon),
 tilings (sphinx tiling, Penrose tiling),
 trees, plants, and the like.
Books
 Przemysław Prusinkiewicz, Aristid Lindenmayer – The Algorithmic Beauty of Plants PDF version available here for free
 Grzegorz Rozenberg, Arto Salomaa – Lindenmayer Systems: Impacts on Theoretical Computer Science, Computer Graphics, and Developmental Biology ISBN 9783540553205
 D.S. Ebert, F.K. Musgrave, et al. – Texturing and Modeling: A Procedural Approach, ISBN 0122287304
 Burry, Jane, Burry Mark, (2010). The New Mathematics of Architecture, New York: Thames and Hudson.
 Aristid Lindenmayer, "Mathematical models for cellular interaction in development." J. Theoret. Biology, 18:280—315, 1968.
See also
Wikimedia Commons has media related to LSystems. 
 Digital morphogenesis
 Fractal
 Iterated function system
 Hilbert curve
 Stochastic contextfree grammar
 SpeedTree
Notes
 ↑ Grzegorz Rozenberg and Arto Salomaa. The mathematical theory of L systems (Academic Press, New York, 1980). ISBN 0125971400
 ↑ Lila Kari. L systems. Pg. 11
External links
 Algorithmic Botany at the University of Calgary
 Branching: Lsystem Tree A Java applet and its source code (open source) of the botanical tree growth simulation using the Lsystem.
 Fractint LSystem True Fractals
 "powerPlant" an opensource landscape modelling software
 Fractint home page
 A simple Lsystems generator (Windows)
 Lyndyhop: another simple Lsystems generator (Windows & Mac)
 An evolutionary Lsystems generator (anyos*)
 eXtended LSystems (XL), Relational Growth Grammars, and opensource software platform GroIMP.
 A JAVA applet with many fractal figures generated by Lsystems.
 My Graphics – an iPhone/iPad app that generates several Lsystem graphics patterns.
 Musical Lsystems: Theory and applications about using Lsystems to generate musical structures, from waveforms to macroforms.
 Online experiments with LSystems using JSXGraph (JavaScript)
 Flea A Ruby implementation of LSYSTEM, using a Domain Specific Language instead of terse generator commands
 Lindenmayer power A plant and fractal generator using Lsystems (JavaScript)
 Rozenberg, G.; Salomaa, A. (2001), "Lsystems", in Hazewinkel, Michiel, Encyclopedia of Mathematics, Springer, ISBN 9781556080104
 Laurens Lapré's LParser
 HTML5 LSystems – try out experiments online
 The vectorgraphics program Inkscape features an LSystem Parser
 Complexity of LSystem
 An implementation of a Lsystem parser and simple turtle graphics in the Icon programming language
 A Lindenmeyer System Generator by Nolan Carroll
 Bloogen: LSystems with a genetic twist