On Bijective Encodings of Compressed de Bruijn Terms and Tree-based Number Systems Paul Tarau Department of Computer Science and Engineering University of North Texas tarau@cs.unt.edu Abstract. We introduce a compression mechanism for the de Bruijn representation of lambda terms. In combination with a tree-based num- ber system, we use it for a bijective size-proportionate G¨odel number- ing scheme that combines into a uniform representation natural number arithmetic with generation and normalization of lambda terms. Keywords: lambda calculus, de Bruijn indices, lambda term compres- sion, tree-based numbering systems, ranking and unranking of lambda terms, normalization with higher order abstract syntax. 1 Introduction A joke about the de Bruijn indices representation of lambda terms [1] is that it can be used to tell apart Battlestar Galactica’s Cylons from humans. Arguably, the compressed de Bruijn representation that we introduce in this paper is taking this fictional use one step further. To alleviate the legitimate fears of our human readers, this representation will be bijectively mapped to the conventional ones, while simplifying the underlying combinatorial structure of lambda terms. It will also facilitate their (bijective) natural number encodings - known to combinato- rialists as ranking / unranking functions and to logicians as G¨odelnumberings. Such encodings, going back to Ackermann’s bijection between natural numbers and hereditarily finite sets [2], are relatively easy to design if one does not care about one side of the bijection exponentially exploding in size. With significant effort, such size-proportionate bijections between term algebras and the set of natural numbers represented with the usual binary notation are defined in [3], using ranking of balanced parentheses languages and a generalization of Cantor’s pairing function [4] to tuples. However, the binary search and complex compu- tations involved in the ranking algorithms limit the encoding described in [3] to relatively small terms and numbers not larger than about 2000 bits. This paper takes a more revolutionary approach. Instead of trying to adjust the bijective G¨ odel numbering scheme to be size-proportionate, we will replace its target: our natural numbers will be represented as binary trees (a member of the Catalan family of combinatorial objects) on which the usual arithmetic oper- ations will be defined ([5], also submission #82 to this conference.) As a result, encodings of lambda terms, that can be seen as a tree-to-tree transformation, are naturally size-proportionate.