Question

I am looking resources for learning resolving of constraints in Prolog. For example,

List=[X, Y, Z], List ins 1..4, X - Y #= Z.
Was it helpful?

Solution

What I understand, your want to get concrete solutions (and not the domains). For this, use label/1 or labeling/2, which will give all the explicit solutions (via backtracking). In SWI-Prolog, these predicates are documented here: labeling/2 .

label(List) is equivalent to labeling([],List).

For this simple example, label(List) would suffice:

?- List=[X, Y, Z], List ins 1..4, X - Y #= Z,label(List).

In general, you would benefit by reading the full documentation of clpfd (here for SWI-Prolog).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top