On the forty-second page of “The Art of Prolog: Advanced Programming Techniques (2nd Ed.)” authors Leon Sterling & Ehud Shapiro wrote (some emphasis added):
![]()
- Add recursive rules for left_of and above from Exercise 2.1(ii) on p. 34. Define higher(Object1,Object2), which is true if Object1 is on a line higher than Object2 in Figure 2.3. For example, the bicycle is higher than the fish in the figure.
- How many nodes are there in the proof tree for connected(a,e) using Programs 2.6 and 2.7? In general, using Program 2.6 and a collection of edge/2 facts, how many nodes are there in a proof tree establishing that two nodes are connected by a path containing n intermediate nodes?
2.4 Loging Programs and the Relational Database Model
Logic programs can be viewed as a powerful extension to the relational database model, the extra power coming from the ability to specify rules. Many of the concepts introduced have meaningful analogues in terms of databases. The converse is also true. The basic operations of the relational algebra are easily expressed within logic programming.
Procedures composed soley of facts correspond to relations, the arity of the relation being the arity of the procedure. Five basis operations define the relational algebra: union, set difference, Cartesian product, projection and selection. We show how each is translated into a logic program.
The union operation creates a relation of arity n from two relations r and s, both of arity n. The new relation, denoted here r_union_s, is the union of r and s. It is defined directly as a logic program by two rules:
r_union_s(X1, ..., Xn) <- r(X1, ..., Xn).
r_union_s(X1, ..., Xn) <- s(X1, ..., Xn).Set difference involves negation. We assume a predicate not. Intuitively, a goal not G is true with respect to program P if G is not a logical consequence of P. Negation in logic programs is discussed in Chapter 5, where limitations on the intuitive definition are indicated. The definition is correct, however, if we deal only with ground facts, as is the case with relational databases.
The definition of r_diff_s of arity n, where r and s are of arity n, is
More information about “The Art of Prolog: Advanced Programming Techniques (2nd Ed.)” (and the book itself) is available from:
(The MIT Press, March 1994. Hardback, 560 pages. ISBN: 0262193388; EAN: 9780262193382.)
Tomorrow is an other day!@
Posted by: Air Jordan | November 13, 2010 at 01:54 AM