A Notation for Lambda Terms II: Refinements and Applications

Issues that are relevant to the representation of lambda terms in contexts where their intensions have to be manipulated are examined. The basis for such a representation is provided by the suspension notation for lambda terms that is described in a companion paper. This notation obviates $\alpha$-conversion in the comparison of terms by using the `nameless'' scheme of de Bruijn and also permits a delaying of substitutions by including a class of terms that encode other terms together with substitutions to be performed on them. The suspension notation contains a mechanism for `merging'' substitutions so that they can be effected in a common structure traversal. The mechanism is cumbersome to implement in its full generality and a simplification to it is considered. In particular, the old merging operations are eliminated in favor of new ones that capture some of their functionality and that permit a simplified syntax for terms. The resulting notation is refined by the addition of annotations to terms that serve to indicate whether or not they can be affected by substitutions generated by external $\beta$-contractions. These annotations permit substitutions to be performed trivially in certain situations, and can consequently lead to a conservation of space and time in a graph-based implementation of reduction. The use of the refined notation in the comparison of terms is then examined. The notion of head normal forms is generalized to its context and shown to be useful in checking terms for equality and a graph-based procedure for finding head normal forms is presented. This procedure is accompanied by a complete proof of its correctness and the tools of analysis afforded by our notation are used in this process. The relevance of the considerations here to an ongoing implementation of the language $\lambda$Prolog is discussed.