Duplicate constraints in CLP (FD) and with diff / 2

In SWI-Prolog, the following query gives the following result:

?- X mod 2 #= 0, X mod 2 #= 0.
X mod 2#=0,
X mod 2#=0.

Although it is true that, obviously, there is no need for a second restriction

Similarly:

?- dif(X,0), dif(X,0).
dif(X, 0),
dif(X, 0).

Is there no way to avoid such duplicate restrictions? (Obviously, the most correct way would be to not write code that leads to this situation, but it is not always so simple).

+4
source share
3 answers

, setof/3. . SICStus. , YAP SWI, , . A SWI .

SICStus frozen/2 :

| ?- dif(X,0), frozen(X,Goal).
Goal = prolog:dif(X,0),
prolog:dif(X,0) ? ;
no
| ?- X mod 2#=0, frozen(X, Goal).
Goal = clpfd:(X in inf..sup,X mod 2#=0),
X mod 2#=0,
X in inf..sup ? ;
no

copy_term/3 , .

call_residue_vars/1 copy_term/3, , . , SICStus....

+3

, , CLP SMT. , (| -)/2 .

G, A, A |- B
------------ (Left-Contraction)
  G, A |- B

, A . , , . , Jekejeke Minlog CLP (FD), . , OP:

?- use_module(library(finite/clpfd)).
% 19 consults and 0 unloads in 829 ms.
Yes

?- Y+X*3 #= 2, 2-Y #= 3*X.
3*X #= -Y+2

?- X #< Y, Y-X #> 0.
X #=< Y-1

A1 * X1 +.. + An * Xn # = B A1 * X1 +.. + An * Xn # = < B, gcd (A1,.., An) = 1 X1,..., Xn , , . CLP (H), .. , . :

?- use_module(library(term/herbrand)).
% 2 consults and 0 unloads in 35 ms.
Yes

?- neq(X,0), neq(X,0).
neq(X, 0),
neq(X, 0)

dif/2 (==)/2 , dif/2. , dif/2, diff/2, . .

, dif/2 . Jekejeke Minlog, , CLP (FD) X1, CLP (H). , diff/2, . .

+3

For dif/2attraction only, it can be tested without any intervention:

difp(X,Y) :-
   (  X \= Y -> true
   ;  dif(X, Y)
   ).
+2
source

Source: https://habr.com/ru/post/1657482/


All Articles