Introduction
In the late 1980s, the development of expert systems relied heavily on logic programming, specifically Prolog. While Prolog’s backward-chaining mechanism is highly effective for automated reasoning, it often functions as a "black box" from the user's perspective. Standard explanation facilities in these systems were typically limited to showing a proof tree for successful conclusions. However, they lacked the transparency required to explain why a specific conclusion was not reached or how control operators like the "cut" (!) influenced the search space. This paper presents a novel architectural solution: a two-layer meta-interpreter designed to reify the internal control flow of Prolog, making failures and pruned branches explicit and explainable.
The Transparency Problem in Logic Programming
Expert systems require transparency to be trustworthy. In Prolog-based systems, this transparency is hindered by three primary factors:
- The "Whynot" Question: Users often need to know why a specific hypothesis was rejected. Standard interpreters simply backtrack upon failure, losing the context of why a particular rule failed to unify or satisfy its subgoals.
- Extra-logical Operators: The "cut" operator (
!) and negation-as-failure are essential for efficiency and logic, but they prune the search tree in ways that are invisible to standard tracers. This makes it difficult to explain why certain valid-looking rules were never even attempted. - Global Context: During execution, users may ask "Why?" to understand the current line of reasoning. Standard systems struggle to provide a global view of the search tree, often only showing the immediate rule being processed.
Previous attempts to solve these issues often involved running two separate interpreters—one for successes and one for failures. This approach was not only computationally expensive but also failed to handle programs with side effects (like I/O operations), which could not be safely executed twice.
The Two-Layer Meta-Interpreter Architecture
The authors propose a unified framework that captures the execution trace in a single pass using a layered meta-interpreter. This design separates the management of a goal's status from the exploration of its individual branches.
The Goal Layer
The top-level Goal Layer is responsible for managing the overall lifecycle of a goal. Instead of allowing Prolog to handle backtracking natively, the Goal Layer calls the Branch Layer and captures its result. It acts as a filter, recording whether a goal succeeded, failed, or was terminated by a "cut." By capturing these statuses, the Goal Layer can construct a comprehensive explanation of the search process, including paths that were abandoned.
The Branch Layer
The Branch Layer functions as a "fail-safe" version of a standard meta-interpreter. When a subgoal fails, the Branch Layer does not simply trigger a backtrack; instead, it returns an explicit status code (e.g., yes, no, or commit). This allows the system to distinguish between a failure to unify and a failure caused by a previous rule's "cut."
Partial Proof Trees and Goal Copying
To support interactive "Why" questions, the system maintains a partially instantiated proof tree. This tree allows users to navigate the current state of the computation, viewing both completed subgoals and those yet to be solved. To prevent the exploration of failed branches from "polluting" the variable bindings of the main execution, the system utilizes Goal Copying. By working on a copy of the goal during failure analysis, the interpreter ensures that the explanation process remains side-effect-free regarding the program's logical state.
Key Insights: The Duality of Failure
A central insight of this work is that failure in Prolog is not a monolithic event. It consists of two distinct scenarios:
- Unification Failure: A specific clause fails to match the goal.
- Exhaustion: All possible clauses for a goal have been tried and failed.
By reifying these events, the meta-interpreter can explain exactly which rules were tried and which specific subgoals within those rules led to the ultimate failure. Furthermore, by treating the "cut" as a commit result, the system can inform the user that certain rules were skipped not because they were invalid, but because a higher-priority rule had already committed the system to a different path.
Results and Functional Advantages
The layered meta-interpreter provides several significant advantages for expert system transparency:
- Faithful Semantics: The system maintains the exact execution order and pruning behavior of standard Prolog, ensuring that the explanations provided are an accurate reflection of the program's logic.
- Interactive Navigation: Users can navigate the proof tree dynamically, asking for more detail on specific subgoals or requesting a high-level view of the computation's history.
- Reporting Inaccessible Clauses: The system identifies "inaccessible clauses"—rules that matched the goal but were never executed due to a cut in a preceding rule. This is a vital feature for debugging complex rule sets where logic may be inadvertently masked by control operators.
Limitations and Future Directions
While the layered approach significantly improves transparency, the authors identify areas for further refinement. Procedural patterns such as "failure-driven loops" remain difficult to explain in a way that feels natural to a non-technical user. The authors suggest that future versions of the system should extend the proof tree to incorporate the history of previous iterations within these loops.
Additionally, there is a need to translate raw Prolog structures into the domain-specific language of the expert system to make explanations more accessible. Finally, while the meta-interpreter is functional, the inherent overhead of meta-interpretation suggests that further optimization would be required for large-scale, real-time applications.
Summary updated