Concepts of Programming Languages

(Sean Pound) #1

740 Chapter 16 Logic Programming Languages


relationships. The answer no means that either the goal was determined to be
false or the system was simply unable to prove it.
Conjunctive propositions and propositions with variables are also legal
goals. When variables are present, the system not only asserts the validity of
the goal but also identifies the instantiations of the variables that make the goal
true. For example,

father(X, mike).

can be asked. The system will then attempt, through unification, to find an
instantiation of X that results in a true value for the goal.
Because goal statements and some nongoal statements have the same form
(headless Horn clauses), a Prolog implementation must have some means of
distinguishing between the two. Interactive Prolog implementations do this
by simply having two modes, indicated by different interactive prompts: one
for entering fact and rule statements and one for entering goals. The user can
change the mode at any time.

16.6.5 The Inferencing Process of Prolog


This section examines Prolog resolution. Efficient use of Prolog requires that
the programmer know precisely what the Prolog system does with his or her
program.
Queries are called goals. When a goal is a compound proposition, each of
the facts (structures) is called a subgoal. To prove that a goal is true, the inferenc-
ing process must find a chain of inference rules and/or facts in the database that
connect the goal to one or more facts in the database. For example, if Q is the
goal, then either Q must be found as a fact in the database or the inferencing pro-
cess must find a fact P 1 and a sequence of propositions P 2 , P 3 , c, Pn such that
P 2 :- P 1
P 3 :- P 2

...
Q :- Pn
Of course, the process can be and often is complicated by rules with compound
right sides and rules with variables. The process of finding the Ps, when they
exist, is basically a comparison, or matching, of terms with each other.
Because the process of proving a subgoal is done through a proposition-
matching process, it is sometimes called matching. In some cases, proving a
subgoal is called satisfying that subgoal.
Consider the following query:


man(bob).

This goal statement is the simplest kind. It is relatively easy for resolution to
determine whether it is true or false: The pattern of this goal is compared with
the facts and rules in the database. If the database includes the fact
Free download pdf