Skip to main content
QUICK REVIEW

[论文解读] More declarative tabling in Prolog using multi-prompt delimited control

Samer Abdallah|arXiv (Cornell University)|Aug 23, 2017
Logic, programming, and type systems参考文献 7被引用 3
一句话总结

本文提出了一种基于多提示限定控制的更声明式 Prolog 表格化方法,受 Johnson 的函数式记忆解析组合子启发。该方法以极少的代码实现增量解交付,性能仅比现有优化系统慢约 2 倍,同时通过 SWI Prolog 中基于延续的控制操作符,保持了 Prolog 的声明式风格。

ABSTRACT

Several Prolog implementations include a facility for tabling, an alternative resolution strategy which uses memoisation to avoid redundant duplication of computations. Until relatively recently, tabling has required either low-level support in the underlying Prolog engine, or extensive program transormation (de Guzman et al., 2008). An alternative approach is to augment Prolog with low level support for continuation capturing control operators, particularly delimited continuations, which have been investigated in the field of functional programming and found to be capable of supporting a wide variety of computational effects within an otherwise declarative language. This technical report describes an implementation of tabling in SWI Prolog based on delimited control operators for Prolog recently introduced by Schrijvers et al. (2013). In comparison with a previous implementation of tabling for SWI Prolog using delimited control (Desouter et al., 2015), this approach, based on the functional memoising parser combinators of Johnson (1995), stays closer to the declarative core of Prolog, requires less code, and is able to deliver solutions from systems of tabled predicates incrementally (as opposed to finding all solutions before delivering any to the rest of the program). A collection of benchmarks shows that a small number of carefully targeted optimisations yields performance within a factor of about 2 of the optimised version of Desouter et al.'s system currently included in SWI Prolog.

研究动机与目标

  • 通过利用限定控制操作符,以更声明式的方式实现 Prolog 表格化,避免低级别引擎修改或复杂程序变换。
  • 实现来自表格化谓词的增量解交付,而非必须在返回任何解之前枚举全部解。
  • 在保持代码简洁性和 Prolog 声明式核心的前提下,实现与现有优化表格化系统相当的性能。
  • 证明仅通过一组有针对性的优化,即可使性能达到当前 SWI Prolog 表格化实现的约 2 倍以内。

提出的方法

  • 将 Johnson 的函数式记忆解析组合子翻译为纯声明式 Prolog,使用传递延续风格和限定控制。
  • 使用 SWI Prolog 的多提示限定控制操作符(来自 Schrijvers 等,2013 年)来挂起和恢复计算线程,实现高效的记忆化与表格化。
  • 通过 `table` 指令引入轻量级程序变换,重命名谓词,并将调用包装在 `cctable/1` 通用调用中以实现表格化行为。
  • 使用红黑树(通过 SWI Prolog 的 `rbtrees`)和存储抽象,以受控方式管理记忆化表格和可变状态。
  • 应用针对性优化,如键复用和高效引用管理,以提升性能,同时不牺牲声明性。
  • 利用 `tries` 库实现基于变体的键匹配,使记忆化在包含变量的项上也能正确工作。

实验结果

研究问题

  • RQ1是否可以仅使用高层控制操作符,无需底层引擎支持,以更声明式的方式实现 Prolog 中的表格化?
  • RQ2是否可以使用限定控制在表格化 Prolog 中实现增量解交付,从而提升非确定性查询的响应能力?
  • RQ3基于延续的表格化系统性能与高度优化的低层表格化实现(在 SWI Prolog 中)相比如何?
  • RQ4在保持竞争性性能的同时,能够多大程度上保留极简的代码库和声明式风格?

主要发现

  • 所提出的表格化系统可实现增量解交付,允许在无需等待完整解枚举的情况下提前获取结果。
  • 与以往基于延续的方法相比,该实现所需代码量显著减少,且更贴近 Prolog 的声明式核心。
  • 仅通过少量有针对性的优化,系统性能即可达到当前 SWI Prolog 优化表格化实现的约 2 倍以内。
  • 多提示限定控制的使用实现了计算线程的高效挂起与恢复,有效模拟了 OLDT 和 SLG 求解的行为。
  • 通过基于延续的记忆化,系统正确处理了左递归和非确定性谓词,类似于 Earley 推理和函数式解析组合子。
  • 通过 `table/1` 指令实现的轻量级程序变换,实现了与现有 Prolog 代码的透明集成,保持了模块化和易用性。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。