test_bound: switch to isl representation earlier
[barvinok.git] / doc / isl.tex
blobb82f6aba63acb3004232520faf526faae3d6fda2
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 set
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 If there are no constraints on the coordinates, i.e., in case of
160 a universe set, the colon may be omitted as well.
161 For example
162 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
163 { [] }
164 \end{lstlisting}
165 represents the entire (unnamed) zero-dimensional space,
166 and should not be confused with
167 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
169 \end{lstlisting}
170 which represents the empty set.
172 Returning to the iteration domain of the loop nest
173 in \autoref{f:loop nest}, we usually do not want to analyze
174 such a program for a specific value of \lstinline{n},
175 but instead for all possible values of \lstinline{n} at once.
176 A generic description of the iteration domain can be obtained
177 through the introduction of a (free) parameter, as in
178 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
179 [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i }
180 \end{lstlisting}
181 The optional parameters should
182 be declared by placing them in a comma delimited list inside \lstinline![]!
183 (followed by an ``\lstinline!->!'') in front of the main set description.
184 The parameters are global and are identified by their names,
185 so the order inside the list is arbitrary.
186 This should be contrasted to the coordinates of a space, the names of
187 which are only relevant within the description of the set and which
188 are instead identified by their positions.
189 That is,
190 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
191 [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i }
192 \end{lstlisting}
193 is equal to
194 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
195 [n] -> { [a,b] : 1 <= a <= n and 1 <= b <= a }
196 \end{lstlisting}
197 but it is not equal to
198 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
199 [n] -> { [j,i] : 1 <= i <= n and 1 <= j <= i }
200 \end{lstlisting}
201 (because the order of the coordinates has changed)
203 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
204 [m] -> { [i,j] : 1 <= i <= m and 1 <= j <= i }
205 \end{lstlisting}
206 (because it involves a different parameter).
208 To plug in a particular value for a parameter, the user should
209 take the \ai{intersection} (\ai[\tt]{*}) with a (typically universal) set that
210 assigns a particular value to the parameter.
211 For example,
212 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
213 S := [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i };
214 S * [n] -> { [i,j] : n = 5 };
215 \end{lstlisting}
216 It should be noted, though, that the result is not the same
217 as simply replacing \lstinline{n} by 5 as the result of the above
218 sequence will still have the global parameter \lstinline{n} set to 5.
219 To avoid this assignment, the user should instead compute
220 the \ai{gist} (\ai[\tt]{\%}) of the original set in the context
221 of setting \lstinline{n} to 5.
222 That is, the result of the sequence below is \lstinline{True}.
223 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
224 S1 := { [i,j] : 1 <= i <= 5 and 1 <= j <= i };
225 S2 := [n] -> { [i,j] : 1 <= i <= n and 1 <= j <= i };
226 (S2 % [n] -> { [i,j] : n = 5}) = S1;
227 \end{lstlisting}
229 \begin{figure}
230 \begin{lstlisting}[escapechar=@]{}
231 for (i = 1; i <= n; i += 3)
232 /* S */
233 \end{lstlisting}
234 \caption{A loop with non-unit stride}
235 \label{f:stride}
236 \end{figure}
238 If a loop has a non-unit stride as in \autoref{f:stride}
239 then affine constraints on the coordinates and the parameters
240 are not sufficient to represent the iteration domain.
241 What is needed is a way to express that the value of
242 \lstinline{i} is equal to 1 plus 3 times some integer and
243 this is where existentially quantified variables can be used.
244 Existentially quantified variables are introduced by the
245 \ai[\tt]{exists} keyword and followed by a colon.
246 They can only be used within a single disjunct.
247 As an example, the iteration domain of the loop in \autoref{f:stride}
248 can be represented as
249 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
250 [n] -> { [i] : exists a : 1 <= i <= n and i = 1 + 3 a }
251 \end{lstlisting}
253 \begin{figure}
254 \begin{lstlisting}[escapechar=@]{}
255 for (i = 1; i <= n; ++i)
256 if ((i + 1) % 5 <= 2)
257 /* S */
258 \end{lstlisting}
259 \caption{A loop with a modulo condition}
260 \label{f:modulo}
261 \end{figure}
263 Existentially quantified variables are also useful to represent
264 modulo constraints. Consider for example the loop in
265 \autoref{f:modulo}. The iterator values \lstinline!i! for which
266 the statement \lstinline!S! is executed lie between
267 1 and \lstinline!n! and are such that the remainder of
268 \lstinline!i + 1! on division by 5 is less than or equal to 2.
269 The constraint $(i + 1) \bmod 5 \le 2$ can be written
270 as $(i + 1) - 5 \floor{\frac{i+1}5} \le 2$, where
271 $f = \floor{\frac{i+1}5}$ is the greatest integer part of $\frac{i+1}5$.
272 That is, $f$ is the unique integer value satisfying the constraints
273 $5 f \le i + 1$ and $5 f \ge (i+1) - 4$.
274 The iteration domain of the statement in \autoref{f:modulo}
275 can therefore be represented as
276 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
277 [n] -> { [i] : exists f : 1 <= i <= n and (i + 1) - 5 f <= 2 and
278 (i + 1) - 4 <= 5 f <= i + 1 }
279 \end{lstlisting}
280 Since greatest integer parts occur relatively frequently, there is
281 a special notation for them in \isl/ using \lstinline![]!.
282 The above set can therefore also be represented as
283 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
284 [n] -> { [i] : 1 <= i <= n and (i + 1) - 5 * [(i + 1)/5] <= 2 }
285 \end{lstlisting}
286 It should be noted that \lstinline![]! always rounds down
287 (towards $-\infty$), while integer division in C truncates
288 (towards 0). When translating conditions in C contain integer
289 divisions and/or modulos to \isl/ constraints, the user should therefore
290 make sure the sign of the dividend is positive. If not, the integer
291 division needs to be translated differently for positive and negative
292 values.
294 \begin{figure}
295 \begin{lstlisting}[escapechar=@]{}
296 for (i = 0; i < n; ++i)
297 T: t[i] = a[i];
298 for (i = 0; i < n; ++i)
299 for (j = 0; j < n - i; ++j)
300 F: t[j] = f(t[j], t[j+1]);
301 for (i = 0; i < n; ++i)
302 B: b[i] = t[i];
303 \end{lstlisting}
304 \caption{A program with three loop nests}
305 \label{f:three loops}
306 \end{figure}
308 Most programs involve more than one statement.
309 Although it is possible to work with different sets, each
310 representing the iteration domain of a statement,
311 it is usually more convenient to collect all iteration domains
312 in a single set. To be able to differentiate between iterations
313 of different statements with the same values for the iterators,
314 \isl/ allows spaces to be named. The name is placed in front
315 of the \lstinline![]! enclosing the iterators.
316 Consider for example the program in \autoref{f:three loops}.
317 The program contains three statements which have been labeled
318 for convenience.
319 The iteration domain of the first statement (\lstinline!T!)
320 can be represented as
321 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
322 [n] -> { T[i] : 0 <= i < n }
323 \end{lstlisting}
324 The union of all iteration domains can be represented as
325 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
326 [n] -> {
327 T[i] : 0 <= i < n;
328 F[i,j] : 0 <= i < n and 0 <= j < n - i;
329 B[i] : 0 <= i < n
331 \end{lstlisting}
332 The semicolon \lstinline{;} is used to express a disjunction
333 between spaces. This should be contrasted with the \lstinline{or}
334 keyword which expresses a disjunction between conjunctions of constraints.
335 For example, the result of the following \iscc/ statement is
336 \lstinline{True}.
337 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
338 { [i] : i = 3 or i = 5 } = { [3]; [5] };
339 \end{lstlisting}
341 \subsubsection{Maps and Access Relations}
343 A second important concept in the polyhedral model is that
344 of an \defindex{access relation}.
345 An access relation connects iterations of a statement
346 to the array elements accessed by those iterations.
347 Such a binary relation can be represented by a map in \isl/.
348 Maps are defined in similar way to sets,
349 except that the single space is replaced by a pair of spaces separated
350 by \verb!->!.
351 As an example, consider once more the program in \autoref{f:three loops}.
352 In particular, consider the access \lstinline{t[j+1]} in
353 statement \lstinline{F}.
354 The index expression maps the pair of iterations \lstinline{i}
355 and \lstinline{j} to \lstinline{t[j+1]}, i.e., element \lstinline{j+1}
356 of a space with name \lstinline{t}.
357 Ignoring the loop bound constraints, this access relation can
358 be represented as
359 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
360 { F[i,j] -> t[j + 1] }
361 \end{lstlisting}
362 It is however customary to include the constraints on the iterators
363 in the access relation, resulting in
364 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
365 [n] -> { F[i,j] -> t[j + 1] : 0 <= i < n and 0 <= j < n - i }
366 \end{lstlisting}
367 The constraints can be added by intersecting the domains
368 of the access relations with the iteration domains.
369 For example, the following sequence constructs the access
370 relation for all reads in the program.
371 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
372 D := [n] -> {
373 T[i] : 0 <= i < n;
374 F[i,j] : 0 <= i < n and 0 <= j < n - i;
375 B[i] : 0 <= i < n
377 Read := {
378 T[i] -> a[i];
379 F[i,j] -> t[j];
380 F[i,j] -> t[j + 1];
381 B[i] -> t[i]
383 Read := Read * D;
384 \end{lstlisting}
385 In this sequence, the \lstinline{*} operator, when applied
386 to a map and a set, intersects the domain of the map with the set.
388 The notation \lstinline{R(S)} can be used to compute the image
389 of the set \lstinline{S} under the map \lstinline{R}.
390 For example, given the sequence above, \lstinline!Read({F[0,1]})!
391 computes the array elements read in iteration $(0,1)$ of statement
392 \lstinline{F} and is equal to
393 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
394 [n] -> { t[2] : n >= 2; t[1] : n >= 2 }
395 \end{lstlisting}
396 That is, elements 1 and 2 of the \lstinline{t} array are read,
397 provided \lstinline{n} is at least 2.
399 Maps need not be single-valued.
400 As an example, assume that \lstinline{A} is a two-dimensional
401 array of size \lstinline{n} in both dimensions.
402 Iterations \lstinline{i} of
403 a statement \lstinline{S} may pass a pointer to an entire row
404 of \lstinline{A} to a function as in \lstinline{f(A[i])}.
405 Without knowing anything about \lstinline{f}, we would have
406 to assume that this function may access any element of the row.
407 The access relation corresponding to \lstinline{A[i]} is therefore
408 \begin{lstlisting}[columns=flexible,escapechar=@,language=]{}
409 [n] -> { S[i] -> A[i,j] : 0 <= i,j < n }
410 \end{lstlisting}
411 This map associates \lstinline{n} elements of \lstinline{A}
412 to each iteration of \lstinline{S}.
414 \subsubsection{Nested Spaces}
416 Each space may contain a nested pair of spaces. Such nested spaces
417 are extremely useful in more advanced applications.
418 As an example, suppose that during equivalence checking
419 \shortcite{Verdoolaege2009equivalence}
420 of two programs the iterations of \verb!S1! in one program are supposed to
421 produce the same results as the same iterations of \verb!SA! in the other program,
422 which may be described using the following map
423 \begin{verbatim}
424 [n] -> { S1[i] -> SA[i] : 0 <= i <= n }
425 \end{verbatim}
426 If the iterations of \verb!S1! depend on the same iterations
427 of \verb!S2!, i.e., \verb!{S1[i]->S2[i]}!, while those of \verb!SA!
428 depend on the next iteration of \verb!B!, i.e., \verb!{SA[i]->SB[i+1]}!,
429 then we can apply the cross product of these two dependence maps, i.e.,
430 \begin{verbatim}
431 { [S1[i] -> SA[i']] -> [S2[i] -> SB[1+i']] }
432 \end{verbatim}
433 to the original map to find
434 out which iterations of \verb!S2! should correspond to which
435 iterations of \verb!SB!.
437 \subsubsection{Basic Operations}
439 Basic operations on sets and maps include intersection (\ai[\tt]{*}),
440 union (\ai[\tt]{+}), difference (\ai[\tt]{-}), cross product (\ai[\tt]{cross}),
441 sampling (\ai[\tt]{sample}), affine hull (\ai[\tt]{aff}),
442 lexicographic optimization (\ai[\tt]{lexmin} or \ai[\tt]{lexmax}),
443 subset (\ai[\tt]{<=}) and equality (\ai[\tt]{=}) tests,
444 code generation (\ai[\tt]{codegen})
445 and the cardinality (\ai[\tt]{card}).
446 Additional operations on maps include computing domain (\ai[\tt]{dom})
447 and range (\ai[\tt]{ran}), differences between image and domain (\ai[\tt]{deltas}),
448 join (\ai[\tt]{.}), inverse (\ai[\tt]{\^{}-1}) and transitive closure (\ai[\tt]{\^{}+}).
449 The latter may result in an overapproximation.
451 The \ai[\tt]{card} operation computes the number of elements in a set
452 or the number of elements in the image of a domain element of a map.
453 The operation is performed exactly and completely symbolically and
454 the result is a piecewise quasipolynomial, i.e., a subdivision of one
455 or more spaces, with a quasipolynomial associated to each cell in the subdivision.
456 As a trivial example, the result of
457 \begin{verbatim}
458 card { A[i] -> B[j] : 0 <= j <= i }
459 \end{verbatim}
460 is \verb!{ A[i] -> (1+i) : i >= 0 }!.
461 Operations on piecewise quasipolynomials include sum (\ai[\tt]{+})
462 and difference (\ai[\tt]{-}) and the computation of an upper bound over the domain.
463 If the domain contains a pair of nested spaces, then the upper bound is computed over
464 the nested range. As another trivial example, the result of
465 \begin{verbatim}
466 ub{ [[i] -> [j]] -> j^2 : -i <= j <= i }
467 \end{verbatim}
469 \verb!({ [i] -> max(i^2) : i >= 0 }, True)!.
470 The first element in this list is the actual bound in the form
471 of a piecewise quasipolynomial fold,
472 i.e., a maximum of quasipolynomials defined over cells.
473 The second indicates whether the bound is tight, i.e., whether
474 a maximum has been computed.
476 \subsubsection{Advanced Operations}
478 While the basic {\tt card} operation simply counts the number of elements
479 in an affine set, it is also possible to assign a weight to each element
480 of the set and to compute the sum of those weights over all the points in the set.
481 The syntax for this weighted counting is to compute the {\tt sum} of
482 a piecewise quasipolynomial over its domain. As in the case of the {\tt ub}
483 operator, if the domain contains a pair of nested space, the sum is computed
484 over the range. As an example, the result
486 \begin{verbatim}
487 sum{ [[i] -> [j]] -> i*j : 0 <= j <= i }
488 \end{verbatim}
490 \verb|{ [i] -> (1/2*i^2+1/2*i^3) : i >= 0 }|.
492 After the computation of some sum or bound, the result may have to
493 be reformulated in terms of other variables. For example, during
494 inter procedural analysis, a result computed in terms of the formal
495 parameters may have to be reformulated in terms of the actual parameters.
496 {\tt iscc} therefore allows maps and
497 piecewise quasipolynomials or folds to be composed.
498 If the map is multi-valued, then the composition maps each domain element
499 to the sum or upper bound of the values at its image elements.
501 Finally, because of its high-level representation, {\tt iscc} can
502 provide a dependence analysis operation taking only three maps as input,
503 the sink accesses, the potential source accesses and a schedule.
504 The result is a single dependence map.
507 \subsubsection{More Examples}
508 \begin{verbatim}
509 P := [n, m] -> { [i,j] : 0 <= i <= n and i <= j <= m };
510 card P;
512 f := [n,m] -> { [i,j] -> i*j + n*i*i*j : i,j >= 0 and 5i + 27j <= n+m };
513 sum f;
514 s := sum f;
515 s @ [n,m] -> { [] : 0 <= n,m <= 20 };
517 f := [n] -> { [i] -> 2*n*i - n*n + 3*n - 1/2*i*i - 3/2*i-1 :
518 (exists j : 0 <= i < 4*n-1 and 0 <= j < n and
519 2*n-1 <= i+j <= 4*n-2 and i <= 2*n-1 ) };
520 ub f;
521 u := (ub f)[0];
522 u @ [n] -> { [] : 0 <= n <= 10 };
524 m := [n] -> { [i,j] -> [i+1,j+1] : 1 <= i,j < n;
525 [i,j] -> [i+1,j-1] : 1 <= i < n and 2 <= j <= n };
526 m^+;
527 (m^+)[0];
529 codegen [N] -> { A[i] -> [i,0] : 0 <= i <= N; B[i] -> [i,1] : 1 <= i <= N };
531 { [k] -> [i] : 1 <= i <= k } . { [n] -> 2 * n : n >= 1 };
533 { [m] -> [c] : 1 <= c <= m } . { [k] -> max((3 * k + k^2)) : k >= 1 };
534 \end{verbatim}
536 \subsubsection{Comparison to other Interactive Polyhedral Tools}
538 Two related interactive polyhedral tools are
539 the Omega calculator \shortcite{Omega_calc}
540 and {\tt SPPoC} \shortcite{Boulet2001SPPoC}.
541 The syntax of {\tt iscc} was very much inspired
542 by that of the Omega calculator. However, the Omega
543 calculator only knows sets and maps. In particular,
544 it does not perform any form of counting. An earlier version
545 of \barvinok/ came with a modified version of
546 the Omega calculator that introduced an operation
547 for counting the number of elements in a set, but it
548 would simply print the result and not allow any further
549 manipulations.
550 {\tt SPPoC} does support counting, but only the basic
551 operation of counting the elements in a set.
552 In particular, it does not support weighted counting,
553 nor the computation of upper bounds.
554 It also only supports (single-valued) functions
555 and not generic relations like the Omega calculator and {\tt iscc}.
556 Internally, {\tt SPPoC} uses {\tt PolyLib}, {\tt PipLib} and {\tt omega}
557 to perform
558 its operations. Although the first two of these libraries may have been
559 state-of-the-art at the time {\tt SPPoC} was created, they are
560 no longer actively maintained and have been largely
561 superseded by more recent libraries.
562 In particular, {\tt PipLib} effectively only supports a single
563 operation, which is now also available in both {\tt isl} and {\tt PPL}.
564 The operations on rational polyhedra in {\tt PolyLib} are also
565 available in {\tt PPL}, usually through a cleaner interface and
566 with a more efficient implementation. As to counting the elements
567 in a parametric polytope, Barvinok's algorithm,
568 implemented in the {\tt barvinok} library, is usually much faster
569 than the algorithm implemented in {\tt PolyLib}
570 \shortcite{Verdoolaege2007parametric}.
571 Furthermore,
572 the ability to work with named and nested spaces and the ability
573 of sets and maps to contain (pairs of) elements from different spaces
574 are not available in the Omega calculator and {\tt SPPoC}.
576 \newpage
577 \tablecaption{{\tt iscc} operations. The variables
578 have the following types,
579 $s$: set,
580 $m$: map,
581 $q$: piecewise quasipolynomial,
582 $f$: piecewise quasipolynomial fold,
583 $l$: list,
584 $i$: integer,
585 $b$: boolean,
586 $S$: string,
587 $o$: object of any type
589 \label{t:iscc}
590 \tablehead{
591 \hline
592 Syntax & Meaning
594 \hline
596 \tabletail{
597 \multicolumn{2}{r}{\small\sl continued on next page}
600 \tablelasttail{}
601 \begin{supertabular}{p{0.35\textwidth}p{0.6\textwidth}}
602 $s_2$ := \ai[\tt]{aff} $s_1$ & affine hull of $s_1$
604 $m_2$ := \ai[\tt]{aff} $m_1$ & affine hull of $m_1$
606 $q$ := \ai[\tt]{card} $s$ &
607 number of elements in the set $s$
609 $q$ := \ai[\tt]{card} $m$ &
610 number of elements in the image of a domain element
612 $s_2$ := \ai[\tt]{coalesce} $s_1$ &
613 simplify the representation of set $s_1$ by trying
614 to combine pairs of basic sets into a single
615 basic set
617 $m_2$ := \ai[\tt]{coalesce} $m_1$ &
618 simplify the representation of map $m_1$ by trying
619 to combine pairs of basic maps into a single
620 basic map
622 $q_2$ := \ai[\tt]{coalesce} $q_1$ &
623 simplify the representation of $q_1$ by trying
624 to combine pairs of basic sets in the domain
625 of $q_1$ into a single basic set
627 $f_2$ := \ai[\tt]{coalesce} $f_1$ &
628 simplify the representation of $f_1$ by trying
629 to combine pairs of basic sets in the domain
630 of $f_1$ into a single basic set
632 \ai[\tt]{codegen} $s$ &
633 generate code for the given domain.
634 This operation is only available if \ai[\tt]{CLooG}
635 support was compiled in.
637 \ai[\tt]{codegen} $m$ &
638 generate code for the given scattering function.
639 This operation is only available if \ai[\tt]{CLooG}
640 support was compiled in.
642 $s_3$ := $s_1$ \ai[\tt]{cross} $s_2$ &
643 Cartesian product of $s_1$ and $s_2$
645 $m_3$ := $m_1$ \ai[\tt]{cross} $m_2$ &
646 Cartesian product of $m_1$ and $m_2$
648 $s$ := \ai[\tt]{deltas} $m$ &
649 the set $\{\, y - x \mid x \to y \in m \,\}$
651 $s$ := \ai[\tt]{dom} $m$ &
652 domain of map $m$
654 $s$ := \ai[\tt]{dom} $q$ &
655 domain of piecewise quasipolynomial $q$
657 $s$ := \ai[\tt]{dom} $f$ &
658 domain of piecewise quasipolynomial fold $f$
660 $s$ := \ai[\tt]{ran} $m$ &
661 range of map $m$
663 $m$ := \ai[\tt]{identity} $s$ &
664 identity relation on $s$
666 $s_2$ := \ai[\tt]{lexmin} $s_1$ &
667 lexicographically minimal element of $s_1$
669 $m_2$ := \ai[\tt]{lexmin} $m_1$ &
670 lexicographically minimal image element
672 $s_2$ := \ai[\tt]{lexmax} $s_1$ &
673 lexicographically maximal element of $s_1$
675 $m_2$ := \ai[\tt]{lexmax} $m_1$ &
676 lexicographically maximal image element
678 $s_2$ := \ai[\tt]{poly} $s_1$ & polyhedral hull of $s_1$
680 $m_2$ := \ai[\tt]{poly} $m_1$ & polyhedral hull of $m_1$
682 $q_2$ := \ai[\tt]{poly} $q_1$ & polynomial approximation of $q_1$
684 $q_2$ := \ai[\tt]{lpoly} $q_1$ & polynomial underapproximation of $q_1$
686 $q_2$ := \ai[\tt]{upoly} $q_1$ & polynomial overapproximation of $q_1$
688 $o$ := \ai[\tt]{read} {\tt "}{\it filename}{\tt"} &
689 read object from file
691 $s_2$ := \ai[\tt]{sample} $s_1$ &
692 a sample element of the set $s_1$
694 $m_2$ := \ai[\tt]{sample} $m_1$ &
695 a sample element of the map $m_1$
697 $s_2$ := \ai[\tt]{scan} $s_1$ &
698 the set $s_1$ split into individual elements,
699 provided $s_1$ contains a finite number of elements
701 $m_2$ := \ai[\tt]{scan} $m_1$ &
702 the map $m_1$ split into individual elements,
703 provided $m_1$ contains a finite number of elements
705 \ai[\tt]{source} {\tt "}{\it filename}{\tt"} &
706 read commands from file
708 $q_2$ := \ai[\tt]{sum} $q_1$ &
709 sum $q_1$ over all integer points in the domain of $q_1$,
710 or, if the domain of $q_1$ wraps a map, over all integer
711 points in the range of the wrapped map.
713 $l$ := \ai[\tt]{ub} $q$ &
714 compute an
715 upper bound on the piecewise quasipolynomial $q$ over
716 all integer points in the domain of $q$
717 and return a list containing the upper bound
718 and a boolean that is true if the upper bound
719 is known to be tight.
720 If the domain of $q$ wraps a map, then the upper
721 bound is computed over all integer points in
722 the range of the wrapped map instead.
724 $l$ := \ai[\tt]{vertices} $s$ &
725 a list of vertices of the rational polytope defined by the same constraints
726 as $s$
728 $s$ := \ai[\tt]{wrap} $m$ &
729 wrap the map in a set
731 $m$ := \ai[\tt]{unwrap} $s$ &
732 unwrap the map from the set
734 $m_4$ := \ai[\tt]{any} $m_1$ \ai[\tt]{before} $m_2$ \ai[\tt]{under} $m_3$ &
735 compute a map from any element $x$ in the domain of $m_1$
736 to any element $y$ in the domain of $m_2$
737 such that their images $m_1(x)$ and $m_2(y)$ overlap
738 and such that $m_3(x) \llt m_3(y)$.
740 $l$ := \ai[\tt]{last} $m_1$ \ai[\tt]{before} $m_2$ \ai[\tt]{under} $m_3$ &
741 compute a map that contains for any element $y$ in the domain of $m_2$
742 a mapping from the lexicographically last element $x$ in the domain of $m_1$
743 (according to the schedule $m_3$) to $y$
744 such that $m_1(x)$ and $m_2(y)$ overlap and such that $m_3(x) \llt m_3(y)$.
745 Return a list containing this map and the set of elements in the domain of
746 $m_2$ for which there is no corresponding element in the domain of $m_1$.
748 $m_5$ := \ai[\tt]{any} $m_1$ \ai[\tt]{last} $m_2$ \ai[\tt]{before} $m_3$
749 \ai[\tt]{under} $m_4$ &
750 compute a map that contains for any element $y$ in the domain of $m_3$
751 a mapping from the lexicographically last element $x$ in the domain of $m_2$
752 (according to the schedule $m_4$) to $y$
753 such that $m_2(x)$ and $m_3(y)$ overlap and such that $m_4(x) \llt m_4(y)$
754 as well as from any element $z$ in the domain of $m_1$ such that
755 $m_1(z)$ and $m_3(y)$ overlap, $m_4(z) \llt m_4(y)$ and such that there
756 is no $x$ in the domain of $m_2$ with
757 $m_2(x) \cap m_3(y) \ne \emptyset$ and $m_4(z) \llt m_4(x) \llt m_4(y)$.
759 $s_3$ := $s_1$ \ai{$+$} $s_2$ & union
761 $m_3$ := $m_1$ \ai{$+$} $m_2$ & union
763 $q_3$ := $q_1$ \ai{$+$} $q_2$ & sum
765 $f_2$ := $f_1$ \ai{$+$} $q$ & sum
767 $f_2$ := $q$ \ai{$+$} $f_1$ & sum
769 $S_3$ := $S_1$ \ai{$+$} $S_2$ & concatenation
771 $S_2$ := $o$ \ai{$+$} $S_1$ &
772 concatenation of stringification of $o$ and $S_1$
774 $S_2$ := $S_1$ \ai{$+$} $o$ &
775 concatenation of $S_1$ and stringification of $o$
777 $s_3$ := $s_1$ \ai{$-$} $s_2$ & set difference
779 $m_3$ := $m_1$ \ai{$-$} $m_2$ & set difference
781 $q_3$ := $q_1$ \ai{$-$} $q_2$ & difference
783 $s_3$ := $s_1$ \ai{$*$} $s_2$ & intersection
785 $m_3$ := $m_1$ \ai{$*$} $m_2$ & intersection
787 $q_3$ := $q_1$ \ai{$*$} $q_2$ & product
789 $m_2$ := $m_1$ \ai{$*$} $s$ & intersect domain of $m_1$ with $s$
791 $q_2$ := $q_1$ \ai{$*$} $s$ & intersect domain of $q_1$ with $s$
793 $f_2$ := $f_1$ \ai{$*$} $s$ & intersect domain of $f_1$ with $s$
795 $s_2$ := $m$($s_1$) & apply map $m$ to set $s_1$
797 $m_3$ := $m_1$ \ai[\tt]{.} $m_2$ & join of $m_1$ and $m_2$
799 $m_3$ := $m_1$ \ai[\tt]{before} $m_2$ & join of $m_1$ and $m_2$
801 $m_3$ := $m_2$($m_1)$ & join of $m_1$ and $m_2$
803 $m_3$ := $m_2$ \ai[\tt]{after} $m_1$ & join of $m_1$ and $m_2$
805 $f_3$ := $f_1$ \ai[\tt]{.} $f_2$ & join of $f_1$ and $f_2$, combining
806 the lists of quasipolynomials over shared domains
808 $q_2$ := $m$ \ai[\tt]{.} $q_1$ & join of $m$ and $q_1$, taking the sum
809 over all elements in the intersection of the range of $m$ and the domain
810 of $q_1$
812 $q_2$ := $m$ \ai[\tt]{before} $q_1$ & $q_2$ := $m$ \ai[\tt]{.} $q_1$
814 $q_2$ := $q_1(m)$ & $q_2$ := $m$ \ai[\tt]{.} $q_1$
816 $q_2$ := $q_1$ \ai[\tt]{after} $m$ & $q_2$ := $m$ \ai[\tt]{.} $q_1$
818 $f_2$ := $m$ \ai[\tt]{.} $f_1$ & join of $m$ and $f_1$, computing a bound
819 over all elements in the intersection of the range of $m$ and the domain
820 of $f_1$
822 $f_2$ := $m$ \ai[\tt]{before} $f_1$ & $f_2$ := $m$ \ai[\tt]{.} $f_1$
824 $f_2$ := $f_1(m)$ & $f_2$ := $m$ \ai[\tt]{.} $f_1$
826 $f_2$ := $f_1$ \ai[\tt]{after} $m$ & $f_2$ := $m$ \ai[\tt]{.} $f_1$
828 $m$ := $s_1$ \ai[\tt]{->} $s_2$ & universal map with domain $s_1$
829 and range $s_2$
831 $q_2$ := $q_1$ \ai{@} $s$ &
832 evaluate the piecewise quasipolynomial $q_1$ in each element
833 of the set $s$ and return a piecewise quasipolynomial
834 mapping each of the individual elements to the resulting
835 constant
837 $q$ := $f$ \ai{@} $s$ &
838 evaluate the piecewise quasipolynomial fold $f$ in each element
839 of the set $s$ and return a piecewise quasipolynomial
840 mapping each of the individual elements to the resulting
841 constant
843 $s_3$ := $s_1$ \ai[\tt]{\%} $s_2$ &
844 simplify $s_1$ in the context of $s_2$, i.e., compute
845 the gist of $s_1$ given $s_2$
847 $m_3$ := $m_1$ \ai[\tt]{\%} $m_2$ &
848 simplify $m_1$ in the context of $m_2$, i.e., compute
849 the gist of $m_1$ given $m_2$
851 $q_2$ := $q_1$ \ai[\tt]{\%} $s$ &
852 simplify $q_1$ in the context of the domain $s$, i.e., compute
853 the gist of $q_1$ given $s$
855 $f_2$ := $f_1$ \ai[\tt]{\%} $s$ &
856 simplify $f_1$ in the context of the domain $s$, i.e., compute
857 the gist of $f_1$ given $s$
859 $m_2$ := $m_1$\ai[\tt]{\^{}-1} & inverse of $m_1$
861 $l$ := $m$\ai[\tt]{\^{}+} &
862 compute an overapproximation of the transitive closure
863 of $m$ and return a list containing the overapproximation
864 and a boolean that is true if the overapproximation
865 is known to be exact
867 $o$ := $l$[$i$] &
868 the element at position $i$ in the list $l$
870 $b$ := $s_1$ \ai[\tt]{=} $s_2$ & is $s_1$ equal to $s_2$?
872 $b$ := $m_1$ \ai[\tt]{=} $m_2$ & is $m_1$ equal to $m_2$?
874 $b$ := $s_1$ \ai[\tt]{<=} $s_2$ & is $s_1$ a subset of $s_2$?
876 $b$ := $m_1$ \ai[\tt]{<=} $m_2$ & is $m_1$ a subset of $m_2$?
878 $b$ := $s_1$ \ai[\tt]{<} $s_2$ & is $s_1$ a proper subset of $s_2$?
880 $b$ := $m_1$ \ai[\tt]{<} $m_2$ & is $m_1$ a proper subset of $m_2$?
882 $b$ := $s_1$ \ai[\tt]{>=} $s_2$ & is $s_1$ a superset of $s_2$?
884 $b$ := $m_1$ \ai[\tt]{>=} $m_2$ & is $m_1$ a superset of $m_2$?
886 $b$ := $s_1$ \ai[\tt]{>} $s_2$ & is $s_1$ a proper superset of $s_2$?
888 $b$ := $m_1$ \ai[\tt]{>} $m_2$ & is $m_1$ a proper superset of $m_2$?
890 $m$ := $s_1$ \ai[\tt]{<<} $s_2$ & a map from
891 $s_1$ to $s_2$ of those elements that live in the same space and
892 such that the elements of $s_1$ are lexicographically strictly smaller
893 than those of $s_2$.
895 $m_3$ := $m_1$ \ai[\tt]{<<} $m_2$ & a map from the domain of
896 $m_1$ to the domain of $m_2$ of those elements such that their images
897 live in the same space and such that the images of the elements of
898 $m_1$ are lexicographically strictly smaller than those of $m_2$.
900 $m$ := $s_1$ \ai[\tt]{<<=} $s_2$ & a map from
901 $s_1$ to $s_2$ of those elements that live in the same space and
902 such that the elements of $s_1$ are lexicographically smaller
903 than those of $s_2$.
905 $m_3$ := $m_1$ \ai[\tt]{<<=} $m_2$ & a map from the domain of
906 $m_1$ to the domain of $m_2$ of those elements such that their images
907 live in the same space and such that the images of the elements of
908 $m_1$ are lexicographically smaller than those of $m_2$.
910 $m$ := $s_1$ \ai[\tt]{>>} $s_2$ & a map from
911 $s_1$ to $s_2$ of those elements that live in the same space and
912 such that the elements of $s_1$ are lexicographically strictly greater
913 than those of $s_2$.
915 $m_3$ := $m_1$ \ai[\tt]{>>} $m_2$ & a map from the domain of
916 $m_1$ to the domain of $m_2$ of those elements such that their images
917 live in the same space and such that the images of the elements of
918 $m_1$ are lexicographically strictly greater than those of $m_2$.
920 $m$ := $s_1$ \ai[\tt]{>>=} $s_2$ & a map from
921 $s_1$ to $s_2$ of those elements that live in the same space and
922 such that the elements of $s_1$ are lexicographically greater
923 than those of $s_2$.
925 $m_3$ := $m_1$ \ai[\tt]{>>=} $m_2$ & a map from the domain of
926 $m_1$ to the domain of $m_2$ of those elements such that their images
927 live in the same space and such that the images of the elements of
928 $m_1$ are lexicographically greater than those of $m_2$.
930 \end{supertabular}