# Logic for Computer Scientists/Predicate Logic/Resolution
## Resolution

In the propositional case we defined the resolution inference rule by "cutting away" a pair of complementary literals in two clauses which are resolved upon. In the first order case however this is not always sufficient:
${\begin{matrix}C_{1}:&p(x)\lor q(x)\\C_{2}:&\lnot p(f(x))\end{matrix}}$
In these two clauses there are no complementary literals, however, after substituting the term $f(a)$ for the variable $x$ in $C_{1}$ and $a$ for $x$ in $C_{2}$ we arrive at:
${\begin{matrix}C_{1}':&p(f(a))\lor q(f(a))\\C_{2}':&\lnot p(f(a))\end{matrix}}$
Now we can apply the inference rule from propositional logic and arrive at the resolvent $q(f(a))$.
Another possibility is to substitute $f(x')$ for $x$ in $C_{1}$ to get
$C_{1}'':p(f(x'))\lor q(f(x'))$
and then we can have the resolvent $q(f(x'))$ from $C_{1}''$ and $C_{2}$, which is in a certain sense more general then the resolvent derived previously.

## Definition 18

A substitution $\sigma$ is a function, which maps variables to terms and which is the identical mapping almost everywhere. Hence it can be represented as
$\sigma =\{x_{1}/t_{1},\cdots ,x_{n}/t_{n}\}$
If $t_{1},\cdots ,t_{n}$ are groundterms, we call $\sigma$ a ground substitution. The empty substitution is notated by $\epsilon$ .

## Definition 19

Let $\theta =\{x_{1}/t_{1},\cdots ,x_{n}/t_{n}\}$ be a substitution and $E$ an expression (i.e. a literal or a term), then $E\theta$ is the expression, obtained from $E$ by replacing simultaneously each occurrence of $X_{i},1\leq i\leq n$ in $E$ by the term $t_{i}$.
Example: With $\theta =\{x/a,y/f(b),z/e\}$ and $E=p(x,y,z)$, we get $E\theta =p(a,f(b),c)$

## Definition 20

Let $\sigma =\{x_{1}/t_{1},\cdots ,x_{n}/t_{n}\}$ and $\lambda =\{y_{1}/s_{1},\cdots ,y_{m}/s_{m}\}$ be substitutions. Then the composition of substitutions, denoted by $\sigma \circ \lambda$, is the substitution, which is obtained from $\{x_{1}/t_{1}\lambda ,\cdots ,x_{n}/t_{n}\lambda ,y_{1}/s_{1},\cdots ,y_{m}/s_{m}\}$ by deleting any element $x_{j}/t_{j}\lambda$ for which $t_{j}\lambda =x_{j}$ and any element $y_{i}/s_{i}$ such that $y_{i}\in \{x_{1},\cdots ,x_{n}\}$ .
Example:

## Definition 21

Let $\{E_{1},\cdots ,E_{n}\}$ be a set of expressions and $\theta$ a substitution, $\theta$ is unifier for $\{E_{1},\cdots ,E_{n}\}$ iff
$E_{1}\theta =E_{2}\theta =\cdots E_{n}\theta$
A unifier $\theta$ is called most general unifier iff for every unifier $\sigma$ there is a substitution $\lambda$ such that $\sigma =\theta \circ \lambda$.
In the following we discuss an algorithm for computing most general unifiers. For this we assume a set of terms $\{t_{1},\cdots ,t_{n}\}$ to be unified. First we transform this into a set of equations by introducing a new variable not yet occurring in this set, say $y$ and by defining the set of equations
$N=\{y=t_{1},\cdots ,y=t_{n}\}$
We will now transform this set such that its unifiers stay invariant, where a $\sigma$ is a unifier of a set of $\{s_{1}=t_{1},\cdots ,s_{n}=t_{n}\}$ if $\{s_{1}\sigma =t_{1}\sigma ,\cdots ,s_{n}\sigma =t_{n}\sigma \}$ holds.
Given a set of expression. Transform it into a set of equations $N$ as defined above. Apply the following transformation rules as long as possible:
* ${\frac {R\uplus \{t=x\}}{R\uplus \{x=t\}}}$ Orient where $x$ is a variable and $t$ a non-variable term
* ${\frac {R\uplus \{s=s\}}{R}}$ Delete
* ${\frac {R\uplus \{f(s_{1},\dots ,s_{n})=f(t_{1},\dots ,t_{n})\}}{R\uplus \{s_{1}=t_{1},\dots ,s_{n}=t_{n}\}}}$ Decompose (Termreduction)
* ${\frac {R\uplus \{x=t\}}{R[x/t]\uplus \{x=t\}}}$ Eliminate (Elimination of variable I) if $x$ not in $t$, but in $R$
* ${\frac {R\uplus \{x=y\}}{R[x/y]\uplus \{x=y\}}}$Coalesce (Elimination of variable II) if $x\neq y$ in $R$
* ${\frac {R\uplus \{f(s_{1},\dots ,s_{m})=g(t_{1},\dots ,t_{n})\}}{\mbox{FAIL}}}$ Conflict if $f\neq g$ or $m\neq n$
* ${\frac {R\uplus \{x=t\}}{\mbox{FAIL}}}$ Occur Check if $x$ in $t$

## Theorem 7

Let $N$ be a set of expressions. The above unification algorithm terminates. If it returns $FAIL$, there is no unifier for $N$, otherwise $N$ is transformed into a set of equation $\{y_{1}=u_{1},\cdots ,y_{m}=u_{m}\}$, which represents the most general unifier for $N$.

## Definition 22

Let two or more literals of a clause $C$ have a unifier $\sigma$, then $C\sigma$ is called a factor of $C$.
Example:
With $C=\{p(x),p(f(y)),\lnot q(x)\}$ and $\sigma =\{x/f(y)\}$ we get the factor $C\sigma =\{p(f(y)),\lnot q(f(y))\}$

## Definition 23

Let $C_{1}$ and $C_{2}$ be two clauses with no variables in common, such that $L_{1}\in C_{1}$ and $L_{2}\in C_{2}$ and $L_{1}$ and $L_{2}$ have a most general unifier $\sigma$. A binary resolvent of $C_{1}$ and $C_{2}$ is
$(C_{1}\sigma -L_{1}\sigma )\cup (C_{2}\sigma -L_{2}\sigma )$
Example: Given $C_{1}=\{p(x),q(x)\}$ and $C_{2}=\{\lnot p(a),r(x)\}$. After renaming $C_{2}$ into $C_{2}=\{\lnot p(a),r(y)\}$ we get the resolvent $\{q(a),r(y)\}$ by using the most general unifier $\{x/a\}$.
We often depict resolvent graphically, e.g.

## Definition 24

A resolvent of two clauses $C_{1}$ and $C_{2}$ is one of the following binary resolvents:
* a binary resolvent of $C_{1}$ and $C_{2}$
* a binary resolvent of $C_{1}$ and a factor of $C_{2}$
* a binary resolvent of a factor of $C_{1}$ and $C_{2}$
* a binary resolvent of a factor of $C_{1}$ and a factor of $C_{2}$
Example:
Given $C_{1}=\{p(x),p(f(y)),r(g(y))\}$ and $C_{2}=\{\lnot p(f(g(a))),q(b)\}$.
A factor of $C_{1}$ is $C_{1}\prime =\{p(f(y)),r(g(y))\}$. A binary resolvent of $C_{1}\prime$ and $C_{2}$ and hence also of $C_{1}$ and $C_{2}$ is $C_{3}=\{r(g(g(a))),q(b)\}$.
The following lemma is used in the completeness proof of resolution.

## Lemma 5 (Lifting lemma)

If $C'_{1}$ and $C'_{2}$ are instances of $C_{1}$ and $C_{2}$, respectively, and $C'$ is a resolvent of $C'_{1}$ and $C'_{2}$, then there is a resolvent $C$ of $C_{1}$ and $C_{2}$ such that $C'$ is an instance of $C$.

## Theorem 8

A set $S$ of clauses is unsatisfiable iff the empty clause can be derived from $S$ by resolution.
Proof: Assume that $S$ is unsatisfiable. Let $A=\{A_{1},A_{2},\ldots \}$ be the ground atom set of $S$, hence the Herbrand basis. Let $T$ be a complete binary tree, as given in Figure 2. According to Herbrand's theorem (version1) there exists a closed finite semantic tree $T'$. There are two cases:
* If $T'$ consists only of one node (hence the root), The interpretation to be collected from the empty branch in this tree falsifies only the empty clause. Hence the empty clause must be in $S$.
* Assume $T'$ consists of more than one node. Then there must be an inference node $N$ in $T'$, hence both its descendants $N_{1}$ and $N_{2}$ are failure nodes. If such a node would not exist, every node would have at least one non-failure node, which would mean that there is at least an infinite path in $T'$, which would violate, that fact that it is a finite closed semantic tree. Let $N,N_{1},N_{2}$ given as described above; and let ${\begin{matrix}I(N)&=&\{m_{1},m_{2},\ldots ,m_{n}\}I(N_{1})&=&\{m_{1},m_{2},\ldots ,m_{n},m_{n},m_{n+1}\}I(N_{2})&=&\{m_{1},m_{2},\ldots ,m_{n},m_{n},\lnot m_{n+1}\}\end{matrix}}$
Now, let $C_{1}'$ and $C_{2}'$ be ground instances of clauses $C_{1}$ and $C_{2}$, such that $C_{1}'$ is falsified by $I(N_{1})$ and $C_{2}'$ by $I(N_{2})$, such that both are not falsified by $I(N)$.
Hence we have $\lnot m_{n+1}\in C_{1}'$ and $m_{n+1}\in C_{2}'$ and we can construct the resolvent
$C'=(C_{1}'-\{\lnot m_{n+1}\})\cup (C_{2}'-\{m_{n+1}\})$
$C'$ must be false in $I(N)$, because both $(C_{1}'-\lnot m_{n+1})$ and $(C_{2}'-m_{n+1})$ are false in $I(N)$. According to the Lifting Lemma 5 there exists a resolvent $C$ of $C_{1}$ and $C_{2}$, such that $C'$ is a ground instance of $C$. Let $T\;''$ be the closed semantic tree for $S\cup \{C\}$ , obtained from $T'$ by deleting all nodes below the first node which falsifies $C'$. Note, that $S$ is unsatisfiable if and only if $S\cup \{C\}$ is unsatisfiable. Clearly, $T\;''$ has less nodes than $T'$ and we now can iterate this process until only the root of the semantic tree is remaining. This, however is only possible if the empty clause $\square$ is derivable. For the opposite direction, assume that $\square$ is derivable by resolution from $S$ and let $R_{1},\ldots ,R_{k}$ the resolvents constructed during this process. Assume $S$ is satisfiable and $M$ to be a model for $S$. From the correctness lemma according to the propositional case we known, that if a model satisfies two clauses it also satisfies its resolvent. Therefore $M$ has to satisfy $R1,\ldots ,R_{k}$; this, however, is impossible, because one of this resolvents is $\square$.

## Problems
#### Problem 14 (Predicate)

Indicate in each case a derivation of the empty clause with predicate-logical resolution!
* $\{\{p(x,0,x)\},\{p(x,s(y),s(z)),\lnot p(x,y,z)\},\{\lnot p(s(s(s(0))),s(s(0)),u)\}\}$
* $\{\{q(x),q(s(x))\},\{\lnot q(x),\lnot q(s(s(x)))\}\}$($\star$)
* $\{\{\lnot r(x,f(x),y),\lnot r(x,g(y),z)\},\{r(c,u,i(v)),r(h(u),v,j(v))\}\}$
$\Box$

#### Problem 15 (Predicate)

Show the following Lifting lemma by means of induction over the term- and formula construction: Is $F$ a predicate-logical formula, and ${\mathcal {I}}$ a fitting interpretation for
$F$ and $F[x/t]$. Then
${\mathcal {I}}(F[x/t])={\mathcal {I}}_{[x/{\mathcal {I}}(t)]}(F),$
is valid, if $t$ does not contain any variable that $[x/t]$ is laced
by the substitution in $F$. $\Box$

#### Problem 16 (Predicate)

Compute - if possible - the most general unifier of following sets of clauses:
* $\{p(x,a),p(f(c),y)\}$
* $\{p(f(x),a,x),p(y,z,z)\}$
* $\{q(x,x),q(g(y),y)\}$
* $\{r(x,x),r(a,h(y))\}$
$\Box$

#### Problem 17 (Predicate)

Determine all direct resolvents of the following pairs of clauses:
* $\{\lnot p(x),q(x,b)\}$ and $\{p(a),q(a,b)\}$
* $\{p(x),p(f(x))\}$ and $\{\lnot p(x),\lnot p(f(f(x)))\}$
* $\{\lnot q(c,g(c))\}$ and $\{\lnot p(x),q(x,x)\}$
* $\{\lnot p(x,y,z),\lnot p(y,u,v),\lnot p(x,v,w),p(z,u,w)\}$ and $\{p(g(x,y),x,y)\}$
$\Box$

#### Problem 18 (Predicate)

Compute - if possible - the most general unifier of following sets of clauses:
* $\{o(x,x),o(a,f(y))\}$
* $\{p(x,a),p(f(c),y)\}$
* $\{q(g(x),a,x),q(y,z,z)\}$
* $\{r(x,x),r(h(y),y)\}$
$\Box$

#### Problem 19 (Predicate)

Determine all direct resolvents of the following pairs of clauses:
* $\{\lnot p(x),\lnot p(b),q(x,b)\}$ and $\{p(a),q(a,b)\}$
* $\{r(x),r(f(x))\}$ and $\{\lnot r(x),\lnot r(f(f(x)))\}$
* $\{\lnot s(c,g(c))\}$ and $\{s(x,x),\lnot t(x)\}$
$\Box$

#### Problem 20 (Predicate)

Give for the following set of clauses (a) a linear derivation, (b) a derivation with unit resolution, (c) a further (maximally short) derivation of the empty clause by means of predicate-logical resolution!
$\{\{\lnot e(x),o(s(x))\},\{\lnot e(x),\lnot o(s(x)),e(s(s(x)))\},\{e(a)\},\{\lnot o(s(s(s(s(s(a))))))\}\}$
$\Box$

#### Problem 21 (Predicate)

Indicate in each case a derivation of the empty clause with predicate-logical resolution!
* $\{\{p(x,0,x)\},\{p(x,s(y),s(z)),\lnot p(x,y,z)\},\{\lnot p(s(s(s(0))),s(s(0)),u)\}\}$
* $\{\{q(x),q(s(x))\},\{\lnot q(x),\lnot q(s(s(x)))\}\}$ ($\star$)
* $\{\{\lnot r(x,f(x),y),\lnot r(x,g(y),z)\},\{r(c,u,i(v)),r(h(u),v,j(v))\}\}$
$\Box$