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 task...
CLP(FD) constraints are provided by all serious Prolog implementations. They allow us to reason about integers in a pure way.
?- X #= 1 + 2.
X = 3.
?- 5 #= Y + 2.
Y = 3.
Prolog itself can be considered as CLP(H): Constraint Logic Programming over Herbrand terms. With this perspective, a Prolog program posts constraints over terms. For example:
?- X = f(Y), Y = a.
X = f(a),
Y = a.
CLP(FD) constraints are completely pure relations. They can be used in all directions for declarative integer arithmetic:
?- X #= 1+2.
X = 3.
?- 3 #= Y+2.
Y = 1.
Traditionally Prolog performed arithmetic using the is and =:= operators. However, several current Prologs offer CLP(FD) (Constraint Logic Programming over Finite Domains) as a cleaner alternative for integer arithmetic. CLP(FD) is based on storing the constraints that apply to an integer value and ...