Section 1.5 Logic Programming
83
13. A Prolog database contains the following, where boss(X, Y ) means “X is Y’s boss” and supervisor(X, Y )
means “X is Y’s supervisor”:
boss(mike, joan)
boss( judith, mike)
boss(anita, judith)
boss( judith, kim)
boss(kim, enrique)
boss(anita, sam)
boss(enrique, jefferson)
boss(mike, hamal)
supervisor(X, Y ) 6= boss(X, Y )
supervisor(X, Y ) 6= boss(X, Z ) and supervisor (Z, Y )
Find the results of the following queries:
a. ?boss(X, sam)
b. ?boss( judith, X )
c. ?supervisor(anita, X )
14. Using the Prolog database from Exercise 13, what are the results of the following queries?
a. ?boss(hamal, X )
b. ?supervisor(X, kim)
15. Suppose a Prolog database exists that gives information about authors and the books they have written.
Books are classified as fiction, biography, or reference.
a. Write a query to ask whether Mark Twain wrote Hound of the Baskervilles.
b. Write a query to find all books written by William Faulkner.
c. Formulate a rule to define nonfiction authors.
d. Write a query to find all nonfiction authors.
16. Suppose a Prolog database exists that gives information about states and capital cities. Some cities are big,
others small. Some states are eastern, others are western.
a. Write a query to find all the small capital cities.
b. Write a query to find all the states with small capital cities.
c. Write a query to find all the eastern states with big capital cities.
d. Formulate a rule to define cosmopolitan cities as big capitals of western states.
e. Write a query to find all the cosmopolitan cities.
17. Suppose a Prolog database exists that gives information about a family. Predicates of male, female, and
parentof are included.
a. Formulate a rule to define fatherof.
b. Formulate a rule to define daughterof.
c. Formulate a recursive rule to define ancestorof.
18. Suppose a Prolog database exists that gives information about the parts in an automobile engine. Predicates
of big, small, and partof are included.
a. Write a query to find all small items that are part of other items.
b. Write a query to find all big items that have small subitems.
c. Formulate a recursive rule to define componentof.
Précédent

- 100/986

Suivant