# Syntactic Refinements

## Unit (Binary) Resolution

In each binary resolution step, one parent must be a unit clause. For the ANL loop, unit input clauses are placed in the ToBeUsed set, non-units in CanBeUsed.

Example
```S2 = { ~p(X) | q(X) | ~r(X),
p(a) | p(b),
~q(Y),
r(a),
r(b) }
```

This refinement is refutation complete for Horn clauses, but refutation incomplete for non-Horn clauses, although it does sometimes work for non-Horn clauses. A special case of refutation completeness for non-Horn sets is when the non-Horn set is renamable (by consistently swapping signs for some predicates) to a Horn set.

Example, S2 renames to
```S' = { p(X) | ~q(X) | ~r(X),
~p(a) | ~p(b),
q(Y),
r(a),
r(b) }
```

Example
```S11 = { p(X) | ~p(f(X))
~p(a)
p(S) | q(S) | r(S)
~q(T) | p(a)
~r(T) | p(a) }
```

## Unit Resulting (UR) resolution

Consider the proof tree from the unit resolution refutation of S2, and any path from a leaf unit clause towards the root of the tree :

On such a path, it is necessary that at some stage a unit clause or the empty clause must be reached. In the path indicated in the above tree, the first unit clause reached is ~p(a). Starting again towards the root, again a unit or empty clause must be reached, in this case immediately at p(b). So, a unit resolution proof can be broken down into chunks that end with the production of a unit resolvant or the empty clause. In the above proof tree the chunks are :

Unit resulting (UR) resolution builds refutations by creating such chunks. The unit clauses used are called electrons, and the single non-unit clause the nucleus. The intermediate clauses of each chunk are not kept, but are instead regenerated, e.g., ~p(X) | r(X) has to be generated twice. UR resolution can be implemented directly in the ANL algorithm by initially placing all unit input clauses into ToBeUsed and the non-units into CanBeUsed. The unit resolvants are placed in ToBeUsed. The first electron of each chunk is the ChosenClause. The nucleus and other electrons are taken from CanBeUsed. There is some loss of effectiveness of subsumption, due to intermediate clauses not being used in subsumption (smart solution - if an intermediate clause subsumes another, replace the other clause with the intermediate clause).

Example
```S2 = { ~p(X) | q(X) | r(X),
p(a) | p(b),
~q(Y),
~r(a),
~r(b) }
```

Example
```S11 = { p(X) | ~p(f(X))
~p(a)
p(S) | q(S) | r(S)
~q(T) | p(a)
~r(T) | p(a) }
```

## Ordering

An ordering is imposed on the Herbrand base elements, and full resolutions are not permitted between literals that are known to be smaller than another literal in their clause. This restriction is imposed on the completed refutation.

Example
```S2 = { ~p(X) | q(X) | r(X),
p(a) | p(b),
~q(Y),
~r(a),
~r(b) }

HB = { p(a), p(b), q(a), q(b), r(a), r(b) }

O = p(a) > p(b) > q(a) > q(b) > r(a) > r(b)
```

Notice all the possible resolutions that are prevented by the ordering strategy.

In the above example, the resolved upon literals all were or became ground in unification. Thus it was always possible to check that the largest Herbrand based literal was used in each clause. However, this is not always the case. If variables are unified then it is not necessarily known that the literal is the largest Herbrand based in the clause. An analogous problem arises if the ordering is not total, i.e., some pairs of terms or literals are not comparable.

Example
```S1 = { p(b) | r(Y) | p(Y),
~p(S) | p(b),
~p(b),
~r(a),
~r(c) }

HB = { p(a), p(b), p(c), r(a), r(b), r(c) }

O = p(a) > p(b) > p(c) > r(a) > r(b) > r(c)
```

Here is the proof tree for the first part of a derivation.

If ~r(a) is used to complete the refutation, the proof does not conform to the ordering restriction at the first resolution. Here's the proof tree with variables instantiated up the tree. Note that p(a) is the largest atom in p(b) | r(a) | p(a)

However, until the time of that last inference, it is not known at the time what value the variable X will instantiated to. Similarly, if ~r(c) is used in the last step instead of ~r(a) then it will still not conform. A proof tree that conforms is:

The solution is to either do restrospective checks, which is very expensive, or ordering the only predicate symbols.

Example
```S2 = { ~p(X) | q(X) | r(X),
p(a) | p(b),
~q(Y),
~r(a),
~r(b) }

O = p/1 > q/1 > r/1
```

Ordering is a refutation complete strategy

Proof
To be filled in. Based on working up the failure tree.

## Knuth-Bendix Ordering

KBO provides a way to order terms and atoms in a way that is consistent with an ordering on the Herbrand Universe or Herbrand Base. First some preliminaries ...

A reduction ordering is ...

• Stable under substitution, i.e., if T1 > T2 then T1θ > T2θ
• Stable under context, i.e., if T1 > T2 and T3[P] then T3[T1] > T3[T2] for an arbitrary subterm P
• Terminating, i.e., there is no infinite sequence of terms T1 > T2 > T3 > ....  Note that it is possible to have a sequence T1 < T2 < T3 < ....
A simplification ordering is a reduction ordering with the property ...
• For a term S[P], S > P, i.e., a term is larger than all of its subterms.

An ordering R is ground complete if for all pairs of ground terms or atoms (elements of the Herbrand Universe or Herbrand Base) HUT1 and HUT2, one of the following holds ...

• HUT1 <R HUT2
• HUT1 is HUT2
• HUT1 >R HUT2

An (simplification) ordering O is ground completable if there exists a ground complete reduction ordering R such that O is a subset of R, i.e., the pairs of terms ordered by O are ordered the same by R, and R may order some more pairs of terms that are not ordered by O.

Example
```F = { joe/1, kevin/1, turkey/0, chicken/0 }
```

if joe(X) > kevin(X) then joe(turkey) > kevin(turkey)

if turkey > chicken then joe(turkey) > joe(chicken)

there is no infinite sequence joe(turkey) > joe(chicken) > kevin(turkey) > kevin(chicken) > turkey > chicken > ????

Knuth-Bendix Ordering is an example of a simplification ordering. It is not ground complete, but is ground completable. KBO uses a precedence ordering ρ and a weighting function ω.

• ρ totally orders the predicate and function symbols, and does not order variables wrt anything.
• ω maps each predicate and function symbol to a non-zero positive integer, and maps all variables to the same positive number less than the mapping of any function or predicate symbol. ω then maps a term T to the sum of the mappings of the symbols in T.
ρ and ω do not need to agree. KBO orders T1 > T2 if
• Every variable in T2 occurs at least the same number of times in T1

and

• ω(T1) > ω(T2)
or
• ω(T1) = ω(T2) and ρ(symbol_of(T1)) > ρ(symbol_of(T2))
or
• ω(T1) = ω(T2) and symbol_of(T1) ≡ symbol_of(T2) and args(1 .. i-1,T1) ≡ args(1 .. i-1,T2) and args(i,T1) > args(i,T2)
It is possible that two terms or atoms may be incomparable.

Example
```S = { even(sum(two_squared,b)),
two_squared = four,
~zero(X) | difference(four,X) = sum(four,X),
zero(b),
~even(difference(two_squared,b)) }
```

ρ : even > zero > = > sum > difference > four > two_squared > b

 ω(even) → 5 ω(zero) → 5 ω(=) → 3 ω(sum) → 4 ω(difference) → 3 ω(four) → 4 ω(two_squared) → 4 ω(b) → 3 ω(X) → 1

 ω(zero(X)) → 6 ω(difference(four,X)) → 8 ω(sum(four,X)) → 9 ω(difference(four,difference(four,four))) → 18 ω(difference(four,X) = sum(four,X)) → 20 sum(four,X) > difference(four,X) sum(four,X) = difference(four,X) > zero(X) even(X) > zero(X) even(sum(X,four)) > even(sum(X,two_squared)) even(sum(X,four)) !> even(sum(four,two_squared)) even(sum(X,four)) !> even(sum(Y,two_squared)) difference(four,difference(four,four)) !> sum(four,X)

KBO can be used to determine the largest literals in a clause according to their atoms, with the additional rule that if a positive and negative literal are identical then the negative one is chosen. If there is equality in the problem and the system uses built-in equality reasoning (see later), then the comparison by arguments must not be used when comparing two equality literals (or must take into account the symmetry of the arguments). This is discussed in the section on equality. The KBO weighting function ω can also be used for clause selection in the ANL loop.

Example, using KBO for everything
• ω maps all predicates and function symbols to 2, and all variables to 1.
• ρ is alphabetic
```S10 = { ~p(a)                [4]
~q(W) | s(W)         [6]
~s(X) | p(a)         [7]
~r(Y) | s(Y)         [6]
p(Z) | q(Z) | r(Z) } [9]
```
 ~p(a) is the ChosenClause ~q(W) | s(W) is the ChosenClause ~r(Y) | s(Y) is the ChosenClause ~s(X) | p(a) is the ChosenClause + ~p(a) » ~s(X) [3] ~s(X) is the ChosenClause p(Z) | q(Z) | r(Z) is the ChosenClause + ~p(a) » q(a) | r(a) [8] q(a) | r(a) is the ChosenClause + ~q(W) | s(W) » r(a) | s(a) [4] r(a) | s(a) is the ChosenClause + ~r(Y) | s(Y) » s(a) | s(a) s(a) | s(a) is the ChosenClause + ~s(X) | p(a) » p(a) p(a) is the ChosenClause + ~p(a) » FALSE

### Other Orderings

LPO (lexicographic path ordering) compares terms in a complicated lexicographic way.

## Lock Resolution

[Boyer 1971] (a very restrictive ordering)

Every occurrence of a literal in the input clauses is uniquely numbered, and binary resolution is only permitted on literals of lowest index in their clause. Resolvant literals inherit their indices from parent clauses. A lock factor is a factor of a clause where the lowest index of the factored literals is retained (hmmm, must one of the factored literals have the lowest index in the clause?). Lock resolution is not compatible with many things (including set of support), but is used in conjunction with model resolution in HLR. WHAT ABOUT SUBSUMPTION?

Example
```S1 = { p(b)1 | r(Y)2 | p(Y)3,
~p(S)4 | p(b)5,
~p(b)6,
~r(a)7,
~r(c)8 }
```

Notice the marked reduction of the search space.

Example
```S2 = { ~p(X)1 | q(X)2 | r(X)3,
p(a)4 | p(b)5,
~q(Y)6,
~r(a)7,
~r(b)8 }
```

Example
```S = { bf(a),
~bg(a),
~bf(X) | bh(X),
~bj(X) | ~bi(X) | bf(X),
~bh(X) | bg(X) | ~bi(Y) | ~bh(Y),
bj(b),
bi(b) }
```

Lock resolution is a refutation complete strategy

Proof
To be filled in.

## Exam Style Questions

1. Show the execution of the ANL loop implementing unit resolution, and then unit resulting (UR) resolution, to derive the empty clause from the following. Use subsumption, writing the subsuming clause next to the crossed out subsumed clause.
```S2 = { ~p(X) | q(X) | r(X),
p(a) | p(b),
~q(Y),
~r(a),
~r(b) } ```
```S11 = { p(X) | ~p(f(X))
~p(a)
p(S) | q(S) | r(S)
~q(T) | p(a)
~r(T) | p(a) } ```

2. Neither of the clause sets in the previous question are Horn. How can you be assured that unit and UR resolution will work for them?

3. What is the relationship between unit resulting and UR resolution?

4. Explain the constaint imposed by ordered resolution.

5. Show the execution of the ANL loop implementing ordered resolution, using least symbol count as the selection strategy. Use reverse dictionary order for the ordering on the Herbrand Base. Use pure literal deletion, tautology deletion, and subsumption. Write the subsuming clause next to the crossed out subsumed clause.
```S2 = { ~p(X) | q(X) | r(X),
p(a) | p(b),
~q(Y),
~r(a),
~r(b) } ```
```S11 = { p(X) | ~p(f(X))
~p(a)
p(S) | q(S) | r(S)
~q(T) | p(a)
~r(T) | p(a) } ```

6. The ordered resolution restriction is on the completed refutation. What difficulty does that cause? What are two possible solutions?

7. Explain the four properties of a simplification ordering.

8. Given an ordering ρ or the predicate and function symbols, and a weighting function ω mapping each predicate and function symbol to a non-zero positive integer, mapping all variables to the same positive number less than the mapping of any function or predicate symbol, describe how two terms are ordered by Knuth-Bendix Ordering (KBO).

9. For reverse alphbetic ρ and ω mapping all predicates to 3, all functions to 2, and all variables to 1, determine the order between all pairs of the following atoms:
```p(f(X),X)        p(f(X),Y)      p(a,X)        q(f(X),X)     q(f(a),X)
p(f(a),a)        p(X,Y)         q(X,Y)        q(X,X)        p(a,a) ```

10. Show the execution of the ANL loop implementing ordered resolution, using KBO weight as the selection strategy. Use KBO order for the ordering on the Herbrand Base, with ω mapping all predicates to 3, all functions 2, and all variables to 1. ρ is reverse alphabetic. Use pure literal deletion, tautology deletion, and subsumption. Write the subsuming clause next to the crossed out subsumed clause.
```S = { t(a)
~t(Z) | q(Z) | r(Z)
~q(W) | ~p(W)
p(X) | ~t(a)
~r(Y) | ~p(Y) }
```
(Disclaimer - I have not worked out the answer to this exercise, so it may go weird on you. Bug reports are welcome :-)