SWI-Prolog / issues

Dummy repository for issue tracking
7 stars 3 forks source link

Wrong answer produced by clp(q) after a copy_term/2 #94

Open maximilianocristia opened 4 years ago

maximilianocristia commented 4 years ago

Hi!

We've found the following error.

Version of SWI-Prolog and operating system:

OS: Linux 4.15.0-74-generic #84-Ubuntu SMP Thu Dec 19 08:06:28 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

SWI-Prolog (threaded, 64 bits, version 7.6.4)

Program that produces the error:

use_module(library(clpq)). G=(M=<X, X=<N, N1>=0, K>=1, N1 = K-1, K = N-M+1), {G}, copy_term(G,T), T=(F,R), {F}.

The answer is:

false

but it should be something along the lines:

G = (M=<X,X=<N,N1>=0,K>=1,N1=K-1,K=N-M+1), T = (_A=<_B,_B=<_C,_D>=0,_E>=1,_D=_E-1,_E=_C-_A+1), F = (_A=<_B), R = (_B=<_C,_D>=0,_E>=1,_D=_E-1,_E=_C-_A+1), {N1= -1+K}, {N= -1+M+K}, {M-X=<0}, {_A-_B=<0}, {M-X+K>=1}

According to Paulo Moura this is the answer given by Sictus Prolog.

Besides, the same goal where the order of the integer constraints in G is slightly changed:

G=(M=<X, X=<N, N1>=0, K>=1, K = N-M+1, N1 = K-1), {G}, copy_term(G,T), T=(F,R), {F}.

produces a correct answer.

This error was found by Gianfranco Rossi and me.

All the best, Maxi

andreaf96 commented 4 years ago

This goal @maximilianocristia

G=(M=<X, X=<N, N1>=0, K>=1, N1 = K-1, K = N-M+1),
{G},
copy_term_nat(G,T),
T=(F,R),
{F}.

produces this output (with the latest development version of CLP(Q,R)).

G = (M=<X, X=<N, N1>=0, K>=1, N1=K-1, K=N-M+1), T = (_59190=<_59192, _59192=<_59204, _59214>=0, _59226>=1, _59214=_59226-1, _59226=_59204-_59190+1), F = (_59190=<_59192), R = (_59192=<_59204, _59214>=0, _59226>=1, _59214=_59226-1, _59226=_59204-_59190+1), {K>=1, N1= -1+K, _59338>=0, N= -1+M+K, X= ... + ... - _59338+K, _59404= ... - ... + K, _59338-K=< -1}, {_59192=_59190+_59458, _59458>=0}.

From https://www.swi-prolog.org/pldoc/doc_for?object=copy_term_nat/2

copy_term_nat(+Term, -Copy) As copy_term/2. Attributes, however, are not copied but replaced by fresh variables.