Finish First-order Logic Overview




CS156

Chris Pollett

Nov 6, 2017

Outline

Introduction

Using First-Order Logic

Example 1st Order Knowledge bases

KBs, First-Order Proofs

Quiz

Which of the following is true?

  1. DPLL's early termination test causes it to return a satisfying assignment if at least one literal in each clause is true according to the current partial assignment.
  2. A first order term is built up of constants and relations.
  3. Any first order formula can be made true in some model with some variable assignment.

Soundness and Completeness

Theorem Proving in First-Order Logic

The basic idea is we want to reduce the first-order case to the propositional case. To do this:

  1. Convert each formula in the set of formulas `KB cup {neg alpha}` using some of the operations previously described into prenex normal form:
    `forall vec(x) exists vec(y) forall vec(z) ... G(vec(x), vec(y), vec(z), ...)`
    where `G` does not involve quantifiers and may involve `neg, vee, wedge`. The reason why we are working with sets rather than the single formula `KB wedge neg alpha` is to allow for the case KB is an infinite set of formulas.
  2. Introduce new function symbols for `forall exists` blocks. For example,
    `forall x_1 forall x_2, exists y_1, exists y_2, exists y_3 G(x_1, x_2, y_1, y_2, y_3) mbox(transforms to) forall x_1 forall x_2,G(x_1, x_2, f_1(x_1, x_2), f_2(x_1, x_2), f_3(x_1, x_2))`
    This process is called Skolemization. Given a formula `A` we denote its Skolemization as `A^S`. For a set of formula `Gamma` applying Skolemization to each formula yields a set `Gamma^S`. One can show `Gamma |== B` iff `Gamma^S |== B`, so if `KB cup { not alpha}` has refutation then so does `(KB cup {not alpha})^S`.
  3. If we have all variables bound, and only universal quantifiers, we can ditch the quantifiers and have an open formula with our variables all free.
  4. Once we get open formulas without any quantifiers, convert to CNF and try to use resolution algorithm.

Some remarks on the above:

  1. How do we handles formulas with just existentials quantifiers and no universal? Answer: we view these as functions from no arguments to a value. I.e., we replace these with fresh constants.
  2. How are the new function symbols related to the existing terms in the language before adding the function symbols? In general, a new function symbol `f` is connected to existing function and predicate symbols in the language but won't necessarily be expressible as a term in the original language. For example, Skolemizing an induction axiom:
    `A(0, vec a) wedge forall x(A(x, vec a) => A(S(x), vec a)) => A(t(vec a), vec a)`
    might yield a function of the predicate `A`, which when given a `t(vec a)` such that `A(0) and neg A(t(vec a))` holds, searches for a value `v` as a function of `vec a` such that `A(v, vec a)` holds but `A(S(v), vec a)` does not. This search operation might not be expressible as a single term in the original language.
  3. To do resolution we might now also need to come up with substitution lists between two atomic formulas in `G`, say `F(vec(t))`, `F(vec(s))`, for the terms `t_1, ..., t_n` and `s_1`, ..., `s_n` so that they are the same formula. This is so that after doing the substitution, we can resolve the two formulas. Unification is an algorithm for doing this.

Unification Algorithm

If x is a list let head(x) denote the first element of the list, x[0], and tail(x) denote x[1:]. The code below relies on Unify-var which is on the next slide.

Unify(x, y, S)
x - a variable, constant, term or list 
y - a variable, constant, term, or list 
S - a substitution so far
if(S == fail) return fail
if (x(S) == y(S)) return S
else if ( var? (x))
    return Unify-var(x, y, S)
else if ( var? (y))
    return Unify-var(y, x, S)
else if ( term? (x) and term? (y))
    return (Unify(args (x), args(y), Unify( op(x), op(y), S))
else if (list? (x) and list? (y) )
    return (Unify(tail(x), tail(y), Unify(head(x), head(y), S)))
else
    return fail

As an example of what I mean by op and args, consider x:=((z*z) +35). Here op is the top operation. So op(x) := a + b as + is the outer most function symbol. Here a,b are new variables that don't appear elsewhere. args(x) := (z*z, 35), so contains two terms: the left and right symbol of +.

Unify-var

Here Unify-var is defined as:

Unify-var(var, y, S)
var - a variable
y - an expression 
S - a substitution
if(var |-> val) exists in S 
    return Unify(val, y, S)
else if (y |-> val) exists in S 
     return Unify(var, val, S)
else if (occur-ck? (var, y)) return fail;
else
    return ( append((var |-> y), S))

Suppose x is f(var), then var occurs in f(var) in the above and occur-ck of (var, x) is true! (note: prolog doesn't do occur-ck's)

Prolog Example

Prolog uses unification. Consider the Prolog program:

num(0).
num(s(X)) :- num(X).

From the prolog prompt we can then do a query like:

|?- num(Y).

It will unify Y with 0 initially and say

Y = 0

To indicate that num(Y) can be made true if we set Y = 0. If we type `n`, we are indicating we don't want that solution and it will try to resatisfying the statement with a different substitution. i.e., it is as if we did the query num(Y), not(Y = 0). To this Prolog, will now make use of the second rule and return:

Y = s(0)

If Prolog did occurs checks then the following kind of query would fail:

|?- num(s (s (X))) 

Example of Unify's Execution

As an example of unify in action, consider:

x' = g(h(x, y), z)
y' = g(w, t(v))

Initially, S is (). Since x' and y' are both terms, we return

Unify((h(x, y), z), (w, t(v)), Unify(g(a, b), g(a, b), ())) 

Notice that a, b are new variable names. The second Unify will return S = (), since both g(a, b) are the same thing.

So now we try to unify two lists (h(x, y), z), (w, t(v)).

So we will do Unify( (z), (t(v)), Unify (h(x, y), w, S)). S is still ().

Now we call Unify-var (w, h(x,y), S).

This statement will return (w |-> h(x, y)). We now need to unify (z) and (t(v)) with respect to the substitution (w |-> h(x,y)). When we get the final recursive answer, we will have ( (z |-> t(v)), (w |-> h(x,y)) )

Example of Theorem Proving Process

The example images below show going from an English riddle to first-order logic formulas expressing that riddle then Skolemizing and converting to clauses for `KB ^^ neg alpha`, then giving a resolution refutation:

Initial riddle
Riddle in Logic
Riddle as clauses
Refutation

Equality