80
Formal Logic
down an infinite path of something eating something eating something and so on,
with nothing telling us when to stop. Recursive definitions always need a stopping
point that consists of specific information.
The Prolog rule for infoodchain incorporates (1) and (2′):
infoodchain(X, Y ) <= eat(X, Y )
infoodchain(X, Y ) <= eat(X, Z ) and infoodchain(Z, Y )
It is a recursive rule because it defines the predicate infoodchain in terms of
infoodchain.
A recursive rule is necessary when the predicate being described is passed on
from one object to the next. The predicate infoodchain has this property:
infoodchain(X, Y ) ` infoodchain(Y, Z ) S infoodchain(X, Z )
eXAMPLe 40
After the infoodchain rule is added to the database of Example 39, the following
query is made:
?infoodchain(bear, Y )
The response follows (numbers are added for reference purposes):
1. fish
7. fish
2. raccoon
8. littlefish
3. fox
9. algae
4. deer
10. rabbit
5. littlefish
11. grass
6. algae
12. grass
Prolog applies the simple case of
infoodchain(bear, Y ) <= eat(bear, Y )
first, obtaining answers 1 through 4 directly from the facts eat(bear, fish), eat(bear,
raccoon), and so on. Moving to the recursive case,
infoodchain(bear, Y ) <= eat(bear, Z) and infoodchain(Z, Y )
a match of eat(bear, Z) occurs with Z equal to “fish.” Prolog then looks for all
solutions to the relation infoodchain(fish, Y ). Using first the simple case of infoodchain, a match occurs with the fact eat(fish, littlefish). This results in response 5,
littlefish. There are no other facts of the form eat(fish, Y ), so the next thing to try
is the recursive case of infoodchain(fish, Y ):
infoodchain(fish, Y ) <= eat(fish, Z) and infoodchain(Z, Y )
A match of eat(fish, Z) occurs with Z equal to “littlefish.” Prolog then looks for
all solutions to the relation infoodchain(littlefish, Y ). Using the simple case of
Formal Logic
down an infinite path of something eating something eating something and so on,
with nothing telling us when to stop. Recursive definitions always need a stopping
point that consists of specific information.
The Prolog rule for infoodchain incorporates (1) and (2′):
infoodchain(X, Y ) <= eat(X, Y )
infoodchain(X, Y ) <= eat(X, Z ) and infoodchain(Z, Y )
It is a recursive rule because it defines the predicate infoodchain in terms of
infoodchain.
A recursive rule is necessary when the predicate being described is passed on
from one object to the next. The predicate infoodchain has this property:
infoodchain(X, Y ) ` infoodchain(Y, Z ) S infoodchain(X, Z )
eXAMPLe 40
After the infoodchain rule is added to the database of Example 39, the following
query is made:
?infoodchain(bear, Y )
The response follows (numbers are added for reference purposes):
1. fish
7. fish
2. raccoon
8. littlefish
3. fox
9. algae
4. deer
10. rabbit
5. littlefish
11. grass
6. algae
12. grass
Prolog applies the simple case of
infoodchain(bear, Y ) <= eat(bear, Y )
first, obtaining answers 1 through 4 directly from the facts eat(bear, fish), eat(bear,
raccoon), and so on. Moving to the recursive case,
infoodchain(bear, Y ) <= eat(bear, Z) and infoodchain(Z, Y )
a match of eat(bear, Z) occurs with Z equal to “fish.” Prolog then looks for all
solutions to the relation infoodchain(fish, Y ). Using first the simple case of infoodchain, a match occurs with the fact eat(fish, littlefish). This results in response 5,
littlefish. There are no other facts of the form eat(fish, Y ), so the next thing to try
is the recursive case of infoodchain(fish, Y ):
infoodchain(fish, Y ) <= eat(fish, Z) and infoodchain(Z, Y )
A match of eat(fish, Z) occurs with Z equal to “littlefish.” Prolog then looks for
all solutions to the relation infoodchain(littlefish, Y ). Using the simple case of
