foundations of computational agents
Instead of being agnostic about the equality of each term and expecting the user to axiomatize which names denote the same individual and which denote different individuals, it is often easier to have the convention that different ground terms denote different individuals.
Consider a student database example where a student must have two courses as science electives. Suppose a student has passed ${m}{\mathit{}}{a}{\mathit{}}{t}{\mathit{}}{h}{\mathit{}}{\mathrm{302}}$ and ${p}{\mathit{}}{s}{\mathit{}}{y}{\mathit{}}{c}{\mathit{}}{\mathrm{303}}$; then you only know whether they have passed two courses if you know ${m}{\mathit{}}{a}{\mathit{}}{t}{\mathit{}}{h}{\mathit{}}{\mathrm{302}}{\mathrm{\ne}}{p}{\mathit{}}{s}{\mathit{}}{y}{\mathit{}}{c}{\mathit{}}{\mathrm{303}}$. That is, the constants ${m}{\mathit{}}{a}{\mathit{}}{t}{\mathit{}}{h}{\mathit{}}{\mathrm{302}}$ and ${p}{\mathit{}}{s}{\mathit{}}{y}{\mathit{}}{c}{\mathit{}}{\mathrm{303}}$ denote different courses. Thus, you must know which course numbers denote different courses. Rather than writing ${n}{\mathrm{*}}{\mathrm{(}}{n}{\mathrm{-}}{\mathrm{1}}{\mathrm{)}}{\mathrm{/}}{\mathrm{2}}$ inequality axioms for ${n}$ individuals, it may be better to have the convention that every course number denotes a different course and thus the use of inequality axioms is avoided.
Under the unique names assumption (UNA) distinct ground terms denote different individuals. That is, for every pair of distinct ground terms ${t}_{1}$ and ${t}_{2}$, it assumes ${t}_{1}\ne {t}_{2}$, where “$\ne $” means “not equal to.”
The unique names assumption does not follow from the semantics for the definite clause language. As far as that semantics was concerned, distinct ground terms ${t}_{1}$ and ${t}_{2}$ could denote the same individual or could denote different individuals.
With the unique names assumption, inequality ($\ne $) can be in the bodies of clauses. If you want to use equality in the body of clauses, you can define equality by adding the clause $X=X$.
The unique names assumption can be axiomatized with the following axiom schema for inequality, which consists of the axiom schema for equality together with the axiom schema:
$c\ne {c}^{\prime}$ for any distinct constants $c$ and ${c}^{\prime}$.
$f({X}_{1},\mathrm{\dots},{X}_{n})\ne g({Y}_{1},\mathrm{\dots},{Y}_{m})$ for any distinct function symbols $f$ and $g$.
$f({X}_{1},\mathrm{\dots},{X}_{n})\ne f({Y}_{1},\mathrm{\dots},{Y}_{n})\leftarrow {X}_{i}\ne {Y}_{i}$, for any function symbol $f$. There are $n$ instances of this schema for every $n$-ary function symbol $f$ (one for each $i$ such that $1\le i\le n$).
$f({X}_{1},\mathrm{\dots},{X}_{n})\ne c$ for any function symbol $f$ and constant $c$.
With this axiomatization, ground terms are identical if and only if they unify. This is not the case for non-ground terms. For example, $a\ne X$ has some instances that are true – for example, when $X$ has value $b$ – and an instance which is false, namely, when $X$ has value $a$.
The unique names assumption is very useful for database applications, in which you do not want, for example, to have to state that $kim\ne sam$ and $kim\ne chris$ and $chris\ne sam$.
Sometimes the unique names assumption is inappropriate – for example, $2+2\ne 4$ is wrong, and it may not be the case that $clark\mathrm{\_}kent\ne superman$.
The top-down proof 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 ${t}_{1}\ne {t}_{2}$, for terms ${t}_{1}$ and ${t}_{2}$ there are three cases:
${t}_{1}$ and ${t}_{2}$ do not unify. In this case, ${t}_{1}\ne {t}_{2}$ succeeds.
For example, the inequality $f(X,a,g(X))\ne f(t(X),X,b)$ succeeds because the two terms do not unify.
${t}_{1}$ and ${t}_{2}$ are identical, including having the same variables in the same positions. In this case, ${t}_{1}\ne {t}_{2}$ fails.
For example, $f(X,a,g(X))\ne f(X,a,g(X))$ fails.
Note that, for any pair of ground terms, one of these first two cases must occur.
Otherwise, there are instances of ${t}_{1}\ne {t}_{2}$ that succeed and instances of ${t}_{1}\ne {t}_{2}$ that fail.
For example, consider the subgoal $f(W,a,g(Z))\ne 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 of 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 13.4, 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.
Consider the rules that specify whether a student has passed at least two courses:
${p}{}{a}{}{s}{}{s}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{w}{}{o}{}{\mathrm{\_}}{}{c}{}{o}{}{u}{}{r}{}{s}{}{e}{}{s}{}{(}{S}{)}{\leftarrow}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{{C}}_{{1}}{\ne}{{C}}_{{2}}{\wedge}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{p}{}{a}{}{s}{}{s}{}{e}{}{d}{}{(}{S}{,}{{C}}_{{1}}{)}{\wedge}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{p}{}{a}{}{s}{}{s}{}{e}{}{d}{}{(}{S}{,}{{C}}_{{2}}{)}{.}$ | ||
${p}{}{a}{}{s}{}{s}{}{e}{}{d}{}{(}{S}{,}{C}{)}{\leftarrow}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{g}{}{r}{}{a}{}{d}{}{e}{}{(}{S}{,}{C}{,}{M}{)}{\wedge}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{M}{\ge}{50}{.}$ | ||
${g}{}{r}{}{a}{}{d}{}{e}{}{(}{s}{}{a}{}{m}{,}{e}{}{n}{}{g}{}{l}{}{101}{,}{87}{)}{.}$ | ||
${g}{}{r}{}{a}{}{d}{}{e}{}{(}{s}{}{a}{}{m}{,}{p}{}{h}{}{y}{}{s}{}{101}{,}{89}{)}{.}$ |
For the query
$${\text{\U0001d622\U0001d634\U0001d62c}}{\mathit{\text{}}}{}{p}{}{a}{}{s}{}{s}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{w}{}{o}{}{\mathrm{\_}}{}{c}{}{o}{}{u}{}{r}{}{s}{}{e}{}{s}{}{(}{s}{}{a}{}{m}{)}{,}$$ |
the subgoal ${{C}}_{{\mathrm{1}}}{\mathrm{\ne}}{{C}}_{{\mathrm{2}}}$ cannot be determined and so must be delayed. The top-down proof procedure can, instead, select ${p}{\mathit{}}{a}{\mathit{}}{s}{\mathit{}}{s}{\mathit{}}{e}{\mathit{}}{d}{\mathit{}}{\mathrm{(}}{s}{\mathit{}}{a}{\mathit{}}{m}{\mathrm{,}}{{C}}_{{\mathrm{1}}}{\mathrm{)}}$, which binds ${e}{\mathit{}}{n}{\mathit{}}{g}{\mathit{}}{l}{\mathit{}}{\mathrm{101}}$ to ${{C}}_{{\mathrm{1}}}$. It can then call ${p}{\mathit{}}{a}{\mathit{}}{s}{\mathit{}}{s}{\mathit{}}{e}{\mathit{}}{d}{\mathit{}}{\mathrm{(}}{s}{\mathit{}}{a}{\mathit{}}{m}{\mathrm{,}}{{C}}_{{\mathrm{2}}}{\mathrm{)}}$, which in turn calls ${g}{\mathit{}}{r}{\mathit{}}{a}{\mathit{}}{d}{\mathit{}}{e}{\mathit{}}{\mathrm{(}}{s}{\mathit{}}{a}{\mathit{}}{m}{\mathrm{,}}{{C}}_{{\mathrm{2}}}{\mathrm{,}}{M}{\mathrm{)}}$, which can succeed with substitution ${\mathrm{\{}}{{C}}_{{\mathrm{2}}}{\mathrm{/}}{e}{\mathit{}}{n}{\mathit{}}{g}{\mathit{}}{l}{\mathit{}}{\mathrm{101}}{\mathrm{,}}{M}{\mathrm{/}}{\mathrm{87}}{\mathrm{\}}}$. At this stage, the variables for the delayed inequality are bound enough to determine that the inequality should fail.
Another clause can be chosen for ${g}{\mathit{}}{r}{\mathit{}}{a}{\mathit{}}{d}{\mathit{}}{e}{\mathit{}}{\mathrm{(}}{s}{\mathit{}}{a}{\mathit{}}{m}{\mathrm{,}}{{C}}_{{\mathrm{2}}}{\mathrm{,}}{M}{\mathrm{)}}$, returning substitution ${\mathrm{\{}}{{C}}_{{\mathrm{2}}}{\mathrm{/}}{p}{h}{y}{s}{\mathrm{101}}$, ${M}{\mathrm{/}}{\mathrm{89}}{\mathrm{\}}}$. The variables in the delayed inequality are bound enough to test the inequality and, this time, the inequality succeeds. It can then go on to prove that ${\mathrm{89}}{\mathrm{>}}{\mathrm{50}}$, and the goal succeeds.
One question that may arise from this example is “why not simply make the inequality the last call, because then it does not need to be delayed?” There are two reasons. First, it may be more efficient to delay. In this example, the delayed inequality can be tested before checking whether ${\mathrm{87}}{\mathrm{>}}{\mathrm{50}}$. Although this particular inequality test may be fast, in many cases substantial computation can be avoided by noticing violated inequalities as soon as possible. Second, if a subproof were to return one of the values before it is bound, the proof procedure should still remember the inequality constraint, so that any future unification that violates the constraint can fail.