CS 541 Lecture -*- Outline -*- * Resolution (logical basis for Prolog) ** An abstract interpreter keeps a set of goals, called a resolvent ---------------- input: a logic program P, and a goal G output: a substitution s, if s[[G]] is deducible from P, or failure if such a deduction is not possible algorithm: (which may fail to terminate) initialize the resolvent to be G while the resolvent is not empty do choose a goal A from the resolvent and a (renamed clause) A' :- B1,...,Bn from P such that A and A' unify with mgu s (exit if no such goal and clause exist) remove A from the resolvent and add B1,...,Bn apply s to the resolvent and to G If the resolvent is empty, output s, else output failure ---------------- to ensure that variables are local to a clause, rename variables each time the clause is chosen to effect a reduction. the new names are fresh ** Why is the abstract interpreter correct? want to know that if a query is deducible from the program, then there is some execution (some choices) that will deduce it. (And conversely, if not deducible, will output failure. so must tie this interpreter to the deduction rules... recall "universal modus ponens": (forall X . (A <== B1,...,Bn)), s[[B1]], ..., s[[Bn]] _____________________________________________________ s a substitution s[[A]] rule "conjunction": s[[P1]], s[[P2]] ________________________ s a substitution, Xi in dom(s) exists X1...Xn . P and P2 *** simpler rules, resolution 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? --------------- **** to eliminate quantifiers, use fresh variables (skolemize) ------------------------ rule 5 becomes logician(X) <== scientist(X) universal modus ponens becomes: (A <== B1,...,Bn), s[[B1]], ..., s[[Bn]] _________________________________________ s a substitution s[[A]] ------------------------- **** to remove implications, use formula: (A <== B) = (A or not B) truth table for implication B\A true false true t f false t t ---------------------- rule 5 becomes logician(X) or not(scientist(X)) universal modus ponens becomes (A or not(B1) or ... or not(Bn)), s[[B1]], ..., s[[Bn]] ______________________________________________________ s a substitution s[[A]] ---------------------- **** to ask a query Q, see if not(Q) produces a contradiction this converts all existential queries into universal statements. ------------------------------------------------ query was exists Y . logician(Y) and american(Y) negation is forall Y . not (logician(Y) and american(Y)) = by deMorgan's laws forall Y . not(logician(Y)) or not(american(Y)) now skolemize this not(logician(Y)) or not(american(Y)) ------------------------------------------------ instead of trying to prove the statement in a query, try to disprove, refute, the negation so instead of conjuction and modus ponens deduction rules, have resolution rule -------------------------------------- resolution: not(s[[A1]]) or ... or not(s[[Ai]]) or ... or not(s[[Am]]), (Ai or not(B1) or ... or not(Bn)) _________________________________________ s a substitution not(s[[A1]]) or ... or not(B1) or ... or not(Bn) or ...or not(s[[Am]]) simpler version: not(R) or not(P), (P or not(Q)) _______________________________ not(R) or not(Q) some consequences: not(R) or not(P), P ___________________ not(R) not(R), R _________ *poof* --------------------------------------- clear connection betwene modus ponens and resolution not(R) or not(P), P <== Q _________________________ not(R) or not(Q) look at the negation of this R and P, P <== Q _________________ R and Q ------------------------ 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(X1) or not scientist(X1) unifying substitution s(Y) = U0, s(X1) = U0 is: not american(U0) or not scientist(U0). summary: to ask a question Q, resolve (not Q) against set of clauses, if reach a contradiction (empty clause) shows that original goal was true ** 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.