Arithmetic operators

All these operators evaluate and compare the arithmetic values of their arguments, these operators can be used like the is/2 operator to force the Prolog interpreter to perform arithmetic evaluation. However unlike the is/2 operator must the left operand not be an empty variable.

Operator Name
=:= arithmetic equal
=\= arithmetic not equal
> arithmetic greater than
>= arithmetic greater than or equal
< arithmetic smaller than
=< arithmetic smaller than or equal
+nonvar =:= @evaluable_arithmetic_expression [ISO]

Compare if both arguments have the same arithmetic value.

Examples  
:- X=5, X =:= 2 + 3. succeeds, X= 2
:- X=4, X =:= 2 + 3. no
+nonvar =\= @evaluable_arithmetic_expression [ISO]

Compare if both arguments have different arithmetic values.

Examples  
:- X=5, X =\= 2 + 3. no
:- X=4, X =\= 2 + 3. succeeds, X=4
+nonvar > @evaluable_arithmetic_expression [ISO]

Compare if the value of the left argument is larger than the value of the right argument.

Examples  
:- X=5, X > 2 + 3. no
:- X=6, X > 2 + 3. succeeds, X=6
+nonvar >= @evaluable_arithmetic_expression [ISO]

Compare if the value of the left argument is larger than or equal to the value of the right argument.

Examples  
:- X=5, X >= 2 + 3. succeeds, X=5
:- X=4, X >= 2 + 3. no
+nonvar < @evaluable_arithmetic_expression [ISO]

Compare if the value of the left argument is smaller than the value of the right argument.

Examples  
:- X=5, X < 2 + 3. no
:- X=2.7, X < 2 + 3. succeeds, X=2.7
+nonvar =< @evaluable_arithmetic_expression [ISO]

Compare if the value of the left argument is smaller than or equal to the value of the right argument.

Examples  
:- X=5, X =< 2 + 3. succeeds, X=5
:- X=4, X =< 2 + 3. succeeds, X=4

see also: bit operators \= /2 = /2  is/2 unify_with_occurs_check/2 arithmetic evaluation

 

info@trinc-prolog.com