X \= X :- true, !, fail. _ \= _.I.e. the arguments are unified, which may cause delayed goals to be woken and constraints to be checked. Only if all this succeeds, \=/2 fails.
This predicate has a negation-as-failure semantics and so if the compared terms are not ground, it may give unexpected results. Note that the original arguments are unchanged after the predicate succeeds.
Success: atom \= neutron. 1.0 \= 1. f(1,2) \= f(1,3). [1,2] \= [1,3]. [a,b,c] \= [a,b|c]. [a,b,c] \= [X]. [a,X,c,Y] \= [X,b,Y,d]. coroutine, X > 1, X \= 1. Fail: X \= Y. 1 \= X. [a,b|X] \= X.