Keep in mind that the Prolog system does not know the meaning of the predicates in a program; it simply manipulates the statements in a totally symbolic manner according to the resolution inference rule. Thus it is up to the programmer to describe all the pertinent features of a predicate in terms of facts and rules. In this light, Prolog facts tend to be used to identify specific instances of a predicate, whereas rules are used to describe general principles. This is the approach followed by the preceding statements regarding the predicate faster. The two facts describe particular instances of "fasterness" while the rule describes a general property. Note that the fact that a rabbit is faster than a snail, though not explicitly stated, is a consequence of the two facts combined with the rule.
When developing software using Prolog, the task of a programmer is to develop the collection of facts and rules that describe the information that in known. These facts and rules constitute the set of initial statements to be used in the deductive system. Once this collection of statements is established, conjectures (called goals in Prolog terminology) can be proposed to the system-usually by typing them at a computer's keyboard. When such a goal is presented to a consequence of the initial statements. Based on our collection of statements describing the relationship faster, each of the goals
faster (turtle, snail).
faster (rabbit, turtle).
faster (rabbit, snail).
could be so confirmed because each is a logical consequence of the initial statements. The first two are identical to facts appearing in the initial statements, whereas the third requires a certain degree of deduction by the system.
More interesting examples are obtained if we provide goals whose arguments are variables rather than constants. In these cases Prolog tries to derive the goal from the initial statements while keeping track of the unifications required to do so. Then if the goal is obtained, Prolog reports these unifications. For example, consider the goal
faster (W, snail).
In response to this, Prolog reports
faster (turtle, snail).
Indeed, this is a consequence of the initial statements and agrees with the goal via unification.
Furthermore, if we asked Prolog to tell us more, it finds and reports the consequence
faster (rabbit, snial).
In contrast, we can ask Prolog to find instances of animals that are slower than a rabbit by proposing the goal
faster (rabbit, W).
In fact, if we started with the goal
faster (V, W).
Prolog would ultimately seek all the faster relationships that can be derived from the initial statements. This implies that a single Prolog program could be used to confirm that a particular animal is faster than another, to find those animals that are faster than a given animal, to find those animals that are slower than a given animal, or to find all faster relationships.
参考资料:Google翻译
本回答被网友采纳