Mutating and breeding function trees

In order to "breed" the most pretty pictures, we make their underlying functions undergo analogues of sexual and asexual reproduction.

Sexual reproduction is simulated by what is called crossover: given two function-trees a subtree from each is selected at random and then the subtrees are swapped. This is illustrated below:



Asexual reproduction is simulated by what is called mutation: given a function-tree, a node is selected at random. If it is a function node, then we replace the function with a random function taking the same arguments, and if it is a leaf then we replace the leaf with either a new random leaf or we can even grow a new subtree at that point. This is illustrated below:



Two forms of mutation are shown, in the first form, a leaf is replaced by a new subtree, and in the second a function node is changed to another function.

These are very simple ways to modify existing function-trees to produce "offspring". By using our imagination, ways different to and many variants of the above sexual and asexual reproduction methods can be conceived to produce a wide variety of offspring.