CS 541 Lecture -*- Outline -*- * Resolution (logical basis for Prolog) ** putting universality together with rules recall (from logic-basics) slide about how we answer queries using rules and with universal facts now we need to do both at once! Q: How can we answer existential queries with universally quantified rules? ** An abstract interpreter keeps a set of goals, called a resolvent ------------------------------------------ ABSTRACT INTERPRETER (may not terminate) input: a logic program P, and a goal G output: a substitution s or failure resolvent <- G. s <- { }. while the resolvent is not empty do choose from the resolvent a goal A and from P a (renamed) clause A' :- B1,...,Bn such that A and A' unify with mgu s'. (fail if no such goal and clause exist) remove A from the resolvent and add B1,...,Bn to the resolvent. resolvent <- s'[[resolvent]] s <- s' o s % compose s' with s done. output s % success ------------------------------------------ the substitution is output if s[[G]] is deducible from P, failure if such a deduction is not possible to ensure that variables are local to a clause, rename free variables each time the clause is chosen to effect a reduction. the new names are fresh ------------------------------------------ COMPOSITION OF SUBSTITUTIONS def: s' o s = {a |-> b | s'[[s[[a]]]] = b} Examples: {Q |-> Z, X |-> sue} o {Y |-> (foo X), R |-> bob} = {Y |-> (foo sue), R |-> bob} ------------------------------------------ ** tracing the abstract interpreter *** Example (for use below) ------------------------------------------ sig some-facts. kind person type. type sue person. type ron person. type scientist person -> o. type spanish person -> o. type american person -> o. type logician person -> o. module some-facts. % facts scientist sue. %1 scientist ron. %2 spanish sue. %3 american ron. %4 % rule logician X :- scientist X. %5 ------------------------------------------ *** tracing a goal % (is there) some Y is both a logician and an american? ------------------------------------------ A FAILURE TRACE [some-facts] ?- (logician Y), (american Y). resolvent = (logician Y), (american Y) s = { } resolves with %5, s' = { Y |-> X' } resolvent = (scientist X'), (american X') s = { Y |-> X' } resolves with %1, s'' = { X' |-> sue } resolvent = (american sue) s = s'' o s' = { Y |-> sue } failure ------------------------------------------ this is what happens if we pick the "wrong" clause to resolve with. (we always rename the X to pervent inadvertant clashes.) This kind of failure will be resolved by backtracking in Prolog, here suppose we somehow picked the right clause... ------------------------------------------ A SUCCESSFUL TRACE ?- (logician Y), (american Y). resolvent = (logician Y), (american Y) s = { } resolves with %5, s' = { Y |-> X' } resolvent = (scientist X'), (american X') s = { Y |-> X' } resolves with %2, s'' = { X' |-> ron } resolvent = (american ron) s = s'' o s' = { Y |-> ron } resolves with %4, s''' = { } resolvent = s = s''' o s'' o s' = { Y |-> ron } output s = { Y |-> ron } ------------------------------------------ ** correctness of the abstract interpreter (skip!) Why is the abstract interpreter correct? because uses universal modus ponens and conjunction rules note the combination of these rules, always used together. This is formalized in resolution theorem proving. Formally, we negate the query, and see if we can derive a contradiction (if we can refute it, then the query was true). *** to ask a query Q, see if not(Q) produces a contradiction this converts all existential queries into universal statements. ------------------------------------------ TO ASK QUERY Q Idea: see if (not Q) is a contradiction ?- (logician Y), (american Y). ------------------------------------------ % (is there) some Y is both a logician and an american? ------------------------------------------ meaning: exists Y . (logician Y) and (american Y) negation is: not (exists Y . (logician Y) and (american Y)) = forall Y . not ((logician Y) and (american Y)) = forall Y . (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 *** to eliminate quantifiers, use fresh variables (skolemize) ------------------------------------------ ELIMINATE QUANTIFIERS BY SKOLEMIZING forall Y . (not (logician Y)) or (not (american Y)) = (not (logician Y)) or (not (american Y)) forall X . (logician X) <== (scientist X) = (logician X) or not(scientist X) universal modus ponens becomes: for s a substitution (A or not(B1) or ... or not(Bn)), s[[B1]], ..., s[[Bn]] __________________________________ 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 **** resolution rule for doing refutations Note: in the first example below, (not R) is the query, R a fact ------------------------------------------ REFUTATION AND RESOLUTION Form of refutations: (not R), R _________________ *contradiction* Conjunctive query in this form: (not R) or (not P), P ___________________ (not R) ------------------------------------------ You can think of the above as modus ponens because this is (not R) <== P, P _______________ (not R) ------------------------------------------ REFUTATION OF A NEGATED QUERY (not (logician Y)) or (not (american Y)), (logician X) or not(scientist X) __________________________________________ not(scientist U) or (not (american U)), (scientist ron) _______________________ (not (american ron)), (american ron) _______________________ *contradiction* ------------------------------------------ Q: What substitutions were used in the refutation? ------------------------------------------ RESOLUTION simple version of resolution: (not R) or (not P), (P or (not Q)) _______________________________ (not R) or (not Q) for s a substitution: (not A1) or ... or (not Ai) or ... or (not Am), (Ai or (not B1) or ... or (not Bn)) ________________________________________ (not s[[A1]]) or ... or (not s[[B1]]) or ... or (not s[[Bn]]) or ... or (not s[[Am]]) ------------------------------------------ Here the premises are previous steps in the refutation, and you are trying to derive a contradiction from the top to the bottom (you start in Prolog with the top) The 2nd premise is a clause from the program. 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 means A or not B or not C not every statement in predicate logic can be stated this way.