Functions as trees

Mathematical functions can be expressed as mathematical trees. Consider the function $ f(x) = (x+3)*x $. In tree form, this looks like



In computer science, like everything else, trees are upside-down. The nodes at the bottom are called leaves and the node at the top is called the root.

The function is evaluated starting at the leaves. The values of the leaves are passed to the function at the node above them to get new values, which are then passed up to the function above them, on so on until the root node is evaluated and the tree returns a value.

Thus in the example above, $ x $ and $ 3 $ are passed to the function $ + $ which computes $ (x+3) $, this is passed along with the right-most leaf $ x $ to the function $ * $ which computes the result of the tree $ (x+3)*x $.

By randomly choosing function nodes and at what point to place leaves, we can "grow" function trees.

The root of a function-tree which represents an image is a function which returns a pixel color and has 3 branches, one for each of the color components red, green, and blue. Lets call the root function $ rgb $, it will take 3 arguments, the amount of red, green, and blue. Imagining that when evaluated it will return a color, the function-tree for the pixel-color function looks abstractly like this



where the function $ rgb $ takes 3 values as input, one for each color component red, green, and blue. The picture illustrates the fact that each color is a separate subtree. Each subtree is some function which can depend on the pixel coordinates. Evaluating the $ rgb $ function for each coordinate in a plane generates an image as discussed in the last section.