Prolog Language Constraint Logic Programming CLP(FD)


Example

CLP(FD) constraints (Finite Domains) implement arithmetic over integers. They are available in all serious Prolog implementations.

There are two major use cases of CLP(FD) constraints:

  • Declarative integer arithmetic
  • Solving combinatorial problems such as planning, scheduling and allocation tasks.

Examples:

?- X #= 1+2.
X = 3.

?- 3 #= Y+2.
Y = 1.

Note that if is/2 were to be used in the second query, an instantiation error would occur:

?- 3 is Y+2.
ERROR: is/2: Arguments are not sufficiently instantiated