Search code examples
prologgnu-prologprolog-findall

findall/3 returns an empty list instead of solutions


I use GNU Prolog to solve a problem. I have defined the following predicate :

% P is the product of X and Y
produit(X,Y,P) :- 
    between(2,200,X),
    between(2,200,Y),
    X #<# Y,
    X*Y #=# P.

% S is the sum of X and Y 
somme(X,Y,S) :-
    between(2,200,X),
    between(2,200,Y),
    X #<# Y,
    X+Y #=# S.

%je ne peux pas deviner
clue_one(X,Y) :-
    produit(X,Y,P),
    XX*YY #=# P,
    XX #\=# X,
    XX #\=# 1,
    YY #\=# 1,
    XX #\=# Y.

%je le savais
clue_two(S) :-
    forall(somme(X,Y,S), clue_one(X,Y)).

Prolog says that clue_two(17) is true but when I try findall(S, clue_two(S), L) , GNU Prolog returns the empty list. Why?


Solution

  • The forall/2 de facto standard predicate is equivalent to:

    forall(Generator, Test) :-
        \+ (Generator, \+ Test).
    

    Due to the use of negation, no bindings resulting from the calls to either Generator or Test are returned.