DPLL, First-Order Logic




CS156

Chris Pollett

Oct 22, 2014

Outline

Introduction

Horn Clauses and Definite Clauses

Prolog

A Prolog Example Logic Program

Consider the Horn program:

a. /* lines end with a period, a rule without a tail is called a fact */
b:- a.
c:-b.
d:- a, b.

How Prolog computes its answers

  • To compute the answer, we can imagine Prolog scanning through the rules of the program, looking for the first rule whose head is our query. If this rule if a fact it outputs true. This is what happened for the query ?- a. Otherwise, it tries to satisfy each of the conditions in the tail of the rule. In the case of ?- d., we find the rule d:- a, b. and then try to satisfy a. We can because it is a fact. Then we try to satisfy b. To do this we scan the rules from the top and find the rule b:-a. So to satisfy this rule we need a, but we have already derived it is a fact, so we have `b`. Now that we have `a,b` we can conclude `d`, and Prolog outputs true.
  • If it was the case that Prolog couldn't satisfy d:- a, b. then Prolog would backtrack and try to find a rule further down in the program with `d` in the head and try to satisfy that.
  • The interpretation of a query on a nonexistent variable like `e` is an error for SWI-Prolog. We can view this as false: we were not able to derive that variable. This corresponds in some degree to the closed world assumption (CWA), things we don't know about we assume are false. i.e., we should favor minimal models. Favoring maximal models on the other hand corresponds to the open world assumption (OWA).
  • A program like:
    d:-d.
    c:-b.
    b:-c.
    
    followed by a query ?- d or a query ?- b would result in an infinite loop.
  • Prolog supports non-Horn rules like:
    e :- not(a).
    f :- false.
    
  • DPLL Algorithm: A general resolution finding algorithm

    DPLL Algorithm

    function DPLL-Satisfiable?(s) returns true or false
       inputs: s a sentence in propositional logic
    
       clauses := the set of clauses in the CNF representation of s
       symbols := a list of the propositional symbols in s
       return DPLL(clauses, symbols, {})
    
    function DPLL(clauses, symbols, model) returns true or false
       if every clause in clauses is true in model then return true
       if some clause in clauses is false in model then return false
       P, value := FIND-PURE-SYMBOL(symbols, clauses, model)
       if P is non-null then return DPLL(clauses, symbols - P, model ∪ {P=value})
       P, value := FIND-UNIT-CLAUSE(clauses, model)
       if P is non-null then return DPLL(clauses, symbols - P, model ∪ {P=value})
       P := FIRST(symbols); //symbols is a list, this get the first element in the list into P
       rest = REST(symbols); //all the elements in the list excluding the first element
       return DPLL(clauses, rest, model ∪ {P=true}) or
           DPLL(clauses, rest, model ∪ {P=false})
    

    First-Order Logic

    Examples