15.13 Exercises

Exercise 15.1.

Consider a domain with two individuals (✂ and ☎), two predicate symbols (p and q), and three constants (a, b, and c). The knowledge base K⁢B is defined by

p⁢(X)←⁢q⁢(X).
q⁢(a).
  • (a)

    Give one interpretation that is a model of K⁢B.

  • (b)

    Give one interpretation that is not a model of K⁢B.

  • (c)

    How many interpretations are there? Give a brief justification for your answer.

  • (d)

    How many of these interpretations are models of K⁢B? Give a brief justification for your answer.

Exercise 15.2.

Suppose a language has constant symbols a, b, and c; predicate symbols p and q; and no function symbols. The following knowledge bases are built from this language:

K⁢B1K⁢B2K⁢B3p⁢(a).p⁢(X)←⁢q⁢(X).p⁢(X)←⁢q⁢(X).p(a).q(b).

Consider possible interpretations for this language of the form I=⟨D,π,ϕ⟩, where D={✂, ☎, ✈, ✎}.

  • (a)

    How many interpretations with the four domain elements exist for our simple language? Give a brief justification for your answer. [Hint: Determine the number of possible assignments ϕ for the constant symbols. Consider how many extensions predicates p and q can have to determine how many assignments π exist.] Do not try to enumerate all possible interpretations.

  • (b)

    Of the interpretations outlined above, how many are models of K⁢B1? Give a brief justification for your answer.

  • (c)

    Of the interpretations outlined above, how many are models of K⁢B2? Give a brief justification for your answer.

  • (d)

    Of the interpretations outlined above, how many are models of K⁢B3? Give a brief justification for your answer.

Exercise 15.3.

Consider the following knowledge base:

r⁢(a).r⁢(e).p⁢(c).q⁢(b).s⁢(a,b).s⁢(d,b).s⁢(e,d).p⁢(X)←⁢q⁢(X)∧⁢r⁢(X).q⁢(X)←⁢s⁢(X,Y)∧⁢q⁢(Y).

Show the set of ground atomic consequences derivable from this knowledge base. Use the bottom-up proof procedure assuming, at each iteration, the first applicable clause is selected in the order shown. Furthermore, applicable constant substitutions are chosen in “alphabetic order” if more than one applies to a given clause; for example, if X/a and X/b are both applicable for a clause at some iteration, derive q⁢(a) first. In what order are consequences derived?

Exercise 15.4.

Consider the following knowledge base:

h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(X,l⁢i⁢b⁢r⁢a⁢r⁢y)←⁢s⁢t⁢u⁢d⁢e⁢n⁢t⁢(X).h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(X,l⁢i⁢b⁢r⁢a⁢r⁢y)←⁢f⁢a⁢c⁢u⁢l⁢t⁢y⁢(X).h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(X,l⁢i⁢b⁢r⁢a⁢r⁢y)←⁢p⁢a⁢r⁢e⁢n⁢t⁢(Y,X)∧⁢h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(Y,l⁢i⁢b⁢r⁢a⁢r⁢y).h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(X,o⁢f⁢f⁢i⁢c⁢e)←⁢h⁢a⁢s⁢_⁢k⁢e⁢y⁢s⁢(X).f⁢a⁢c⁢u⁢l⁢t⁢y⁢(d⁢i⁢a⁢n⁢e).f⁢a⁢c⁢u⁢l⁢t⁢y⁢(m⁢i⁢n⁢g).s⁢t⁢u⁢d⁢e⁢n⁢t⁢(w⁢i⁢l⁢l⁢i⁢a⁢m).s⁢t⁢u⁢d⁢e⁢n⁢t⁢(m⁢a⁢r⁢y).p⁢a⁢r⁢e⁢n⁢t⁢(d⁢i⁢a⁢n⁢e,k⁢a⁢r⁢e⁢n).p⁢a⁢r⁢e⁢n⁢t⁢(d⁢i⁢a⁢n⁢e,r⁢o⁢b⁢y⁢n).p⁢a⁢r⁢e⁢n⁢t⁢(s⁢u⁢s⁢a⁢n,s⁢a⁢r⁢a⁢h).p⁢a⁢r⁢e⁢n⁢t⁢(s⁢a⁢r⁢a⁢h,a⁢r⁢i⁢e⁢l).p⁢a⁢r⁢e⁢n⁢t⁢(k⁢a⁢r⁢e⁢n,c⁢h⁢e⁢l⁢s⁢e⁢y).p⁢a⁢r⁢e⁢n⁢t⁢(k⁢a⁢r⁢e⁢n,t⁢o⁢d⁢d).
  • (a)

    Provide an SLD derivation of the query h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(t⁢o⁢d⁢d,l⁢i⁢b⁢r⁢a⁢r⁢y), similar to Figure 15.6.

  • (b)

    The query h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(m⁢a⁢r⁢y,l⁢i⁢b⁢r⁢a⁢r⁢y) has two SLD derivations. Give both, but do not show the clauses chosen or the substitutions.

  • (c)

    Is there a derivation for h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(a⁢r⁢i⁢e⁢l,l⁢i⁢b⁢r⁢a⁢r⁢y)? Explain why, or why not.

  • (d)

    Explain why the set of answers to the query h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(X,o⁢f⁢f⁢i⁢c⁢e) is empty.

  • (e)

    Suppose the following clause is added to the knowledge base:

    h⁢a⁢s⁢_⁢k⁢e⁢y⁢s⁢(X)←⁢f⁢a⁢c⁢u⁢l⁢t⁢y⁢(X).

    What are the answers to the query h⁢a⁢s⁢_⁢a⁢c⁢c⁢e⁢s⁢s⁢(X,o⁢f⁢f⁢i⁢c⁢e)?

Exercise 15.5.

What is the result of the following applications of substitutions?

  • (a)

    f⁢(A,X,Y,X,Y)⁢{A/X,Z/b,Y/c}.

  • (b)

    y⁢e⁢s⁢(F,L)←a⁢p⁢p⁢e⁢n⁢d⁢(F,c⁢(L,n⁢i⁢l),c⁢(l,c⁢(i,c⁢(s,c⁢(t,n⁢i⁢l)))))
        {F/c⁢(l,X1),Y1/c⁢(L,n⁢i⁢l),A1/l,Z1/c⁢(i,c⁢(s,c⁢(t,n⁢i⁢l)))}.

  • (c)

    a⁢p⁢p⁢e⁢n⁢d⁢(c⁢(A1,X1),Y1,c⁢(A1,Z1))←a⁢p⁢p⁢e⁢n⁢d⁢(X1,Y1,Z1)
        {F/c⁢(l,X1),Y1/c⁢(L,n⁢i⁢l),A1/l,Z1/c⁢(i,c⁢(s,c⁢(t,n⁢i⁢l)))}.

Exercise 15.6.

Give a most general unifier of the following pairs of expressions:

  • (a)

    p⁢(f⁢(X),g⁢(g⁢(b))) and p⁢(Z,g⁢(Y))

  • (b)

    g⁢(f⁢(X),r⁢(X),t) and g⁢(W,r⁢(Q),Q)

  • (c)

    b⁢a⁢r⁢(v⁢a⁢l⁢(X,b⁢b),Z) and b⁢a⁢r⁢(P,P)

Exercise 15.7.

For each of the following pairs of atoms, either give a most general unifier or explain why one does not exist:

  • (a)

    p⁢(X,Y,a,b,W) and p⁢(E,c,F,G,F)

  • (b)

    p⁢(Y,a,b,Y) and p⁢(c,F,G,F)

  • (c)

    f⁢o⁢o⁢(Z,[a,z|X],X) and f⁢o⁢o⁢([a,m|W],W,[i,n,g])

  • (d)

    a⁢p⁢(F⁢0,c⁢(b,c⁢(B⁢0,L⁢0)),c⁢(a,c⁢(b,c⁢(a,e⁢m⁢p)))) and a⁢p⁢(c⁢(H⁢1,T⁢1),L⁢1,c⁢(H⁢1,R⁢1)).

Exercise 15.8.

List all of the ground atomic logical consequences of the following knowledge base:

q⁢(Y)←⁢s⁢(Y,Z)∧⁢r⁢(Z).p⁢(X)←⁢q⁢(f⁢(X)).s⁢(f⁢(a),b).s⁢(f⁢(b),b).s⁢(c,b).r⁢(b).
Exercise 15.9.

Consider the following logic program:

r⁢d⁢(c⁢o⁢n⁢s⁢(H,c⁢o⁢n⁢s⁢(H,T)),T).
r⁢d⁢(c⁢o⁢n⁢s⁢(H,T),c⁢o⁢n⁢s⁢(H,R))←r⁢d⁢(T,R).

Give a top-down derivation, showing all substitutions for the query

ask ⁢r⁢d⁢(c⁢o⁢n⁢s⁢(a,c⁢o⁢n⁢s⁢(c⁢o⁢n⁢s⁢(a,X),c⁢o⁢n⁢s⁢(B,c⁢o⁢n⁢s⁢(c,Z)))),W).

What is the answer corresponding to this derivation?

Is there a second answer? If yes, show the derivation; if not, explain why.

Exercise 15.10.

Consider the following logic program:

a⁢p⁢(e⁢m⁢p,L,L).
a⁢p⁢(c⁢(H,T),L,c⁢(H,R))←⁢a⁢p⁢(T,L,R).
a⁢d⁢j⁢(A,B,L)←⁢a⁢p⁢(F,c⁢(A,c⁢(B,E)),L).
  • (a)

    Give a top-down derivation (including all substitutions) for one answer to the query

    ask ⁢a⁢d⁢j⁢(b,Y,c⁢(a,c⁢(b,c⁢(b,c⁢(a,e⁢m⁢p))))).
  • (b)

    Are there any other answers? If so, explain where a different choice could be made in the derivation in the previous answer, and continue the derivation, showing another answer. If there are no other answers, explain why not.

[You are meant to do this exercise as if you were a computer, without knowing what the symbols mean. If you want to give a meaning to this program, you could read a⁢p as a⁢p⁢p⁢e⁢n⁢d, c as c⁢o⁢n⁢s, e⁢m⁢p as e⁢m⁢p⁢t⁢y, and a⁢d⁢j as a⁢d⁢j⁢a⁢c⁢e⁢n⁢t.]

Exercise 15.11.

The aim of this question is to get practice writing simple logic programs.

  • (a)

    Write a relation r⁢e⁢m⁢o⁢v⁢e⁢(E,L,R) that is true if R is the list resulting from removing one instance of E from list L. The relation is false if E is not a member of L.

  • (b)

    Give all of the answers to the following queries:

    ask ⁢r⁢e⁢m⁢o⁢v⁢e⁢(a,[b,a,d,a],R).
    ask ⁢r⁢e⁢m⁢o⁢v⁢e⁢(E,[b,a,d,a],R).
    ask ⁢r⁢e⁢m⁢o⁢v⁢e⁢(E,L,[b,a,d]).
    ask ⁢r⁢e⁢m⁢o⁢v⁢e⁢(p⁢(X),[a,p⁢(a),p⁢(p⁢(a)),p⁢(p⁢(p⁢(a)))],R).
  • (c)

    Write a relation s⁢u⁢b⁢s⁢e⁢q⁢u⁢e⁢n⁢c⁢e⁢(L⁢1,L⁢2) that is true if list L⁢1 contains a subset of the elements of L⁢2 in the same order.

  • (d)

    How many different proofs are there for each of the following queries:

    ask ⁢s⁢u⁢b⁢s⁢e⁢q⁢u⁢e⁢n⁢c⁢e⁢([a,d],[b,a,d,a]).
    ask ⁢s⁢u⁢b⁢s⁢e⁢q⁢u⁢e⁢n⁢c⁢e⁢([b,a],[b,a,d,a]).
    ask ⁢s⁢u⁢b⁢s⁢e⁢q⁢u⁢e⁢n⁢c⁢e⁢([X,Y],[b,a,d,a]).
    ask ⁢s⁢u⁢b⁢s⁢e⁢q⁢u⁢e⁢n⁢c⁢e⁢(S,[b,a,d,a]).

    Explain why there are that many.

Exercise 15.12.

In this question, you are to write a definite-clause knowledge base for the design of custom video presentations.

Assume that the video is annotated using the relation

s⁢e⁢g⁢m⁢e⁢n⁢t⁢(S⁢e⁢g⁢I⁢d,D⁢u⁢r⁢a⁢t⁢i⁢o⁢n,C⁢o⁢v⁢e⁢r⁢s)

where S⁢e⁢g⁢I⁢d is an identifier for the segment. (In a real application this will be enough information to extract the video segment.) D⁢u⁢r⁢a⁢t⁢i⁢o⁢n is the running time of the segment (in seconds). C⁢o⁢v⁢e⁢r⁢s is a list of topics covered by the video segment. An example of a video annotation is the database

s⁢e⁢g⁢m⁢e⁢n⁢t⁢(s⁢e⁢g⁢0,10,[w⁢e⁢l⁢c⁢o⁢m⁢e]).
s⁢e⁢g⁢m⁢e⁢n⁢t⁢(s⁢e⁢g⁢1,30,[s⁢k⁢i⁢i⁢n⁢g,v⁢i⁢e⁢w⁢s]).
s⁢e⁢g⁢m⁢e⁢n⁢t⁢(s⁢e⁢g⁢2,50,[w⁢e⁢l⁢c⁢o⁢m⁢e,a⁢r⁢t⁢i⁢f⁢i⁢c⁢i⁢a⁢l⁢_⁢i⁢n⁢t⁢e⁢l⁢l⁢i⁢g⁢e⁢n⁢c⁢e,r⁢o⁢b⁢o⁢t⁢s]).
s⁢e⁢g⁢m⁢e⁢n⁢t⁢(s⁢e⁢g⁢3,40,[g⁢r⁢a⁢p⁢h⁢i⁢c⁢s,d⁢r⁢a⁢g⁢o⁢n⁢s]).
s⁢e⁢g⁢m⁢e⁢n⁢t⁢(s⁢e⁢g⁢4,50,[s⁢k⁢i⁢i⁢n⁢g,r⁢o⁢b⁢o⁢t⁢s]).

A presentation is a sequence of segments. Represent a presentation by a list of segment identifiers.

  • (a)

    Axiomatize a predicate

    p⁢r⁢e⁢s⁢e⁢n⁢t⁢a⁢t⁢i⁢o⁢n⁢(M⁢u⁢s⁢t⁢C⁢o⁢v⁢e⁢r,M⁢a⁢x⁢t⁢i⁢m⁢e,S⁢e⁢g⁢m⁢e⁢n⁢t⁢s)

    that is true if S⁢e⁢g⁢m⁢e⁢n⁢t⁢s is a presentation whose total running time is less than or equal to M⁢a⁢x⁢t⁢i⁢m⁢e seconds, such that all of the topics in the list M⁢u⁢s⁢t⁢C⁢o⁢v⁢e⁢r are covered by a segment in the presentation. The aim of this predicate is to design presentations that cover a certain number of topics within a time limit.

    For example, the query

    ask ⁢p⁢r⁢e⁢s⁢e⁢n⁢t⁢a⁢t⁢i⁢o⁢n⁢([w⁢e⁢l⁢c⁢o⁢m⁢e,s⁢k⁢i⁢i⁢n⁢g,r⁢o⁢b⁢o⁢t⁢s],90,S⁢e⁢g⁢s)

    should return at least the following two answers (perhaps with the segments in some other order):

    p⁢r⁢e⁢s⁢e⁢n⁢t⁢a⁢t⁢i⁢o⁢n⁢([w⁢e⁢l⁢c⁢o⁢m⁢e,s⁢k⁢i⁢i⁢n⁢g,r⁢o⁢b⁢o⁢t⁢s],90,[s⁢e⁢g⁢0,s⁢e⁢g⁢4])
    p⁢r⁢e⁢s⁢e⁢n⁢t⁢a⁢t⁢i⁢o⁢n⁢([w⁢e⁢l⁢c⁢o⁢m⁢e,s⁢k⁢i⁢i⁢n⁢g,r⁢o⁢b⁢o⁢t⁢s],90,[s⁢e⁢g⁢2,s⁢e⁢g⁢1]).

    Give the intended interpretation of all symbols used and demonstrate that you have tested your axiomatization (including finding all answers to your query) in AIPython (aipython.org) or Prolog. Explain briefly why each answer is an answer.

  • (b)

    Assuming you have a good user interface and a way to actually view the presentations, list three things that the preceding program does not do that you may want in such a presentation system. (There is no correct answer for this part. You must be creative to get full marks.)

Exercise 15.13.

The extra arguments in a definite-clause grammar makes it strictly more powerful than a context-free grammar. The language {an⁢bn⁢cn∣n≥0}, which consists of sentences that are made up of a number of as, followed by the same number of bs followed by the same number of cs cannot be defined with a context-free grammar. Define this language using a definite clause grammar. [Hint: Define a predicate c⁢o⁢p⁢i⁢e⁢s for a non-terminal that creates n copies of one of its arguments, and represent numbers using 0 for zero and s⁢(N) for the numbers after n.]

Exercise 15.14.

Construct a knowledge base and a dictionary based on Figure 15.12 to answer geographical questions such as that given in Figure 1.3. For each query, either show how it can be answered or explain why it is difficult to answer given the tools presented in this chapter.

Exercise 15.15.

Consider what would happen in Example 15.44 if e⁢m⁢p⁢t⁢y⁢_⁢c⁢o⁢u⁢r⁢s⁢e had been defined as

e⁢m⁢p⁢t⁢y⁢_⁢c⁢o⁢u⁢r⁢s⁢e⁢(C)←⁢c⁢o⁢u⁢r⁢s⁢e⁢(C)∧∼⁢e⁢n⁢r⁢o⁢l⁢l⁢e⁢d⁢(S,C).

Suppose the rest of the knowledge base is

c⁢o⁢u⁢r⁢s⁢e⁢(c⁢s⁢422).c⁢o⁢u⁢r⁢s⁢e⁢(c⁢s⁢486).c⁢o⁢u⁢r⁢s⁢e⁢(c⁢s⁢987).e⁢n⁢r⁢o⁢l⁢l⁢e⁢d⁢(h⁢u⁢a⁢n,c⁢s⁢422).e⁢n⁢r⁢o⁢l⁢l⁢e⁢d⁢(s⁢a⁢l⁢l⁢y,c⁢s⁢486).
  • (a)

    What is Clark’s completion of the clause for e⁢m⁢p⁢t⁢y⁢_⁢c⁢o⁢u⁢r⁢s⁢e?

  • (b)

    What is a counter example to the soundness of the completion? Give an instance of the clause for which the body is true and the head is false.

  • (c)

    What does an implementation with negation as failure (e.g., Prolog) give? Compare with e⁢m⁢p⁢t⁢y⁢_⁢c⁢o⁢u⁢r⁢s⁢e⁢(C)←∼⁢e⁢n⁢r⁢o⁢l⁢l⁢e⁢d⁢(S,C)∧⁢c⁢o⁢u⁢r⁢s⁢e⁢(C).