-
This works to find all combinations of integers >= 0 whose sum is 3. :- use_module(library(clpz)). % for ins, #=, and label
:- use_module(library(format)).
demo :-
[A, B, C] ins 0..sup,
A + B + C #= 3,
label([A, B, C]),
format("~d + ~d + ~d = 3~n", [A, B, C]). This code is very similar, but does not work. :- use_module(library(clpz)). % for ins, #=, and label
:- use_module(library(format)).
demo2 :-
[A, B, C] ins -6..6,
A * B * C #= -6,
label([A, B, C]),
format("~d * ~d * ~d = -6~n", [A, B, C]). The output from this code is the following rather than giving specific values:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Same with Shorter:
While this answer is not incorrect, all the additional constraints are no longer needed. In general, whenever you try out constraints, it helps to just stick to the top level. It will print out everything for you. |
Beta Was this translation helpful? Give feedback.
-
Well spotted, thank you a lot for reporting this! I have filed #1938 to address this, please have a look. Other than that, @UWN has already raised an important point: The toplevel reports results for you, you can simply press |
Beta Was this translation helpful? Give feedback.
As an example, so that you can remove side-effects from the program, we can write:
Yielding:
Such answers can be easily tested and reasoned about. Further, programs without side-effects can be run with any execution strategy, a major attraction of Prolog.