Information Technology Reference
In-Depth Information
However, althouth the operational semantics of P2 is still the same as that of P1,
the declarative semantics of P2 is changed as follows: the maximum value of X
and Y is always X, it can also be Y in the case of X≤Y. Obviously, the semantics
of P2 is different from our original intention.
The “fail” is another predication used by Prolog. Acting as a sub-goal, the
predication “fail” can not be solved at all and therefore will give rise to a
backtracking. The predication CUT can be placed prior to the predication “fail”
and forms the so-called cut-fail composition. During the SLD resolution process,
in the case that a clause which contains a cut-fail composition is examined for
resolution, resolution of the father-goal of the CUT predication will be finished
directly. Therefore, efficiency of search will be increased.
For example, consider the following program P:
(1) strong(X):- heart_disease(X), fail.
(2) strong(X):- tuberculosis(X), fail.
(3) strong(X):- nearsight(X), fail.
(4) strong(X).
(5) heart_disease(Zhang).
Let “?- strong(Zhang)” be the goal. According to the first clause of program P,
the goal “strong(Zhang)” can be first unified with a resolvent “heart_disease(Zhang),
fail”; then a backtracking will be triggered by the “fail” after the unification of
“heart_disease(Zhang)”. In the following steps, sub-goals “tuberculosis(Zhang)”
(or “nearsight(Zhang)”) which are generated according to the second clause
(resp., the third clause) can not be unified. Finally, the goal “strong(Zhang)” will
be unified according to the forth clause of P and produce a positive result.
Backtracking is triggered with three times in this example. We can reduce the
backtracking according to place a CUT prior to the “fail” occurring in the P. For
example, the first three clauses of P can be changed as follows:
(1) strong(X):- heart_disease(X), !, fail.
Search WWH ::




Custom Search