0

I want to know if it is possible to force a result e.g.

test(0, 0, 0).

to be false in Prolog.

repeat
  • 18,496
  • 4
  • 54
  • 166
SEPS
  • 95
  • 4

1 Answers1

3

Yes, you can do it with a little helper predicate like so:

:- use_module(library(clpfd)).

test_(X,Y,Z) :-                        % base relation
   Z #= X+Y.                           % here: integer sum

test(X,Y,Z) :-                         % exclude (0,0,0) as a solution
   abs(X) + abs(X-Y) + abs(Y-Z) #\= 0,
   test_(X,Y,Z).

Sample queries:

?- test(1,1,2).
true
?- test(1,-1,0).
true

Note how the unwanted solution is excluded:

?- test_(0,0,0).            % 0+0 = 0
true
?- test(0,0,0).
false
repeat
  • 18,496
  • 4
  • 54
  • 166