Incorporating Generalization Heuristics into Verification of Prolog Programs

Hirohisa Seki

Abstract

Verifying the correctness and termination of logic programs often requires inductive reasoning. However, automated induction frequently fails when the initial theorem is too weak or when program structures, such as accumulators, create mismatches between induction hypotheses and conclusions. This paper presents a framework for incorporating generalization heuristics into an inductive theorem prover for Prolog. By utilizing both mechanical simplification and an "intelligent" generalization scheme that infers missing constraints, the system can automatically prove complex properties that previously required manual intervention.

Introduction

In the domain of formal methods, verifying that a logic program adheres to its specification typically necessitates mathematical induction. While Prolog's declarative nature is well-suited for formal reasoning, automated verification systems often encounter "creative gaps." These gaps occur when the system must move beyond the literal statement of a theorem to find a more general or constrained version that allows the inductive proof to succeed. Traditionally, these steps required human insight. This research explores the automation of these creative steps by integrating generalization heuristics into an "extended execution" style of verification.

The Challenge of Induction in Logic Programming

Inductive proofs in Prolog often stall due to two primary issues:

  1. Weak Induction Hypotheses: The specific theorem being proved may not be strong enough to support the inductive step. In such cases, a more general version of the theorem must be proven first to make the mathematics tractable.
  2. Argument Mismatch in Accumulators: Efficient Prolog programs frequently use accumulators—extra variables that carry state through recursive calls. During induction, the accumulator value in the hypothesis (e.g., an empty list []) often conflicts with the value in the conclusion (e.g., a populated list [A|X]), preventing the application of the hypothesis.

Proposed Methods: Generalization Heuristics

The core of the proposed framework is the categorization and automation of two distinct generalization strategies within the theorem prover.

Mechanical Generalization

Inspired by the Boyer-Moore theorem prover (BMTP), mechanical generalization involves replacing specific terms with variables to simplify the goal. In this framework, the author demonstrates that mechanical generalization need not be an ad-hoc "hack." Instead, it emerges naturally as a byproduct of a standard simplification rule within the logic programming context, unifying "cross-fertilization" and generalization under a single mechanism.

Intelligent Generalization

To address the complexities of accumulators, the paper introduces an "intelligent" generalization scheme. This is a proactive strategy that follows a four-step pipeline when a mismatch is detected:

  1. Identification: The system identifies mismatching arguments between the induction hypothesis and the current goal.
  2. Over-Generalization: It replaces these arguments with new variables, creating a version of the goal that is intentionally too general.
  3. Pseudo-Verification: The system attempts to verify this over-generalized goal to identify the specific conditions under which it would be true.
  4. Constraint Inference: Finally, it infers a new Prolog predicate—a constraint relation—that bridges the gap. This effectively "discovers" the necessary auxiliary lemma required to complete the proof.

Evaluation and Benchmarks

As a study in formal methods, the framework was evaluated using classic benchmarks known for their difficulty in automated induction:

  • reverse-reverse: Proving that reversing a list twice returns the original list. This is notoriously difficult when using an accumulator-based version of reverse because the state changes in ways that standard induction cannot easily track.
  • append associativity: Proving corollaries related to list concatenation and the structural properties of joined lists.

Key Insights and Results

The research demonstrates that "creative" proof steps can be successfully automated. The system's ability to "over-generalize then constrain" allows it to discover the exact constraints needed to make a theorem provable.

Key results include:

  • Automated Lemma Discovery: The system successfully generated intelligent generalizations for accumulator-based programs, automatically discovering the need for auxiliary constraint relations.
  • Unified Framework: The heuristics were naturally integrated into the "extended execution" style of Prolog interpreters. This makes the verifier feel like a natural extension of the language environment rather than an external tool.
  • Implementation: The heuristics were implemented in DEC-10 Prolog on a DEC-2060 mainframe, proving the feasibility of the approach on contemporary hardware of the era.

Limitations and Future Work

While the framework represents a significant step forward, it has limitations. The current implementation of constraint inference is restricted to relations that can be expressed as Horn clauses; more complex mathematical or non-linear relations may still require manual assistance. Additionally, like all automated theorem provers, the system must manage the risk of a "combinatorial explosion" when searching for the correct generalization.

Future work involves integrating these features into the Sequential Inference Machine (PSI) as part of the Japanese Fifth Generation Computer Systems initiative. This integration aims to further explore the potential for automated program transformation and synthesis based on these inductive techniques.

Summary updated

BibTeX
@inproceedings{seki1985incorporating,
  author = {Hirohisa Seki},
  title = {{Incorporating Generalization Heuristics into Verification of Prolog Programs}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {1985},
}
Figure