Вы находитесь на странице: 1из 23

Constraints: An International Journal, 4, 313335 (1999)

c
1999 Kluwer Academic Publishers, Boston. Manufactured in The Netherlands.
From Prolog III to Prolog IV:
The Logic of Constraint Programming Revisited
GUY A. NARBONI implexe@gulliver.fr
Implexe Operational Intelligence for Industry, Marseille, France
Abstract. Constraint programming languages stem from the integration of constraints in conditional rules. By
taking a close look at the design choices made for Prolog IV, the author retraces the general evolution of this recent
and novel paradigm, from its roots in inference systems and optimization, to its applications in model building
and problem solving.
Keywords: logic programming, mathematical programming, interval computations, constraint-directed search
1.0. Introduction
Constraints set bounds, correlate variables, and generally shape the geometry of a problem.
In so doing, they delimit its solution space. What remains to be done for solving is ultimately
searchto isolate solutions.
Constraints are not new in computer science. They rst appeared with the early models of
Operations Research, for long-term planning and decision-making. In that context, a single
solution is usually sought, one that hits the best score for some economic gauge. The focus
is on optimization.
The new idea Constraint Programming introduces today is not in constraints . . . but in
programming. It is the possibility of using constraints dynamically.
Because they enforce conditions, constraints can guide deduction. They can be used to
screen admissible caseseven on the basis of partial information. They can be accumulated
in the course of a logical development, setting at each stage further conditions to be satised.
This can have the effect of pruning a search tree, signicantly and on the y.
By coupling numerical solving to expert system search techniques, constraint program-
ming opens up a variety of formerly combinatorial problems to solution. This includes cases
where solutions may be scattered, instead of forming a continuum. Constraint-directed
search can in turn prove effective in problems of discrete optimization.
Constraint Logic Programming (CLP for short) more specically refers to the integra-
tion of constraints in a Prolog-like rule-based language. Developments in this eld have
been considerable since the mid 80s, showing a successful interplay between theory and
practice.
In this article, we take the example of the Marseilles Prolog line to report on this evolution.
Starting from a well-known specimen of the rst generation: Prolog III, we examine the
relevance of CLP to problemsolving in industry. Then, based on more recent work by Alain
Colmerauers team, we introduce its successor: Prolog IV, a language whose extensive
314 G. A. NARBONI
Table 1. Forerunners in CLP.
CLP emerged in the mid 80s, from european and american labs. Most inuential
was the work of the CLP(R) team led by Jean-Louis Lassez at IBM, who coined the
word CLP and set its theoretical foundations. Colmerauers Prolog II was then the
only instance of a promising scheme. A denite interest in nite domains arose from
the work on the CHIP concept (Constraints Handling in Prolog) by Mehmet Dincbas
and collaborators at the joint Bull-ICL-Siemens European Computer-Industry Research
Center. Both CHIP and Prolog III later turned into products.
coverage of the numeric domain sets a new standard, as for the ratio reached between
expressive power and computational efciency.
2.0. Prolog III
2.1. Constraint Statements in a Logic Program
Constraint programming amounts to specifying a problem in terms of variables subject to
constraints. As in algebra, variables represent the unknowns. Constraints express relations
that embody the problem properties. These properties can be incremented, as new ones
come to light in the problemdenition. Constraints gradually restrict the degree of freedom
of the problem variablesup to assigning them to single values. Constraints can thus be
viewed as invariant statements. They characterize at a time (i.e., at a given program point)
the problem solutions.
In Constraint Logic Programming [15], logic provides the basic connectives for compos-
ing complex relations out of a few primitive ones.
Originally, the only primitive relation Prolog I came equipped with was equalityfor
general pattern matching purposes. By substituting equals for equals, Prolog has the built-
in ability to solve any kind of equations among data structures (i.e., trees in Prolog). This
process is called unication. To equality, Prolog II added the negation of equality, i.e. the
possibility of requiring that two objects are different. Yet, the notions of equal and different
remained purely syntactic. It is only with Prolog III that the semantics of numbers and of
their operations comes into the picture.
With rudiments of linear algebra at the heart of its inference abilities and a consistent
handling of the relations =, and =, Prolog III typies CLP.
2.2. Introductory Example
In keeping with a French tradition of introducing Prolog with a menu program[7, 8], here is
a Prolog III example that uses monetary constraints and shows howto order a not-so-French
meal.
FROM PROLOG III TO PROLOG IV 315
Table 2. Delicious menu program.
meal(tray(U, V, W), X + Y + Z) :-
main dish(V, Y),
glass(U, X),
side dish(W, Z)
{X 1, Y 1, Z 0} .
glass(orange juice, 2) .
glass(diet cola, 1) .
main dish(double burger, 3) .
main dish(chicken nuggets, 5) .
side dish(french fries, 1) .
side dish(nothing else, 0) .
Table 2 denes four relations. The last three represent the restaurants menu in the form
of a database (possible choices are listed with their prices).
Similarly, the relation meal(m, p) associates a meal m with its price p. A rule indicates
how to compose it by lling a tray. There are slots for a drink u, some food v, and an
optional side-order w. (Note that variable names in Prolog begin with a capital letter.)
The rule symbol :- is read if and it separates the conclusion of the rule from its
premisses (a possibly empty conjunction). If x is the price of u, y the price of v, and z the
price of w, then their total (a linear expression) is the price of the meal tray. Note the order
in which these statements appear is irrelevant: the program is declarative.
Additional constraints are enclosed in curly brackets. They recall that prices are positive
(implicit knowledge) and that there is no item (drink or food), cheaper than $1.
The following query would sufce to determine what can be ordered for less than $5:
meal(Meal, Price) {Price 5} ?
To answer this query, Prolog III tries to compute the set of meal-price pairs
{(m, p) | meal(m, p) p 5}. The price constraint p 5 only allows 3 solutions:
{Meal = tray(orange juice,double burger,nothing else),Price = 5} (A)
{Meal = tray(diet cola,double burger,french fries), Price = 5} (B)
{Meal = tray(diet cola,double burger,nothing else), Price = 4} (C)
The computation is depicted in gure 1. Each box represents a node of the solution space
search tree, and is divided into a conjunction of primitive constraints (on the left) and dened
relations (on the right). At each step Prolog attempts to replace a dened relation with its
denition. Each rule application adds a new lower-level node (disjunction). A branch only
316 G. A. NARBONI
Figure 1. Search tree for the Menu program.
develops if the constraints brought in by the rule prove compatible with those accumulated
in the ancestor nodes (conjunction). Eventually, a set of leaves is obtained, representing
the solutions (i.e., a disjunction of conjunctions). In this example, each leaf is reduced to a
single solution.
In the gure, the branch leading to solution (B) is outlined. Barred boxes indicate fail-
ures, i.e., search nodes where the solver detects inconsistencies among constraints (e.g.,
x + 5 + z 5, with x 1 and z 0). Empty boxes thus represent nodes never visited,
thanks to such pruning. All possibilities are explored by backtracking.
The graph in gure 2 depicts the projection of the monetary constraints on the (x, y)
plane. Because of the budget restriction, the solutions have to be within the triangle dened
by x +y 5 in the rst quadrant. With the option of a side dish (w = french fries, z = 1),
the solution space contracts to the smaller triangle dened by x + y 4, in which case the
discrete choices provided by the menu leave only a single possible solution: a cola at $1
and a burger at $3.
2.3. When Articial Intelligence blends with Operations Research
As shown by the example, program execution combines two mechanisms:
1. general search
2. constraint solving.
FROM PROLOG III TO PROLOG IV 317
Figure 2. Projection onto the (x, y) plane.
The rst of these mechanisms is driven by the rules (i.e., program driven). It acts as a
solution generator. It is the built-in, automatic mechanism that has made Prolog a language
ideally suited for case-based search in Articial Intelligenceprovided the search tree
remains of tractable size.
The second mechanism is driven by the properties collected on the problem unknowns
(i.e., in a way, data driven). It comes into play at each inference node, after rule selection,
to help decide whether or not to continue in the selected direction. It has evolved to include
sophisticated mechanisms inspired by the numerical algorithms of Operations Research for
the handling of geometrical properties.
Addingconstraints toPrologtherefore amounts toaugmentingthe set of primitive relations
offered by the language, and providing decision procedures to handle them correctly. A
direct result is a gain in modeling power, but that is not all. Since inferences become
more selective, the search itself can be better circumscribed. Such early pruning of fruitless
branches is particularly important in the control of combinatorial problems where the growth
of the search tree is exponential.
3.0. In Practice
To try to give a concrete viewof the potential offered by CLP, we have selected two technical
engineering studies in elds where Prolog applications are unusual: numerical analysis (in
318 G. A. NARBONI
Table 3. Constraint Solving: Decision and Elimination.
What is meant by constraint solving exactly?
Two things.
I Proving that a given set of constraints is (or isnt) consistent
(i.e., has solutions).
and if it is:
II Simplifying constraintswhenever possible, to conjunctions of
explicit-form equations: x
i
= constant (to output solutions).
the case of the ROentgen SATellite) and mathematical programming (in the case of a robot
line schedule).
The former is a diagnosis problem. It makes use of Prolog III for processing and solving
the simultaneous equations obtained by discretization of an ordinary differential equation
(ODE). The latter is a discrete optimization problem that uses mixed integer and linear
constraints [23]. It illustrates coordination between constraint solving and search.
3.1. The ROSAT Diagnosis Problem
ROSAT is a satellite dedicated to astronomy. It points a telescope at X-ray sources in space
then reorients it for new observations. During a rotation maneuver, orientation is estimated
by integrating the measurements of the satellite gyroscopes. At the end of the maneuver,
the telescopes orientation can be checked against a map of the target region, thanks to a
star tracker.
After a few months of successful operation, severe degradations of the gyros began to be
observed.
1
The consequence of this malfunction was an accumulation of estimation errors.
The risk was such that at the end of a maneuver, the satellite could be completely lost.
ROSATs autonomy was at stake. For the mission to recover, the ground station had to
re-estimate the gyroscope parameters on the basis of telemetry data.
As long as it remains small, the difference between the actual rotation rate and the angular
rate measured by the gyros can be modeled by an afne transformation featuring a drift

d (angular rotation rate measurement bias) and a scale factor error



s . These quantities
are unknown parameters but remain constant over the duration of a maneuver. Therefore,
the satellites dynamics can be approximated by a differential equation which is linear in
the orientation error

q
, i.e., in the difference between the actual orientation,

q
, of the
telescope and the one estimated by integration of the biased gyro measurements.
Taking an established approach to the numerical integration of ordinary differential equa-
tions, this formulation can be transformed into a system of difference equations. The size
of this system is proportional to the number of integration steps.
FROM PROLOG III TO PROLOG IV 319
Figure 3. Pointing maneuver.
Here, each step linearly involves two successive vectors

q
i
and

q
i +1
in a parametric
relation, where the parameters are the rate measured by the gyros (which is given for the
time interval by telemetry data) and the compensation vectors

d and

s , (which are to be
determined).
Recursively applying this difference pattern to all values of i generates a systemof several
thousand equations. Given that the orientation error is precisely known at the start and
the end of the maneuver (boundary conditions), the linear elimination of the intermediate
variables

q
i
reduces it to a linear equation system relating the gyro parameters to the
known boundary values

q
n
and

q
0
. In matrix notation:

q
n
= M

q
0
(where

d and

s are parameters of the transformation M) (P)
320 G. A. NARBONI
CURVE DEFINED BY THE DIFFERENCE EQUATIONS
Figure 4. Global constraint system.
This gives three equations in six unknowns: the coefcients of the drift,

d , and of the
scale factor error,

s , in the matrix. The systembecomes fully determined with the equations
of two maneuvers.
One can view the ROSAT case as a kind of inverse problem where the question is to
identify part of the model parameters, given the input and output of the system.
The study conducted by Daimler-Benz Aerospace [25] compared a Fortran based solution
to a CLP one written in Prolog III. Its conclusions are that, although faster in execution,
the traditional approach requires more effort in program design and implementation (since,
prior to execution, one has to isolate parameters buried in the system), whereas the CLP
solution is a direct transcription of the ODE statement. Besides, the same program (P) can
be used for forward and backward simulation (

d and

s known,

q
0
or

q
n
unknown),
thanks to a liberal use of the linear product notation [9].
3.2. An Assembly Line Scheduling Problem
Electro-plating is a chemical processing used in the manufacture of printed circuit boards.
It is carried out in highly automated production lines.
For a given batch of boards, the operating procedure denes the sequence of treatments
the boards must undergo. The boards are immersed into a series of tanks containing
FROM PROLOG III TO PROLOG IV 321
Figure 5. Schematic view of Electroplating line.
the chemical solutions. Because of production quality requirements, the boards must
remain in the tanks for periods of time that lie within strict bounds (double inequality
constraints).
A robot mechanism is used to place the boards into tanks, remove them from tanks and
transport them between tanks. The robots have to be programmed so as to maximize the
throughput of the line while conforming to the quality requirements. Therefore, the problem
is to derive an optimal cyclic schedule for the robot movements.
The solution to this problem is enumerative by nature.
The complexity stems from the combinations of alternatives (disjunctive constraints),
which potentially result in an exponential growth of the search tree.
Consider the tank exit movements for a pair of boards, a and b, present in the line. If n
is the number of operations in the procedure, the unknowns are the instants t
a,i
when the
robot grasps board a in tank i in order to transfer it to the next tank i +1. We start with the
following orders:
for a: t
a0
t
ai
t
an
for b: t
b0
t
bj
t
bn
What are the constraints relating t
ai
and t
bj
? If d
i
denotes the delay required to transfer a
board from tank i to tank i +1, and if d
i j
denotes the duration of a simple arm movement
between tanks i and j with no transfer (set-up time), we have an alternative which can be
322 G. A. NARBONI
Top: constraint system before branching.
Bottom: constraint systems after branching.
BOUNDING CONDITION
When searching, costs have to improve upon previously found solutions.
This optimization criterion acts as a generalized cut on the search space.
Figure 6. Branching pattern (choice point).
expressed by two rules:
either t
ai
precedes t
bj
, and we must have: t
ai
+d
i
+d
i +1, j
t
bj
or t
bj
precedes t
ai
, and we must have: t
bj
+d
j
+d
j +1,i
t
ai
Note this rule-based approach avoids encumbering the model with articial decision vari-
ables (as in mixed integer programs).
In practice, the problem is tightly constrained and the linear inequalities prune the search
tree effectively. This means that with clever guidance (disjunctions can be grouped in
families) a branch and bound procedure is able to control development of the tree.
The single-robot problem can be viewed as an academic case. The industrial interest of
the model developed in Prolog III for the Tubalex company by Laboratoire dAutomatique
de Besanon lies in its ease of generalization to the multi-robot scheduling problems met
in production lines [19]. The reasons reported are:
1. adding newconstraints (to prevent collisions in the multi-robot case) does not invalidate
the base model: its implementation can be reused
2. adapting control strategies is a matter of specifying new search heuristics: CLP offers
a language for that.
Rules are an adequate means to input problem-specic expertise to gear the control
ow, and more generally to meta-program it, which is a crucial complement when
facing combinatorial issues.
FROM PROLOG III TO PROLOG IV 323
3.3. Summing Up
1. Prolog is a relational language. As a matter of fact, this quality smoothes away obstacles
to the integration of constraints into a syntax, a semantics, and a programming style.
2. Constraint solving is to logic programming what assignment is to imperative program-
ming (i.e., an atomic operation for the language). As shown by the examples above, this
high level of abstraction makes CLP well suited to both rapid application development
and experimentation in problem solving heuristics.
In the gyros diagnosis case, Prolog III acts as a modeler and a solver. The computa-
tion path is deterministic. But the equations generated appear in a somewhat unorthodox
form: the main unknowns are the parameters of the system. Normally, it would be neces-
sary to invert it prior to achieve the solution, using carefully hand-designed mathematical
transformations. In CLP, the problem can be solved as isan appreciable advantage in
time-critical development situations.
Whereas conjunctions of constraints reduce the search space, disjunctions extend it. In
the robot scheduling case, computations are non-deterministic. We are not reasoning on a
single linear model that we rene. We are instead considering a large number of alternative
models. Exploration is directed by the rules (branching step) and each rule adds constraints
dynamically (cutting step). This branch and cut process (where you constrain the search
while you generate) is powerful enough to curb combinatorial explosion.
Denitely, if Algorithm=Logic +Control [17], constraints bring into programs a richer
logic and a better control.
With Prolog III, we have emphasized the role of linear constraints, which are most often
used. They appear naturally in calculations, and they are essential for the modeling of
continuous systems, where linear approximation is always attempted rst. Moreover, when
the problem is to decide whether or not a linear system has solutions, we can always get a
clear-cut answer rather efciently. Computationally speaking, linear constraint solving is
complete. Conceptually, the merge of linear programming with logic programming offers
a unifying viewpoint on many approaches to optimization [20].
Still, it is an awkward restriction to have to limit a general purpose solver to linear
expressions. The feedback from practical use [4, 13] and a careful analysis of the language
requirements have thus contributed to preparing the next theoretical and technical evolution.
4.0. Prolog IV
4.1. Versatile in Numerical Computations
Colmerauers new design for Prolog IV widens the scope of number processing to express
non-linear constraints on real numbers as well as constraints on the integers. The latter
capability to address discrete problems is readily extended to Boolean algebra. In order to
mix quantitative with qualitative expressions in models, Prolog IV recasts boolean values
as integers, which are themselves instances of real numbers.
324 G. A. NARBONI
In its current implementation, Prolog IV includes more than a hundred new primitive
relations, covering practically the entire numeric eld (including trigonometric and hyper-
bolic relations). It is still inspired by the same philosophy according to which the problem
variables are simply linked by constraints, without indicating any directionality. In this
way, x = log(y) and y = exp(x) are two facets of the same relation: log(x, y).
There is another side to this enrichment: it is the loss of completeness in constraint solving.
After all, if we just consider elementary operations, the generalization of equation solving
outside the linear case comes up against the prohibitive complexity of algebraic equations
(for continuous problems) or diophantine equations (in discrete domains). Hence, evolution
means moving fromperfect solving in a limited framework to approximate solving in a much
larger framework.
But is exact reasoning possible using approximations? The merit of the theory on which
Prolog IVis based resides in a clear re-denition of the logic of the computations performed
when a problem is presented to the machine.
This evolution came about because of the profound inuence of two other constraint-based
Prologs, contemporaries of Prolog III:
BNR[24], whose constraints on the intervals of the real line are inspired by the relational
theory of arithmetic proposed by J. G. Cleary [6]
CHIP [12, 26], whose nite domain constraints demonstrate that it is possible to
tackle discrete optimization problems in an effective manner, following the work of
J-L. Lauri` ere [18].
Prolog IV synthesizes these two original approaches in a unied theoretical model [10],
which indeed is capable of performing inferences on nite domains by means of a general
interval narrowing mechanism.
Prolog IIIs successors equation can therefore be written:
Prolog IV = Prolog III +Interval solving.
4.2. Language Foundations
To integrate these new elements into Prolog IIIs heritage, Prolog IV adopts two different
methods for calculation and provides for interaction among these by means of a small
number of key conventions.
4.2.1. Numbers and their Representation
Linear calculations are carried out on rational numbers. Given that the integer numerator or
denominator of a fraction cannot be bound in size, an arbitrary precision library is supplied
with the language processor.
All the other calculations are oating point. But instead of approximating a result (or in-
put) with a oating-point number of the machinethus leading to common rounding errors,
FROM PROLOG III TO PROLOG IV 325
care is taken to control precision by enclosing each value within a pair of IEEE oating-
point numbers [14]. Computations on reals are consequently replaced by computations on
intervals.
This two-tier approach in the calculations introduces two levels of interpretation:
1. a standard (or concrete) level corresponding to the problem denition.
Real numbers are the elements of the modeling domain. Rationals (which include
oating-point numbers) are the only constants computed.
2. an approximation (or abstract) level corresponding to the problem relaxation.
Sets of real numbers are the elements of this added-on computation domain. Its con-
stants are the oating-point intervals dened as follows:
the real line R (between and +),
open and closed half-lines with a oating-point number at the end,
intervals (open or closed) with distinct oating-point numbers as end-points,
the points of the real line that are exactly represented by oating-point numbers
(there are a nite number of themas in a slide rule, and they are all rational).
4.2.2. Constraints and their Interpretation
Linear constraints take the form:

n
i =1
a
i
x
i

=
=
a
0
where the a
i
s are rationals.
2
Systems of linear constraints are handled globally, as in Prolog III. Prolog IV operates at
the standard level: the one of computer algebra.
All the other constraints, from x equals to x is prime, are relaxed locally, i.e.,
they are approximated to allow efcient processing. By moving to the approximation level,
Prolog IV replaces complex calculations on individuals (e.g., reals) by simpler calculations
on sets of individuals (e.g., intervals).
This dual semantics is depicted in gure 7, where r is a relation on R, and where r is the
relation used to approximate r on the set of subsets of R.
For the approximation to be correct, it must contain the relation that it approximates.
Therefore:
(x
1
, . . . , x
n
) r ({x
1
}, . . . , {x
n
}) r (1)
Conversely, if the approximation reaches point precision (i.e., the lower bounds equal the
upper bounds), Prolog IV requires the approximated relation to match the original relation:
({x
1
}, . . . , {x
n
}) r (x
1
, . . . , x
n
) r (2)
Eventually, the constraint r(x
1
, . . . , x
n
) can be replaced by n real assignments.
326 G. A. NARBONI
Figure 7. Approximation of a binary relation on R.
In practice, Prolog IV systematically approximates a relation by the cross-product of its
projections on each axisor more exactly, by the smallest Cartesian product of oating-
point intervals containing the set implicitly dened by the relation. This box approxi-
mation is dynamic in the sense that any restriction, via variable bounds, on the denition
domain of the relation automatically results in a new, tighter, approximation. Approxi-
mating this way a conjunction of primitive constraints provides more information than just
intersecting their individual approximations (but not all information on the intersection).
4.2.3. Solvers and their Operations
Linear constraints are dispatched to a linear solver. Consistency is checked using classical
methods [16, 21]:
a Gaussian elimination algorithm, to incrementally solve systems of equations,
a Simplex optimization routine, to incrementally solve systems of inequalities.
Proving, for a vector x 0, that an inequality ax k is compatible with a sys-
tem Ax b (already in solved form) amounts to proving (by optimization) that the
difference ax k (objective function) can be made positive.
As for the other numerical constraints, they are dispatched to an interval solver [2, 22]
which associates to each relation r on R
n
the relation r dened by (3).
(We note X Y the Cartesian product of the sets X and Y, and

X the box approximation
of X):
(X
1
, . . . , X
n
) r X
1
X
n
= r X
1
X
n
(3)
This implicit denition characterizes a stable state and suggests a xed point mechanism
to reach it. It clearly satises requirements (1) and (2) and furthermore provides us with a
decision procedure which is completeat the approximation level.
Any set of the form {(X
1
, . . . , X
n
) | r
1
(X
1
, . . . , X
n
) r
m
(X
1
, . . . , X
n
)}
possesses a maximal element that can be calculated by xed point.
3
Operationally, this mechanism is known as domain propagation [11].
FROM PROLOG III TO PROLOG IV 327
Below are two examples illustrating the inference capabilities of this general approxima-
tion principle, in the areas of non-linear and integer programming.
Figure 8 shows the solving of the intersection of a straight line and a sinusoidal curve.
The solution process starts with no interval restriction on the variables, i.e., with
x (, +) and y (, +). At each step, we indicate the constraint that
causes an interval reduction. The process goes on until no more reductions can apply.
For the sake of illustration, we assume that the calculator used to compute the table has a
maximum precision of two decimal digits (in other words, we use a standard graph paper
for plotting the curve, instead of a logarithmic one).
y = x y = cos(x) x y
(, +) (, +)

(, +) [1, 1]

[1, 1] [1, 1]

[1, 1] (0.54, 1]

(0.54, 1] (0.54, 1]

(0.54, 1] (0.54, 0.86)

(0.54, 0.86) (0.54, 0.86)

(0.54, 0.86) (0.65, 0.86)

(0.65, 0.86) (0.65, 0.86)

(0.65, 0.86) (0.65, 0.80)

(0.65, 0.80) (0.65, 0.80)

(0.65, 0.80) (0.69, 0.80)

(0.69, 0.80) (0.69, 0.80)

(0.69, 0.80) (0.69, 0.78)

(0.69, 0.78) (0.69, 0.78)

(0.69, 0.78) (0.71, 0.78)

(0.71, 0.78) (0.71, 0.78)

(0.71, 0.78) (0.71, 0.76)

(0.71, 0.76) (0.71, 0.76)

(0.71, 0.76) (0.72, 0.76)

(0.72, 0.76) (0.72, 0.76)


(0.72, 0.76) (0.72, 0.76)
The entire calculation becomes a single inference:
from x = cos(x), we deduce x = cos(x) x (0.72, 0.76).
Knowing that the solution is 0.739085 . . . , we see that the process stops before the ap-
proximation reaches the precision limit allowed by the numerical representation, i.e.,
x (0.73, 0.74). The same would be true, at a ner precision scale, with a standard
oating point representation.
328 G. A. NARBONI
Figure 8. Solution of: cos(x) = x, i.e., y = cos(x) y = x.
The behaviour of Prolog IVs integer constraint (which restricts a number to be an integer)
can be explained in a similar way. It continually reduces interval bounds to integers.
Figure 9 shows integer cuts isolating the solutions of:
5x +2y 3 (1 < x 1) (1 < y 4) integer(x) integer(y)
Figure 9. Solutions of: 5x +2y 3 x (1, 1] y (1, 4] integer(x) integer(y).
FROM PROLOG III TO PROLOG IV 329
Narrowing takes place when all the constraints are solved in the intervals
approximation.
The result of the computation is independent of the reduction order.
5x +2y 3 integer(x) integer(y) x y
(1, 1] (1, 4]

[0, 1] (1, 4]

[0, 1] [0, 4]

[0, 0.6] [0, 1.5]

[0, 0.6] [0, 1]

[0, 0] [0, 1]
[0, 0] [0, 1]
The simplifed constraint system: x = 0integer(y) y [0, 1] gives a tight intensional
representation of the set of solutions. By comparison, a linear relaxation of the same
problem would have produced the whole lower triangular area of gure 9. (In both cases,
the 2 solution points can be produced by enumeration.)
This shows how Prolog IVs approximate solving machinery works: it associates a sub-
domain (e.g., a oating-point interval) with each variable, and goes on reducing it dynam-
ically. As long as no domain is empty, there is a presumption of a solution. Backtracking
occurs as soon as there is no solution in the approximation.
It is easy to remember two simple properties of this approximation:
1. no solution exists outside the computed interval;
2. if there is a solution, its projection lies within the computed interval.
At the problemlevel, this mechanismamounts to checking necessary but no longer sufcient
conditions for consistency. Contrary to the linear solver, the interval solver cannot detect
the inconsistency of a system like:
x + y + z = 1 x + y + z = 2 x [0, 1] y [0, 1] z [0, 1]
Prolog IV users must therefore be vigilant and not presume that an answer to a query is a
proof of a solution: this answer can denote an empty set! However, if there is a solution, it
will be found among the answer solutions. If the search terminates with no such success
leaf, this then proves the non-existence of solutions.
4.2.4. Additional Features
Up to now, two cases have been considered separately:
either constraints are linear, and the calculation is performed on rationalsin which
case the solver inferences are complete,
330 G. A. NARBONI
The sub-domains Prolog IV uses in its solvers can be rened by
intersectionlike dynamic data types. The major ones are:
the set of all trees (the universe)
the set of nite trees
the set of lists
all the sets of lists of size n, where n is a non-negative integer
the set of trees which are but leaves
the set of identiers
all the sets corresponding to a oating-point interval.
Figure 10. Overview of Prolog-IV sub-domains.
or they are not linear, and the calculation is performed on oating-point intervalsin
which case the inferences are partial (incomplete).
When both cases are present at the same time, Prolog IV ensures a synchronization of the
solving mechanisms, via the communication of rational constants. If a is such a constant,
the inter-solver protocol requires:
x = a X = {a} (4)
X = {a} x = a (5)
This is how Prolog IV moves back from approximate precision to exact precision. (More
elaborate communication mechanisms can be implemented between an interval solver and
a linear solver with bounded variables [3].)
The few principles sketched above are general, and apply to the language as a whole. The
concept of approximation is not specic to the numeric domain. It also exists, though to
a lesser extent, in constraint-solving algorithms on data trees, i.e., in the Prolog kernel of
Prolog IV. It is especially used for lists, which come equipped with the size, concatenation
and n
th
projection operations dened as follows:
size([x
1
, . . . , x
l
]) = l (for l 0)
conc([x
1
, . . . , x
k
], [x
k+1
, . . . , x
l
]) = [x
1
, . . . , x
l
] (for 0 k l)
index([x
1
, . . . , x
l
], i ) = x
i
(for 1 i l)
An interesting sub-domain of lists is list of numbers which, besides embodying the
important concept of a vector, opens the way to formulation of powerful global constraints
[1, 5].
FROM PROLOG III TO PROLOG IV 331
4.3. A Prolog IV Program
We end the article as we started it, with a classic constraint programming exercise [8].
With this small puzzle of high complexity, we would like to demonstrate the language ability
for stating and solving hard combinatorial problems with greater elegance and improved
efciency.
The problem is to nd magic sequences of integers (x
0
, . . . , x
n1
) for which each x
i
is
equal to the number of occurrences of the integer i in the sequence. For example (1, 2, 1, 0)
is a solution for n = 4 (the sequence has one zero, 2 ones, 1 two and 0 threes).
Assuming that (x
j
= i ) has the value 1 when x
j
and i are equal, and 0 when they are
different, we can write:
i {0, . . . , n 1} x
i
=
n1

j =0
(x
j
= i )
But how to translate the nested equalities? We base our formulation on the fact that any
primitive constraint in Prolog IV is coupled with a boolean function which converts the
result of an evaluation into a computer boolean, i.e., an integer in [0, 1]. This makes it
possible to count equalities that are true. This also gives a way of handling disjunction.
The program thus decomposes into a conjunction of cardinality constraints. Each con-
straint is itself a sum of tests. Hence a double recurrence on n.
The n constraints of the problem are set by equation system(n, L) where L is the list of
unknowns whose size is set to n by the primitive constraint size. The primitive constraint
index(x
i
, L, i +1) is used to bind x
i
to the i +1
th
element in the list. Summation is dened,
for each i , by sum occurrences(L, i, s) which states that s is the total number of occurrences
of i in L. Finally, the primitive constraint beq(b
i j
, x
j
, i ) translates the boolean equation
(x
j
= i ) = b
i j
.
To lighten notations, we use + and for addition and comparison in the intervals ap-
proximation.
Approximation alone is insufcient to solve the problem. We have to resort to enu-
meration. A built-in primitive intsplit reduces the approximation grain by subdividing the
intervals, so as to identify the smallest domains of solutions. Here, as for integer prob-
lems, the calculations yield explicit values, which removes any doubt as to the existence of
solutions.
The program nds two solutions for n = 4.
magic solution(4, L) ?
{L = [2, 0, 2, 0]}
{L = [1, 2, 1, 0]}
It follows from the problem statement that the x
i
s are integers in [0, n 1]. Since the
enumeration applies to the n main variables (x
i
), the theoretical complexity of the search
is in n
n
. In practice, search remains limited, due to the dynamic restrictions imposed by
the constraints on the domain range of each variablewith the effect of pushing back the
wall of intractability. The enumeration can be worked through efciently up to and beyond
n = 100. For this value we (only) explore 1,261 nodes in the search tree.
332 G. A. NARBONI
Table 4. Magic sequence program.
sum occurrences([], I, 0) .
sum occurrences([Xj | OtherXs], I, B + Remainder) :-
beq(B, Xj, I) ,
sum occurrences(OtherXs, I, Remainder) .
equation system(0, ListofXs) .
equation system(J, ListofXs) :-
J > 0 ,
I = J - 1,
index(ListofXs, J, Xi) ,
sum occurrences(ListofXs, I, Xi) ,
equation system(I, ListofXs) .
magic solution(N, ListofXs) :-
size(ListofXs, N) ,
equation system(N, ListofXs) ,
intsplit(ListofXs) .
This gure falls to 195 when the following couple of constraints is added:
n1

i =0
i x
i
=
n1

i =0
x
i
= n
These constraints are redundant at the problem level, not at the approximation level.
5.0. Conclusion
A decade ago, when Alain Colmerauer had just put the nishing touches to the theoretical
model for Prolog III, he gave the following answer to a reporter who had asked whether the
language would have a successor:
As far as I am concerned it wont, because it represents a huge effort in personnel
and in nancial terms. An extensive range of knowledge is required. Its not
sufcient to be a computer scientist or a mathematician. Prolog III is based on
about ten theorems which have to be conceived and proved, and also on the solving
of extremely difcult implementation problems, for example garbage collection.
Its a gigantic task.
The title of the article was There will not be a Prolog IV. . .,
4
proof enough that the name
was predestined. Although Prolog IV exists today, its genesis has borne out everything just
quoted.
In this article we have used concrete applications to show the motivation for pursuing the
extension. We have then attempted to indicate a new way of envisaging constraint solving
FROM PROLOG III TO PROLOG IV 333
Table 5. A table for comparison.
Since Prolog IVs announcement in 1995, other new generation products have been
released on the market. Beyond the language vs. library contest, the following table
provides an updated view of the leading offers from Cosytec, Ilog and PrologIA.
Offer Technology
Linear Boolean Finite Interval
Product Company Unication solver solver
a
Domains solver
Prolog IV PrologIA
Prolog III PrologIA
Ilog Solver Ilog
Ilog Planner Ilog
Ilog Numerica
b
Ilog
CHIP V.5 Cosytec
a. In the Boolean case, we only mention implementations of complete solvers.
b. See [27].
in logic programming. In the compromise reached (which relies on exact approximations
for directing search efciently), a programmer has more freedom for expressing problems,
but also more responsibility in interpreting the results.
With Prolog IVs generation, Constraint Programming achieves a new level of maturity.
Compared to Prolog III, the implementation of the linear part gives denite performance
improvements (with up to three orders of magnitude gained in the Gaussian elimination
case, due to the combined effect of a new innite-precision library, a new solving algorithm
and compilation of program execution).
(A comparison with other closely related commercial products is given in table 5, on a
technical feature base.)
Prolog IVs far-sighted design makes it possible to combine constraints of varied origins,
while retaining a clear logic-based foundation.
Its present embodiment is a rich language in which relations can be dened and queried
in discrete or continuous domains, using precise or imprecise data.
Since intelligent approximation, not brute force computation, is still the key to effec-
tive modeling (Herbert Simon), it should be a tool worth considering for machine-based
problem solving.
Acknowledgments
This article would not have seen the light of day without the support of Alain Colmerauer,
whom the author would like to thank most deeply for the teaching provided throughout
334 G. A. NARBONI
the project that gave rise to Prolog IV. Jacques Cohen was also supportive and his encour-
agements are kindly acknowledged. The author thanks the company PrologIA and all its
partners in the PRINCEproject for the work carried out together, and the European Commis-
sion for its nancial support (ESPRIT 5246). Special thanks are due to Reinhard Skuppin
and Thomas Bckle of Daimler-Benz and Daimler-Benz Aerospace for their pedagogical
explanations concerning the ROSAT example. Credit for the Tubalex application goes to
Bruno Legeard, Christophe Varnier and the LABs teamat University of Besan con. Finally,
the readers owe a great deal to Drew Adams friendly help in polishing the manuscript.
Notes
1. The Pathnder robot had a similar glitch on Mars.
2. Prolog IV provides a distinctive syntax for linear operations and equation symbols.
3. The niteness of the oating-point intervals semi-lattice ensures termination.
4. 01 Informatique, December 1987.
References
1. N. Beldiceanu and E. Contejean (1994). Introducing global constraints in CHIP. Mathl. Comput. Modelling
20(12): 97123.
2. F. Benhamou and Touravane (1995). Prolog IV: langage et algorithmes. In Proc. of JFPL 95, Dijon.
3. H. Beringer and B. De Backer (1995). Combinatorial problem solving in constraint logic programming
with cooperating solvers. In C. Beierle and L. Pl umer, editors, Logic Programming: Formal Methods and
Practical Applications, pages 245272. Elsevier.
4. C. Bisi` ere (1995). SD-solver: towards a multidirectional CLP-based simulation tool. Computation Eco-
nomics.
5. N. Bleuzen Guernalec and A. Colmerauer (1997). Narrowing a 2n-block of sortings in O(n log n). In Proc.
of CP97. Schloss Hagenberg.
6. J. G. Cleary (1987). Logical arithmetic. Future Generation Computing Systems 2(2): 125149.
7. A. Colmerauer (1985). Prolog in 10 gures. Communications of the ACM 28(12): 12961310.
8. A. Colmerauer (1990). An introduction to Prolog III. Communications of the ACM 33(7): 6990.
9. A. Colmerauer (1993). Naive solving of non-linear constraints. In F. Benhamou and A. Colmerauer, editors,
Constraint Logic Programming: Selected Research, pages 89112. The MIP Press.
10. A. Colmerauer (1996). Les bases de Prolog IV. In Le Manuel de Prolog IV, PrologIA.
11. J.-Y. Cras (1993). A review of industrial constraint solving tools. AI Intelligence.
12. M. Dincbas, et al. (1988). The constraint logic programming language CHIP. In Proc. of FGCS88, Tokyo.
13. P.-J. Gailly, et al. (1992). The Prince project and its applications. In G. Comyn, N. E. Fuchs, and M. J.
Ratcliffe, editors, Logic Programming in Action, Proc. of LPSS92, LNCS 636, pages 5463. Springer
Verlag.
14. IEEE (1985). IEEE standard for binary oating-point arithmetic. Technical Report 754, ANSI.
15. J. Jaffar and J.-L. Lassez (1987). Constraint logic programming. In Proc. of ACM Symposium on the Prin-
ciples of Programming Languages, pages 111119, Munich.
16. J. Jaffar and M. Maher (1994). Constraint logic programming: A survey. Jounal of Logic Programming
1920: 503581.
FROM PROLOG III TO PROLOG IV 335
17. R. A. Kowalski (1979). Algorithm = Logic + Control. Communications of the ACM 22: 424431.
18. J.-L. Lauri` ere (1978). A language and a program for stating and solving combinatorial problems. Articial
Intelligence 10: 29127.
19. M.-A. Manier, C. Varnier and P. Baptiste (1994). A multi-hoist scheduling problem approach. In Proc. of
the 4th Int. Workshop on Project Management and Scheduling, pages 110115, Leuven.
20. K. McAloon and C. Tretkoff (1996). Optimization and Computational Logic. Wiley - Interscience.
21. G. A. Narboni (1992). About Gaussian elimination and innite precision. 2nd Int. Workshop on Constraint
Logic Programming, Marseille.
22. S. NDong and M. Van Caneghem (1996). Global behaviour of complex constraints. In Proc. of CP96,
Boston.
23. G. L. Nemhauser and L. A. Wolsey (1988). Integer and Combinatorial Optimization. Wiley - Interscience.
24. W. Older and A. Vellino (1993). Constraint arithmetic on real intervals. In F. Benhamou and A. Colmerauer,
editors, Constraint Logic Programming: Selected Research, pages 175195. The MIP Press.
25. R. Skuppin and T. B uckle (1994). Estimating Gyro Errors by Solving an Ordinary Differential Equation
Boundary Value Problem. Technical report F3-94-036, Daimler-Benz Research Center, Ulm.
26. P. Van Hentenryck (1989). Constraint Satisfaction in Logic Programming. The MIP Press.
27. P. Van Hentenryck, L. Michel, and Y. Deville (1997). Numerica, a Modeling Language for Global Opti-
mization. The MIT Press.
Notes added in Proof:
Since this paper was drafted, several PhD dissertations have further expanded the framework presented in
this paper. Among them, one could mention Zhous thesis on interval-based methods for solving combinatorial
optimization problems with a permutation constraint [a], and Azulays latest results on the use of arbitrary precision
in simplex computations [b].
The robot scheduling problem presented in the Prolog III section has been further investigated by Wallace and
Rodosek [c], from a hybrid-algorithm perspective. Their approach takes advantage of both linear and interval
solvers, thereby increasing the algorithms robustness.
Apedagogical introduction covering the area of Constraint Logic Programming is presently available in a recent
book by Marriott and Stuckey [d].
[a] J. Zhou (1997). A permutation-based approach for solving the job-shop problem. Constraints 2: 185213.
[b] D. Azulay (1998). Optimized Q-pivot for exact linear solvers. In: Proc. CP 98, Pisa, Maher and Puget, Eds.,
LNCS 1520, Springer, pages 5571.
[c] R. Rodosek and M. Wallace (1998). A generic model and hybrid algorithm for Hoist Scheduling Problems In:
Proc. CP 98, Pisa, Maher and Puget, Eds., LNCS 1520, Springer, pages 385399.
[d] K. Marriott and P. Stuckey (1998). Programming with Constraints: an introduction. The MIT Press.

Вам также может понравиться