Logic programming
Prolog (programmation en logique), developed by Alain Colmerauer and Phillipe Roussel in 1972, was the first logic programming language. A logic programming language is one in which the programmer states the logic rules, and the language provides the control. In practice, the programmer must often provide implicit or explicit guidance for the control.
The CLP family of languages adds domain-specific constraint solvers to Prolog.
CLP(R)
CLP(R) defines a constraint logic language over the real numbers. The essence of logic programming is that, given a set of rules and a goal to be satisfied over those goals, the solver should search the domain of the rules automatically and determine two properties:
- Is the goal satisfiable?
- What valuations satisfy the goal, if any?
abs(X, A) :- X < 0, -X = A. /* A rule. */ abs(X, A) :- X >= 0, X = A. /* Another rule. */ abs(N, M), N = 3. /* A goal using the rules */ Given an infinitely fast computer, we could simply try every valuation in the domain. Unfortunately, computers are of finite speed, and the space of all reals is infinitely large. Even the tree domain (Prolog's domain) has exponential size in the number of rules.
Therefore, instead of exhaustive search, our solver uses a disciplined means of reasoning over the rules; basically, it searches the derivation tree:
< abs(N,M), N = 3 | true > (R1) / \ (R2) < X=N,A=M,X<0,-X=A, N=3 | true > | < X=N,A=M,X>0,X=A, N=3 | true > | < A=M,X<0,-X=A, N=3 | X=N > | < A=M,X>0,X=A, N=3 | X=N > | < X<0,-X=A, N=3 | X=N,A=M > | < X>0,X=A, N=3 | X=N,A=M > | < -X=A, N=3 | X=N,A=M,X<0 > | < X=A, N=3 | X=N,A=M,X>0 > | < N=3 | X=N,A=M,X<0,-X=A > | < N=3 | X=N,A=M,X>0,X=A > | < nil | X=N,A=M,X<0,-X=A,N=3 > | < nil | X=N,A=M,X>0,X=A,N=3 > (infeasible; backtrack) | (feasible; accept)