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