Section 1.5 Logic Programming
75
Queries may contain the logical connectives and, or, and not.
pRaCtiCe 28 Given the database
eat(bear, fish)
eat(bear, fox)
eat(deer, grass)
animal(bear)
animal(fish)
animal(fox)
animal(deer)
plant(grass)
what will be Prolog’s response to the query
?eat(X, Y ) and plant(Y )
The second type of item in a Prolog database is a prolog rule. A rule is a description of a predicate by means of an implication (the implication arrow in the rule
goes from right to left). For example, we might use a rule to define a predicate of prey:
prey(X ) <= eat(Y, X ) and animal(X )
This statement says that X is a prey if it is an animal that is eaten. If we add this
rule to our database, then in response to the query
?prey(X )
we would get
fish
fox
horn Clauses and resolution
How do Prolog facts and rules relate to more formal predicate logic? We can describe the facts in our database as wffs:
E(b, fi)
E(b, fo)
E(d, g)
A(b)
A( fi)
A( fo)
A(d)
P(g)
and the rule by the wff
E( y, x) ` A(x) S Pr(x)
Précédent

- 92/986

Suivant