# Unification Functions

I need to apply the unification function to unify the following expression:

foo(X,X,Y) and foo(Z,p(Z),w)

So far, I've determined that I must substitute 'w's for occurances of 'Y', making

foo(X,X,w) and foo(Z,p(Z),w)

Then, I can saw X/Z (replaces 'Z' with 'X'), making:

foo(X,X,w) and foo(X,p(X),w)

Now all that's left is making p(X) equivalent to X

My question here is, is it allowed to replace this P(X) with X using the substitution X/p(X)? Or am I going about the question in the wrong pattern?

Thank you!

In the first step, you inferred that $w=Y$.
In the second step, you inferred that $X=p(Z)$.
In the third step, you inferred that $X=Z$.
It follows that you can infer $Z=p(Z)$. So we know $X=Z=p(Z)$ and $w=Y$.