Re: order
Daniel Diaz <[email protected]> Thu, 17 Nov 2011 09:09:09 +0100
| Newsgroups | gmane.comp.gnu.prolog.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hi, It is not a bug. fd_domain (called by last clause of is_square/1) expects 2 integers. If the labeling is done before then X is an integer when is_square is called. If you don't perform the labeling before then X is an FD variable and fd_domain throws an exception. change your clause as follows: is_square(X) :- Y #>= 1, Y #=< X, X #= Y * Y. BTW: you use #<=#, #=#,... which perform more propagation but are very time consuming. You should consider using #<=, #=,... instead (as done above). Daniel Le 15/11/2011 22:11, Robert Jäschke a écrit : > Hello, > > When I load the following prolog program: > > works(L) :- > L = [Z1, Z2], > fd_domain(L, 10, 99), > fd_prime(Z1), > cross_sum(Z1, Z2), > fd_labeling(L), > is_square(Z2) > . > > broken(L) :- > L = [Z1, Z2], > fd_domain(L, 10, 99), > fd_prime(Z1), > cross_sum(Z1, Z2), > is_square(Z2), > fd_labeling(L) > . > > > cross_sum(X, X) :- X #<# 10. > cross_sum(X, Y) :- X #># 9, Y1 #=# X rem 10, X1 #=# X // 10, > cross_sum(X1, Z), Y #=# Z + Y1. > > is_square(1). > is_square(4). > is_square(9). > is_square(X) :- fd_domain(Y, 1, X), X #=# Y * Y. > > > I get an error when invoking broken(L): > > | ?- broken(L). > uncaught exception: error(type_error(integer,_#2097948(10..18)),fd_domain/3) > > while works(L) gives me results: > > | ?- works(L). > > L = [79,16] ? ; > > L = [97,16] ? > > yes > > > The only difference between the two methods is the order of > fd_labeling(L) and is_square(Z2). To the best of my knowledge the order > should not matter. Thus, I assume that I hit a bug. Can you confirm this? > > > > Information about my environment: > >> uname -a > Linux tp 2.6.32-5-amd64 #1 SMP Mon Oct 3 03:59:20 UTC 2011 x86_64 GNU/Linux >> gprolog --version > Prolog top-Level (GNU Prolog) 1.4.0 > > > > Best regards, > Robert > > > -- Ce message a ete verifie par MailScanner pour des virus ou des polluriels et rien de suspect n'a ete trouve.