FD constraints - strange behavior

"Fred Bapst" <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
 Hello,

Using Gnu-Prolog up to 1.3.0, I'm facing something strange (might be a bug
?) illustrated in the predicates below. Why on earth doesn't v1(_) find the
solution ? Defining a new variable for the subexpression (C+30) seems to
help Gnu-Prolog...

It could be related to an overflow problem, but It would be surprising : we
are far below max_integer. It does not seem to be related to the "FD sparse
representation" pitfall (setting fd_set_vector_max to a big value has no
effect).

Thanks in advance.

-----------
Execution :
-----------

| ?- v1(Res).
     no
| ?- v2(Res).
     Res = [9,7]
     yes
| ?- v3(Res).
     Res = [9,7]
     yes

-----------
Listing :
-----------

v1(Ls) :-
        Ls = [C,G],
        fd_domain(C, 8, 9), fd_domain(G, 7, 8),
        780 + 52*(C+30) + 12*G*(C+30) #= 156*(C+30),
        fd_labelingff(Ls).
v2(Ls) :-
        Ls = [C,G],
        fd_domain(C, 8, 9), fd_domain(G, 7, 8),
        C30#=30+C, % replacing expression in v1
        780 + 52*(C30) + 12*G*(C30) #= 156*(C30),
        fd_labelingff(Ls).
v3(Ls) :-
        Ls = [C,G],
        fd_domain(C, 8, 9), fd_domain(G, 7, 8),
        C#=9,  % adding a constraint to v1
        780 + 52*(C+30) + 12*G*(C+30) #= 156*(C+30),
        fd_labelingff(Ls).
--------------------------------------------------

By the way, my original code (for a CLP problem taken from a book) showing
the "bug" was :

fractions1(Ls) :-
        Ls = [A,B,C,D,E,F,G,H,I],
        fd_domain(Ls, 1, 9),
        fd_all_different(Ls),
        BC #= 10*B+C, EF #= 10*E+F, HI #= 10*H+I,
        A*EF*HI + D*BC*HI + G*BC*EF #= BC*EF*HI,
        fd_labelingff(Ls).

_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.