I present a simple algorithm for enumerating the trees generated by a Context Free Grammar (CFG). The algorithm uses a pairing function to form a bijection between CFG derivations and natural numbers, so that trees can be uniquely decoded from counting. This provides a general way to number expressions in natural logical languages, and potentially can be extended to other combinatorial problems. I also show how this algorithm may be generalized to more general forms of derivation, including analogs of Lempel-Ziv coding on trees.
翻译:本文提出一种从上下文无关文法(CFG)生成树形结构的简单枚举算法。该算法利用配对函数在CFG推导过程与自然数之间建立双射关系,从而通过计数唯一解码出树形结构。此方法为自然逻辑语言中的表达式编号提供了通用途径,并可能推广至其他组合问题。同时,本文展示了该算法如何泛化至更一般的推导形式,包括树形结构上的Lempel-Ziv编码模拟。