File: clpqr.doc

package info (click to toggle)
swi-prolog 8.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,084 kB
  • sloc: ansic: 362,656; perl: 322,276; java: 5,451; cpp: 4,625; sh: 3,047; ruby: 1,594; javascript: 1,509; yacc: 845; xml: 317; makefile: 156; sed: 12; sql: 6
file content (251 lines) | stat: -rw-r--r-- 8,448 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
\libdoc{clpqr}{Constraint Logic Programming over Rationals and Reals}
\label{sec:lib:clpqr}

\begin{quote}
Author: \emph{Christian Holzbaur}, ported to SWI-Prolog by \emph{Leslie De Koninck}, K.U. Leuven
\end{quote}

This CLP(Q,R) system is a port of the CLP(Q,R) system of Sicstus
Prolog by Christian Holzbaur: Holzbaur C.: OFAI clp(q,r) Manual,
Edition 1.3.3, Austrian Research Institute for Artificial Intelligence,
Vienna, TR-95-09, 1995.%
	\footnote{http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09}
This manual is roughly based on the manual of the above mentioned CLP(Q,R)
implementation.

The CLP(Q,R) system consists of two components: the CLP(Q) library for handling
constraints over the rational numbers and the CLP(R) library for handling
constraints over the real numbers (using floating point numbers as
representation). Both libraries offer the same predicates (with exception of
\predref{bb_inf}{4} in CLP(Q) and \predref{bb_inf}{5} in CLP(R)). It is allowed
to use both libraries in one program, but using both CLP(Q) and CLP(R)
constraints on the same variable will result in an exception.

Please note that the \pllib{clpqr} library is \emph{not} an
\jargon{autoload} library and therefore this library must be loaded
explicitly before using it:

\begin{code}
:- use_module(library(clpq)).
\end{code}

or

\begin{code}
:- use_module(library(clpr)).
\end{code}

\subsection{Solver predicates}
\label{sec:clpqr-predicates}
%=============================

The following predicates are provided to work with constraints:

\begin{description}
	\predicate{{}}{1}{+Constraints}
Adds the constraints given by \arg{Constraints} to the constraint store.

	\predicate{entailed}{1}{+Constraint}
Succeeds if \arg{Constraint} is necessarily true within the current
constraint store. This means that adding the negation of the constraint
to the store results in failure.

	\predicate{inf}{2}{+Expression, -Inf}
Computes the infimum of \arg{Expression} within the current state of the
constraint store and returns that infimum in \arg{Inf}. This predicate
does not change the constraint store.

	\predicate{sup}{2}{+Expression, -Sup}
Computes the supremum of \arg{Expression} within the current state of
the constraint store and returns that supremum in \arg{Sup}. This
predicate does not change the constraint store.

	\predicate{minimize}{1}{+Expression}
Minimizes \arg{Expression} within the current constraint store. This is
the same as computing the infimum and equating the expression to that
infimum.

	\predicate{maximize}{1}{+Expression}
Maximizes \arg{Expression} within the current constraint store. This is
the same as computing the supremum and equating the expression to that
supremum.

	\predicate{bb_inf}{5}{+Ints, +Expression, -Inf, -Vertex, +Eps}
This predicate is offered in CLP(R) only. It computes the infimum of
\arg{Expression} within the current constraint
store, with the additional constraint that in that infimum, all
variables in \arg{Ints} have integral values. \arg{Vertex} will contain
the values of \arg{Ints} in the infimum. \arg{Eps} denotes how much a
value may differ from an integer to be considered an integer. E.g.\ when
\arg{Eps} = 0.001, then X = 4.999 will be considered as an integer (5 in
this case). \arg{Eps} should be between 0 and 0.5.

	\predicate{bb_inf}{4}{+Ints, +Expression, -Inf, -Vertex}
This predicate is offered in CLP(Q) only. It behaves the same as
\predref{bb_inf}{5} but does not use an error margin.

	\predicate{bb_inf}{3}{+Ints, +Expression, -Inf}
The same as \predref{bb_inf}{5} or \predref{bb_inf}{4} but without returning
the values of the integers. In CLP(R), an error margin of 0.001 is used.

	\predicate{dump}{3}{+Target, +Newvars, -CodedAnswer}
Returns the constraints on \arg{Target} in the list \arg{CodedAnswer}
where all variables of \arg{Target} have been replaced by \arg{NewVars}.
This operation does not change the constraint store. E.g.\ in

\begin{code}
dump([X,Y,Z],[x,y,z],Cons)
\end{code}

\verb$Cons$ will contain the constraints on X, Y and Z, where these variables
have been replaced by atoms x, y and z.

\end{description}

\subsection{Syntax of the predicate arguments}
\label{sec:clpqr-arg-syntax}
%=============================================

The arguments of the predicates defined in the subsection above are
defined in \tabref{clpqrbnf}. Failing to meet the syntax rules will
result in an exception.

\begin{table}
\begin{center}
\begin{tabular}{|lrl|l|}
\hline
<Constraints> \isa <Constraint>				& single constraint \\
	      \ora <Constraint> , <Constraints>		& conjunction \\
	      \ora <Constraint> ; <Constraints>		& disjunction \\

<Constraint> \isa <Expression> {<} <Expression>		& less than \\
	     \ora <Expression> {>} <Expression>		& greater than \\
	     \ora <Expression> {=<} <Expression>	& less or equal \\
	     \ora {<=}(<Expression>, <Expression>)	& less or equal \\
	     \ora <Expression> {>=} <Expression>	& greater or equal \\
	     \ora <Expression> {=\=} <Expression>	& not equal \\
	     \ora <Expression> =:= <Expression>		& equal \\
	     \ora <Expression> = <Expression>		& equal \\

<Expression> \isa <Variable>				& Prolog variable \\
	     \ora <Number>				& Prolog number \\
	     \ora +<Expression>				& unary plus \\
	     \ora -<Expression>				& unary minus \\
	     \ora <Expression> + <Expression>		& addition \\
	     \ora <Expression> - <Expression>		& substraction \\
	     \ora <Expression> * <Expression>		& multiplication \\
	     \ora <Expression> / <Expression>		& division \\
	     \ora abs(<Expression>)			& absolute value \\
	     \ora sin(<Expression>)			& sine \\
	     \ora cos(<Expression>)			& cosine \\
	     \ora tan(<Expression>)			& tangent \\
	     \ora exp(<Expression>)			& exponent \\
	     \ora pow(<Expression>)			& exponent \\
	     \ora <Expression> {^} <Expression>		& exponent \\
	     \ora min(<Expression>, <Expression>)	& minimum \\
	     \ora max(<Expression>, <Expression>)	& maximum \\
\hline
\end{tabular}
    \caption{CLP(Q,R) constraint BNF}
    \label{tab:clpqrbnf}
\end{center}
\end{table}


\subsection{Use of unification}
\label{sec:clpqr-unification}

Instead of using the \predref{{}}{1} predicate, you can also use the standard
unification mechanism to store constraints. The following code samples
are equivalent:

\begin{itemlist}

\item [Unification with a variable]

\begin{code}
{X =:= Y}
{X = Y}
X = Y
\end{code}

\item [Unification with a number]

\begin{code}
{X =:= 5.0}
{X = 5.0}
X = 5.0
\end{code}

\end{itemlist}

\subsection{Non-linear constraints}
\label{sec:clpqr-non-linear}
%==================================

The CLP(Q,R) system deals only passively with non-linear constraints. They
remain in a passive state until certain conditions are satisfied. These
conditions, which are called the isolation axioms, are given in
\tabref{clpqraxioms}.

\begin{table}
\begin{center}
\begin{tabular}{|l|p{0.3\linewidth}|p{0.3\linewidth}|}
\hline
$A = B * C$ & B or C is ground			& A = 5 * C or A = B * 4 \\
	    & A and (B or C) are ground		& 20 = 5 * C or 20 = B * 4 \\
\hline
$A = B / C$ & C is ground			& A = B / 3 \\
	    & A and B are ground		& 4 = 12 / C \\
\hline
$X = min(Y,Z)$ & Y and Z are ground		& X = min(4,3) \\
$X = max(Y,Z)$ & Y and Z are ground		& X = max(4,3) \\
$X = abs(Y)$   & Y is ground			& X = abs(-7) \\
\hline
$X = pow(Y,Z)$ & X and Y are ground		& 8 = 2 {^} Z \\
$X = exp(Y,Z)$ & X and Z are ground		& 8 = Y {^} 3 \\
$X = Y$ {^} $Z$  & Y and Z are ground		& X = 2 {^} 3 \\
\hline
$X = sin(Y)$	& X is ground			& 1 = sin(Y) \\
$X = cos(Y)$	& Y is ground			& X = sin(1.5707) \\
$X = tan(Y)$    && \\
\hline
\end{tabular}
	\caption{CLP(Q,R) isolating axioms}
	\label{tab:clpqraxioms}
\end{center}
\end{table}

\subsection{Status and known problems}
\label{sec:clpqr-status}

The clpq and clpr libraries are `orphaned', i.e., they currently have
no maintainer.

\begin{itemlist}
    \item [Top-level output]
The top-level output may contain variables not present in the original
query:

\begin{code}
?- {X+Y>=1}.
{Y=1-X+_G2160, _G2160>=0}.

?-
\end{code}

Nonetheless, for linear constraints this kind of answer means
unconditional satisfiability.

    \item [Dumping constraints]
The first argument of dump/3 has to be a list of free variables at
call-time:

\begin{code}
?- {X=1},dump([X],[Y],L).
ERROR: Unhandled exception: Unknown message:
       instantiation_error(dump([1],[_G11],_G6),1)
?-
\end{code}

\end{itemlist}