Professional Documents
Culture Documents
DAN E. TAMIR
RAVI ANANTHAKRISHNAN
Department of Computer Science, Florida Institute of Technology, 150 W. University
Bculeward., Melbourne Florida 32901
AI3RAHAM KANDEL
Department of domputer Science and Engineering, University of South Florida, 4202
Eost Fowler Avenue, Tampa Florida 33620
ABSTRACT
This work involves the design and coding of an interpreter for pure Prolog and
building a visual debugger for it. Most of the available Prolog interpreters contain
some tracing facilities. They do not incorporate, however, a comprehensive visual
debugger. The interpreter performs the operations of parsing, unification, res-
olution, and search in a state-space representation of the Prolog program. The
visual debugger incorporates the graphical visualization and the manipulation
of the SLD resolution tree. The user visualizes the execution of a pure Prolog
program and interacts with the program inside a windowing environment. The
program execution may be viewed without interruption or the execution can be
stopped at any moment in time. At this point the “snapshot” can be scrutinized
w-ith the help of break-points and data displays. This software aims itself to those
who wish to observe the actual process of predicate unification, substitution, reso
lution, and goal matching in a Prolog program and to visually interact with the
interpreter using a highly friendly and pleasing user interface. An advanced fea-
ture, referred to as debugging on the tree, provides the user with the ability to
insert break-points directly on the SLD tree, to choose the path of execution,
and change the search mode. The resultant search algorithm can be a mixture
of depth-first and breadth-first search, avoiding infinite search paths.
1. INTRODUCTION
1.1. Motivation
Prolog is a declarative logic programming language with a fixed and
deterministic control structure. The program control is based on the pro-
cess of proof by refutation of first order logic. Along with Lisp, Prolog is
one of the two most commonly used artificial intelligence (AI) languages.
A variety of AI applications have been developed in Prolog. Hence, of
major concern for the AI community are the issues governing efficient in-
terpretation of Prolog programs, parallel execution of Prolog programs,
and construction of efficient Prolog development tools.
In an ideal declarative language, the programmer specifies the problem
to be solved rather than the algorithm for problem solution. This approach
has several advantages over other programming paradigms. First, from the
software engineering point of view, the process of program development
“terminates” in the stage of problem specifications. Second, it has the ad-
vantage of freeing the programmer from the details of execution control.
Finally, because the programmer is not concerned with execution control,
the actual implementation of the control unit can be optimized and paral-
lelized independently of the user programs.
Nevertheless, the lack of interaction between the programmer and the
program exeuction control can lead to a less efficient problem solution.
Furthermore, a programmer who is not aware of the details of the fixed
execution control might find it extremely difficult to locate logic errors
(“bugs”).
Prolog is not an ideal declarative language. Hence, some of the foregoing
problems are amplified. On one hand, some execution control clauses are
available in practical Prolog implementations, so the programmer is not
completely free from execution control considerations. On the other hand,
the built-in control of Prolog, the procedure of proof by refutation, is not
trivial or simple to explain. Hence, many Prolog textbooks present a naive
and distorted view of Prolog to new Prolog programmers. For these rea-
sons, the development of Prolog debugging tools that visualize the actual
execution model of Prolog is an important consideration.
This research concentrates on the problem of Prolog development tools.
The visual debugger for Prolog reported in this paper is part of our current
effort to develop an efficient visual debugger for a parallel Prolog inter-
preter.
A VISUAL DEBUGGER FOR PURE PROLOG 129
clauses. Another set of logic errors is related to the fact that the “occur
check” that is an essential part of unification is not being implemented in
Prolog (the exact definitions of the search method and the occur check are
given in a later section). In this case the debugger can help the program-
mer to identify a run-time error that is due to the lack of the occur check.
The programmer can then resolve the problem through a simple renaming
of variables. Finally, most of the Prolog textbooks and training courses
present a naive and nonaccurate view of Prolog, trying to equate Prolog
with procedural languages. The result is that many Prolog programmers
have a distorted view of the Prolog execution model. A tool that enables
program execution in a manner that shows the various paths of control flow
and the intermediate values of the parameters involved in the program can
help the programmer to understand accurately the details of the program
execution.
The difference between Prolog and other programming languages im-
poses conceptual and practical difficulties on the development of Prolog
debugging tools. ‘I’he main purpose of a debugger is to enable controlled
execution of a program. However, if the language does not enable con-
trol over the program execution, then how can the debugger enable this
control? In other words, how can the programmer insert a break-point
in a declarative language with no control structures. As a result of this
difficulty, traditional Prolog debugging tools concentrate on tracing rather
than controlling the execution. Nevertheless, because the control struc-
ture is fixed and independent of the program, it is possible to visualize the
general execution model of Prolog. This feature is not straightforward in
other programming language where the execution model depends on the
program. The visual model of Prolog execution can be used to animate
the execution of specific programs. Moreover, with additional facilities it
can be used to enable controlled execution of the program. In this sense,
the visual debugger reported in this paper is unique. As with other visual
Prolog tracers, our debugger draws the SLD tree while the Prolog program
executes. However, in contrast to existing Prolog debugging tools, it en-
ables control over the program execution using features such as inserting
break-points into the SLD tree and selecting alternative execution models
interactively.
Generally, a Prolog interpreter incorporates special predicates for trac-
ing, which enable limited debugging1 of the execution of Prolog programs.
The most commonly used model for tracing has been developed by Byrd
[2]. This model tries to equate Prolog execution with procedural language
2. PROLOG INTERPRETATION
first order logic. However, Prolog is using an inference rule that includes
unification and binary resolution rather than using modus ponens.
‘Unification is a process that consolidates two literals by substituting
ter:ms for variables in the literals. The list of substitutions is called a
unifier. If the unifier is applied to both literals, the literals become equal.
.Let p be a literal and let R and S be two sets of clauses. The binary
resolution principal implies that one can infer {RvS} given {pvR} and
(1;pvS).
Although the semantics of different Prolog systems deviate very little
from each other (most systems perform a depth-first search on the SLD
refutation tree [4]), the pragmatics and underlying implementation mecha-
nisms vary greatly. Some systems compile Prolog code directly to a specific
machine architecture. Other systems compile Prolog code where the target
system is an abstract machine such as Warrens abstract machine [8]. The
use of an abstract machine allows any architecture that has the abstract
machine implemented on it to run the Prolog system. Other Prolog systems
are interpreted, they maintain their own data structures, and have action
sequences for Prolog code as opposed to several machine instructions.
The next sections describe the Prolog model of interpretation in more
details.
The interpreter constructs the SLD tree and a searches for solutions
(empty clauses) on the tree. Because the SLD tree may be infinite, a
system employing depth-first search on the tree is not complete, whereas
a system employing breadth-first search is complete in the sense that it
A VISUAL DEBUGGER FOR PURE PROLOG 135
finds every existing solution [8, lo]. The problem, however, is that the
amount of resources required for breadth-first search grows exponentially
with the depth of the search. In contrast, the amount of resources required
to implement a depth-first search is a linear function of the depth level [lo].
For this reason, the search implemented by Prolog is a depth-first search
procedure. After finding one solution or reaching a dead end, the program
has to back up and search for alternative routes. Thus, a backtracking
version of depth-first search is employed [IO].
3. IMPLEMENTATION OVERVIEW
Grammar Checking
The Prolog program is read in by the interpreter and the clauses are
examined for any illegal pattern or usage. Any deviation from the right
syntax is flagged as an error. On finding an error, the program transfers
control to a print-error procedure that outputs the actual line in which the
error has occurred.
Resolution Tree
The software draws the resolution tree as the Prolog program executes.
The predicate information along with the various substitutions are stored
in the Substitution-table. These predicates are displayed in the form of a
tree on an XView canvas. The tree encapsulates all the solution paths of
a given set of clauses. Starting from the query, it displays the branches
representing the different rules, the various resolvents, and the solutions.
Another facility provided is “debugging on the tree.” The user can
select any node on the tree by clicking the mouse button. Upon selection
of a node, the program continues evaluation from the selected node. This
gives the user the flexibility to ignore paths that are potentially leading to
dead-ends or to pursue a specific path of interest.
I
5
f
$
140 TAMIR ET AL.
the tree, i.e., drawing a part of the tree, is provided. Under this option, as
soon as the program detects a dead-end or a solution, it erases the preceding
part of the tree and displays only the current node of interest. At any point
in time, the user is able to either see the entire tree or concentrate on the
neighborhood of the node currently being evaluated. For “debugging on
the tree,” the user manipulates the SLD tree with the help of the mouse.
This can be done under the “full tree” option as well as under the “part
tree” option.
4. EXAMPLE PROGRAMS
Rl.P(X) + P(X).
&:&a)?
Performing unification and resolution, the negation of the query, i.e.,
-p(a), unifies with the clause and results in the clause {Tp(a)}. This
results in an endless loop because it resolves with the same rule repeatedly.
The program terminates when the resources are exhausted or when the
“quit” option of the debugger is selected. Figure 3 shows a snapshot in the
execution of program one. Note that the break-point has been set on RI.
Under the “naive” representation of Prolog, this program would be de-
scribed as a recursive procedure with no termination condition.
h 8
P
8
\ 0 P
142 TAMIR ET AL.
The program contains four clauses in the form of “father(X, Y),” which
can represent the relation “X is the father of Y.” In an expert system
paradigm, these clauses are referred to as facts. The clauses, RI and Rz
can be used to define the relations of grandfather and great-grandfather. In
production system terminology RI and Rz are referred to as “rules.” Solv-
ing the query results in identifying the great-grandfather of nancy provided
that there is enough information about him in the fact base.
Figure 4 shows a snapshot of executing the program under PROVIS.
The current goal in this snapshot is to find X, W, and V such that X is
the father of W, W is the father of V, and V is the father of nancy. To save
space, the program has been rewritten so that each predicate and variable
is represented using its distinguished prefix. Thus “f” stands for father,
“n” stands for nancy, “gra” denotes “grandg,” and “gre” denotes “greatg.”
Q : P@J,4.
In this case RI states that p is a reflexive relation and R2 states that p
holds for (a, b). The query Q tries to identify if there is a Z such that p
holds for (b, Z). The trivial answer is Z = a. However, due to the fixed
control structure of Prolog the program runs into an infinite brunch and
A VISUAL DEBUGGER FOR PURE PROLOG 143
L
-
144 TAMIR ET AL,.
5. CONCLUSIONS
The software performs the functions of a visual debugger for Prolog. The
basic functions, such as setting up break-points, single stepping through in-
structions, printing variable values, resuming execution from a break-point,
clearing break-points, and quitting the program, are provided along with
the interpretation of Prolog. All the above-mentioned features incorpo-
rated in an XView graphical user interface that allows the use of windows,
panels, and a drawing canvas. The canvas displays the resolution tree and
gives the user a picture of the unification, resolution, and the substitution
process. In addition, the user can manipulate the SLD tree by selecting
various paths for traversal and abandoning searches along specific paths.
Many researchers have identified that logic programming languages-
Prolog in particular-have a high potential for parallel processing [8]. As
a result, several interpreters for parallel Prolog have been implemented.
Common to most of these interpreters is the approach that some parts of
the SLD tree are explored simultaneously by different processes on differ-
ent machines. Intuitively, parallel Prolog can be viewed as a set of tasks
executed by several processors. Each task consists of the original Prolog
program with a different query.
Our current effort is the design of an interpreter and a visual debugger
for parallel Prolog. In addition to facilitating the debugging of a paral-
A VISUAL DEBUGGER FOR PURE PROLOG
(b)
(4 ,
Fig. 5. Cont.
A VISUAL DEBUGGER FOR PURE PROLOG 147
lel Prolog program, this debugger will enable monitoring the process of
distributing the tasks among the processors. It can lead to an interac-
tiv,e parallel execution of Prolog, where an operator decides which node to
explore next and which machine should be used for the exploration.
RE:FERENCES