Various results in swi-prolog and yap

The sample program lists and counts the number of solutions with 8 crowns. (sorry if the code is hard to read, this is machine-generated from an S-expression. Source code https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_11.html )

regulations:

[user]. (perm([X|Y],Z) :- (perm(Y,W),takeout(X,Z,W))). perm([],[]). takeout(X,[X|R],R). (takeout(X,[F|R],[F|S]) :- (takeout(X,R,S))). (solve(P) :- (perm([1,2,3,4,5,6,7,8],P),combine([1,2,3,4,5,6,7,8],P,S,D),alldiff(S),alldiff(D))). (combine([X1|X],[Y1|Y],[S1|S],[D1|D]) :- (is(S1,+(X1,Y1)),is(D1,-(X1,Y1)),combine(X,Y,S,D))). combine([],[],[],[]). (alldiff([X|Y]) :- (\+ member(X,Y),alldiff(Y))). alldiff([X]). end_of_file. 

request:

 (setof(P,solve(P),Set),length(Set,L),write(L),write('\n'),fail). 

swipl returns 92; and yap returns 40320. In addition, when I ask for solve(P) , swipl returns only two solutions (which also contradicts 92); yap returns a lot more (maybe 40320 of them). So why the difference? Is there such a serious compatibility issue?

Versions:

  • YAP 6.2.2 (x86_64-linux): Sat Sep 17 13:59:03 UTC 2016
  • SWI-Prolog version 7.2.3 for amd64
+7
prolog iso-prolog
source share
1 answer

In older versions of YAP, the request for the undefined predicate simply failed. In the above case, this is member/2 , which is not defined in YAP. And for this reason, your alldif/1 test always succeeds - so you get a lot.

The behavior for this is determined by the Prolog unknown flag, whose default value should be error . In YAP 6.2, the default value is (incorrect) fail . This has been fixed in 6.3. Let's say

 :- set_prolog_flag(unknown, error). 

to get a clean error for undefined predicates. Then you will need to define member/2 .

+7
source share

All Articles