[Paper Review] Pure Prolog Execution in 21 Rules
This paper presents a formal 21-rule calculus, S:PP, for pure Prolog execution using a 4-port model (call, exit, fail, redo) to capture control flow. It models execution states via two stacks—an ancestor stack (A-stack) and a bet stack (B-stack)—enabling both forward and backward derivation, with modularity that supports formal reasoning about program properties such as correctness and transformation adequacy.
A simple mathematical definition of the 4-port model for pure Prolog is given. The model combines the intuition of ports with a compact representation of execution state. Forward and backward derivation steps are possible. The model satisfies a modularity claim, making it suitable for formal reasoning.
Motivation & Objective
- To provide a formal, mathematically rigorous definition of Prolog's 4-port control flow (call, exit, fail, redo) that is amenable to formal reasoning.
- To overcome the theoretical ambiguity of ports in Prolog by defining them as transitions between execution events, grounded in state changes.
- To establish a modular execution model that supports both forward and backward derivation steps, crucial for program analysis and debugging.
- To enable formal verification of program properties such as adequacy and non-interference in program transformations.
- To extend the model to full Prolog control flow, with a prototype already implemented, while focusing on pure Prolog in this work.
Proposed method
- Define a canonical form for logic programs, where each predicate is expressed as a single clause with a canonical head and body, and disjunctions are uniformly represented.
- Model execution states using two stacks: an A-stack (ancestor stack) to track context (parent goals), and a B-stack (bet stack) to memoize used definitions and disjuncts during execution.
- Define 21 formal derivation rules that capture port transitions (e.g., call → exit, fail → redo) as deterministic state transitions between events, with explicit context via the A-stack.
- Use symbolic notation: sans-serif for object-level terms (e.g., true), italics or blackboard font for meta-level constructs (e.g., call, Σ, U).
- Ensure modularity by allowing abstraction of subgoal execution—e.g., if a goal A succeeds, its execution can be replaced by its computed answer substitution.
- Support both forward derivation (from call to exit/fail) and backward derivation (from exit/fail to call/redo), enabling proof reconstruction and debugging.
Experimental results
Research questions
- RQ1How can the four control flow ports (call, exit, fail, redo) in Prolog be formally defined as transitions between execution states?
- RQ2Can a stack-based model with A-stack and B-stack capture the full control flow of pure Prolog execution while preserving modularity?
- RQ3Does the proposed model support both forward and backward derivation steps, enabling formal reasoning about program behavior?
- RQ4Can the model be extended to full Prolog, including cut and dynamic predicates, while retaining formal tractability?
- RQ5Can the model be used to formally verify non-trivial program properties such as adequacy and non-interference in program transformations?
Key findings
- The S:PP calculus provides a complete, formal, and modular 21-rule model of pure Prolog execution using two stacks (A-stack and B-stack), enabling precise state representation.
- The model supports both forward and backward derivation steps, as demonstrated by the legal derivation rules (2) and (3) in Lemma 5, which allow inference from exit/fail events back to their causes.
- Modularity is achieved: the execution of a subgoal can be abstracted using its computed answer substitution, as shown in Example 4, where success or failure of A is used to derive the behavior of A,B.
- The model ensures correctness of transitions through strict rule overlap avoidance and explicit context tracking, preventing invalid derivations (e.g., fail B, fail cannot follow exit B, fail).
- The B-stack effectively captures both used predicate definitions and used disjuncts, solving the problem of state reentrancy and dynamic changes in predicate definitions during redo.
- The model is extendable to full Prolog, with a working prototype already implemented, suggesting practical applicability beyond pure logic programming.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.