Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clpb missing a solution #338

Open
infradig opened this issue Sep 17, 2023 · 18 comments
Open

clpb missing a solution #338

infradig opened this issue Sep 17, 2023 · 18 comments
Labels
bug Something isn't working

Comments

@infradig
Copy link
Contributor

The only example from the clpb.pl doc that is out-right wrong (so far)...

~/trealla (devel) $ tpl
Trealla Prolog (c) Infradig 2020-2023, v2.27.20-1-gc049-dirty
?- use_module(library(clpb)).
   true.
?- sat(X*Y + X*Z), labeling([X,Y,Z]).
   X = 1, Y = X, Z = 0
;  X = 1, Y = X, Z = X
;  false.
?- 

The first solution is missing, as per below...

~/trealla (devel) $ scryer-prolog
?- use_module(library(clpb)).
   true.
?- sat(X*Y + X*Z), labeling([X,Y,Z]).
   X = 1, Y = 0, Z = 1
;  X = 1, Y = 1, Z = 0
;  X = 1, Y = 1, Z = 1.
?- 
@infradig infradig added the bug Something isn't working label Sep 17, 2023
@triska
Copy link

triska commented Sep 20, 2023

The choicepoint is also unexpected!

@infradig
Copy link
Contributor Author

Gone from missing a solution to having one extra...

~/trealla (devel) $ tpl
Trealla Prolog (c) Infradig 2020-2023, v2.27.54-2-g9792
?- use_module(library(clpb)).
   true.
?-  sat(X*Y + X*Z), labeling([X,Y,Z]).
   X = 1, Y = 0, Z = Y
;  X = 1, Y = 0, Z = X
;  X = 1, Y = X, Z = 0
;  X = 1, Y = X, Z = X.
?- 

@triska
Copy link

triska commented Sep 29, 2023

I highly recommend first getting clpb right, and only then start looking at the clpz issue!

@infradig
Copy link
Contributor Author

This clpz query is about as simple as it gets:

  ?- A#=B+C.
  false.

no hook involved, so it seems a good place to work on. Also, all remaining clpz errors seem to end up at the same place so i'm optimistic it's possibly the last stumbling block.

@triska
Copy link

triska commented Oct 4, 2023

I highly recommend you focus on library(clpb) first.

For the present issue, we can see a problem already without labeling/1:

?- sat(X*Y + X*Z).
   clpb:sat(X=\=X*Z#Z), unexpected.

For comparison, Scryer Prolog yields the expected answer:

?- sat(X*Y + X*Z).
   X = 1, clpb:sat(Y=\=Y*Z#Z).

And a simpler goal, with Trealla:

?- clpb:parse_sat(X*Y + X*Z, Sat).
   Sat = X+Z, clpb:sat(X=:=X),clpb:sat(Z=:=Z), unexpected.

Whereas with Scryer, we get the expected answer:

?- clpb:parse_sat(X*Y + X*Z, Sat).
   Sat = X*Y+X*Z, clpb:sat(X=:=X), clpb:sat(Y=:=Y), clpb:sat(Z=:=Z).

@triska
Copy link

triska commented Oct 4, 2023

Systematically reducing it further, we have:

?- clpb:sat_rewrite(X*Y + X*Z, Sat). 
   Sat = X+Z, unexpected.

The expected answer is:

?- clpb:sat_rewrite(X*Y + X*Z, Sat).
   Sat = X*Y+X*Z.

@triska
Copy link

triska commented Oct 4, 2023

Here is a small sample program that shows the problem:

sat_rewrite(V, V)       :- var(V), !.
sat_rewrite(P0*Q0, P*Q) :- sat_rewrite(P0, P), sat_rewrite(Q0, Q).
sat_rewrite(P0+Q0, P+Q) :- sat_rewrite(P0, P), sat_rewrite(Q0, Q).

We get:

?- sat_rewrite(X*Y + X*Z, Sat).
   Sat = X+Z, unexpected.

Whereas the expected result is:

?- sat_rewrite(X*Y + X*Z, Sat).
   Sat = X*Y+X*Z.

So, something really elementary is currently broken.

@triska
Copy link

triska commented Oct 6, 2023

The issue persists:

?- sat_rewrite(X*Y + X*Z, Sat).
   Sat = X+Z, unexpected.

@triska
Copy link

triska commented Oct 8, 2023

The issue still persists:

?- sat_rewrite(X*Y + X*Z, Sat).
   Sat = X+Z.

@infradig
Copy link
Contributor Author

infradig commented Oct 8, 2023 via email

@triska
Copy link

triska commented Oct 8, 2023

Here is the full interaction, using the code I posted in #338 (comment):

$ ./tpl 
Trealla Prolog (c) Infradig 2020-2023, v2.29.2
?- [user].
sat_rewrite(V, V)       :- var(V), !.
sat_rewrite(P0*Q0, P*Q) :- sat_rewrite(P0, P), sat_rewrite(Q0, Q).
sat_rewrite(P0+Q0, P+Q) :- sat_rewrite(P0, P), sat_rewrite(Q0, Q).
% Ctrl+d
   true.
?- sat_rewrite(X*Y + X*Z, Sat).
   Sat = X+Z.

No attributes occur in this example! This is really basic code, it would be ridiculous to try to tackle library(clpz) as long as such elementary errors are present in the engine.

I can confirm that the problem is not present when I invoke Trealla with -O0.

@infradig
Copy link
Contributor Author

infradig commented Oct 8, 2023 via email

@infradig
Copy link
Contributor Author

infradig commented Oct 8, 2023 via email

@triska
Copy link

triska commented Oct 9, 2023

As far as I can tell, the issue persists:

$ ./tpl
Trealla Prolog (c) Infradig 2020-2023, v2.29.5
?- [user].
sat_rewrite(V, V)       :- var(V), !.
sat_rewrite(P0*Q0, P*Q) :- sat_rewrite(P0, P), sat_rewrite(Q0, Q).
sat_rewrite(P0+Q0, P+Q) :- sat_rewrite(P0, P), sat_rewrite(Q0, Q).

   true.
?- sat_rewrite(X*Y + X*Z, Sat).
   Sat = X+Z.

@infradig
Copy link
Contributor Author

infradig commented Oct 9, 2023 via email

@infradig
Copy link
Contributor Author

Ok, I think all the issues above are resolved excpet the original problem, which is back to missing one solution...

~/trealla (devel) $ tpl
Trealla Prolog (c) Infradig 2020-2023, v2.29.7
?- use_module(library(clpb)).
true.
?- sat(XY + XZ), labeling([X,Y,Z]).
X = 1, Y = X, Z = 0
; X = 1, Y = X, Z = X.
?-

@infradig
Copy link
Contributor Author

Can you please recheck this one as well?

@triska
Copy link

triska commented Dec 14, 2023

I get:

?- sat(X*Y + X*Z), labeling([X,Y,Z]).
   X = 1, Y = 1, Z = 0
;  X = 1, Y = 1, Z = 1
;  false.

You can easily see that this is not correct, from the comparison with Scryer Prolog:

?- sat(X*Y + X*Z), labeling([X,Y,Z]).
   X = 1, Y = 0, Z = 1
;  X = 1, Y = 1, Z = 0
;  X = 1, Y = 1, Z = 1.

You can also use Trealla itself to see that either the first or the following is wrong, because adding constraints succeeds where a generalization fails:

?- X = 1, Y = 0, Z = 1, sat(X*Y + X*Z), labeling([X,Y,Z]).
   X = 1, Y = 0, Z = 1.

In short, we have:

?- sat(X*Y + X*Z), labeling([X,Y,Z]), Y = 0.
   false.

Whereas:

?- Y = 0, sat(X*Y + X*Z), labeling([X,Y,Z]).
   Y = 0, X = 1, Z = 1
;  false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants