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.5 Meta-Interpreter to Build Proof Trees

To implement the how question of Section 5.4.3, the interpreter can build a proof tree for a derived answer. Figure 14.13 gives a meta-interpreter that implements built-in predicates and builds a representation of a proof tree. This proof tree can be traversed to implement how questions. In this algorithm, a proof tree is either t⁢r⁢u⁢e, b⁢u⁢i⁢l⁢t⁢_⁢i⁢n, of the form i⁢f⁢(G,T) where G is an atom and T is a proof tree, or of the form (L&R) where L and R are proof trees.

% h⁢p⁢r⁢o⁢v⁢e⁢(G,T) is true if base-level body G is a logical consequence of the base-level knowledge base, and T is a representation of the proof tree for the corresponding proof.

h⁢p⁢r⁢o⁢v⁢e⁢(t⁢r⁢u⁢e,t⁢r⁢u⁢e).
h⁢p⁢r⁢o⁢v⁢e⁢((A&B),(L&R))←
    h⁢p⁢r⁢o⁢v⁢e⁢(A,L)∧
    h⁢p⁢r⁢o⁢v⁢e⁢(B,R).
h⁢p⁢r⁢o⁢v⁢e⁢(H,i⁢f⁢(H,b⁢u⁢i⁢l⁢t⁢_⁢i⁢n))←
    b⁢u⁢i⁢l⁢t⁢_⁢i⁢n⁢(H)∧
    c⁢a⁢l⁢l⁢(H).
h⁢p⁢r⁢o⁢v⁢e⁢(H,i⁢f⁢(H,T))←
    (H⇐B)∧
    h⁢p⁢r⁢o⁢v⁢e⁢(B,T).
Figure 14.13: A meta-interpreter that builds a proof tree
Example 14.21.

Consider the base-level clauses for the wiring domain and the base-level query 𝖺𝗌𝗄 ⁢l⁢i⁢t⁢(L). There is one answer, namely L=l2. The meta-level query 𝖺𝗌𝗄 ⁢h⁢p⁢r⁢o⁢v⁢e⁢(l⁢i⁢t⁢(L),T) returns the answer L=l2 and the tree T=if(lit(l2), i⁢f⁢(l⁢i⁢g⁢h⁢t⁢(l2),t⁢r⁢u⁢e)& i⁢f⁢(o⁢k⁢(l2),t⁢r⁢u⁢e)& if(live(l2), i⁢f⁢(c⁢o⁢n⁢n⁢e⁢c⁢t⁢e⁢d⁢_⁢t⁢o⁢(l2,w4),t⁢r⁢u⁢e)& if(live(w4), if(connected_to(w4,w3), if(up(s3),true))& if(live(w3), if(connected_to(w3,w5), if(ok(cb1),true))& if(live(w5), i⁢f⁢(c⁢o⁢n⁢n⁢e⁢c⁢t⁢e⁢d⁢_⁢t⁢o⁢(w5,o⁢u⁢t⁢s⁢i⁢d⁢e),t⁢r⁢u⁢e)& if(live(outside),true)))))). Although this tree can be understood if properly formatted, it requires a skilled user to understand it. The how questions of Section 5.4.3 traverse this tree. The user only has to see clauses, not this tree. See Exercise 13.