projog

3.18. CLP predicates for comparing numeric values.

Examples

?- X in 7..9, X#=8.
X = 8

yes

?- X in 7..9, X#\=8.
X = {7, 9}

yes

?- X in 7..9, X#>8.
X = 9

yes

?- X in 7..9, X#>=8.
X = 8..9

yes

?- X in 7..9, X#<8.
X = 7

yes

?- X in 7..9, X#=<8.
X = 7..8

yes

?- 16#=X+7.
X = 9

yes

?- 16#=9+X.
X = 7

yes

?- X-7#=16.
X = 23

yes

?- 23-X#=16.
X = 7

yes

?- 16#=-X+2.
X = -14

yes

?- 16#=X*8.
X = 2

yes

?- 16#=X*7.

no

?- 16#=abs(X)+2.
X = -14..14

yes

?- 16#=abs(X)+2, label([X]).
X = -14

yes;
X = 14

yes;

no

?- 9 #= X // 3.
X = 27..29

yes

?- 9 #= X // 3, label([X]).
X = 27

yes;
X = 28

yes;
X = 29

yes;

no

?- 9 #= 27 // X.
X = 3

yes

?- 9 #= 28 // X.
X = 3

yes

?- 9 #= 29 // X.
X = 3

yes

?- 9 #= 26 // X.

no

?- 9 #= 30 // X.

no

?- [X,Y] ins 0..50, 9 #= X // Y, label([X,Y]).
X = 9
Y = 1

yes;
X = 18
Y = 2

yes;
X = 19
Y = 2

yes;
X = 27
Y = 3

yes;
X = 28
Y = 3

yes;
X = 29
Y = 3

yes;
X = 36
Y = 4

yes;
X = 37
Y = 4

yes;
X = 38
Y = 4

yes;
X = 39
Y = 4

yes;
X = 45
Y = 5

yes;
X = 46
Y = 5

yes;
X = 47
Y = 5

yes;
X = 48
Y = 5

yes;
X = 49
Y = 5

yes;

no

?- W in 1..3, X in 2..4, Y #= min(W,X), Z #= max(W,X), label([W,X,Y,Z]).
W = 1
X = 2
Y = 1
Z = 2

yes;
W = 1
X = 3
Y = 1
Z = 3

yes;
W = 1
X = 4
Y = 1
Z = 4

yes;
W = 2
X = 2
Y = 2
Z = 2

yes;
W = 2
X = 3
Y = 2
Z = 3

yes;
W = 2
X = 4
Y = 2
Z = 4

yes;
W = 3
X = 2
Y = 2
Z = 3

yes;
W = 3
X = 3
Y = 3
Z = 3

yes;
W = 3
X = 4
Y = 3
Z = 4

yes;

no

?- 7#=8.

no

?- 8#=8.

yes

?- 9#=8.

no

?- 7#\=8.

yes

?- 8#\=8.

no

?- 9#\=8.

yes

?- 7#>8.

no

?- 8#>8.

no

?- 9#>8.

yes

?- 7#>=8.

no

?- 8#>=8.

yes

?- 9#>=8.

yes

?- 7#<8.

yes

?- 8#<8.

no

?- 9#<8.

no

?- 7#=<8.

yes

?- 8#=<8.

yes

?- 9#=<8.

no

?- X#=a.

Cannot find CLP expression: a/0

?- X#=1/2.

Cannot find CLP expression: //2