CS 342 Lecture -*- Outline -*- * Resolution (logical basis for Prolog) interpreter tries to verify the goal statement (or prove false) through a proof procedure. proof procedure = inference system + search strategy inference is resolution + selection of leftmost term (SL resolution) resolution derives a new goal from goal and a pattern motivating example: ---------------- imokay :- youreokay, hesokay. % C1 youreokay :- theyreokay. % C2 hesokay. % C3 theyreokay. % C4 ?- imokay. ---------------- draw time (x-axis) vs. goals (stacked on Y axis) pictures ---------------- hesnotokay :- imnotokay. % C5 shesokay :- hesnotokay. % C6 shesokay :- theyreokay. % C7 ?- shesokay. ---------------- draw pictures, show backtracking ---------------- hesnotokay :- shesokay. % C8 hesnotokay :- imokay. % C9 ?- shesokay. ---------------- gets into an infinite loop this picture is accurate for variable-free prolog, but need to do more to show how it works with variables. ** Example (for use below) ------------- %facts scientist(sue). %1 scientist(ron). %2 spanish(sue). %3 american(ron). %4 %rule logician(X) :- scientist(X). %5 %goal ?- logician(Y), american(Y). % (is there) some Y is both a logician and an american? --------------- ** resolution theorem proving *** rule of inference (resolution) R or P, (not P or Q) --------------------- R or Q use CNF to remove implications, skolemize (drop universal quantification) leaves set of disjunctions (clauses) e.g. for all X: logician(X) if scientist(X) CNF form is for all X: logician(X) or not scientist(X) skolemized: logician(X) or not scientist(X) truth table for implication A ==> B, i.e., B if A, same as (B or not A) A\B true false true t f false t t *** the resolution rule (mechanical) suppose clause A contains some term s, clause B contains negation of term t, s and t are unifiable by some subst sigma, then resolvent of A and B is generated by 1. combining the clauses to form A or B 2. removing s and t (from the resulting term) 3. applying substitution sigma to result e.g., resolvent of: not scientist(sue) with scientist(sue) formed by combining: not scientist(sue) or scientist(sue), then deleting matching parts: *poof!* e.g., resolvent of: not logician(Y) or not american(Y) with: logician(X) or not scientist(X) is: not american(_0) or not scientist(_0). *** to ask a question Q, resolve (not Q) against set of clauses, if reach a contradiction (empty clause) shows that original goal was true denial of goal: for all Y, not (logician(Y) and american(Y)) = for all Y, not logician(Y) or not american(Y) *** practical questions in using resolution (and Prolog's answers) what clause to resolve? (goal or descendent) what disjunct in goal to resolve? (leftmost = linear) what clause to resolve against? (from original set, top-down) what subsitution to use? (most general) search strategy breadth-first - sure to find solution (complete) depth first - less storage for backtracking *** SL resolution (**draw following tree as you go**) not logician(Y) or not american(Y) | X = _0 | Y = _0 | | not scientist(_0) or not american(_0) | | _0 = sue | | _0 = ron | | not american(sue) not american(ron) | | fails! succeeds (answer the query ?- locician(Y), american(Y)) 0. denial of query: not logician(Y) or not american(Y) 1. select not logician(Y), unifies with lhs of 5, with Y = _0, X = _0, get new goal list: :- not scientist(_0) or not american(_0) 2. select scientist(_0), unifies with 1 by _0 = sue, get new goal list: :- not american(sue) 3. american(sue) does not unify with any lhs, so proof fails 4. backtrack to last selection, (2), can unify scientist(_0) with _0 = ron, get new goal list: :- not american(ron) 5. american(ron) unifies with rule 4, new goal list empty. means denial of goal was inconsistent substitution was Y=_0=ron ** Why Horn clauses? lhs of rules is always positive e.g., A if B and C ==> A or not B or not C not every statement in predicate logic can be stated this way. ** Top-down vs. bottom up control *** top-down control (backward chaining) as in Prolog goal directed, start with goal as in resolution algorithm only works well when there is a small set of possible answers *** bottom up control (forward chaining) as in OPS5 hard to know what goals to generate ** Depth-first search vs breadth-first search. *draw trees* breadth-first search strategy guaranteed to find refutation if possible may require exponential amount of space (hence time) to track *mimics parallel search! depth-first may not find refutation on another branch requires less space if succeeds. makes order of clauses tried very important example: p :- p, q. p. q. Prolog goes into infinite loop on goal ?- p. breadth first search finds answer.