P. 1
Logic Programming through Prolog

Logic Programming through Prolog

|Views: 692|Likes:
Published by api-19625511

More info:

Published by: api-19625511 on Nov 28, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Resolution is a better candidate for machine implementation than ground reso-
lution, but it still suffers from some drawbacks. One is that there are several
ways that resolution might be used to produce a refutation of a goal. We might
try using clauses from the program directly on the goal, matching the clause
head with literals in the goal, and deriving a new goal, or we might try using
resolution to combine program clauses with each other, making new clauses that
can be used on the goal.
This choice of methods makes it appear that a machine searching for a refu-
tation must explore a large and complex search space, sometimes carrying out
resolution steps that do not involve the current goal at all. But luckily this com-
plexity is an illusion, because (as we shall show in this chapter) every refutation
can be recast in a ‘straight-line’ form, where every resolution step involves a clause
taken directly from the program and the goal that was produced in the previous
step. Derivation trees in straight-line form consist of a long, thin spine, with the
original goal at the top and the empty goal at the bottom. All the nodes that are
not on the spine are leaves, labelled with variants of program clauses. This means
that the machine can search for a refutation in a systematic way by starting with
the goal and repeatedly choosing a program clause to resolve with it. There is
still some choice here – and in fact it is this remaining element of choice that
makes logic programs non-deterministic – but the choice is severely restricted.
Another apparent source of complexity in searching for a refutation is that a
goal may have several literals, and we may choose to solve them in any order.
Even with straight-line derivations, we might choose to work on any one of the
goal literals in the first resolution step, and subsequently we may choose from
both the other literals of the original goal and the new literals introduced by pre-
vious resolution steps. It appears that, in order to succeed in finding a refutation,
we might have to consider the literals in a particular order, and even perhaps
interleave steps in the solution of one literal with the solution of other ones.
Again, this complexity is only apparent, because every straight-line refutation

69

70 SLD–resolution and answer substitutions

can be rearranged until the literals are solved in a predetermined order. To keep
the discussion simple, we shall consider only the strict left-to-right order that is
used by Prolog, but in fact the same argument shows that any choice of order is
permissible.

It is important to cut down the search space of derivations that a machine
must examine, because this makes execution of logic programs more efficient. If
we can show that every goal that has a refutation at all has one in a certain
restricted form, then we can build an execution mechanism that considers only
refutations in that restricted form. Also, if the form of refutations is restricted,
it may be possible to use more efficient data structures to represent derivations
inside the implementation. The Prolog approach, in which derivations have a
straight-line form and literals are considered in a fixed order, is known as SLD–

resolution. It allows a particularly simple and efficient form of search, and allows

derivations to be represented by a simple stack-like data structure similar to the
one used in implementing other programming languages.
The first part of this chapter treats SLD–resolution in more detail, showing
that resolution remains complete when we adopt the restrictions of straight-line
form and a fixed order of solving literals. The second part discusses a method
for extracting an answer substitution from a refutation, so that solving a goal
does not yield just a simple ‘yes’ or ‘no’, but also specific values of variables that
make the literals of the goal true if possible. Answer substitutions extracted by
this method are what Prolog displays when it has succeeded in solving a goal.
We shall prove that the answers extracted from refutations are correct, and that
every correct answer can be obtained in this way.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->