In beta reduction, one defines the value of the expression on the left to be that on the right:
- or (Replace all x in E(body) by y)
While this is a conceptually simple operation, the computational complexity of the step can be non-trivial: a naive algorithm would scan the expression E for all occurrences of the free variable x. Such an algorithm is clearly O(n) in the length of the expression E. Thus, one is motivated to somehow track the occurrences of the free variables in the expression. One may attempt to track the position of every free variable, wherever it may occur in the expression, but this can clearly become very costly in terms of storage; furthermore, it provides a level of detail that is not really needed. Director strings suggest that the correct model is to track free variables in a hierarchical fashion, by tracking their use in component terms.
Consider, for simplicity, a term algebra, that is, a collection of free variables, constants, and operators which may be freely combined. Assume that a term t takes the form
where f is a function, of arity n, with no free variables, and the are terms that may or may not contain free variables. Let V denote the set of all free variables that may occur in the set of all terms. The director is then the map
from the free variables to the power set of the set . The values taken by are simply a list of the indices of the in which a given free variable occurs. Thus, for example, if a free variable occurs in and but in no other terms, then one has .
Thus, for every term in the set of all terms T, one maintains a function , and instead of working only with terms t, one works with pairs . Thus, the time complexity of finding the free variables in t is traded for the space complexity of maintaining a list of the terms in which a variable occurs.