SWI-Prolog 7.6.4:
?- dif(X, f(Y)), X=f(a). X = f(a), dif(f(f(a), Y), f(f(Y), a)).
Note that I use f/1 in the query, but the cons
f/1