Table of Contents
Fetching ...

A Prolog Program for Bottom-up Evaluation

David S. Warren

TL;DR

The paper tackles bottom-up evaluation for positive Horn clause programs by presenting a Prolog metainterpreter that transforms object rules into implies/2 rules and processes them in a deterministic fixed-point loop using assert/1. It demonstrates the method on a transitive-closure example, discusses complexity and semi-naive behavior, and presents folding techniques to limit body sizes. The key contribution is a simple, executable Prolog implementation that illustrates bottom-up interpretation inside Prolog, useful for teaching, debugging, and understanding logic programs. The work highlights how procedural Prolog code can implement logical evaluation with clear semantics and minimal backtracking.

Abstract

This short paper describes a simple and intuitive Prolog program, a metainterpreter, that computes the bottom up meaning of a simple positive Horn clause definition. It involves a simple transformation of the object program rules into metarules, which are then used by a metainterpreter to compute bottom up the model of the original program. The resulting algorithm is a form of semi-naive bottom-up evaluation. We discuss various reasons why this Prolog program is particularly interesting. In particular, this is perhaps the only Prolog program for which I find the use of Prolog's assert/1 to be intrinsic, easily understood, and the best, most perspicuous, way to program an algorithm. This short paper might be best characterized as a Prolog programming pearl.

A Prolog Program for Bottom-up Evaluation

TL;DR

The paper tackles bottom-up evaluation for positive Horn clause programs by presenting a Prolog metainterpreter that transforms object rules into implies/2 rules and processes them in a deterministic fixed-point loop using assert/1. It demonstrates the method on a transitive-closure example, discusses complexity and semi-naive behavior, and presents folding techniques to limit body sizes. The key contribution is a simple, executable Prolog implementation that illustrates bottom-up interpretation inside Prolog, useful for teaching, debugging, and understanding logic programs. The work highlights how procedural Prolog code can implement logical evaluation with clear semantics and minimal backtracking.

Abstract

This short paper describes a simple and intuitive Prolog program, a metainterpreter, that computes the bottom up meaning of a simple positive Horn clause definition. It involves a simple transformation of the object program rules into metarules, which are then used by a metainterpreter to compute bottom up the model of the original program. The resulting algorithm is a form of semi-naive bottom-up evaluation. We discuss various reasons why this Prolog program is particularly interesting. In particular, this is perhaps the only Prolog program for which I find the use of Prolog's assert/1 to be intrinsic, easily understood, and the best, most perspicuous, way to program an algorithm. This short paper might be best characterized as a Prolog programming pearl.

Paper Structure

This paper contains 7 sections, 2 equations.