Skip to main content
QUICK REVIEW

[Paper Review] More declarative tabling in Prolog using multi-prompt delimited control

Samer Abdallah|arXiv (Cornell University)|Aug 23, 2017
Logic, programming, and type systems7 references3 citations
TL;DR

This paper presents a more declarative approach to Prolog tabling using multi-prompt delimited control, inspired by Johnson's functional memoising parser combinators. It achieves incremental solution delivery with minimal code and performance within a factor of 2 of optimized existing systems, all while preserving Prolog's declarative style through continuation-based control operators in SWI 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.

Motivation & Objective

  • To implement Prolog tabling in a more declarative way by leveraging delimited control operators, avoiding low-level engine modifications or complex program transformations.
  • To enable incremental solution delivery from tabled predicates, rather than requiring all solutions before any are returned.
  • To achieve performance competitive with existing optimized tabling systems while maintaining code simplicity and adherence to Prolog's declarative core.
  • To demonstrate that a minimal set of targeted optimizations can yield performance within a factor of 2 of the current SWI Prolog tabling implementation.

Proposed method

  • Translating Johnson's functional memoising parser combinators into pure, declarative Prolog using continuation-passing style and delimited control.
  • Using SWI Prolog's multi-prompt delimited control operators (from Schrijvers et al., 2013) to suspend and resume computation threads, enabling efficient memoisation and tabling.
  • Introducing a shallow program transformation via the `table` directive to rename predicates and wrap calls in a `cctable/1` meta-call for tabling behavior.
  • Employing red-black trees (via SWI Prolog's `rbtrees`) and a store abstraction to manage memoization tables and mutable state in a controlled way.
  • Applying targeted optimizations such as key reuse and efficient reference management to improve performance without sacrificing declarativeness.
  • Leveraging the `tries` library for variant-based key matching, allowing memoization to work correctly even with variable-containing terms.

Experimental results

Research questions

  • RQ1Can tabling in Prolog be implemented more declaratively using only high-level control operators, without low-level engine support?
  • RQ2Can incremental solution delivery be achieved in tabled Prolog using delimited control, improving responsiveness in non-deterministic queries?
  • RQ3How does performance of a continuation-based tabling system compare to a highly optimized, low-level tabling implementation in SWI Prolog?
  • RQ4To what extent can a minimal codebase and declarative style be preserved while achieving competitive performance?

Key findings

  • The proposed tabling system delivers solutions incrementally, allowing early access to results without waiting for full solution enumeration.
  • The implementation requires significantly less code than previous continuation-based approaches and stays much closer to the declarative core of Prolog.
  • With only a small number of targeted optimizations, the system achieves performance within a factor of about 2 of the current optimized tabling implementation in SWI Prolog.
  • The use of multi-prompt delimited control enables efficient suspension and resumption of computation threads, effectively modeling the behavior of OLDT and SLG resolution.
  • The system correctly handles left-recursive and non-deterministic predicates by leveraging continuation-based memoisation, similar to Earley deduction and functional parser combinators.
  • The shallow program transformation via `table/1` directive enables transparent integration with existing Prolog code, preserving modularity and ease of use.

Better researchstarts right now

From reading papers to final review, dramatically reduce your research time.

No credit card · Free plan available

This review was created by AI and reviewed by human editors.