Source-linked AI summary

WAMpy: Efficient Synthesis of Prolog Programs in Python

Dominik Magiera, Lukas Röhrig, Frank Jäkel

arXiv:2610.03234v1cs.PLcs.AI

TL;DR

General-purpose Prolog systems are not optimized for repeatedly compiling and evaluating candidate programs against unchanged background knowledge. WAMpy specializes Python-based Prolog execution for that setting, reporting approximately 38.5 times faster performance than Janus SWI-Prolog.

  • Problem

    General-purpose Prolog systems are not optimized for synthesis workloads that repeatedly compile and evaluate candidate programs while background knowledge remains unchanged.

    Source: §1 · p. 1
  • Method

    WAMpy is a Python framework that compiles Prolog into a targeted array-based WAM subset and recompiles candidate hypotheses against precompiled background knowledge.

    Source: §1 · p. 1, Efficient Partial Recompilation · p. 3
  • Results

    Approximately 38.5 times faster than Janus SWI-Prolog, WAMpy reports for program-synthesis workloads when leveraging partial recompilation.

    Source: Conclusion · p. 4
  • Takeaways & Limitations

    Broader Prolog support and evaluation on larger inductive logic programming benchmarks remain future work.

    Source: Conclusion · p. 4

    WAMpy implements only an X-register WAM subset and lacks a general SWI-Prolog built-in predicate library, including arithmetic and meta-calls.

    Source: Limitations · p. 3

Abstract

from arXiv · show

We present WAMpy, a Python framework optimized for synthesizing Prolog programs. Unlike general-purpose Prolog systems, WAMpy targets workloads that repeatedly generate and evaluate small candidate programs. WAMpy compiles Prolog clauses into NumPy array-based WAM instructions and supports partial recompilation of hypotheses against fixed background knowledge. Performance-critical routines are accelerated using Numba just-in-time (JIT) compilation. In a benchmark of repeated compilation-and-evaluation workloads, WAMpy improves end-to-end performance compared with SWI-Prolog accessed from Python using Janus.

1 Usage and Implementation

WAMpy is a Python library for synthesizing Prolog programs through repeated compilation and evaluation, using a targeted array-based WAM subset and Numba-accelerated routines. It reduces repeated compilation work by reusing compiled background knowledge and recompiling candidate hypotheses.

Usage.

  • WAMpy is used as a Python library rather than a standalone interpreter, and its high-level API handles parsing, compilation, and query backtracking.Source: Usage · p. 1
  • Uncompiled programs use fixed-layout NumPy arrays of separate top-level term ASTs, trading higher memory use for efficient Numba-compiled processing.The layout fixes upper bounds on terms, nodes per term, and children per node; symbol and child arrays store the AST data.Source: Implementation · p. 2

Implementation.

  • Compilation lowers ASTs into WAM instruction rows and a predicate entry table, while SLD resolution, unification, and backtracking evaluate queries.Multiple clauses use choice instructions, and built-in tracing of predicate calls can support candidate-hypothesis evaluation.Source: Implementation · p. 2
  • WAMpy compiles background knowledge once, then appends candidate clauses and uses WAM jump instructions to preserve backtracking into background clauses.A single background clause uses a JMP_TRUST bridge; predicates with multiple background clauses use JMP_RETRY.Source: Efficient Partial Recompilation · p. 3

Efficient Partial Recompilation.

  • WAMpy implements an X-register WAM subset for synthesis workloads, supporting terms, calls, tail calls, unification, and linear clause backtracking but not general built-ins such as arithmetic or meta-calls.Source: Limitations · p. 3

2 Evaluation

WAMpy’s evaluation tests core Prolog behavior and benchmarks repeated compilation and querying on a family-relation program. Both WAMpy compilation modes outperform Janus end to end, with partial recompilation increasingly reducing compilation time.

2 Evaluation

  • Pytest validates parsing, compilation, unification, backtracking, and query evaluation by checking that Prolog programs produce expected answers.Source: §2 · p. 3

Benchmark.

  • At higher iteration counts, WAMpy’s end-to-end runtime is (16.51 ± 0.13) µs with full compilation and (6.17 ± 0.03) µs with partial recompilation, versus Janus at around 240 µs.The paper summarizes the workload advantage as approximately 38.5 times faster than Janus when leveraging partial recompilation.Source: Figure 2 · p. 3, Benchmark · p. 4, Conclusion · p. 4
  • Partial recompilation reaches (3.64 ± 0.03) µs, compared with (13.98 ± 0.13) µs for full compilation.Both modes start at around 54 µs; the gap grows as the number of iterations increases.Source: Figure 2 · p. 3, Benchmark · p. 4
  • The benchmark uses 13 gender facts, 13 parent facts, and seven rules, with three hypothesis rules and 30 background clauses, repeatedly querying father(X, luke).It compares WAMpy with Janus 1.5.32 using SWI-Prolog 10.0.2 and Python 3.13, with 10 samples per iteration-count setting.Source: Benchmark · pp. 3–4
  • Future work will extend Prolog support, explore GPU acceleration with Numba CUDA, and evaluate larger inductive logic programming benchmarks.Source: Conclusion · p. 4
Loading 2610.03234v1…