==/2 — terms are identical
\==/2 — terms are not identical
Term1 == Term2 Term1 \== Term2
Term1 is identical to
Term1 == Term2) if they can be unified, and variables occupying equivalent positions in both terms are identical. For atoms and variables, this is an absolute identity check. Viewing Prolog terms as trees in memory,
==/2 determines whether
Term2 are isomorphic trees whose leaves are identical. Unlike
=/2, no variables are bound inside a call to
\==/2 fails when
==/2 succeeds, and conversely.
?- bar \== foo. yes. ?- f(b)==f(b). yes. ?- X==Y. no. ?- f(X)\==f(X). no. ?- [a,b,c]\==[a,b,c]. no.