大型语言模型的Y组合子:用λ演算解决长上下文循环问题
The Y-Combinator for LLMs: Solving Long-Context Rot with λ-Calculus
March 20, 2026
作者: Amartya Roy, Rasul Tutunov, Xiaotong Ji, Matthieu Zimmer, Haitham Bou-Ammar
cs.AI
摘要
大型语言模型(LLM)正日益成为通用推理工具,但固定上下文窗口始终是长文本输入的瓶颈。递归语言模型(RLM)通过将提示外部化并递归求解子问题来解决这一难题。然而现有RLM依赖于开放式的读取-求值-输出循环(REPL),模型会生成任意控制代码,导致执行过程难以验证、预测和分析。
我们提出λ-RLM这一长上下文推理框架,用基于λ演算的类型化函数式运行时替代自由形式的递归代码生成。该框架执行经过预验证的小型组合子库,仅对有限叶子子问题使用神经推理,将递归推理转化为具有显式控制流的结构化函数式程序。我们证明λ-RLM能实现标准RLM缺失的形式化保障,包括终止性、闭式成本边界、随递归深度可控的精度缩放,以及简单成本模型下的最优划分规则。在四项长上下文推理任务和九个基础模型的实验中,λ-RLM在36组模型-任务对比中有29项优于标准RLM,跨模型层级的平均准确率最高提升21.9个百分点,延迟最高降低4.1倍。这些结果表明,类型化符号控制为长上下文推理提供了比开放式递归代码生成更可靠高效的基础。λ-RLM完整实现已开源:https://github.com/lambda-calculus-LLM/lambda-RLM。
English
LLMs are increasingly used as general-purpose reasoners, but long inputs remain bottlenecked by a fixed context window. Recursive Language Models (RLMs) address this by externalising the prompt and recursively solving subproblems. Yet existing RLMs depend on an open-ended read-eval-print loop (REPL) in which the model generates arbitrary control code, making execution difficult to verify, predict, and analyse.
We introduce λ-RLM, a framework for long-context reasoning that replaces free-form recursive code generation with a typed functional runtime grounded in λ-calculus. It executes a compact library of pre-verified combinators and uses neural inference only on bounded leaf subproblems, turning recursive reasoning into a structured functional program with explicit control flow. We show that λ-RLM admits formal guarantees absent from standard RLMs, including termination, closed-form cost bounds, controlled accuracy scaling with recursion depth, and an optimal partition rule under a simple cost model. Empirically, across four long-context reasoning tasks and nine base models, λ-RLM outperforms standard RLM in 29 of 36 model-task comparisons, improves average accuracy by up to +21.9 points across model tiers, and reduces latency by up to 4.1x. These results show that typed symbolic control yields a more reliable and efficient foundation for long-context reasoning than open-ended recursive code generation. The complete implementation of λ-RLM, is open-sourced for the community at: https://github.com/lambda-calculus-LLM/lambda-RLM.