gen_fun::add: perform trivial reduction step
[barvinok.git] / doc / Usage.tex
blob7bcf77efb06ede110f7a1a07e76fb34feed84f48
1 \section{\texorpdfstring{Usage of the \protect\ai[\tt]{barvinok} library}
2 {Usage of the barvinok library}}
3 \label{a:usage}
5 \index{barvinok@{\tt barvinok}!availability}
6 {\sloppy
7 This section describes some application programs
8 provided by the \barvinok/ library,
9 available from {\tt http://freshmeat.net/projects/barvinok/.}
10 For compilation instructions we refer to the \verb+README+ file
11 included in the distribution.
14 Common option to all programs:\\
15 \begin{tabular}{lll}
16 \ai[\tt]{--version} & \ai[\tt]{-V} & print version
17 \end{tabular}
19 \subsection{\texorpdfstring{\protect\ai[\tt]{barvinok\_count}}{barvinok\_count}}
21 The program \ai[\tt]{barvinok\_count} enumerates a
22 non-parametric polytope. It takes one polytope
23 in \PolyLib/ notation as input and prints the number
24 of integer points in the polytope.
25 The \PolyLib/ notation corresponds to the internal
26 representation of \ai[\tt]{Polyhedron}s as explained
27 in Section~\ref{a:existing}.
28 \index{input format!constraints}
29 The first line of the input contains the number of rows
30 and the number of columns in the \ai[\tt]{Constraint} matrix.
31 The rest of the input is composed of the elements of the matrix.
32 Recall that the number of columns is two more than the number
33 of variables, where the extra first columns is one or zero
34 depending on whether the constraint is an inequality ($\ge 0$)
35 or an equality ($= 0$). The next columns contain
36 the coefficients of the variables and the final column contains
37 the constant in the constraint.
38 E.g., the set
39 $S = \lb\, s \mid s \geq 0 \wedge 2 s \leq 13 \, \rb$
40 from \citeN[Example~38 on page~134]{Verdoolaege2005PhD}
41 corresponds to the following input and
42 output.
43 \begin{verbatim}
44 > cat S
45 2 3
47 1 1 0
48 1 -2 13
49 > ./barvinok_count < S
50 POLYHEDRON Dimension:1
51 Constraints:2 Equations:0 Rays:2 Lines:0
52 Constraints 2 3
53 Inequality: [ 1 0 ]
54 Inequality: [ -2 13 ]
55 Rays 2 3
56 Vertex: [ 0 ]/1
57 Vertex: [ 13 ]/2
59 \end{verbatim}
60 \index{PolyLib@{\tt PolyLib}!version 5.22.0 or newer}
61 Note that if you use \PolyLib/ version 5.22.0 or newer then the output
62 may look slightly different as the computation of the \ai[\tt]{Rays}
63 may have been postponed to a later stage.
64 The program \ai[\tt]{latte2polylib.pl} can be used to
65 convert a polytope from \ai[\tt]{LattE} \shortcite{latte1.1}
66 notation to \PolyLib/ notation.
68 \index{input format!vertices}
69 As an alternative to the constraints based input, the input polytope
70 may also be specified by its \ai[\tt]{Ray} matrix.
71 The first line of the input contains the single word \ai[\tt]{vertices}.
72 The second line contains the number of rows
73 and the number of columns in the \ai[\tt]{Ray} matrix.
74 The rest of the input is composed of the elements of the matrix.
75 Recall that the number of columns is two more than the number
76 of variables, where the extra first columns is one or zero
77 depending on whether the ray is a line or not.
78 The next columns contain
79 the numerators of the coordinates and the final column contains
80 the denominator of the vertex or $0$ for a ray.
81 E.g., the above set can also be described as
82 \begin{verbatim}
83 vertices
85 2 3
87 1 0 1
88 1 13 2
89 \end{verbatim}
91 \subsection{\texorpdfstring{\protect\ai[\tt]{barvinok\_enumerate}}
92 {barvinok\_enumerate}}
94 The program \ai[\tt]{barvinok\_enumerate} enumerates a
95 parametric polytope. It takes two polytopes in \PolyLib/
96 notation as input, optionally followed by a list of parameter
97 names.
98 The two polytopes refer to arguments \verb+P+ and \verb+C+
99 of the corresponding function. (See Section~\ref{a:counting:functions}.)
100 The following example was taken by \shortciteN{Loechner1999}
101 from \shortciteN[Chapter II.2]{Loechner97phd}.
102 \begin{verbatim}
103 > cat loechner
104 # Dimension of the matrix:
105 7 7
106 # Constraints:
107 # i j k P Q cte
108 1 1 0 0 0 0 0 # 0 <= i
109 1 -1 0 0 1 0 0 # i <= P
110 1 0 1 0 0 0 0 # 0 <= j
111 1 1 -1 0 0 0 0 # j <= i
112 1 0 0 1 0 0 0 # 0 <= k
113 1 1 -1 -1 0 0 0 # k <= i-j
114 0 1 1 1 0 -1 0 # Q = i + j + k
116 # 2 parameters, no constraints.
118 > ./barvinok_enumerate < loechner
119 POLYHEDRON Dimension:5
120 Constraints:6 Equations:1 Rays:5 Lines:0
121 Constraints 6 7
122 Equality: [ 1 1 1 0 -1 0 ]
123 Inequality: [ 0 1 1 1 -1 0 ]
124 Inequality: [ 0 1 0 0 0 0 ]
125 Inequality: [ 0 0 1 0 0 0 ]
126 Inequality: [ 0 -2 -2 0 1 0 ]
127 Inequality: [ 0 0 0 0 0 1 ]
128 Rays 5 7
129 Ray: [ 1 0 1 1 2 ]
130 Ray: [ 1 1 0 1 2 ]
131 Vertex: [ 0 0 0 0 0 ]/1
132 Ray: [ 0 0 0 1 0 ]
133 Ray: [ 1 0 0 1 1 ]
134 POLYHEDRON Dimension:2
135 Constraints:1 Equations:0 Rays:3 Lines:2
136 Constraints 1 4
137 Inequality: [ 0 0 1 ]
138 Rays 3 4
139 Line: [ 1 0 ]
140 Line: [ 0 1 ]
141 Vertex: [ 0 0 ]/1
142 - P + Q >= 0
143 2P - Q >= 0
144 1 >= 0
146 ( -1/2 * P^2 + ( 1 * Q + 1/2 )
147 * P + ( -3/8 * Q^2 + ( -1/2 * {( 1/2 * Q + 0 )
148 } + 1/4 )
149 * Q + ( -5/4 * {( 1/2 * Q + 0 )
150 } + 1 )
153 Q >= 0
154 P - Q -1 >= 0
155 1 >= 0
157 ( 1/8 * Q^2 + ( -1/2 * {( 1/2 * Q + 0 )
158 } + 3/4 )
159 * Q + ( -5/4 * {( 1/2 * Q + 0 )
160 } + 1 )
162 \end{verbatim}
163 The output corresponds to
165 \begin{cases}
166 \makebox[0pt][l]{$-\frac 1 2 P^2 + P Q + \frac 1 2 P - \frac 3 8 Q^2
167 + \left( \frac 1 4 - \frac 1 2 \left\{ \frac 1 2 Q \right\} \right)
168 Q + 1
169 - \frac 5 4 \left\{ \frac 1 2 Q \right\}$} \\
171 \hbox{if $P \le Q \le 2 P$}
173 \frac 1 8 Q^2 +
174 \left( \frac 3 4 - \frac 1 2 \left\{ \frac 1 2 Q \right\} \right)
175 - \frac 5 4 \left\{ \frac 1 2 Q \right\}
176 \qquad
177 \qquad
178 \qquad
179 \qquad
180 \qquad
182 \hbox{if $0 \le Q \le P-1$}
184 \end{cases}
187 Options:\\
188 \begin{tabular}{lll}
189 \ai[\tt]{--floor} & \ai[\tt]{-f} &
190 convert \ai[\tt]{fractional}s to \ai[\tt]{flooring}s
192 \ai[\tt]{--convert} & \ai[\tt]{-c} &
193 convert \ai[\tt]{fractional}s to \ai[\tt]{periodic}s
194 \end{tabular}
196 \subsection{\texorpdfstring{\protect\ai[\tt]{barvinok\_enumerate\_e}}
197 {barvinok\_enumerate\_e}}
199 The program \ai[\tt]{barvinok\_enumerate\_e} enumerates a
200 parametric projected set. It takes a single polytope in \PolyLib/
201 notation as input, followed by two lines indicating the number
202 or existential variables and the number of parameters and
203 optionally followed by a list of parameter names.
204 The syntax for the line indicating the number of existential
205 variables is the letter \verb+E+ followed by a space and the actual number.
206 For indicating the number of parameters, the letter \verb+P+ is used.
207 The following example corresponds to
208 \citeN[Example~36 on page~129]{Verdoolaege2005PhD}.
209 \begin{verbatim}
210 > cat projected
212 # k i j p cst
213 1 0 1 0 0 -1
214 1 0 -1 0 0 8
215 1 0 0 1 0 -1
216 1 0 0 -1 1 0
217 0 -1 6 9 0 -7
221 > ./barvinok_enumerate_e <projected
222 POLYHEDRON Dimension:4
223 Constraints:5 Equations:1 Rays:4 Lines:0
224 Constraints 5 6
225 Equality: [ 1 -6 -9 0 7 ]
226 Inequality: [ 0 1 0 0 -1 ]
227 Inequality: [ 0 -1 0 0 8 ]
228 Inequality: [ 0 0 1 0 -1 ]
229 Inequality: [ 0 0 -1 1 0 ]
230 Rays 4 6
231 Vertex: [ 50 8 1 1 ]/1
232 Ray: [ 0 0 0 1 ]
233 Ray: [ 9 0 1 1 ]
234 Vertex: [ 8 1 1 1 ]/1
235 exist: 2, nparam: 1
236 P -3 >= 0
237 1 >= 0
239 ( 3 * P + 10 )
240 P -1 >= 0
241 - P + 2 >= 0
243 ( 8 * P + 0 )
244 \end{verbatim}
246 Options:\\
247 \begin{tabular}{llp{0.7\textwidth}}
248 \ai[\tt]{--floor} & \ai[\tt]{-f} &
249 convert \ai[\tt]{fractional}s to \ai[\tt]{flooring}s
251 \ai[\tt]{--convert} & \ai[\tt]{-c} &
252 convert \ai[\tt]{fractional}s to \ai[\tt]{periodic}s
254 \ai[\tt]{--omega} & \ai[\tt]{-o} &
255 use \Omegalib/ as a preprocessor
257 \ai[\tt]{--pip} & \ai[\tt]{-p} &
258 \raggedright
259 call \ai[\tt]{barvinok\_enumerate\_pip} instead of \ai[\tt]{barvinok\_enumerate\_e}
260 \end{tabular}
262 \subsection{\texorpdfstring{\protect\ai[\tt]{barvinok\_series}}
263 {barvinok\_series}}
265 The program \ai[\tt]{barvinok\_series} enumerates a
266 parametric polytope in the form of a \rgf/.
267 The input of this program is the same as that of
268 \ai[\tt]{barvinok\_enumerate}, except that the input polyhedron
269 is assumed to be full-dimensional.
270 The following is an example of Petr Lison\u{e}k\index{Lison\u{e}k, P.}.
271 \begin{verbatim}
272 > cat petr
274 1 -1 -1 -1 1 0
275 1 1 -1 0 0 0
276 1 0 1 -1 0 0
277 1 0 0 1 0 -1
281 > ./barvinok_series < petr
282 POLYHEDRON Dimension:4
283 Constraints:5 Equations:0 Rays:5 Lines:0
284 Constraints 5 6
285 Inequality: [ -1 -1 -1 1 0 ]
286 Inequality: [ 1 -1 0 0 0 ]
287 Inequality: [ 0 1 -1 0 0 ]
288 Inequality: [ 0 0 1 0 -1 ]
289 Inequality: [ 0 0 0 0 1 ]
290 Rays 5 6
291 Ray: [ 1 1 1 3 ]
292 Ray: [ 1 1 0 2 ]
293 Ray: [ 1 0 0 1 ]
294 Ray: [ 0 0 0 1 ]
295 Vertex: [ 1 1 1 3 ]/1
296 POLYHEDRON Dimension:1
297 Constraints:1 Equations:0 Rays:2 Lines:1
298 Constraints 1 3
299 Inequality: [ 0 1 ]
300 Rays 2 3
301 Line: [ 1 ]
302 Vertex: [ 0 ]/1
303 (n^3)/((1-n) * (1-n) * (1-n^2) * (1-n^3))
304 \end{verbatim}
306 Options:\\
307 \begin{tabular}{llp{0.7\textwidth}}
308 \ai[\tt]{--explicit} & \ai[\tt]{-e} &
309 convert computed \rgf/ to a \psp/
310 \end{tabular}
312 \subsection{\texorpdfstring{\protect\ai[\tt]{barvinok\_union}}
313 {barvinok\_union}}
315 The program \ai[\tt]{barvinok\_union} enumerates a \ai{union} of
316 parametric polytopes. It takes as input the number of parametric
317 polytopes in the union, the polytopes in combined data and
318 parameter space in \PolyLib/ notation, the context in parameter space
319 in \PolyLib/ notation and optionally a list of parameter names.
321 Options:\\
322 \begin{tabular}{llp{0.7\textwidth}}
323 \ai[\tt]{--series} & \ai[\tt]{-s} &
324 compute \rgf/ instead of \psp/
325 \end{tabular}
327 \subsection{\texorpdfstring{\protect\ai[\tt]{barvinok\_ehrhart}}
328 {barvinok\_ehrhart}}
330 The program \ai[\tt]{barvinok\_ehrhart} computes the
331 \ai{Ehrhart quasi-polynomial} of a polytope $P$, i.e., a quasi-polynomial
332 in $n$ that evaluates to the number of integer points in the dilation
333 of $P$ by a factor $n$.
334 The input is the same as that of \ai[\tt]{barvinok\_count}, except that
335 it may be followed by the variable name.
336 The functionality is the same as running \ai[\tt]{barvinok\_enumerate}
337 (or \ai[\tt]{barvinok\_series} if the \ai[\tt]{--series} option was given)
338 on the cone over $P$ placed at $n=1$.
340 Options:\\
341 \begin{tabular}{llp{0.7\textwidth}}
342 \ai[\tt]{--floor} & \ai[\tt]{-f} &
343 convert \ai[\tt]{fractional}s to \ai[\tt]{flooring}s
345 \ai[\tt]{--convert} & \ai[\tt]{-c} &
346 convert \ai[\tt]{fractional}s to \ai[\tt]{periodic}s
348 \ai[\tt]{--series} & \ai[\tt]{-s} &
349 compute \ai{Ehrhart series} instead of \ai{Ehrhart quasi-polynomial}
350 \end{tabular}