Inequality

DEC-10 Prolog, C-Prolog, and Quintus Prolog provide two inequality operations:


Term1 \== Term2
Term1 is not currently identical to Term2
Expr1 =\= Expr2
Expr1 and Expr2 are arithmetic expressions with different values

=\=/2 is reasonably straightforward. Either it is true, and will remain true, or it is false, and will remain false, or the Prolog system will report an error if it cannot determine which. Thus 1 =\= 2 is true, 1 =\= 1.0 is false, and _ =\= 3 will result in an error exception.

\==/2 is not really a logical relation, but a meta-logical relation like var/1. It tests whether two terms are exactly identical, down to having the same variables in the same places. It either succeeds or fails; and if it fails it will continue to do so, but if it succeeds it may fail later on. For example,

     | ?- X \== Y,  % succeeds
     |    X  =  Y,  % succeeds, unifying X and Y
     |    X \== Y.  % FAILS, now that X and Y are unified
     
     no
     

It is safe to use ==/2 and \==/2 to test the equality of terms when you know in advance that the terms will be ground by the time the test is made.