CS 541 Lecture -*- Outline -*- * Procedural model of Prolog ** practical questions in using resolution (and Prolog's answers) our abstract interpreter has a number of choices to make... -------------------------------------- what substitution to use? (most general) no limitation here what clause to resolve? (goal or descendent of goal) backwards chaining what disjunct in goal to resolve? (leftmost = linear) what clause to resolve against? (from original set, top-down) search strategy breadth-first - sure to find solution (complete) depth first - less storage for backtracking (Prolog) -------------------------------------- *** 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. ** SL resolution 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 (**draw following tree as you go**) not logician(Y) or not american(Y) | X = U0 | Y = U0 | | not scientist(U0) or not american(U0) | | U0 = sue | | U0 = ron | | not american(sue) not american(ron) | | fails! succeeds (answer the query ?- logician(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 = U0, X = U0, get new goal list: :- not scientist(U0) or not american(U0) 2. select scientist(U0), unifies with 1 by U0 = 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(U0) with U0 = 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=U0=ron substitution was Y=U0=ron interpreter tries to verify the goal statement (or prove false) through a proof procedure. 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 ** Another way to see examples, time vs. goals stack graphs ---------------- 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. draw time vs. goals picture ** practical implications declarative, or logical meaning of a Prolog program does not match the way it really executes. def: a computation of a goal Q by a program P terminates if Prolog comes up with a substitution, or fails in a finite time. *** order of rules matters determines order in which solutions are found, and termination *** order of clauses in body matters determines order of new subgoals, and hence the search tree recall searched depth first *** termination domain def: domain is a set of goals, D, such that if A is in D and A' is an instance of A, then A' is in D. (closed under instantiation) def: a termination domain of a program P is a domain D such that every computation of P on D terminates