Equality for Prolog

TL;DR

This paper introduces "Prolog-with-Equality," an extension to the Prolog logic programming language that allows for the inclusion of equality assertions. This enables more expressive data abstraction, akin to object-oriented programming, and a more flexible way to handle partially specified data, significantly enhancing Prolog's power and generality without substantial performance overhead.

What Problem Does This Paper Address?

Standard Prolog, based on Horn clause resolution, lacks a built-in mechanism for handling equality. This means that even if we define relationships like "6 is the successor of 5," Prolog cannot automatically unify terms like P(6) and P(successor(5)). This limitation restricts Prolog's ability to express sophisticated data structures and perform flexible computations. The authors aim to bridge this gap by integrating equality reasoning directly into Prolog's unification process, allowing terms that are not syntactically identical to be unified if an equality theorem can prove them equivalent. This addresses the need for more powerful data abstraction and a more natural way to represent and manipulate complex data.

Methods

The core innovation is a modification to Prolog's unification algorithm. When a standard unification attempt fails, the system now checks for an equality assertion in the database that can prove the two terms are equal. If such a proof succeeds, the unification proceeds with the variable bindings established during the equality proof. This mechanism is described as a "Prolog-with-Equality" system.

Key techniques and ideas include:

  • Equality Theorems: Assertions in the form of (equals term1 term2) :- body. are introduced. These theorems define when two terms are considered equal.
  • Augmented Unification: The unification process is extended to consult equality theorems when direct unification fails.
  • Paramodulation Analogy: The authors note the similarity of their equality theorems to the paramodulation rule in theorem proving literature.
  • Extensible Datatypes: The system allows for the creation of new data types (e.g., rational numbers) and defining their equality relations. This provides a mechanism for data abstraction and modularity, similar to object-oriented languages.
  • Partially Specified Objects: A novel concept of "Ω terms" (e.g., (Ω variable relation)) is introduced. These terms represent sets of values that satisfy a given relation, allowing for more flexible handling of partially instantiated data and avoiding expensive backtracking for enumeration.
  • Functional Notation: Equality theorems are used to introduce functional notation (e.g., (Xplus +x +y) +z) as a more readable alternative to relational style for certain operations.

Datasets

Not discussed in the paper. The paper focuses on introducing a new language feature and demonstrating its capabilities with illustrative examples rather than empirical evaluation on specific datasets.

Key Insights and Ideas

  • Object-Oriented Capabilities in Logic Programming: Equality theorems provide a powerful way to achieve data abstraction and generic operations, mimicking the benefits of object-oriented languages like Smalltalk within a logic programming paradigm.
  • Flexible Data Handling: The introduction of Ω terms significantly enhances Prolog's ability to work with partially specified data. This can replace expensive backtracking-based enumeration with more efficient set intersection-like operations.
  • "Automatic Type Conversion": The equality mechanism allows for implicit conversions between different representations of the same conceptual entity (e.g., a rational number and an integer), which the authors liken to automatic type conversion in other languages.
  • Efficiency without Backtracking: For certain problems, particularly those involving arithmetic and partially specified objects, the equality mechanism can lead to solutions without backtracking, improving efficiency.
  • Simplicity of Implementation: The authors claim the modifications to the Prolog interpreter were surprisingly simple, requiring only an evening of programming.

Key Results

The paper presents qualitative results and demonstrates the power of Prolog-with-Equality through various examples:

  • Rational Number Datatype: A complete example of defining rational numbers and their equality using cross-multiplication.
  • Extensible Datatypes: Demonstrations of defining classes like regular-polygon and equilateral-triangle, showing how equality assertions can model subclass relationships and enable generic operations like calculating area.
  • Partially Specified Objects: Examples of using Ω terms to represent sets of numbers satisfying inequalities, and how these terms can be unified.
  • Functional Notation: Examples of defining arithmetic functions like Xplus and Stimes using equality theorems.
  • Efficiency: The authors suggest that the computational overhead for interpreted Prolog is minimal and that compilation can eliminate most of this overhead. They also highlight that for certain problems, like arithmetic and partially specified objects, the new approach avoids expensive backtracking.

Limitations and Future Work

  • Unification Directionality: Equality assertions are restricted to being used in one direction to prevent infinite loops. The authors acknowledge this is a restriction.
  • Deterministic Unification: The current system's unification is deterministic. For models beyond the standard Herbrand model, where multiple most general unifiers might exist, a backtracking point in unification might be necessary.
  • Characterizing ft Term Usefulness: It is not yet clear under which conditions Ω terms are definitively preferable to standard Prolog generators.
  • Practical Program Development: While the generality is demonstrated, the authors note that esoteric proof paths could make simple programs take a long time.
  • Future Work: The authors suggest exploring the need for backtracking in unification for more complex equational theories and further investigating the practical applications and efficiency of Ω terms. They also mention the potential for compilers to precompute information to quickly detect failing unifications.

Summary updated

BibTeX
@inproceedings{1983equality,
  title = {{Equality for Prolog}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {1983},
}
Figure