Of course, the only thing TT-ENTAILS is to call TT-CHECK-ALL with the appropriate parameters, so there is not much to say. Interesting bits begin with the else part of TT-CHECK-ALL , which recursively builds a huge conjunction for all possible assignments for characters found in the knowledge base and query ("models").
For example, TT-CHECK-ALL(KB, a, [P, Q], []) will evaluate the value
( TT-CHECK-ALL(KB, a, [], [P=true, Q=true]) and TT-CHECK-ALL(KB, a, [], [P=true, Q=false]) ) and ( TT-CHECK-ALL(KB, a, [], [P=false, Q=true]) and TT-CHECK-ALL(KB, a, [], [P=false, Q=false]) )
The first part of TT-CHECK-ALL , which is executed when all characters are assigned a value in the model, checks whether the given model, for example. [P = true, Q = false], consistent with the knowledge base ( PL-TRUE?(KB, model) ). These models correspond to rows in the truth table that have true in the KB column. For them, the algorithm then checks if the query matches the true ( PL-TRUE?(query, model) ). All other models that are incompatible with KB in the first place are not considered, returning true , which is a neutral interface element.
In other words, this is the same as PL-TRUE?(KB, model) -> PL-TRUE?(query, model) .
So, TT-CHECK-ALL checks that for each model (each possible assignment is "true" or "false" for different characters), compatible with KB, the request is evaluated as true:
foreach model: PL-TRUE?(KB, model) -> PL-TRUE?(query, model)
Which is logically equivalent
not exist model: PL-TRUE?(KB, model) and not PL-TRUE?(query, model)
That is, there is no model, so KB and the negation of the request can be true, i.e. KB and request denial are logically incompatible.
And this is just the definition of KB entails query .
Edit: About symbols . These are atomic propositional characters in a dictionary. In the example in the book, these will be different P_i,j and B_i,j , indicating whether (i, j) there is a pit and / or a breeze. Note that R1 through R5 are not part of symbols , as they are simply abbreviated for convenience, representing more complex terms. Therefore, when transferring KB to the algorithm, we would not have passed R1 and R2 and ... R5 , but (not P_1,1) and (B_1,1 <=> (P_1,2 or P_2,1)) and ... and (B_2,1) .