2

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?

Saroupille
  • 609
  • 8
  • 14
  • 1
    `findall/3` shows no solutions because `clue_two(S)` finds no solutions, which is explained by Paulo's answer. – lurker May 23 '14 at 15:59
  • 2
    You are mixing here contraints and more traditional programming style in one program. Not sure this is what you want. – false May 23 '14 at 17:29

1 Answers1

2

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.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33