from pfrom prolog iii to prolog iv: the logic of constraint programming revisitedrolog iii to prolog...

Upload: askethi

Post on 02-Jun-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    1/23

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

    c1999 Kluwer Academic Publishers, Boston. Manufactured in The Netherlands.

    From Prolog III to Prolog IV:The Logic of Constraint Programming Revisited

    GUY A. NARBONI [email protected] Operational Intelligence for Industry, Marseille, France

    Abstract. Constraint programming languages stem from the integration of constraints in conditional rules. Bytakinga close look at thedesign choices made forProlog IV, theauthor retraces thegeneral evolution of this recentand novel paradigm, from its roots in inference systems and optimization, to its applications in model buildingand 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 first 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 canbe accumulated

    in the course of a logical development, setting at each stage further conditions to be satisfied.

    This can have the effect of pruning a search tree, significantly and on the fly.

    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 specifically refers to the integra-

    tion of constraints in a Prolog-like rule-based language. Developments in this field 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 first generation: Prolog III, we examine the

    relevance of CLP to problem solving in industry. Then, based on more recent work by Alain

    Colmerauers team, we introduce its successor: Prolog IV, a language whose extensive

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    2/23

    314 G. A. NARBONI

    Table 1. Forerunners in CLP.

    CLP emerged in the mid 80s, from european and american labs. Most influentialwas the work of the CLP(R) team led by Jean-Louis Lassez at IBM, who coined theword CLP and set its theoretical foundations. Colmerauers Prolog II was then theonly instance of a promising scheme. A definite interest in finite domains arose fromthe work on the CHIP concept (Constraints Handling in Prolog) by Mehmet Dincbasand collaborators at the joint Bull-ICL-Siemens European Computer-Industry ResearchCenter. 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 efficiency.

    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 problem definition. Constraints gradually restrict the degree of freedomof 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 unification. 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 typifies 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 how to order a not-so-French

    meal.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    3/23

    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 defines 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 mealm with its price p. A rule indicates

    how to compose it by filling a tray. There are slots for a drinku, some food v, and an

    optional side-orderw. (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). Ifx is the price ofu , y the price ofv, andz the

    price ofw, 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 suffice 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 figure 1. Each box represents a node of the solution space

    searchtree, and is divided into a conjunction of primitive constraints (on the left) and defined

    relations (on the right). At each step Prolog attempts to replace a defined relation with its

    definition. Each rule application adds a new lower-level node (disjunction). A branch only

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    4/23

    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 figure, 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 figure 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 defined

    byx

    +y

    5 in the first quadrant. With the option of a side dish (w

    =french fries,z

    =1),

    the solution space contracts to the smaller triangle defined by x + y 4, in which case thediscrete choices provided by the menu leave only a single possible solution: a cola at $1

    and a burger at $3.

    2.3. When Artificial Intelligence blends with Operations Research

    As shown by the example, program execution combines two mechanisms:

    1. general search

    2. constraint solving.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    5/23

    FROM PROLOG III TO PROLOG IV 317

    Figure 2. Projection onto the(x,y)plane.

    The first 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 Artificial 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.

    Adding constraints to Prologthereforeamounts to augmentingthe set of primitiverelations

    offered by the language, and providing decision procedures to handle them correctly. Adirect 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 particularlyimportantin thecontrol of combinatorial problems where thegrowth

    of the search tree is exponential.

    3.0. In Practice

    To try to give a concrete view of the potential offered by CLP, we have selected two technical

    engineering studies in fields where Prolog applications are unusual: numerical analysis (in

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    6/23

    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 ofexplicit-form equations: xi= 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 angularrate measured by the gyros can be modeled by an affine 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.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    7/23

    FROM PROLOG III TO PROLOG IV 319

    Figure 3. Pointing maneuver.

    Here, each step linearly involves two successive vectors q i and

    q i+1in 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 ofigenerates a system of 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

    variablesq i reduces it to a linear equation system relating the gyro parameters to the

    known boundary valuesq n and

    q 0. In matrix notation:

    q n= M

    q 0 (where

    d and s are parameters of the transformation M) (P)

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    8/23

    320 G. A. NARBONI

    CURVE DEFINED BY THE DIFFERENCE EQUATIONS

    Figure 4. Global constraint system.

    This gives three equations in six unknowns: the coefficients of the drift,

    d, and of the

    scale factor error,s , in the matrix. The system becomes 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 defines the sequence of treatments

    the boards must undergo. The boards are immersed into a series of tanks containing

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    9/23

    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 inequalityconstraints).

    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 theline while conforming to the quality requirements. Therefore, theproblem

    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. Ifn

    is the number of operations in the procedure, the unknowns are the instantsta,i when the

    robot grasps boarda in tanki in order to transfer it to the next tanki+1. We start with thefollowing orders:

    fora: ta0 tai tanforb: tb0 tbj tbn

    What are the constraints relating tai andtbj ? Ifdi denotes the delay required to transfer a

    board from tanki to tanki+ 1, and ifdi j denotes the duration of a simple arm movementbetween tanksi and j with no transfer (set-up time), we have an alternative which can be

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    10/23

    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:

    eithertai precedestbj , and we must have: tai

    +di

    +di+1,j

    tbj

    ortbj precedestai , and we must have: tbj+ dj+ dj+1,i tai

    Note this rule-based approach avoids encumbering the model with artificial 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 new constraints (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-specific expertise to gear the control

    flow, and more generally to meta-program it, which is a crucial complement when

    facing combinatorial issues.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    11/23

    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 refine. 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

    whileyou generate) is powerful enough to curb combinatorial explosion.

    Definitely, if Algorithm = Logic + Control [17], constraints bring into programs a richerlogic 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 first. Moreover, when

    the problem is to decide whether or not a linear system has solutions, we can always get a

    clear-cut answer rather efficiently. 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.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    12/23

    324 G. A. NARBONI

    In its current implementation, Prolog IV includes more than a hundred new primitive

    relations, covering practically the entire numeric field (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 theloss of completenessin 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 from perfect solving in a limited framework to approximate solving in a muchlarger framework.

    But is exact reasoning possible using approximations? The merit of the theory on which

    Prolog IV is based resides in a clear re-definition of the logic of the computations performed

    when a problem is presented to the machine.

    This evolution came about because of theprofoundinfluenceof two other constraint-based

    Prologs, contemporaries of Prolog III:

    BNR[24], whose constraints on theintervalsof the real line areinspired by the relationaltheory of arithmetic proposed by J. G. Cleary [6]

    CHIP [12, 26], whose finite domain constraints demonstrate that it is possible totackle discrete optimization problems in an effective manner, following the work of

    J-L. Lauriere [18].

    Prolog IV synthesizes these two original approaches in a unified theoretical model [10],

    which indeed is capable of performing inferences on finite 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 smallnumber 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 floating point. But instead of approximating a result (or in-

    put) with a floating-point number of the machinethus leading to common rounding errors,

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    13/23

    FROM PROLOG III TO PROLOG IV 325

    care is taken to control precision by enclosing each value within a pair of IEEE floating-

    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)levelcorresponding to the problem definition.

    Real numbers are the elements of the modeling domain. Rationals (which include

    floating-point numbers) are the only constants computed.

    2. an approximation(or abstract)levelcorresponding to the problem relaxation.Sets of real numbers are the elements of this added-on computation domain. Its con-

    stants are the floating-point intervals defined as follows:

    the real lineR (between and +), open and closed half-lines with a floating-point number at the end, intervals (open or closed) with distinct floating-point numbers as end-points, the points of the real line that are exactly represented by floating-point numbers

    (there are a finite 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=1aixi==

    a0where theai 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 efficient 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 figure 7, where ris a relation onR, and whereris the

    relation used to approximateron the set of subsets ofR.

    For the approximation to be correct, it must contain the relation that it approximates.Therefore:

    (x1, . . . ,xn) r ({x1}, . . . , {xn}) 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:

    ({x1}, . . . , {xn}) r (x1, . . . ,xn) r (2)

    Eventually, the constraint r(x1, . . . ,xn)can be replaced byn real assignments.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    14/23

    326 G. A. NARBONI

    Figure 7. Approximation of a binary relation onR.

    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 floating-

    point intervals containing the set implicitly defined by the relation. This box approxi-

    mation is dynamic in the sense that any restriction, via variable bounds, on the definition

    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 thedifferenceax 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 ronRn the relationrdefined by (3).

    (We noteXYthe Cartesian product of the setsXand Y, andX the box approximationofX):(X1, . . . ,Xn) r X1 Xn= r X1 Xn (3)

    This implicit definition characterizes a stable state and suggests a fixed point mechanism

    to reach it. It clearly satisfies requirements (1) and (2) and furthermore provides us with a

    decision procedure which is completeat the approximation level.

    Any set of the form{(X1, . . . ,Xn )| r1(X1, . . . ,Xn ) rm (X1, . . . ,Xn )}possesses a maximal element that can be calculated by fixed point.3

    Operationally, this mechanism is known as domain propagation [11].

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    15/23

    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 thatcauses 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:

    fromx= 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 finer precision scale, with a standardfloating point representation.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    16/23

    328 G. A. NARBONI

    Figure 8. Solution of: cos(x ) = x , i.e., y= cos(x) y= x .

    Thebehaviour of Prolog IVs integerconstraint (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).

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    17/23

    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= 0 integer(y) y [0, 1] gives a tight intensionalrepresentation of the set of solutions. By comparison, a linear relaxation of the same

    problem would have produced the whole lower triangular area of figure 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 floating-point interval) with each variable, and goes on reducing it dynam-

    ically. As long as no domain is empty, there is a presumptionof 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 theproblem level, this mechanismamounts to checking necessarybut no longersufficient

    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, itwill be found among the answer solutions. If the search terminates with no such success

    leaf, this thenprovesthe 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 whichcase the solver inferences are complete,

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    18/23

    330 G. A. NARBONI

    The sub-domains Prolog IV uses in its solvers can be refined byintersectionlike dynamic data types. The major ones are:

    the set of all trees (the universe) the set of finite trees the set of lists all the sets of lists of sizen, wheren is a non-negative integer the set of trees which are but leaves

    the set of identifiers

    all the sets corresponding to a floating-point interval.

    Figure 10. Overview of Prolog-IV sub-domains.

    or they are not linear, and the calculation is performed on floating-point intervalsinwhich 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. Ifa 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 specific 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

    andn th projection operations defined as follows:

    size([x1, . . . ,xl ]) = l (forl 0)conc([x1, . . . ,xk], [xk+1, . . . ,xl ]) = [x1, . . . ,xl ] (for 0 k l)index([x1, . . . ,xl ], i ) = x i (for 1 i l)

    An interesting sub-domain of lists is list of numbers which, besides embodying the

    importantconcept of a vector, opens the way to formulation of powerful global constraints

    [1, 5].

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    19/23

    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 puzzleof high complexity, we would like to demonstrate the language ability

    for stating and solving hard combinatorial problems with greater elegance and improved

    efficiency.

    The problem is to find magic sequences of integers (x0, . . . ,xn1)for which eachxi isequal to the number of occurrences of the integer iin the sequence. For example (1, 2, 1, 0)

    is a solution forn= 4 (the sequence has one zero, 2 ones, 1 two and 0 threes).Assuming that (xj= i ) has the value 1 when xj andi are equal, and 0 when they aredifferent, we can write:

    i {0, . . . , n 1} xi=n1

    j=0(xj= 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.

    Then 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 constraintindex(xi ,L , i +1)is used to bindxi to the i + 1th element in the list. Summation is defined,for each i , by sum occurrences(L , i, s) which states that sis the total number of occurrences

    ofi in L . Finally, the primitive constraint beq(bi j ,xj , i ) translates the boolean equation

    (xj= i ) = bi j .To lighten notations, we use+andfor addition and comparison in the intervals ap-

    proximation.

    Approximation alone is insufficient 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 finds two solutions forn=

    4.

    magic solution(4, L) ?

    {L = [2, 0, 2, 0]}{L = [1, 2, 1, 0]}

    It follows from the problem statement that the xi s are integers in [0, n 1]. Since theenumeration applies to the n main variables (xi ), the theoretical complexity of the search

    is inn 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 efficiently up to and beyond

    n= 100. For this value we (only) explore 1,261 nodes in the search tree.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    20/23

    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 figure falls to 195 when the following couple of constraints is added:

    n1

    i=0i xi

    =

    n1

    i=0xi

    =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 finishing 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 financial terms. An extensive range of knowledge is required. Its notsufficient 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 difficult 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

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    21/23

    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 IntervalProduct Company Unification s olver solvera Domains solver

    Prolog IV PrologIA Prolog III PrologIA Ilog Solver Ilog Ilog Planner Ilog Ilog Numericab 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 approximationsfor directing search efficiently), 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 definite performance

    improvements (with up to three orders of magnitude gained in the Gaussian elimination

    case, due to the combined effect of a new infinite-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 defined 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

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    22/23

    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 thework carried out together, andthe European Commis-

    sion for its financial 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 team at University of Besancon. Finally,

    the readers owe a great deal to Drew Adams friendly help in polishing the manuscript.

    Notes

    1. The Pathfinder robot had a similar glitch on Mars.

    2. Prolog IV provides a distinctive syntax for linear operations and equation symbols.

    3. The finiteness of the floating-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. Modelling20(12): 97123.

    2. F. Benhamou and Touravane (1995). Prolog IV: langage et algorithmes. InProc. of JFPL 95, Dijon.

    3. H. Beringer and B. De Backer (1995). Combinatorial problem solving in constraint logic programmingwith cooperating solvers. In C. Beierle and L. Plumer, editors,Logic Programming: Formal Methods andPractical Applications, pages 245272. Elsevier.

    4. C. Bisiere (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 inO (nlog 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 figures.Communications of the ACM28(12): 12961310.

    8. A. Colmerauer (1990). An introduction to Prolog III.Communications of the ACM33(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. InLe 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. InProc. 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. SpringerVerlag.

    14. IEEE (1985). IEEE standard for binary floating-point arithmetic. Technical Report 754, ANSI.

    15. J. Jaffar and J.-L. Lassez (1987). Constraint logic programming. InProc. 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.

  • 8/11/2019 From PFrom Prolog III to Prolog IV: The Logic of Constraint Programming Revisitedrolog III to Prolog IV

    23/23

    FROM PROLOG III TO PROLOG IV 335

    17. R. A. Kowalski (1979). Algorithm = Logic + Control. Communications of the ACM22: 424431.18. J.-L. Lauriere (1978). A language and a program for stating and solving combinatorial problems. Artificial

    Intelligence10: 29127.

    19. M.-A. Manier, C. Varnier and P. Baptiste (1994). A multi-hoist scheduling problem approach. In Proc. ofthe 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 infinite precision.2nd Int. Workshop on ConstraintLogic Programming, Marseille.

    22. S. NDong and M. Van Caneghem (1996). Global behaviour of complex constraints. InProc. 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. Buckle (1994). Estimating Gyro Errors by Solving an Ordinary Differential EquationBoundary 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 inthis paper. Among them, one could mention Zhous thesis on interval-based methods for solving combinatorialoptimization problemswith a permutation constraint [a], andAzulays latest results on theuse of arbitraryprecisionin simplex computations [b].

    The robot scheduling problem presented in the Prolog III section has been further investigated by Wallace andRodosek [c], from a hybrid-algorithm perspective. Their approach takes advantage of both linear and intervalsolvers, thereby increasing the algorithms robustness.

    A pedagogical introduction coveringthe area of Constraint Logic Programming is presentlyavailable in a recentbook by Marriott and Stuckey [d].

    [a] J. Zhou (1997). A permutation-based approach for solving the job-shop problem. Constraints2: 185213.

    [b] D. Azulay (1998). Optimized Q-pivot for exact linear solvers. In: Proc. CP 98, Pisa, Maher and Puget, Eds.,LNCS1520, 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.,LNCS1520, Springer, pages 385399.

    [d] K. Marriott and P. Stuckey (1998). Programming with Constraints: an introduction. The MIT Press.