projog

2.5. Prolog Term Comparison

Prolog provides commands for comparing terms. The criteria for deciding the order of terms is as follows:

The Prolog term comparison operators are: =, ==, @<, @>, @>= and @=<.

Prolog also has numeric comparison operators which specifically deal with numerical comparison.

Examples

Examples of comparing a uninstantiated variable to a whole number.

?- X @< 2.
X = UNINSTANTIATED VARIABLE

yes

?- 2 @< X.

no

?- X @=< 2.
X = UNINSTANTIATED VARIABLE

yes

?- 2 @=< X.

no

?- X @> 2.

no

?- 2 @> X.
X = UNINSTANTIATED VARIABLE

yes

?- X @>= 2.

no

?- 2 @>= X.
X = UNINSTANTIATED VARIABLE

yes

Examples of comparing a uninstantiated variable to an atom.

?- X @< atom.
X = UNINSTANTIATED VARIABLE

yes

?- atom @< X.

no

?- X @=< atom.
X = UNINSTANTIATED VARIABLE

yes

?- atom @=< X.

no

?- X @> atom.

no

?- atom @> X.
X = UNINSTANTIATED VARIABLE

yes

?- X @>= atom.

no

?- atom @>= X.
X = UNINSTANTIATED VARIABLE

yes

Examples of comparing a uninstantiated variable to a structure.

?- X @< structure(a,b,c).
X = UNINSTANTIATED VARIABLE

yes

?- structure(a,b,c) @< X.

no

?- X @=< structure(a,b,c).
X = UNINSTANTIATED VARIABLE

yes

?- structure(a,b,c) @=< X.

no

?- X @> structure(a,b,c).

no

?- structure(a,b,c) @> X.
X = UNINSTANTIATED VARIABLE

yes

?- X @>= structure(a,b,c).

no

?- structure(a,b,c) @>= X.
X = UNINSTANTIATED VARIABLE

yes