Quote:

> Can anybody give me answer to the following Prolog terms

> determine whether the terms match. Justify your answers and, where the

> terms match, give the substitutions that make the terms equivalent.

> a) A(X,[Y,Z]) and a(x,y,z)

> b) A([],X) and a([Y,Z], d)

> c) A(A,[a, b]) and a([b,a], B)

I will assume that the version of Prolog you are using allows

variables to have arguments.

The constructive way to answer your question is by applying the

definition of what it means to unify Prolog terms.

Here is such a definition [taken from Chin-Lin Chang and Richard

Char-Tung Lee, /Symbolic Logic and Mechanical Theorem-Proving/, Academic

Press, 1973, and modified for the purposes of this discussion]:

Definition 1. The /disagreement set/ of a nonempty finite set W of

Prolog terms is obtained by locating the first symbol (counting from the

left) at which not all terms in W have exactly the same symbol, and then

extracting from each term in W the constituent term that begins with the

symbol occupying that position. The set of these respective constituent

terms is the disagreement set of W.

Example:

W = { p(X,f(Y,Z)), p(X,a), p(X,g(h(k(X))) }

^^^^ ^^^^ ^^^^

The disagreement set of W is

D = { f(Y,Z) , a , g(h(k(X))) }

Definition 2. Unification Algorithm

Let W be a set of Prolog terms.

Step 0. If the members of W are identical, stop; W is unified.

Otherwise, go to Step 1.

Step 1. Find the difference set D for W.

Step 2. If there exist elements v and t in D such that v

is a variable that does not occur in t, go to Step 3.

Otherwise, stop; W is not unifiable.

Step 3. Replace every occurrence of v in W by t

and go to Step 0.

Example 1.

[0] W = { p(a,X,f(g(Y))), p(Z,f(Z),f(U)) }

^^ ^^

[1] D = { a , Z }

[2] v = Z , t = a

[3] W = { p(a,X,f(g(Y))), p(a,f(a),f(U)) }

^^^^ ^^^^

[1] D = { X , f(a) }

[2] v = X , t = f(a)

[3] W = { p(a,f(a),f(g(Y))) , p(a,f(a),f(U)) }

^^^^^^^^^^^ ^^^^^^^^^^^

[1] D = { g(Y) , U }

[2] v = U , t = g(Y)

[3] W = { p(a,f(a),f(g(Y))) , p(a,f(a),f(g(Y)) }

[0] Done.

Example 2.

[0] W = { [a,X,Y] , [a,Y,c] }

^^^ ^^^

[1] D = { X , Y }

[2] v = X , t = Y

[3] W = { [a,Y,Y] , [a,Y,c] }

^^^^^ ^^^^^

[1] D = { Y , c }

[2] v = Y , t = c

[3] W = { [a,c,c] , [a,c,c] }

[0] Done.

Example 3.

[0] W = { A(A,[a, b]) , a([b,a], B) }

^ ^

[1] D = { A , a }

[2] v = A , t = a

[3] W = { a(a,[a, b]) , a([b,a], B) }

^^ ^^

[1] D = { a , [b,a] }

[2] Fail.

Theorem [stated without proof]: The Unification Algorithm given above

will terminate at Step 0 if and only if the set W is unifiable, and it

will terminate at Step 2 if and only if the set W is not unifiable.

Quote:

> Thanx in advance

> Btw Which is best site to study about prolog

If you want to develop any meaningful degree of skill at using Prolog,

you have to be willing to spend at least 120 solid hours writing Prolog

programs and debugging them on a computer -- and that's just for starters.

I do not recommend using any of the so-called standard versions of

Prolog for that purpose. I do recommend using Turbo Prolog 2.0 or PDC

Prolog 3.21 on MS-DOS -- if you can still find copies anywhere -- or PDC

Visual Prolog 5.2 for Windows. A "nagged" version of 5.2 can be freely

downloaded from SimTel but it only costs $60 to buy, so I would

recommend grabbing a copy while it is still available if you are

that interested. (PDC Visual Prolog 6.0 is in early alpha stage.)

Bill

--

http://www.sonic.net/~sequitur