14.4 Implementing Knowledge-Based Systems

The third edition of Artificial Intelligence: foundations of computational agents, Cambridge University Press, 2023 is now available (including full text).

14.4.6 Delaying Goals

One of the most useful abilities of a meta-interpreter is to delay goals. Some goals, rather than being proved, can be collected in a list. At the end of the proof, the system derives the implication that, if the delayed goals were all true, the computed answer would be true.

Providing a facility for collecting goals that should be delayed is useful for a number of reasons:

  • •

    to implement proof by contradiction as used in consistency-based diagnosis or to implement abduction, the assumables are delayed

  • •

    to delay subgoals with variables, in the hope that subsequent calls will ground the variables, and

  • •

    to create new rules that leave out intermediate steps – for example, if the delayed goals are to be asked of a user or queried from a database.

% d⁢p⁢r⁢o⁢v⁢e⁢(G,D0,D1) is true if D0 is an ending of D1 and G logically follows from the conjunction of the delayable atoms in D1.

d⁢p⁢r⁢o⁢v⁢e⁢(t⁢r⁢u⁢e,D,D).
d⁢p⁢r⁢o⁢v⁢e⁢((A&B),D1,D3)←
    d⁢p⁢r⁢o⁢v⁢e⁢(A,D1,D2)∧
    d⁢p⁢r⁢o⁢v⁢e⁢(B,D2,D3).
d⁢p⁢r⁢o⁢v⁢e⁢(G,D,[G|D])←
    d⁢e⁢l⁢a⁢y⁢(G).
d⁢p⁢r⁢o⁢v⁢e⁢(H,D1,D2)←
    (H⇐B)∧
    d⁢p⁢r⁢o⁢v⁢e⁢(B,D1,D2).
Figure 14.14: A meta-interpreter that collects delayed goals

Figure 14.14 gives a meta-interpreter that provides delaying. A base-level atom G can be made delayable using the meta-level fact d⁢e⁢l⁢a⁢y⁢(G). The delayable atoms can be collected into a list without being proved.

If you can prove d⁢p⁢r⁢o⁢v⁢e⁢(G,[],D), you know that the implication G⇐⁢D is a logical consequence of the clauses, and d⁢e⁢l⁢a⁢y⁢(d) is true for all d∈D. This idea of deriving a new clause from a knowledge base is an instance of partial evaluation. It is the basis for explanation-based learning which treats the derived clauses as learned clauses that can replace the original clauses.

Example 14.22.

As an example of delaying for consistency-based diagnosis, consider the base-level knowledge base of Figure 14.10, but without the rules for o⁢k. Suppose, instead, that o⁢k⁢(G) is delayable. This is represented as the meta-level fact

d⁢e⁢l⁢a⁢y⁢(o⁢k⁢(G)).

The query

𝘢𝘴𝘬 ⁢d⁢p⁢r⁢o⁢v⁢e⁢(l⁢i⁢v⁢e⁢(p1),[],D).

has one answer, namely, D=[o⁢k⁢(c⁢b1)]. If o⁢k⁢(c⁢b1) were true, then l⁢i⁢v⁢e⁢(p1) would be true.

The query

𝘢𝘴𝘬 ⁢d⁢p⁢r⁢o⁢v⁢e⁢((l⁢i⁢t⁢(l2)&l⁢i⁢v⁢e⁢(p1)),[],D).

has the answer D=[o⁢k⁢(c⁢b1),o⁢k⁢(c⁢b1),o⁢k⁢(s3)]. If c⁢b1 and s3 are o⁢k, then l2 will be lit and p1 will be live.

Note that o⁢k⁢(c⁢b1) appears as an element of this list twice. d⁢p⁢r⁢o⁢v⁢e does not check for multiple instances of delayables in the list. A less naive version of d⁢p⁢r⁢o⁢v⁢e would not add duplicate delayables. See Exercise 9.