#### 12.7.2.1 Top-Down Procedure for the Unique Names Assumption

The top-down procedure incorporating the unique names assumption should not treat inequality as just another predicate, mainly because too many different individuals exist for any given individual.

If there is a subgoal t1≠t2, for terms t1 and t2 there are three cases:

1. t1 and t2 do not unify. In this case, t1≠t2 succeeds.

For example, the inequality f(X,a,g(X))≠f(t(X),X,b) succeeds because the two terms do not unify.

2. t1 and t2 are identical, including having the same variables in the same positions. In this case, t1≠t2 fails.

For example, f(X,a,g(X))≠f(X,a,g(X)) fails.

Note that, for any pair of ground terms, one of these first two cases must occur.

3. Otherwise, there are instances of t1≠t2 that succeed and instances of t1≠t2 that fail.

For example, consider the subgoal f(W,a,g(Z))≠f(t(X),X,Y). The MGU of f(W,a,g(Z)) and f(t(X),X,Y) is {X/a, W/t(a), Y/g(Z) }. Some instances of the inequality, such as the ground instances consistent with the unifier, should fail. Any instance that is not consistent with the unifier should succeed. Unlike other goals, you do not want to enumerate every instance that succeeds because that would mean unifying X with every function and constant different than a, as well as enumerating every pair of values for Y and Z where Y is different than g(Z).

The top-down proof procedure can be extended to incorporate the unique names assumption. Inequalities of the first type can succeed and those of the second type can fail. Inequalities the third type can be delayed, waiting for subsequent goals to unify variables so that one of the first two cases occur. To delay a goal in the proof procedure of Figure 12.3, when selecting an atom in the body of ac, the algorithm should select one of the atoms that is not being delayed. If there are no other atoms to select, and neither of the first two cases is applicable, the query should succeed. There is always an instance of the inequality that succeeds, namely, the instance where every variable gets a different constant that does not appear anywhere else. When this occurs, the user has to be careful when interpreting the free variables in the answer. The answer does not mean that it is true for every instance of the free variables, but rather that it is true for some instance.

Example 12.44: Consider the rules that specify whether a student has passed at least two courses:
passed_two_courses(S) ←
C1 ≠C2
passed(S,C1)∧
passed(S,C2).
passed(S,C) ←