remove polyhedron_range
[barvinok.git] / doc / isl.tex
blob592aef88c1d45bfb35cfc204ade49171c7516239
1 \section{\protect\isl/ interface}
3 \let\llt\prec
4 \let\lle\preccurlyeq
5 \let\lgt\succ
7 \subsection{Library}
9 The \barvinok/ library currently supports only a few
10 functions that interface with the \isl/ library.
11 In time, this interface will grow and is set to replace
12 the \PolyLib/ interface.
13 For more information on the \isl/ data structures, see
14 the \isl/ user manual.
16 \begin{verbatim}
17 __isl_give isl_pw_qpolynomial *isl_set_card(__isl_take isl_set *set);
18 __isl_give isl_union_pw_qpolynomial *isl_union_set_card(
19 __isl_take isl_union_set *uset);
20 \end{verbatim}
21 Compute the number of elements in an \ai[\tt]{isl\_set}
22 or \ai[\tt]{isl\_union\_set}.
23 The resulting \ai[\tt]{isl\_pw\_qpolynomial}
24 or \ai[\tt]{isl\_union\_pw\_qpolynomial} has purely parametric cells.
26 \begin{verbatim}
27 __isl_give isl_pw_qpolynomial *isl_map_card(__isl_take isl_map *map);
28 __isl_give isl_union_pw_qpolynomial *isl_union_map_card(
29 __isl_take isl_union_map *umap);
30 \end{verbatim}
31 Compute a closed form expression for the number of image elements
32 associated to any element in the domain of the given \ai[\tt]{isl\_map}
33 or \ai[\tt]{isl\_union\_map}.
34 The union of the cells in the resulting \ai[\tt]{isl\_pw\_qpolynomial}
35 is equal to the domain of the input \ai[\tt]{isl\_map}.
37 \begin{verbatim}
38 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_sum(
39 __isl_take isl_pw_qpolynomial *pwqp);
40 __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_sum(
41 __isl_take isl_union_pw_qpolynomial *upwqp);
42 \end{verbatim}
43 Compute the sum of the given piecewise quasipolynomial over
44 all integer points in the domain. The result is a piecewise
45 quasipolynomial that only involves the parameters.
46 If, however, the domain of the piecewise quasipolynomial wraps
47 a relation, then the sum is computed over all integer points
48 in the range of that relation and the domain of the relation
49 becomes the domain of the result.
51 \begin{verbatim}
52 __isl_give isl_pw_qpolynomial *isl_map_apply_pw_qpolynomial(
53 __isl_take isl_map *map, __isl_take isl_pw_qpolynomial *pwqp);
54 __isl_give isl_union_pw_qpolynomial *isl_union_map_apply_union_pw_qpolynomial(
55 __isl_take isl_union_map *umap,
56 __isl_take isl_union_pw_qpolynomial *upwqp);
57 \end{verbatim}
58 Compose the given map with the given piecewise quasipolynomial.
59 That is, compute the sum over all elements in the intersection
60 of the range of the map and the domain of the piecewise quasipolynomial
61 as a function of an element in the domain of the map.
63 \subsection{Calculator}
65 The \ai[\tt]{iscc} calculator offers an interface to some
66 of the functionality provided by the \isl/, \cloog/ and \barvinok/
67 libraries.
68 The language used by \ai[\tt]{iscc} is extremely simple. The calculator
69 supports operations on constants and dynamically typed variables and
70 assignments (\ai[\tt]{:=}) to those variables. If the result of an expression
71 is not used inside another expression and not assigned to a variable,
72 then this result is printed on the screen. The operators are overloaded
73 based on the types of the arguments, which may be sets, relations,
74 piecewise quasipolynomials, piecewise quasipolynomial folds, lists,
75 strings or booleans.
76 The supported operations are shown in \autoref{t:iscc}.
77 Note that when an operation requires an argument of a certain
78 type, a binary list with the first element of the required type
79 may also be used instead.
81 \subsubsection{Sets and Iteration Domains}
83 \begin{figure}
84 \begin{lstlisting}[escapechar=@]{}
85 for (i = 1; i <= n; ++i)
86 for (j = 1; j <= i; ++j)
87 /* S */
88 \end{lstlisting}
89 \caption{A loop nest}
90 \label{f:loop nest}
91 \end{figure}
93 \begin{figure}
94 \begin{tikzpicture}[>=stealth,x=0.7cm,y=-0.7cm]
95 \draw[thick] (1,1)--(5,5)--(1,5)--(1,1);
96 \draw[->] (-0.6,0) to (5.6,0) node[anchor=south east] {$j$};
97 \draw[->] (0,-0.6) to (0,5.6) node[anchor=south east] {$i$};
98 \draw[help lines,step=0.7cm] (-0.6,5.6) grid (5.6,-0.6);
99 \foreach \i in {1,...,5}{
100 \foreach \j in {1,...,\i}{
101 \fill (\j,\i) circle (2pt);
104 \end{tikzpicture}
105 \caption{The iteration domain of the loop nest in \autoref{f:loop nest}}
106 \label{f:iteration domain}
107 \end{figure}
109 Within the polyhedral model for analysis and transformation of
110 static affine programs, the most basic kind of set is the
111 \defindex{iteration domain}.
112 The iteration domain represents the iterations of a statement in a loop nest.
113 Take, for example, the loop nest in \autoref{f:loop nest}
114 and assume first that \lstinline{n} has a fixed value, say 5.
115 The pairs of values of \lstinline{i} and \lstinline{j} for
116 which statement \lstinline{S} is executed are shown graphically
117 in \autoref{f:iteration domain}.
118 Mathematically, this set of pairs can be represented as
120 \{\,
121 (i,j) \in \ZZ^2 \mid 1 \le i \le 5 \wedge 1 \le j \le i
122 \,\}
124 and the \isl/ notation is very similar:
125 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
126 { [i,j] : 1 <= i <= 5 and 1 <= j <= i }
127 \end{lstlisting}
128 In this notation,
129 the coordinates are separated by commas and enclosed in square
130 brackets. This description of the space in which the set lives
131 is followed by a colon and the constraints on the coordinates.
132 Assuming the iterators are incremented by one in every iterations
133 of the loop, a lower and upper bound on each loop iterator
134 can be read off from the initialization and the test.
135 Note that in an \iscc/ set,
136 the coordinates are assumed to be integer by default.
137 For an iteration domain to be representable by such a set,
138 the iterators therefore need to be integers.
140 The constraints of a set need to be affine, i.e., linear plus constant term.
141 The constraints also need to be given in \indac{DNF}, with disjuncts
142 separated by the \ai[\tt]{or} keyword and conjuncts separated
143 by the \ai[\tt]{and} keyword.
144 Note that this is not a real restriction because \iscc/ supports
145 basic operations on sets such as intersection (\ai[\tt]{*}),
146 union (\ai[\tt]{+}) and difference (\ai[\tt]{-}) that allow
147 the user to construct a set of elements satisfying constraints that
148 are not in \indac{DNF}.
149 For example, the following square with its diagonal removed,
151 \{\,
152 (i,j) \mid 0 \le i,j \le 10 \wedge \lnot (i = j)
153 \,\}
155 can be constructed as
156 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
157 { [i,j] : 0 <= i,j <= 10 } - { [i,i] }
158 \end{lstlisting}
159 Note that an occurrence of a relational operator in a set description
160 may define several constraints, one for each pair of arguments.
161 The elements in a list of arguments are separated by a comma.
162 If there are no constraints on the coordinates, i.e., in case of
163 a universe set, the colon may be omitted as well.
164 For example
165 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
166 { [] }
167 \end{lstlisting}
168 represents the entire (unnamed) zero-dimensional space,
169 and should not be confused with
170 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
172 \end{lstlisting}
173 which represents the empty set.
175 Returning to the iteration domain of the loop nest
176 in \autoref{f:loop nest}, we usually do not want to analyze
177 such a program for a specific value of \lstinline{n},
178 but instead for all possible values of \lstinline{n} at once.
179 A generic description of the iteration domain can be obtained
180 through the introduction of a (free) parameter, as in
181 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
182 [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i }
183 \end{lstlisting}
184 The optional parameters should
185 be declared by placing them in a comma delimited list inside \lstinline![]!
186 (followed by an ``\lstinline!->!'') in front of the main set description.
187 The parameters are global and are identified by their names,
188 so the order inside the list is arbitrary.
189 This should be contrasted to the coordinates of a space, the names of
190 which are only relevant within the description of the set and which
191 are instead identified by their positions.
192 That is,
193 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
194 [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i }
195 \end{lstlisting}
196 is equal to
197 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
198 [n] -> { [a,b] : 1 <= a <= n and 1 <= b <= a }
199 \end{lstlisting}
200 but it is not equal to
201 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
202 [n] -> { [j,i] : 1 <= i <= n and 1 <= j <= i }
203 \end{lstlisting}
204 (because the order of the coordinates has changed)
206 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
207 [m] -> { [i,j] : 1 <= i <= m and 1 <= j <= i }
208 \end{lstlisting}
209 (because it involves a different parameter).
211 To plug in a particular value for a parameter, the user should
212 take the \ai{intersection} (\ai[\tt]{*}) with a (typically universal) set that
213 assigns a particular value to the parameter.
214 For example,
215 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
216 S := [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i };
217 S * [n] -> { [i,j] : n = 5 };
218 \end{lstlisting}
219 It should be noted, though, that the result is not the same
220 as simply replacing \lstinline{n} by 5 as the result of the above
221 sequence will still have the global parameter \lstinline{n} set to 5.
222 To avoid this assignment, the user should instead compute
223 the \ai{gist} (\ai[\tt]{\%}) of the original set in the context
224 of setting \lstinline{n} to 5.
225 That is, the result of the sequence below is \lstinline{True}.
226 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
227 S1 := { [i,j] : 1 <= i <= 5 and 1 <= j <= i };
228 S2 := [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i };
229 (S2 % [n] -> { [i,j] : n = 5}) = S1;
230 \end{lstlisting}
232 \begin{figure}
233 \begin{lstlisting}[escapechar=@]{}
234 for (i = 1; i <= n; i += 3)
235 /* S */
236 \end{lstlisting}
237 \caption{A loop with non-unit stride}
238 \label{f:stride}
239 \end{figure}
241 If a loop has a non-unit stride as in \autoref{f:stride}
242 then affine constraints on the coordinates and the parameters
243 are not sufficient to represent the iteration domain.
244 What is needed is a way to express that the value of
245 \lstinline{i} is equal to 1 plus 3 times some integer and
246 this is where existentially quantified variables can be used.
247 Existentially quantified variables are introduced by the
248 \ai[\tt]{exists} keyword and followed by a colon.
249 They can only be used within a single disjunct.
250 As an example, the iteration domain of the loop in \autoref{f:stride}
251 can be represented as
252 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
253 [n] -> { [i] : exists a : 1 <= i <= n and i = 1 + 3 a }
254 \end{lstlisting}
256 \begin{figure}
257 \begin{lstlisting}[escapechar=@]{}
258 for (i = 1; i <= n; ++i)
259 if ((i + 1) % 5 <= 2)
260 /* S */
261 \end{lstlisting}
262 \caption{A loop with a modulo condition}
263 \label{f:modulo}
264 \end{figure}
266 Existentially quantified variables are also useful to represent
267 modulo constraints. Consider for example the loop in
268 \autoref{f:modulo}. The iterator values \lstinline!i! for which
269 the statement \lstinline!S! is executed lie between
270 1 and \lstinline!n! and are such that the remainder of
271 \lstinline!i + 1! on division by 5 is less than or equal to 2.
272 The constraint $(i + 1) \bmod 5 \le 2$ can be written
273 as $(i + 1) - 5 \floor{\frac{i+1}5} \le 2$, where
274 $f = \floor{\frac{i+1}5}$ is the greatest integer part of $\frac{i+1}5$.
275 That is, $f$ is the unique integer value satisfying the constraints
276 $5 f \le i + 1$ and $5 f \ge (i+1) - 4$.
277 The iteration domain of the statement in \autoref{f:modulo}
278 can therefore be represented as
279 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
280 [n] -> { [i] : exists f : 1 <= i <= n and (i + 1) - 5 f <= 2 and
281 (i + 1) - 4 <= 5 f <= i + 1 }
282 \end{lstlisting}
283 Since greatest integer parts occur relatively frequently, there is
284 a special notation for them in \isl/ using \lstinline![]!.
285 The above set can therefore also be represented as
286 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
287 [n] -> { [i] : 1 <= i <= n and (i + 1) - 5 * [(i + 1)/5] <= 2 }
288 \end{lstlisting}
289 It should be noted that \lstinline![]! always rounds down
290 (towards $-\infty$), while integer division in C truncates
291 (towards 0). When translating conditions in C contain integer
292 divisions and/or modulos to \isl/ constraints, the user should therefore
293 make sure the sign of the dividend is positive. If not, the integer
294 division needs to be translated differently for positive and negative
295 values.
297 \begin{figure}
298 \begin{lstlisting}[escapechar=@]{}
299 for (i = 0; i < n; ++i)
300 T: t[i] = a[i];
301 for (i = 0; i < n; ++i)
302 for (j = 0; j < n - i; ++j)
303 F: t[j] = f(t[j], t[j+1]);
304 for (i = 0; i < n; ++i)
305 B: b[i] = t[i];
306 \end{lstlisting}
307 \caption{A program with three loop nests}
308 \label{f:three loops}
309 \end{figure}
311 Most programs involve more than one statement.
312 Although it is possible to work with different sets, each
313 representing the iteration domain of a statement,
314 it is usually more convenient to collect all iteration domains
315 in a single set. To be able to differentiate between iterations
316 of different statements with the same values for the iterators,
317 \isl/ allows spaces to be named. The name is placed in front
318 of the \lstinline![]! enclosing the iterators.
319 Consider for example the program in \autoref{f:three loops}.
320 The program contains three statements which have been labeled
321 for convenience.
322 The iteration domain of the first statement (\lstinline!T!)
323 can be represented as
324 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
325 [n] -> { T[i] : 0 <= i < n }
326 \end{lstlisting}
327 The union of all iteration domains can be represented as
328 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
329 [n] -> {
330 T[i] : 0 <= i < n;
331 F[i,j] : 0 <= i < n and 0 <= j < n - i;
332 B[i] : 0 <= i < n
334 \end{lstlisting}
335 The semicolon \lstinline{;} is used to express a disjunction
336 between spaces. This should be contrasted with the \lstinline{or}
337 keyword which expresses a disjunction between conjunctions of constraints.
338 For example, the result of the following \iscc/ statement is
339 \lstinline{True}.
340 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
341 { [i] : i = 3 or i = 5 } = { [3]; [5] };
342 \end{lstlisting}
344 \subsubsection{Maps and Access Relations}
346 A second important concept in the polyhedral model is that
347 of an \defindex{access relation}.
348 An access relation connects iterations of a statement
349 to the array elements accessed by those iterations.
350 Such a binary relation can be represented by a map in \isl/.
351 Maps are defined in similar way to sets,
352 except that the single space is replaced by a pair of spaces separated
353 by \verb!->!.
354 As an example, consider once more the program in \autoref{f:three loops}.
355 In particular, consider the access \lstinline{t[j+1]} in
356 statement \lstinline{F}.
357 The index expression maps the pair of iterations \lstinline{i}
358 and \lstinline{j} to \lstinline{t[j+1]}, i.e., element \lstinline{j+1}
359 of a space with name \lstinline{t}.
360 Ignoring the loop bound constraints, this access relation can
361 be represented as
362 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
363 { F[i,j] -> t[j + 1] }
364 \end{lstlisting}
365 It is however customary to include the constraints on the iterators
366 in the access relation, resulting in
367 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
368 [n] -> { F[i,j] -> t[j + 1] : 0 <= i < n and 0 <= j < n - i }
369 \end{lstlisting}
370 The constraints can be added by intersecting the domains
371 of the access relations with the iteration domains.
372 For example, the following sequence constructs the access
373 relation for all reads in the program.
374 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
375 D := [n] -> {
376 T[i] : 0 <= i < n;
377 F[i,j] : 0 <= i < n and 0 <= j < n - i;
378 B[i] : 0 <= i < n
380 Read := {
381 T[i] -> a[i];
382 F[i,j] -> t[j];
383 F[i,j] -> t[j + 1];
384 B[i] -> t[i]
386 Read := Read * D;
387 \end{lstlisting}
388 In this sequence, the \lstinline{*} operator, when applied
389 to a map and a set, intersects the domain of the map with the set.
391 The notation \lstinline{R(S)} can be used to compute the image
392 of the set \lstinline{S} under the map \lstinline{R}.
393 For example, given the sequence above, \lstinline!Read({F[0,1]})!
394 computes the array elements read in iteration $(0,1)$ of statement
395 \lstinline{F} and is equal to
396 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
397 [n] -> { t[2] : n >= 2; t[1] : n >= 2 }
398 \end{lstlisting}
399 That is, elements 1 and 2 of the \lstinline{t} array are read,
400 provided \lstinline{n} is at least 2.
402 Maps need not be single-valued.
403 As an example, assume that \lstinline{A} is a two-dimensional
404 array of size \lstinline{n} in both dimensions.
405 Iterations \lstinline{i} of
406 a statement \lstinline{S} may pass a pointer to an entire row
407 of \lstinline{A} to a function as in \lstinline{f(A[i])}.
408 Without knowing anything about \lstinline{f}, we would have
409 to assume that this function may access any element of the row.
410 The access relation corresponding to \lstinline{A[i]} is therefore
411 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
412 [n] -> { S[i] -> A[i,j] : 0 <= i,j < n }
413 \end{lstlisting}
414 This map associates \lstinline{n} elements of \lstinline{A}
415 to each iteration of \lstinline{S}.
417 \subsubsection{Nested Spaces}
419 Each space may contain a nested pair of spaces. Such nested spaces
420 are extremely useful in more advanced applications.
421 As an example, suppose that during equivalence checking
422 \shortcite{Verdoolaege2009equivalence}
423 of two programs the iterations of \verb!S1! in one program are supposed to
424 produce the same results as the same iterations of \verb!SA! in the other program,
425 which may be described using the following map
426 \begin{verbatim}
427 [n] -> { S1[i] -> SA[i] : 0 <= i <= n }
428 \end{verbatim}
429 If the iterations of \verb!S1! depend on the same iterations
430 of \verb!S2!, i.e., \verb!{S1[i]->S2[i]}!, while those of \verb!SA!
431 depend on the next iteration of \verb!B!, i.e., \verb!{SA[i]->SB[i+1]}!,
432 then we can apply the cross product of these two dependence maps, i.e.,
433 \begin{verbatim}
434 { [S1[i] -> SA[i']] -> [S2[i] -> SB[1+i']] }
435 \end{verbatim}
436 to the original map to find
437 out which iterations of \verb!S2! should correspond to which
438 iterations of \verb!SB!.
440 \subsubsection{Basic Operations}
442 Basic operations on sets and maps include intersection (\ai[\tt]{*}),
443 union (\ai[\tt]{+}), difference (\ai[\tt]{-}), cross product (\ai[\tt]{cross}),
444 sampling (\ai[\tt]{sample}), affine hull (\ai[\tt]{aff}),
445 lexicographic optimization (\ai[\tt]{lexmin} or \ai[\tt]{lexmax}),
446 subset (\ai[\tt]{<=}) and equality (\ai[\tt]{=}) tests,
447 code generation (\ai[\tt]{codegen})
448 and the cardinality (\ai[\tt]{card}).
449 Additional operations on maps include computing domain (\ai[\tt]{dom})
450 and range (\ai[\tt]{ran}), differences between image and domain (\ai[\tt]{deltas}),
451 join (\ai[\tt]{.}), inverse (\ai[\tt]{\^{}-1}) and transitive closure (\ai[\tt]{\^{}+}).
452 The latter may result in an overapproximation.
454 The \ai[\tt]{card} operation computes the number of elements in a set
455 or the number of elements in the image of a domain element of a map.
456 The operation is performed exactly and completely symbolically and
457 the result is a piecewise quasipolynomial, i.e., a subdivision of one
458 or more spaces, with a quasipolynomial associated to each cell in the subdivision.
459 As a trivial example, the result of
460 \begin{verbatim}
461 card { A[i] -> B[j] : 0 <= j <= i }
462 \end{verbatim}
463 is \verb!{ A[i] -> (1+i) : i >= 0 }!.
464 Operations on piecewise quasipolynomials include sum (\ai[\tt]{+})
465 and difference (\ai[\tt]{-}) and the computation of an upper bound over the domain.
466 If the domain contains a pair of nested spaces, then the upper bound is computed over
467 the nested range. As another trivial example, the result of
468 \begin{verbatim}
469 ub{ [[i] -> [j]] -> j^2 : -i <= j <= i }
470 \end{verbatim}
472 \verb!({ [i] -> max(i^2) : i >= 0 }, True)!.
473 The first element in this list is the actual bound in the form
474 of a piecewise quasipolynomial fold,
475 i.e., a maximum of quasipolynomials defined over cells.
476 The second indicates whether the bound is tight, i.e., whether
477 a maximum has been computed.
479 \subsubsection{Advanced Operations}
481 While the basic {\tt card} operation simply counts the number of elements
482 in an affine set, it is also possible to assign a weight to each element
483 of the set and to compute the sum of those weights over all the points in the set.
484 The syntax for this weighted counting is to compute the {\tt sum} of
485 a piecewise quasipolynomial over its domain. As in the case of the {\tt ub}
486 operator, if the domain contains a pair of nested space, the sum is computed
487 over the range. As an example, the result
489 \begin{verbatim}
490 sum{ [[i] -> [j]] -> i*j : 0 <= j <= i }
491 \end{verbatim}
493 \verb|{ [i] -> (1/2*i^2+1/2*i^3) : i >= 0 }|.
495 After the computation of some sum or bound, the result may have to
496 be reformulated in terms of other variables. For example, during
497 inter procedural analysis, a result computed in terms of the formal
498 parameters may have to be reformulated in terms of the actual parameters.
499 {\tt iscc} therefore allows maps and
500 piecewise quasipolynomials or folds to be composed.
501 If the map is multi-valued, then the composition maps each domain element
502 to the sum or upper bound of the values at its image elements.
504 Finally, because of its high-level representation, {\tt iscc} can
505 provide a dependence analysis operation taking only three maps as input,
506 the sink accesses, the potential source accesses and a schedule.
507 The result is a single dependence map.
510 \subsubsection{More Examples}
511 \begin{verbatim}
512 P := [n, m] -> { [i,j] : 0 <= i <= n and i <= j <= m };
513 card P;
515 f := [n,m] -> { [i,j] -> i*j + n*i*i*j : i,j >= 0 and 5i + 27j <= n+m };
516 sum f;
517 s := sum f;
518 s @ [n,m] -> { [] : 0 <= n,m <= 20 };
520 f := [n] -> { [i] -> 2*n*i - n*n + 3*n - 1/2*i*i - 3/2*i-1 :
521 (exists j : 0 <= i < 4*n-1 and 0 <= j < n and
522 2*n-1 <= i+j <= 4*n-2 and i <= 2*n-1 ) };
523 ub f;
524 u := (ub f)[0];
525 u @ [n] -> { [] : 0 <= n <= 10 };
527 m := [n] -> { [i,j] -> [i+1,j+1] : 1 <= i,j < n;
528 [i,j] -> [i+1,j-1] : 1 <= i < n and 2 <= j <= n };
529 m^+;
530 (m^+)[0];
532 codegen [N] -> { A[i] -> [i,0] : 0 <= i <= N; B[i] -> [i,1] : 1 <= i <= N };
534 { [k] -> [i] : 1 <= i <= k } . { [n] -> 2 * n : n >= 1 };
536 { [m] -> [c] : 1 <= c <= m } . { [k] -> max((3 * k + k^2)) : k >= 1 };
537 \end{verbatim}
539 \subsubsection{Comparison to other Interactive Polyhedral Tools}
541 Two related interactive polyhedral tools are
542 the Omega calculator \shortcite{Omega_calc}
543 and {\tt SPPoC} \shortcite{Boulet2001SPPoC}.
544 The syntax of {\tt iscc} was very much inspired
545 by that of the Omega calculator. However, the Omega
546 calculator only knows sets and maps. In particular,
547 it does not perform any form of counting. An earlier version
548 of \barvinok/ came with a modified version of
549 the Omega calculator that introduced an operation
550 for counting the number of elements in a set, but it
551 would simply print the result and not allow any further
552 manipulations.
553 {\tt SPPoC} does support counting, but only the basic
554 operation of counting the elements in a set.
555 In particular, it does not support weighted counting,
556 nor the computation of upper bounds.
557 It also only supports (single-valued) functions
558 and not generic relations like the Omega calculator and {\tt iscc}.
559 Internally, {\tt SPPoC} uses {\tt PolyLib}, {\tt PipLib} and {\tt omega}
560 to perform
561 its operations. Although the first two of these libraries may have been
562 state-of-the-art at the time {\tt SPPoC} was created, they are
563 no longer actively maintained and have been largely
564 superseded by more recent libraries.
565 In particular, {\tt PipLib} effectively only supports a single
566 operation, which is now also available in both {\tt isl} and {\tt PPL}.
567 The operations on rational polyhedra in {\tt PolyLib} are also
568 available in {\tt PPL}, usually through a cleaner interface and
569 with a more efficient implementation. As to counting the elements
570 in a parametric polytope, Barvinok's algorithm,
571 implemented in the {\tt barvinok} library, is usually much faster
572 than the algorithm implemented in {\tt PolyLib}
573 \shortcite{Verdoolaege2007parametric}.
574 Furthermore,
575 the ability to work with named and nested spaces and the ability
576 of sets and maps to contain (pairs of) elements from different spaces
577 are not available in the Omega calculator and {\tt SPPoC}.
579 \newpage
580 \tablecaption{{\tt iscc} operations. The variables
581 have the following types,
582 $s$: set,
583 $m$: map,
584 $q$: piecewise quasipolynomial,
585 $f$: piecewise quasipolynomial fold,
586 $l$: list,
587 $i$: integer,
588 $b$: boolean,
589 $S$: string,
590 $o$: object of any type
592 \label{t:iscc}
593 \tablehead{
594 \hline
595 Syntax & Meaning
597 \hline
599 \tabletail{
600 \multicolumn{2}{r}{\small\sl continued on next page}
603 \tablelasttail{}
604 \begin{supertabular}{p{0.35\textwidth}p{0.6\textwidth}}
605 $s_2$ := \ai[\tt]{aff} $s_1$ & affine hull of $s_1$
607 $m_2$ := \ai[\tt]{aff} $m_1$ & affine hull of $m_1$
609 $q$ := \ai[\tt]{card} $s$ &
610 number of elements in the set $s$
612 $q$ := \ai[\tt]{card} $m$ &
613 number of elements in the image of a domain element
615 $s_2$ := \ai[\tt]{coalesce} $s_1$ &
616 simplify the representation of set $s_1$ by trying
617 to combine pairs of basic sets into a single
618 basic set
620 $m_2$ := \ai[\tt]{coalesce} $m_1$ &
621 simplify the representation of map $m_1$ by trying
622 to combine pairs of basic maps into a single
623 basic map
625 $q_2$ := \ai[\tt]{coalesce} $q_1$ &
626 simplify the representation of $q_1$ by trying
627 to combine pairs of basic sets in the domain
628 of $q_1$ into a single basic set
630 $f_2$ := \ai[\tt]{coalesce} $f_1$ &
631 simplify the representation of $f_1$ by trying
632 to combine pairs of basic sets in the domain
633 of $f_1$ into a single basic set
635 \ai[\tt]{codegen} $s$ &
636 generate code for the given domain.
637 This operation is only available if \ai[\tt]{CLooG}
638 support was compiled in.
640 \ai[\tt]{codegen} $m$ &
641 generate code for the given scattering function.
642 This operation is only available if \ai[\tt]{CLooG}
643 support was compiled in.
645 $s_3$ := $s_1$ \ai[\tt]{cross} $s_2$ &
646 Cartesian product of $s_1$ and $s_2$
648 $m_3$ := $m_1$ \ai[\tt]{cross} $m_2$ &
649 Cartesian product of $m_1$ and $m_2$
651 $s$ := \ai[\tt]{deltas} $m$ &
652 the set $\{\, y - x \mid x \to y \in m \,\}$
654 $s$ := \ai[\tt]{dom} $m$ &
655 domain of map $m$
657 $s$ := \ai[\tt]{dom} $q$ &
658 domain of piecewise quasipolynomial $q$
660 $s$ := \ai[\tt]{dom} $f$ &
661 domain of piecewise quasipolynomial fold $f$
663 $s$ := \ai[\tt]{domain} $m$ &
664 domain of map $m$
666 $s$ := \ai[\tt]{domain} $q$ &
667 domain of piecewise quasipolynomial $q$
669 $s$ := \ai[\tt]{domain} $f$ &
670 domain of piecewise quasipolynomial fold $f$
672 $m_2$ := \ai[\tt]{domain\_map} $m_1$ &
673 a map from a wrapped copy of $m_1$ to the domain of $m_1$
675 $s$ := \ai[\tt]{ran} $m$ &
676 range of map $m$
678 $s$ := \ai[\tt]{range} $m$ &
679 range of map $m$
681 $m_2$ := \ai[\tt]{range\_map} $m_1$ &
682 a map from a wrapped copy of $m_1$ to the range of $m_1$
684 $m$ := \ai[\tt]{identity} $s$ &
685 identity relation on $s$
687 $s_2$ := \ai[\tt]{lexmin} $s_1$ &
688 lexicographically minimal element of $s_1$
690 $m_2$ := \ai[\tt]{lexmin} $m_1$ &
691 lexicographically minimal image element
693 $s_2$ := \ai[\tt]{lexmax} $s_1$ &
694 lexicographically maximal element of $s_1$
696 $m_2$ := \ai[\tt]{lexmax} $m_1$ &
697 lexicographically maximal image element
699 $s_2$ := \ai[\tt]{poly} $s_1$ & polyhedral hull of $s_1$
701 $m_2$ := \ai[\tt]{poly} $m_1$ & polyhedral hull of $m_1$
703 $q_2$ := \ai[\tt]{poly} $q_1$ & polynomial approximation of $q_1$
705 $q_2$ := \ai[\tt]{lpoly} $q_1$ & polynomial underapproximation of $q_1$
707 $q_2$ := \ai[\tt]{upoly} $q_1$ & polynomial overapproximation of $q_1$
709 $o$ := \ai[\tt]{read} {\tt "}{\it filename}{\tt"} &
710 read object from file
712 $s_2$ := \ai[\tt]{sample} $s_1$ &
713 a sample element of the set $s_1$
715 $m_2$ := \ai[\tt]{sample} $m_1$ &
716 a sample element of the map $m_1$
718 $s_2$ := \ai[\tt]{scan} $s_1$ &
719 the set $s_1$ split into individual elements,
720 provided $s_1$ contains a finite number of elements
722 $m_2$ := \ai[\tt]{scan} $m_1$ &
723 the map $m_1$ split into individual elements,
724 provided $m_1$ contains a finite number of elements
726 \ai[\tt]{source} {\tt "}{\it filename}{\tt"} &
727 read commands from file
729 $q_2$ := \ai[\tt]{sum} $q_1$ &
730 sum $q_1$ over all integer points in the domain of $q_1$,
731 or, if the domain of $q_1$ wraps a map, over all integer
732 points in the range of the wrapped map.
734 $S$ := \ai[\tt]{typeof} $o$ &
735 a string representation of the type of $o$
737 $l$ := \ai[\tt]{ub} $q$ &
738 compute an
739 upper bound on the piecewise quasipolynomial $q$ over
740 all integer points in the domain of $q$
741 and return a list containing the upper bound
742 and a boolean that is true if the upper bound
743 is known to be tight.
744 If the domain of $q$ wraps a map, then the upper
745 bound is computed over all integer points in
746 the range of the wrapped map instead.
748 $l$ := \ai[\tt]{vertices} $s$ &
749 a list of vertices of the rational polytope defined by the same constraints
750 as $s$
752 $s$ := \ai[\tt]{wrap} $m$ &
753 wrap the map in a set
755 $m$ := \ai[\tt]{unwrap} $s$ &
756 unwrap the map from the set
758 \ai[\tt]{write} {\tt "}{\it filename}{\tt"} $o$ &
759 write object to file
761 $m_4$ := \ai[\tt]{any} $m_1$ \ai[\tt]{before} $m_2$ \ai[\tt]{under} $m_3$ &
762 compute a map from any element $x$ in the domain of $m_1$
763 to any element $y$ in the domain of $m_2$
764 such that their images $m_1(x)$ and $m_2(y)$ overlap
765 and such that $m_3(x) \llt m_3(y)$.
767 $l$ := \ai[\tt]{last} $m_1$ \ai[\tt]{before} $m_2$ \ai[\tt]{under} $m_3$ &
768 compute a map that contains for any element $y$ in the domain of $m_2$
769 a mapping from the lexicographically last element $x$ in the domain of $m_1$
770 (according to the schedule $m_3$) to $y$
771 such that $m_1(x)$ and $m_2(y)$ overlap and such that $m_3(x) \llt m_3(y)$.
772 Return a list containing this map and the set of elements in the domain of
773 $m_2$ for which there is no corresponding element in the domain of $m_1$.
775 $m_5$ := \ai[\tt]{any} $m_1$ \ai[\tt]{last} $m_2$ \ai[\tt]{before} $m_3$
776 \ai[\tt]{under} $m_4$ &
777 compute a map that contains for any element $y$ in the domain of $m_3$
778 a mapping from the lexicographically last element $x$ in the domain of $m_2$
779 (according to the schedule $m_4$) to $y$
780 such that $m_2(x)$ and $m_3(y)$ overlap and such that $m_4(x) \llt m_4(y)$
781 as well as from any element $z$ in the domain of $m_1$ such that
782 $m_1(z)$ and $m_3(y)$ overlap, $m_4(z) \llt m_4(y)$ and such that there
783 is no $x$ in the domain of $m_2$ with
784 $m_2(x) \cap m_3(y) \ne \emptyset$ and $m_4(z) \llt m_4(x) \llt m_4(y)$.
786 $s_3$ := $s_1$ \ai{$+$} $s_2$ & union
788 $m_3$ := $m_1$ \ai{$+$} $m_2$ & union
790 $q_3$ := $q_1$ \ai{$+$} $q_2$ & sum
792 $f_2$ := $f_1$ \ai{$+$} $q$ & sum
794 $f_2$ := $q$ \ai{$+$} $f_1$ & sum
796 $S_3$ := $S_1$ \ai{$+$} $S_2$ & concatenation
798 $S_2$ := $o$ \ai{$+$} $S_1$ &
799 concatenation of stringification of $o$ and $S_1$
801 $S_2$ := $S_1$ \ai{$+$} $o$ &
802 concatenation of $S_1$ and stringification of $o$
804 $s_3$ := $s_1$ \ai{$-$} $s_2$ & set difference
806 $m_3$ := $m_1$ \ai{$-$} $m_2$ & set difference
808 $q_3$ := $q_1$ \ai{$-$} $q_2$ & difference
810 $s_3$ := $s_1$ \ai{$*$} $s_2$ & intersection
812 $m_3$ := $m_1$ \ai{$*$} $m_2$ & intersection
814 $q_3$ := $q_1$ \ai{$*$} $q_2$ & product
816 $m_2$ := $m_1$ \ai{$*$} $s$ & intersect domain of $m_1$ with $s$
818 $q_2$ := $q_1$ \ai{$*$} $s$ & intersect domain of $q_1$ with $s$
820 $f_2$ := $f_1$ \ai{$*$} $s$ & intersect domain of $f_1$ with $s$
822 $s_2$ := $m$($s_1$) & apply map $m$ to set $s_1$
824 $q_2$ := $q_1$($s$) & apply $q_1$ to each element in $s$ and compute
825 the sum of the results
827 $l$ := $f$($s$) & apply $f$ to each element in $s$, compute
828 a bound of the results
829 and return a list containing the bound
830 and a boolean that is true if the bound
831 is known to be tight.
833 $m_3$ := $m_1$ \ai[\tt]{.} $m_2$ & join of $m_1$ and $m_2$
835 $m_3$ := $m_1$ \ai[\tt]{before} $m_2$ & join of $m_1$ and $m_2$
837 $m_3$ := $m_2$($m_1)$ & join of $m_1$ and $m_2$
839 $m_3$ := $m_2$ \ai[\tt]{after} $m_1$ & join of $m_1$ and $m_2$
841 $f_3$ := $f_1$ \ai[\tt]{.} $f_2$ & join of $f_1$ and $f_2$, combining
842 the lists of quasipolynomials over shared domains
844 $q_2$ := $m$ \ai[\tt]{.} $q_1$ & join of $m$ and $q_1$, taking the sum
845 over all elements in the intersection of the range of $m$ and the domain
846 of $q_1$
848 $q_2$ := $m$ \ai[\tt]{before} $q_1$ & $q_2$ := $m$ \ai[\tt]{.} $q_1$
850 $q_2$ := $q_1(m)$ & $q_2$ := $m$ \ai[\tt]{.} $q_1$
852 $q_2$ := $q_1$ \ai[\tt]{after} $m$ & $q_2$ := $m$ \ai[\tt]{.} $q_1$
854 $l$ := $m$ \ai[\tt]{.} $f$ & join of $m$ and $f$, computing a bound
855 over all elements in the intersection of the range of $m$ and the domain
856 of $f$ and returning a list containing the bound
857 and a boolean that is true if the bound is known to be tight.
859 $l$ := $m$ \ai[\tt]{before} $f$ & $l$ := $m$ \ai[\tt]{.} $f$
861 $l$ := $f(m)$ & $l$ := $m$ \ai[\tt]{.} $f$
863 $l$ := $f$ \ai[\tt]{after} $m$ & $l$ := $m$ \ai[\tt]{.} $f$
865 $m$ := $s_1$ \ai[\tt]{->} $s_2$ & universal map with domain $s_1$
866 and range $s_2$
868 $q_2$ := $q_1$ \ai{@} $s$ &
869 evaluate the piecewise quasipolynomial $q_1$ in each element
870 of the set $s$ and return a piecewise quasipolynomial
871 mapping each of the individual elements to the resulting
872 constant
874 $q$ := $f$ \ai{@} $s$ &
875 evaluate the piecewise quasipolynomial fold $f$ in each element
876 of the set $s$ and return a piecewise quasipolynomial
877 mapping each of the individual elements to the resulting
878 constant
880 $s_3$ := $s_1$ \ai[\tt]{\%} $s_2$ &
881 simplify $s_1$ in the context of $s_2$, i.e., compute
882 the gist of $s_1$ given $s_2$
884 $m_3$ := $m_1$ \ai[\tt]{\%} $m_2$ &
885 simplify $m_1$ in the context of $m_2$, i.e., compute
886 the gist of $m_1$ given $m_2$
888 $q_2$ := $q_1$ \ai[\tt]{\%} $s$ &
889 simplify $q_1$ in the context of the domain $s$, i.e., compute
890 the gist of $q_1$ given $s$
892 $f_2$ := $f_1$ \ai[\tt]{\%} $s$ &
893 simplify $f_1$ in the context of the domain $s$, i.e., compute
894 the gist of $f_1$ given $s$
896 $m_2$ := $m_1$\ai[\tt]{\^{}-1} & inverse of $m_1$
898 $l$ := $m$\ai[\tt]{\^{}+} &
899 compute an overapproximation of the transitive closure
900 of $m$ and return a list containing the overapproximation
901 and a boolean that is true if the overapproximation
902 is known to be exact
904 $o$ := $l$[$i$] &
905 the element at position $i$ in the list $l$
907 $b$ := $s_1$ \ai[\tt]{=} $s_2$ & is $s_1$ equal to $s_2$?
909 $b$ := $m_1$ \ai[\tt]{=} $m_2$ & is $m_1$ equal to $m_2$?
911 $b$ := $s_1$ \ai[\tt]{<=} $s_2$ & is $s_1$ a subset of $s_2$?
913 $b$ := $m_1$ \ai[\tt]{<=} $m_2$ & is $m_1$ a subset of $m_2$?
915 $b$ := $s_1$ \ai[\tt]{<} $s_2$ & is $s_1$ a proper subset of $s_2$?
917 $b$ := $m_1$ \ai[\tt]{<} $m_2$ & is $m_1$ a proper subset of $m_2$?
919 $b$ := $s_1$ \ai[\tt]{>=} $s_2$ & is $s_1$ a superset of $s_2$?
921 $b$ := $m_1$ \ai[\tt]{>=} $m_2$ & is $m_1$ a superset of $m_2$?
923 $b$ := $s_1$ \ai[\tt]{>} $s_2$ & is $s_1$ a proper superset of $s_2$?
925 $b$ := $m_1$ \ai[\tt]{>} $m_2$ & is $m_1$ a proper superset of $m_2$?
927 $m$ := $s_1$ \ai[\tt]{<<} $s_2$ & a map from
928 $s_1$ to $s_2$ of those elements that live in the same space and
929 such that the elements of $s_1$ are lexicographically strictly smaller
930 than those of $s_2$.
932 $m_3$ := $m_1$ \ai[\tt]{<<} $m_2$ & a map from the domain of
933 $m_1$ to the domain of $m_2$ of those elements such that their images
934 live in the same space and such that the images of the elements of
935 $m_1$ are lexicographically strictly smaller than those of $m_2$.
937 $m$ := $s_1$ \ai[\tt]{<<=} $s_2$ & a map from
938 $s_1$ to $s_2$ of those elements that live in the same space and
939 such that the elements of $s_1$ are lexicographically smaller
940 than those of $s_2$.
942 $m_3$ := $m_1$ \ai[\tt]{<<=} $m_2$ & a map from the domain of
943 $m_1$ to the domain of $m_2$ of those elements such that their images
944 live in the same space and such that the images of the elements of
945 $m_1$ are lexicographically smaller than those of $m_2$.
947 $m$ := $s_1$ \ai[\tt]{>>} $s_2$ & a map from
948 $s_1$ to $s_2$ of those elements that live in the same space and
949 such that the elements of $s_1$ are lexicographically strictly greater
950 than those of $s_2$.
952 $m_3$ := $m_1$ \ai[\tt]{>>} $m_2$ & a map from the domain of
953 $m_1$ to the domain of $m_2$ of those elements such that their images
954 live in the same space and such that the images of the elements of
955 $m_1$ are lexicographically strictly greater than those of $m_2$.
957 $m$ := $s_1$ \ai[\tt]{>>=} $s_2$ & a map from
958 $s_1$ to $s_2$ of those elements that live in the same space and
959 such that the elements of $s_1$ are lexicographically greater
960 than those of $s_2$.
962 $m_3$ := $m_1$ \ai[\tt]{>>=} $m_2$ & a map from the domain of
963 $m_1$ to the domain of $m_2$ of those elements such that their images
964 live in the same space and such that the images of the elements of
965 $m_1$ are lexicographically greater than those of $m_2$.
967 \end{supertabular}