Introduction
Standard logic programming languages, most notably Prolog, have traditionally relied on syntactic unification. In this paradigm, two terms match only if they are identical or can be made identical through variable binding. While powerful, this rigidity poses significant challenges for data abstraction. For instance, Prolog cannot inherently recognize that $2/3$ and $4/6$ represent the same rational number, nor can it naturally express that a "square" should inherit the properties of a "rectangle" without explicit, often cumbersome, conversion logic.
This paper by William Kornfeld introduces a transformative extension to the Prolog interpreter. By incorporating equality assertions, the system can unify terms that are syntactically distinct but semantically equivalent. This shift not only bridges the gap between logic programming and object-oriented design but also introduces a robust framework for constraint-based reasoning.
The Mechanism of Semantic Unification
The core innovation lies in a modification of the Prolog interpreter's unification algorithm. When the system encounters two terms that fail to unify syntactically, it does not immediately trigger a failure. Instead, it attempts to satisfy a new goal: (equals term1 term2).
The equals Predicate
Users can define specific axioms for the equals predicate to handle domain-specific logic. For example, a rule for rational numbers might define equality based on cross-multiplication. If the system is asked to unify (rat 2 3) and (rat 4 6), the failure of syntactic matching triggers the equals rule, which then confirms their mathematical equivalence.
Procedural Safeguards and Efficiency
To maintain computational efficiency and prevent infinite recursion (e.g., A equals B, and B equals A), the implementation requires that the first functor of an equality assertion be explicitly defined. This allows the compiler to utilize hash tables to quickly discard unifications where no equality path exists, ensuring that the overhead for failing unifications remains a small, constant cost.
Partially Specified Objects: The $\Omega$ Functor
Beyond simple equality, the paper introduces the $\Omega$ functor—represented as $\Omega(\text{variable}, \text{relation})$—to handle partially specified objects. This mechanism allows a variable to carry an inherent constraint.
In standard Prolog, a variable is a "blank slate" that is filled during search, often leading to a "generate-and-test" approach where the system guesses values and backtracks upon failure. With $\Omega$ terms, a variable might represent "any integer greater than 10." When two such terms are unified, the system calculates the intersection of their constraints. This shifts the execution model from blind backtracking toward a more efficient constraint logic programming style, capable of solving systems of equations without the traditional overhead.
Equality as a Bridge to Object-Orientation
One of the paper's most profound insights is the functional equivalence between equality assertions and class inheritance.
- Inheritance through Equality: By asserting that an
equilateral-triangleis equal to aregular-polygonwith three sides, the triangle automatically "inherits" all relations and calculations (such as area or perimeter formulas) defined for the broader polygon class. - Late Binding of Classes: Unlike traditional object-oriented languages like Smalltalk, where an object's class is fixed at instantiation, this system allows an object's "class" to be determined dynamically during the proof process. This provides a level of flexibility in data modeling that is difficult to achieve in imperative OO languages.
- Functional Notation: Equality theorems also allow for the integration of Lisp-like functional nesting (e.g.,
(%plus 2 3)) within Prolog’s relational structure, effectively treating functions as a special case of relations.
Implementation and Results
The author successfully implemented these features within a Lisp-based Prolog system. Key results include:
- Multi-directional Functions: The system can solve arithmetic constraints regardless of which variables are instantiated. For example, a single
plusrelation can act as both addition and subtraction depending on the input. - Efficiency: By indexing equality theorems by their functors, the system minimizes the cost of failed unifications, which is the most frequent case in logic programming.
- Real-world Application: The system was applied to a music theory project involving species counterpoint. In this context, $\Omega$ terms represented sets of possible musical pitches that were progressively narrowed down as various musical rules and constraints were applied.
Limitations and Future Directions
While the system provides a powerful extension to logic programming, it is not "logically complete." To ensure practical performance and avoid infinite loops, certain procedural restrictions were necessary. Furthermore, the current implementation assumes a "most general unifier." In more complex equational theories where multiple valid unifications might exist, the system would need to introduce backtracking points within the unification process itself—a significant increase in architectural complexity.
Future work would involve deeper integration into Prolog compilers to further minimize the computational cost of equality checks and exploring more complex equational theories.
Summary updated