3 C<isl> is a thread-safe C library for manipulating
4 sets and relations of integer points bounded by affine constraints.
5 The descriptions of the sets and relations may involve
6 both parameters and existentially quantified variables.
7 All computations are performed in exact integer arithmetic
9 The C<isl> library offers functionality that is similar
10 to that offered by the C<Omega> and C<Omega+> libraries,
11 but the underlying algorithms are in most cases completely different.
13 The library is by no means complete and some fairly basic
14 functionality is still missing.
15 Still, even in its current form, the library has been successfully
16 used as a backend polyhedral library for the polyhedral
17 scanner C<CLooG> and as part of an equivalence checker of
18 static affine programs.
19 For bug reports, feature requests and questions,
20 visit the the discussion group at
21 L<http://groups.google.com/group/isl-development>.
25 The source of C<isl> can be obtained either as a tarball
26 or from the git repository. Both are available from
27 L<http://freshmeat.net/projects/isl/>.
28 The installation process depends on how you obtained
31 =head2 Installation from the git repository
35 =item 1 Clone or update the repository
37 The first time the source is obtained, you need to clone
40 git clone git://repo.or.cz/isl.git
42 To obtain updates, you need to pull in the latest changes
46 =item 2 Get submodule (optional)
48 C<isl> can optionally use the C<piplib> library and provides
49 this library as a submodule. If you want to use it, then
50 after you have cloned C<isl>, you need to grab the submodules
55 To obtain updates, you only need
59 Note that C<isl> currently does not use any C<piplib>
60 functionality by default.
62 =item 3 Generate C<configure>
68 After performing the above steps, continue
69 with the L<Common installation instructions>.
71 =head2 Common installation instructions
77 Building C<isl> requires C<GMP>, including its headers files.
78 Your distribution may not provide these header files by default
79 and you may need to install a package called C<gmp-devel> or something
80 similar. Alternatively, C<GMP> can be built from
81 source, available from L<http://gmplib.org/>.
85 C<isl> uses the standard C<autoconf> C<configure> script.
90 optionally followed by some configure options.
91 A complete list of options can be obtained by running
95 Below we discuss some of the more common options.
97 C<isl> can optionally use C<piplib>, but no
98 C<piplib> functionality is currently used by default.
99 The C<--with-piplib> option can
100 be used to specify which C<piplib>
101 library to use, either an installed version (C<system>),
102 an externally built version (C<build>)
103 or no version (C<no>). The option C<build> is mostly useful
104 in C<configure> scripts of larger projects that bundle both C<isl>
111 Installation prefix for C<isl>
113 =item C<--with-gmp-prefix>
115 Installation prefix for C<GMP> (architecture-independent files).
117 =item C<--with-gmp-exec-prefix>
119 Installation prefix for C<GMP> (architecture-dependent files).
121 =item C<--with-piplib>
123 Which copy of C<piplib> to use, either C<no> (default), C<system> or C<build>.
125 =item C<--with-piplib-prefix>
127 Installation prefix for C<system> C<piplib> (architecture-independent files).
129 =item C<--with-piplib-exec-prefix>
131 Installation prefix for C<system> C<piplib> (architecture-dependent files).
133 =item C<--with-piplib-builddir>
135 Location where C<build> C<piplib> was built.
143 =item 4 Install (optional)
151 =head2 Initialization
153 All manipulations of integer sets and relations occur within
154 the context of an C<isl_ctx>.
155 A given C<isl_ctx> can only be used within a single thread.
156 All arguments of a function are required to have been allocated
157 within the same context.
158 There are currently no functions available for moving an object
159 from one C<isl_ctx> to another C<isl_ctx>. This means that
160 there is currently no way of safely moving an object from one
161 thread to another, unless the whole C<isl_ctx> is moved.
163 An C<isl_ctx> can be allocated using C<isl_ctx_alloc> and
164 freed using C<isl_ctx_free>.
165 All objects allocated within an C<isl_ctx> should be freed
166 before the C<isl_ctx> itself is freed.
168 isl_ctx *isl_ctx_alloc();
169 void isl_ctx_free(isl_ctx *ctx);
173 All operations on integers, mainly the coefficients
174 of the constraints describing the sets and relations,
175 are performed in exact integer arithmetic using C<GMP>.
176 However, to allow future versions of C<isl> to optionally
177 support fixed integer arithmetic, all calls to C<GMP>
178 are wrapped inside C<isl> specific macros.
179 The basic type is C<isl_int> and the following operations
180 are available on this type.
181 The meanings of these operations are essentially the same
182 as their C<GMP> C<mpz_> counterparts.
183 As always with C<GMP> types, C<isl_int>s need to be
184 initialized with C<isl_int_init> before they can be used
185 and they need to be released with C<isl_int_clear>
190 =item isl_int_init(i)
192 =item isl_int_clear(i)
194 =item isl_int_set(r,i)
196 =item isl_int_set_si(r,i)
198 =item isl_int_abs(r,i)
200 =item isl_int_neg(r,i)
202 =item isl_int_swap(i,j)
204 =item isl_int_swap_or_set(i,j)
206 =item isl_int_add_ui(r,i,j)
208 =item isl_int_sub_ui(r,i,j)
210 =item isl_int_add(r,i,j)
212 =item isl_int_sub(r,i,j)
214 =item isl_int_mul(r,i,j)
216 =item isl_int_mul_ui(r,i,j)
218 =item isl_int_addmul(r,i,j)
220 =item isl_int_submul(r,i,j)
222 =item isl_int_gcd(r,i,j)
224 =item isl_int_lcm(r,i,j)
226 =item isl_int_divexact(r,i,j)
228 =item isl_int_cdiv_q(r,i,j)
230 =item isl_int_fdiv_q(r,i,j)
232 =item isl_int_fdiv_r(r,i,j)
234 =item isl_int_fdiv_q_ui(r,i,j)
236 =item isl_int_read(r,s)
238 =item isl_int_print(out,i,width)
242 =item isl_int_cmp(i,j)
244 =item isl_int_cmp_si(i,si)
246 =item isl_int_eq(i,j)
248 =item isl_int_ne(i,j)
250 =item isl_int_lt(i,j)
252 =item isl_int_le(i,j)
254 =item isl_int_gt(i,j)
256 =item isl_int_ge(i,j)
258 =item isl_int_abs_eq(i,j)
260 =item isl_int_abs_ne(i,j)
262 =item isl_int_abs_lt(i,j)
264 =item isl_int_abs_gt(i,j)
266 =item isl_int_abs_ge(i,j)
268 =item isl_int_is_zero(i)
270 =item isl_int_is_one(i)
272 =item isl_int_is_negone(i)
274 =item isl_int_is_pos(i)
276 =item isl_int_is_neg(i)
278 =item isl_int_is_nonpos(i)
280 =item isl_int_is_nonneg(i)
282 =item isl_int_is_divisible_by(i,j)
286 =head2 Sets and Relations
288 C<isl> uses four types of objects for representing sets and relations,
289 C<isl_basic_set>, C<isl_basic_map>, C<isl_set> and C<isl_map>.
290 C<isl_basic_set> and C<isl_basic_map> represent sets and relations that
291 can be described as a conjunction of affine constraints, while
292 C<isl_set> and C<isl_map> represent unions of
293 C<isl_basic_set>s and C<isl_basic_map>s, respectively.
294 The difference between sets and relations (maps) is that sets have
295 one set of variables, while relations have two sets of variables,
296 input variables and output variables.
298 =head2 Memory Management
300 Since a high-level operation on sets and/or relations usually involves
301 several substeps and since the user is usually not interested in
302 the intermediate results, most functions that return a new object
303 will also release all the objects passed as arguments.
304 If the user still wants to use one or more of these arguments
305 after the function call, she should pass along a copy of the
306 object rather than the object itself.
307 The user is then responsible for make sure that the original
308 object gets used somewhere else or is explicitly freed.
310 The arguments and return values of all documents functions are
311 annotated to make clear which arguments are released and which
312 arguments are preserved. In particular, the following annotations
319 C<__isl_give> means that a new object is returned.
320 The user should make sure that the returned pointer is
321 used exactly once as a value for an C<__isl_take> argument.
322 In between, it can be used as a value for as many
323 C<__isl_keep> arguments as the user likes.
324 There is one exception, and that is the case where the
325 pointer returned is C<NULL>. Is this case, the user
326 is free to use it as an C<__isl_take> argument or not.
330 C<__isl_take> means that the object the argument points to
331 is taken over by the function and may no longer be used
332 by the user as an argument to any other function.
333 The pointer value must be one returned by a function
334 returning an C<__isl_give> pointer.
335 If the user passes in a C<NULL> value, then this will
336 be treated as an error in the sense that the function will
337 not perform its usual operation. However, it will still
338 make sure that all the the other C<__isl_take> arguments
343 C<__isl_keep> means that the function will only use the object
344 temporarily. After the function has finished, the user
345 can still use it as an argument to other functions.
346 A C<NULL> value will be treated in the same way as
347 a C<NULL> value for an C<__isl_take> argument.
351 =head2 Dimension Specifications
353 Whenever a new set or relation is created from scratch,
354 its dimension needs to be specified using an C<isl_dim>.
357 __isl_give isl_dim *isl_dim_alloc(isl_ctx *ctx,
358 unsigned nparam, unsigned n_in, unsigned n_out);
359 __isl_give isl_dim *isl_dim_set_alloc(isl_ctx *ctx,
360 unsigned nparam, unsigned dim);
361 __isl_give isl_dim *isl_dim_copy(__isl_keep isl_dim *dim);
362 void isl_dim_free(__isl_take isl_dim *dim);
363 unsigned isl_dim_size(__isl_keep isl_dim *dim,
364 enum isl_dim_type type);
366 The dimension specification used for creating a set
367 needs to be created using C<isl_dim_set_alloc>, while
368 that for creating a relation
369 needs to be created using C<isl_dim_alloc>.
370 C<isl_dim_size> can be used
371 to find out the number of dimensions of each type in
372 a dimension specification, where type may be
373 C<isl_dim_param>, C<isl_dim_in> (only for relations),
374 C<isl_dim_out> (only for relations), C<isl_dim_set>
375 (only for sets) or C<isl_dim_all>.
377 It is often useful to create objects that live in the
378 same space as some other object. This can be accomplished
379 by creating the new objects
380 (see L<Creating New Sets and Relations> or
381 L<Creating New (Piecewise) Quasipolynomials>) based on the dimension
382 specification of the original object.
385 __isl_give isl_dim *isl_basic_set_get_dim(
386 __isl_keep isl_basic_set *bset);
387 __isl_give isl_dim *isl_set_get_dim(__isl_keep isl_set *set);
390 __isl_give isl_dim *isl_basic_map_get_dim(
391 __isl_keep isl_basic_map *bmap);
392 __isl_give isl_dim *isl_map_get_dim(__isl_keep isl_map *map);
394 #include <isl_polynomial.h>
395 __isl_give isl_dim *isl_qpolynomial_get_dim(
396 __isl_keep isl_qpolynomial *qp);
397 __isl_give isl_dim *isl_pw_qpolynomial_get_dim(
398 __isl_keep isl_pw_qpolynomial *pwqp);
400 The names of the individual dimensions may be set or read off
401 using the following functions.
404 __isl_give isl_dim *isl_dim_set_name(__isl_take isl_dim *dim,
405 enum isl_dim_type type, unsigned pos,
406 __isl_keep const char *name);
407 __isl_keep const char *isl_dim_get_name(__isl_keep isl_dim *dim,
408 enum isl_dim_type type, unsigned pos);
410 Note that C<isl_dim_get_name> returns a pointer to some internal
411 data structure, so the result can only be used while the
412 corresponding C<isl_dim> is alive.
413 Also note that every function that operates on two sets or relations
414 requires that both arguments have the same parameters. This also
415 means that if one of the arguments has named parameters, then the
416 other needs to have named parameters too and the names need to match.
418 =head2 Input and Output
420 C<isl> supports its own input/output format, which is similar
421 to the C<Omega> format, but also supports the C<PolyLib> format
426 The C<isl> format is similar to that of C<Omega>, but has a different
427 syntax for describing the parameters and allows for the definition
428 of an existentially quantified variable as the integer division
429 of an affine expression.
430 For example, the set of integers C<i> between C<0> and C<n>
431 such that C<i % 10 <= 6> can be described as
433 [n] -> { [i] : exists (a = [i/10] : 0 <= i and i <= n and
436 A set or relation can have several disjuncts, separated
437 by the keyword C<or>. Each disjunct is either a conjunction
438 of constraints or a projection (C<exists>) of a conjunction
439 of constraints. The constraints are separated by the keyword
442 =head3 C<PolyLib> format
444 If the represented set is a union, then the first line
445 contains a single number representing the number of disjuncts.
446 Otherwise, a line containing the number C<1> is optional.
448 Each disjunct is represented by a matrix of constraints.
449 The first line contains two numbers representing
450 the number of rows and columns,
451 where the number of rows is equal to the number of constraints
452 and the number of columns is equal to two plus the number of variables.
453 The following lines contain the actual rows of the constraint matrix.
454 In each row, the first column indicates whether the constraint
455 is an equality (C<0>) or inequality (C<1>). The final column
456 corresponds to the constant term.
458 If the set is parametric, then the coefficients of the parameters
459 appear in the last columns before the constant column.
460 The coefficients of any existentially quantified variables appear
461 between those of the set variables and those of the parameters.
466 __isl_give isl_basic_set *isl_basic_set_read_from_file(
467 isl_ctx *ctx, FILE *input, int nparam);
468 __isl_give isl_basic_set *isl_basic_set_read_from_str(
469 isl_ctx *ctx, const char *str, int nparam);
470 __isl_give isl_set *isl_set_read_from_file(isl_ctx *ctx,
471 FILE *input, int nparam);
472 __isl_give isl_set *isl_set_read_from_str(isl_ctx *ctx,
473 const char *str, int nparam);
476 __isl_give isl_basic_map *isl_basic_map_read_from_file(
477 isl_ctx *ctx, FILE *input, int nparam);
478 __isl_give isl_basic_map *isl_basic_map_read_from_str(
479 isl_ctx *ctx, const char *str, int nparam);
480 __isl_give isl_map *isl_map_read_from_file(
481 struct isl_ctx *ctx, FILE *input, int nparam);
482 __isl_give isl_map *isl_map_read_from_str(isl_ctx *ctx,
483 const char *str, int nparam);
485 The input format is autodetected and may be either the C<PolyLib> format
486 or the C<isl> format.
487 C<nparam> specifies how many of the final columns in
488 the C<PolyLib> format correspond to parameters.
489 If input is given in the C<isl> format, then the number
490 of parameters needs to be equal to C<nparam>.
491 If C<nparam> is negative, then any number of parameters
492 is accepted in the C<isl> format and zero parameters
493 are assumed in the C<PolyLib> format.
497 Before anything can be printed, an C<isl_printer> needs to
500 __isl_give isl_printer *isl_printer_to_file(isl_ctx *ctx,
502 __isl_give isl_printer *isl_printer_to_str(isl_ctx *ctx);
503 void isl_printer_free(__isl_take isl_printer *printer);
504 __isl_give char *isl_printer_get_str(
505 __isl_keep isl_printer *printer);
507 The behavior of the printer can be modified in various ways
509 __isl_give isl_printer *isl_printer_set_output_format(
510 __isl_take isl_printer *p, int output_format);
511 __isl_give isl_printer *isl_printer_set_indent(
512 __isl_take isl_printer *p, int indent);
513 __isl_give isl_printer *isl_printer_set_prefix(
514 __isl_take isl_printer *p, const char *prefix);
515 __isl_give isl_printer *isl_printer_set_suffix(
516 __isl_take isl_printer *p, const char *suffix);
518 The C<output_format> may be either C<ISL_FORMAT_ISL>, C<ISL_FORMAT_OMEGA>
519 or C<ISL_FORMAT_POLYLIB> and defaults to C<ISL_FORMAT_ISL>.
520 Each line in the output is indented by C<indent> spaces
521 (default: 0), prefixed by C<prefix> and suffixed by C<suffix>.
522 In the C<PolyLib> format output,
523 the coefficients of the existentially quantified variables
524 appear between those of the set variables and those
527 To actually print something, use
530 __isl_give isl_printer *isl_printer_print_basic_set(
531 __isl_take isl_printer *printer,
532 __isl_keep isl_basic_set *bset);
533 __isl_give isl_printer *isl_printer_print_set(
534 __isl_take isl_printer *printer,
535 __isl_keep isl_set *set);
538 __isl_give isl_printer *isl_printer_print_basic_map(
539 __isl_take isl_printer *printer,
540 __isl_keep isl_basic_map *bmap);
541 __isl_give isl_printer *isl_printer_print_map(
542 __isl_take isl_printer *printer,
543 __isl_keep isl_map *map);
545 When called on a file printer, the following function flushes
546 the file. When called on a string printer, the buffer is cleared.
548 __isl_give isl_printer *isl_printer_flush(
549 __isl_take isl_printer *p);
551 =head2 Creating New Sets and Relations
553 C<isl> has functions for creating some standard sets and relations.
557 =item * Empty sets and relations
559 __isl_give isl_basic_set *isl_basic_set_empty(
560 __isl_take isl_dim *dim);
561 __isl_give isl_basic_map *isl_basic_map_empty(
562 __isl_take isl_dim *dim);
563 __isl_give isl_set *isl_set_empty(
564 __isl_take isl_dim *dim);
565 __isl_give isl_map *isl_map_empty(
566 __isl_take isl_dim *dim);
568 =item * Universe sets and relations
570 __isl_give isl_basic_set *isl_basic_set_universe(
571 __isl_take isl_dim *dim);
572 __isl_give isl_basic_map *isl_basic_map_universe(
573 __isl_take isl_dim *dim);
574 __isl_give isl_set *isl_set_universe(
575 __isl_take isl_dim *dim);
576 __isl_give isl_map *isl_map_universe(
577 __isl_take isl_dim *dim);
579 =item * Identity relations
581 __isl_give isl_basic_map *isl_basic_map_identity(
582 __isl_take isl_dim *set_dim);
583 __isl_give isl_map *isl_map_identity(
584 __isl_take isl_dim *set_dim);
586 These functions take a dimension specification for a B<set>
587 and return an identity relation between two such sets.
589 =item * Lexicographic order
591 __isl_give isl_map *isl_map_lex_lt(
592 __isl_take isl_dim *set_dim);
593 __isl_give isl_map *isl_map_lex_le(
594 __isl_take isl_dim *set_dim);
595 __isl_give isl_map *isl_map_lex_gt(
596 __isl_take isl_dim *set_dim);
597 __isl_give isl_map *isl_map_lex_ge(
598 __isl_take isl_dim *set_dim);
599 __isl_give isl_map *isl_map_lex_lt_first(
600 __isl_take isl_dim *dim, unsigned n);
601 __isl_give isl_map *isl_map_lex_le_first(
602 __isl_take isl_dim *dim, unsigned n);
603 __isl_give isl_map *isl_map_lex_gt_first(
604 __isl_take isl_dim *dim, unsigned n);
605 __isl_give isl_map *isl_map_lex_ge_first(
606 __isl_take isl_dim *dim, unsigned n);
608 The first four functions take a dimension specification for a B<set>
609 and return relations that express that the elements in the domain
610 are lexicographically less
611 (C<isl_map_lex_lt>), less or equal (C<isl_map_lex_le>),
612 greater (C<isl_map_lex_gt>) or greater or equal (C<isl_map_lex_ge>)
613 than the elements in the range.
614 The last four functions take a dimension specification for a map
615 and return relations that express that the first C<n> dimensions
616 in the domain are lexicographically less
617 (C<isl_map_lex_lt_first>), less or equal (C<isl_map_lex_le_first>),
618 greater (C<isl_map_lex_gt_first>) or greater or equal (C<isl_map_lex_ge_first>)
619 than the first C<n> dimensions in the range.
623 A basic set or relation can be converted to a set or relation
624 using the following functions.
626 __isl_give isl_set *isl_set_from_basic_set(
627 __isl_take isl_basic_set *bset);
628 __isl_give isl_map *isl_map_from_basic_map(
629 __isl_take isl_basic_map *bmap);
631 Sets and relations can be copied and freed again using the following
634 __isl_give isl_basic_set *isl_basic_set_copy(
635 __isl_keep isl_basic_set *bset);
636 __isl_give isl_set *isl_set_copy(__isl_keep isl_set *set);
637 __isl_give isl_basic_map *isl_basic_map_copy(
638 __isl_keep isl_basic_map *bmap);
639 __isl_give isl_map *isl_map_copy(__isl_keep isl_map *map);
640 void isl_basic_set_free(__isl_take isl_basic_set *bset);
641 void isl_set_free(__isl_take isl_set *set);
642 void isl_basic_map_free(__isl_take isl_basic_map *bmap);
643 void isl_map_free(__isl_take isl_map *map);
645 Other sets and relations can be constructed by starting
646 from a universe set or relation, adding equality and/or
647 inequality constraints and then projecting out the
648 existentially quantified variables, if any.
649 Constraints can be constructed, manipulated and
650 added to basic sets and relations using the following functions.
652 #include <isl_constraint.h>
653 __isl_give isl_constraint *isl_equality_alloc(
654 __isl_take isl_dim *dim);
655 __isl_give isl_constraint *isl_inequality_alloc(
656 __isl_take isl_dim *dim);
657 void isl_constraint_set_constant(
658 __isl_keep isl_constraint *constraint, isl_int v);
659 void isl_constraint_set_coefficient(
660 __isl_keep isl_constraint *constraint,
661 enum isl_dim_type type, int pos, isl_int v);
662 __isl_give isl_basic_map *isl_basic_map_add_constraint(
663 __isl_take isl_basic_map *bmap,
664 __isl_take isl_constraint *constraint);
665 __isl_give isl_basic_set *isl_basic_set_add_constraint(
666 __isl_take isl_basic_set *bset,
667 __isl_take isl_constraint *constraint);
669 For example, to create a set containing the even integers
670 between 10 and 42, you would use the following code.
674 struct isl_constraint *c;
675 struct isl_basic_set *bset;
678 dim = isl_dim_set_alloc(ctx, 0, 2);
679 bset = isl_basic_set_universe(isl_dim_copy(dim));
681 c = isl_equality_alloc(isl_dim_copy(dim));
682 isl_int_set_si(v, -1);
683 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
684 isl_int_set_si(v, 2);
685 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
686 bset = isl_basic_set_add_constraint(bset, c);
688 c = isl_inequality_alloc(isl_dim_copy(dim));
689 isl_int_set_si(v, -10);
690 isl_constraint_set_constant(c, v);
691 isl_int_set_si(v, 1);
692 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
693 bset = isl_basic_set_add_constraint(bset, c);
695 c = isl_inequality_alloc(dim);
696 isl_int_set_si(v, 42);
697 isl_constraint_set_constant(c, v);
698 isl_int_set_si(v, -1);
699 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
700 bset = isl_basic_set_add_constraint(bset, c);
702 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 1);
708 struct isl_basic_set *bset;
709 bset = isl_basic_set_read_from_str(ctx,
710 "{[i] : exists (a : i = 2a and i >= 10 and i <= 42)}", -1);
712 =head2 Inspecting Sets and Relations
714 Usually, the user should not have to care about the actual constraints
715 of the sets and maps, but should instead apply the abstract operations
716 explained in the following sections.
717 Occasionally, however, it may be required to inspect the individual
718 coefficients of the constraints. This section explains how to do so.
719 In these cases, it may also be useful to have C<isl> compute
720 an explicit representation of the existentially quantified variables.
722 __isl_give isl_set *isl_set_compute_divs(
723 __isl_take isl_set *set);
724 __isl_give isl_map *isl_map_compute_divs(
725 __isl_take isl_map *map);
727 This explicit representation defines the existentially quantified
728 variables as integer divisions of the other variables, possibly
729 including earlier existentially quantified variables.
730 An explicitly represented existentially quantified variable therefore
731 has a unique value when the values of the other variables are known.
732 If, furthermore, the same existentials, i.e., existentials
733 with the same explicit representations, should appear in the
734 same order in each of the disjuncts of a set or map, then the user should call
735 either of the following functions.
737 __isl_give isl_set *isl_set_align_divs(
738 __isl_take isl_set *set);
739 __isl_give isl_map *isl_map_align_divs(
740 __isl_take isl_map *map);
742 To iterate over all the basic sets or maps in a set or map, use
744 int isl_set_foreach_basic_set(__isl_keep isl_set *set,
745 int (*fn)(__isl_take isl_basic_set *bset, void *user),
747 int isl_map_foreach_basic_map(__isl_keep isl_map *map,
748 int (*fn)(__isl_take isl_basic_map *bmap, void *user),
751 The callback function C<fn> should return 0 if successful and
752 -1 if an error occurs. In the latter case, or if any other error
753 occurs, the above functions will return -1.
755 It should be noted that C<isl> does not guarantee that
756 the basic sets or maps passed to C<fn> are disjoint.
757 If this is required, then the user should call one of
758 the following functions first.
760 __isl_give isl_set *isl_set_make_disjoint(
761 __isl_take isl_set *set);
762 __isl_give isl_map *isl_map_make_disjoint(
763 __isl_take isl_map *map);
765 To iterate over the constraints of a basic set or map, use
767 #include <isl_constraint.h>
769 int isl_basic_map_foreach_constraint(
770 __isl_keep isl_basic_map *bmap,
771 int (*fn)(__isl_take isl_constraint *c, void *user),
773 void isl_constraint_free(struct isl_constraint *c);
775 Again, the callback function C<fn> should return 0 if successful and
776 -1 if an error occurs. In the latter case, or if any other error
777 occurs, the above functions will return -1.
778 The constraint C<c> represents either an equality or an inequality.
779 Use the following function to find out whether a constraint
780 represents an equality. If not, it represents an inequality.
782 int isl_constraint_is_equality(
783 __isl_keep isl_constraint *constraint);
785 The coefficients of the constraints can be inspected using
786 the following functions.
788 void isl_constraint_get_constant(
789 __isl_keep isl_constraint *constraint, isl_int *v);
790 void isl_constraint_get_coefficient(
791 __isl_keep isl_constraint *constraint,
792 enum isl_dim_type type, int pos, isl_int *v);
794 The explicit representations of the existentially quantified
795 variables can be inspected using the following functions.
796 Note that the user is only allowed to use these functions
797 if the inspected set or map is the result of a call
798 to C<isl_set_compute_divs> or C<isl_map_compute_divs>.
800 __isl_give isl_div *isl_constraint_div(
801 __isl_keep isl_constraint *constraint, int pos);
802 void isl_div_get_constant(__isl_keep isl_div *div,
804 void isl_div_get_denominator(__isl_keep isl_div *div,
806 void isl_div_get_coefficient(__isl_keep isl_div *div,
807 enum isl_dim_type type, int pos, isl_int *v);
811 =head3 Unary Properties
817 The following functions test whether the given set or relation
818 contains any integer points. The ``fast'' variants do not perform
819 any computations, but simply check if the given set or relation
820 is already known to be empty.
822 int isl_basic_set_fast_is_empty(__isl_keep isl_basic_set *bset);
823 int isl_basic_set_is_empty(__isl_keep isl_basic_set *bset);
824 int isl_set_is_empty(__isl_keep isl_set *set);
825 int isl_basic_map_fast_is_empty(__isl_keep isl_basic_map *bmap);
826 int isl_basic_map_is_empty(__isl_keep isl_basic_map *bmap);
827 int isl_map_fast_is_empty(__isl_keep isl_map *map);
828 int isl_map_is_empty(__isl_keep isl_map *map);
832 int isl_basic_set_is_universe(__isl_keep isl_basic_set *bset);
833 int isl_basic_map_is_universe(__isl_keep isl_basic_map *bmap);
834 int isl_set_fast_is_universe(__isl_keep isl_set *set);
836 =item * Single-valuedness
838 int isl_map_is_single_valued(__isl_keep isl_map *map);
842 =head3 Binary Properties
848 int isl_set_fast_is_equal(__isl_keep isl_set *set1,
849 __isl_keep isl_set *set2);
850 int isl_set_is_equal(__isl_keep isl_set *set1,
851 __isl_keep isl_set *set2);
852 int isl_map_is_equal(__isl_keep isl_map *map1,
853 __isl_keep isl_map *map2);
854 int isl_map_fast_is_equal(__isl_keep isl_map *map1,
855 __isl_keep isl_map *map2);
856 int isl_basic_map_is_equal(
857 __isl_keep isl_basic_map *bmap1,
858 __isl_keep isl_basic_map *bmap2);
862 int isl_set_fast_is_disjoint(__isl_keep isl_set *set1,
863 __isl_keep isl_set *set2);
867 int isl_set_is_subset(__isl_keep isl_set *set1,
868 __isl_keep isl_set *set2);
869 int isl_set_is_strict_subset(
870 __isl_keep isl_set *set1,
871 __isl_keep isl_set *set2);
872 int isl_basic_map_is_subset(
873 __isl_keep isl_basic_map *bmap1,
874 __isl_keep isl_basic_map *bmap2);
875 int isl_basic_map_is_strict_subset(
876 __isl_keep isl_basic_map *bmap1,
877 __isl_keep isl_basic_map *bmap2);
878 int isl_map_is_subset(
879 __isl_keep isl_map *map1,
880 __isl_keep isl_map *map2);
881 int isl_map_is_strict_subset(
882 __isl_keep isl_map *map1,
883 __isl_keep isl_map *map2);
887 =head2 Unary Operations
893 __isl_give isl_set *isl_set_complement(
894 __isl_take isl_set *set);
898 __isl_give isl_basic_map *isl_basic_map_reverse(
899 __isl_take isl_basic_map *bmap);
900 __isl_give isl_map *isl_map_reverse(
901 __isl_take isl_map *map);
905 __isl_give isl_basic_set *isl_basic_set_project_out(
906 __isl_take isl_basic_set *bset,
907 enum isl_dim_type type, unsigned first, unsigned n);
908 __isl_give isl_basic_map *isl_basic_map_project_out(
909 __isl_take isl_basic_map *bmap,
910 enum isl_dim_type type, unsigned first, unsigned n);
911 __isl_give isl_set *isl_set_project_out(__isl_take isl_set *set,
912 enum isl_dim_type type, unsigned first, unsigned n);
913 __isl_give isl_map *isl_map_project_out(__isl_take isl_map *map,
914 enum isl_dim_type type, unsigned first, unsigned n);
915 __isl_give isl_basic_set *isl_basic_map_domain(
916 __isl_take isl_basic_map *bmap);
917 __isl_give isl_basic_set *isl_basic_map_range(
918 __isl_take isl_basic_map *bmap);
919 __isl_give isl_set *isl_map_domain(
920 __isl_take isl_map *bmap);
921 __isl_give isl_set *isl_map_range(
922 __isl_take isl_map *map);
926 __isl_give isl_basic_set *isl_basic_map_deltas(
927 __isl_take isl_basic_map *bmap);
928 __isl_give isl_set *isl_map_deltas(__isl_take isl_map *map);
930 These functions return a (basic) set containing the differences
931 between image elements and corresponding domain elements in the input.
935 Simplify the representation of a set or relation by trying
936 to combine pairs of basic sets or relations into a single
937 basic set or relation.
939 __isl_give isl_set *isl_set_coalesce(__isl_take isl_set *set);
940 __isl_give isl_map *isl_map_coalesce(__isl_take isl_map *map);
944 __isl_give isl_basic_set *isl_set_convex_hull(
945 __isl_take isl_set *set);
946 __isl_give isl_basic_map *isl_map_convex_hull(
947 __isl_take isl_map *map);
949 If the input set or relation has any existentially quantified
950 variables, then the result of these operations is currently undefined.
954 __isl_give isl_basic_set *isl_set_simple_hull(
955 __isl_take isl_set *set);
956 __isl_give isl_basic_map *isl_map_simple_hull(
957 __isl_take isl_map *map);
959 These functions compute a single basic set or relation
960 that contains the whole input set or relation.
961 In particular, the output is described by translates
962 of the constraints describing the basic sets or relations in the input.
966 (See \autoref{s:simple hull}.)
972 __isl_give isl_basic_set *isl_basic_set_affine_hull(
973 __isl_take isl_basic_set *bset);
974 __isl_give isl_basic_set *isl_set_affine_hull(
975 __isl_take isl_set *set);
976 __isl_give isl_basic_map *isl_basic_map_affine_hull(
977 __isl_take isl_basic_map *bmap);
978 __isl_give isl_basic_map *isl_map_affine_hull(
979 __isl_take isl_map *map);
983 __isl_give isl_map *isl_map_power(__isl_take isl_map *map,
984 unsigned param, int *exact);
986 Compute a parametric representation for all positive powers I<k> of C<map>.
987 The power I<k> is equated to the parameter at position C<param>.
988 The result may be an overapproximation. If the result is exact,
989 then C<*exact> is set to C<1>.
990 The current implementation only produces exact results for particular
991 cases of piecewise translations (i.e., piecewise uniform dependences).
993 =item * Transitive closure
995 __isl_give isl_map *isl_map_transitive_closure(
996 __isl_take isl_map *map, int *exact);
998 Compute the transitive closure of C<map>.
999 The result may be an overapproximation. If the result is known to be exact,
1000 then C<*exact> is set to C<1>.
1001 The current implementation only produces exact results for particular
1002 cases of piecewise translations (i.e., piecewise uniform dependences).
1006 =head2 Binary Operations
1008 The two arguments of a binary operation not only need to live
1009 in the same C<isl_ctx>, they currently also need to have
1010 the same (number of) parameters.
1012 =head3 Basic Operations
1016 =item * Intersection
1018 __isl_give isl_basic_set *isl_basic_set_intersect(
1019 __isl_take isl_basic_set *bset1,
1020 __isl_take isl_basic_set *bset2);
1021 __isl_give isl_set *isl_set_intersect(
1022 __isl_take isl_set *set1,
1023 __isl_take isl_set *set2);
1024 __isl_give isl_basic_map *isl_basic_map_intersect_domain(
1025 __isl_take isl_basic_map *bmap,
1026 __isl_take isl_basic_set *bset);
1027 __isl_give isl_basic_map *isl_basic_map_intersect_range(
1028 __isl_take isl_basic_map *bmap,
1029 __isl_take isl_basic_set *bset);
1030 __isl_give isl_basic_map *isl_basic_map_intersect(
1031 __isl_take isl_basic_map *bmap1,
1032 __isl_take isl_basic_map *bmap2);
1033 __isl_give isl_map *isl_map_intersect_domain(
1034 __isl_take isl_map *map,
1035 __isl_take isl_set *set);
1036 __isl_give isl_map *isl_map_intersect_range(
1037 __isl_take isl_map *map,
1038 __isl_take isl_set *set);
1039 __isl_give isl_map *isl_map_intersect(
1040 __isl_take isl_map *map1,
1041 __isl_take isl_map *map2);
1045 __isl_give isl_set *isl_basic_set_union(
1046 __isl_take isl_basic_set *bset1,
1047 __isl_take isl_basic_set *bset2);
1048 __isl_give isl_map *isl_basic_map_union(
1049 __isl_take isl_basic_map *bmap1,
1050 __isl_take isl_basic_map *bmap2);
1051 __isl_give isl_set *isl_set_union(
1052 __isl_take isl_set *set1,
1053 __isl_take isl_set *set2);
1054 __isl_give isl_map *isl_map_union(
1055 __isl_take isl_map *map1,
1056 __isl_take isl_map *map2);
1058 =item * Set difference
1060 __isl_give isl_set *isl_set_subtract(
1061 __isl_take isl_set *set1,
1062 __isl_take isl_set *set2);
1063 __isl_give isl_map *isl_map_subtract(
1064 __isl_take isl_map *map1,
1065 __isl_take isl_map *map2);
1069 __isl_give isl_basic_set *isl_basic_set_apply(
1070 __isl_take isl_basic_set *bset,
1071 __isl_take isl_basic_map *bmap);
1072 __isl_give isl_set *isl_set_apply(
1073 __isl_take isl_set *set,
1074 __isl_take isl_map *map);
1075 __isl_give isl_basic_map *isl_basic_map_apply_domain(
1076 __isl_take isl_basic_map *bmap1,
1077 __isl_take isl_basic_map *bmap2);
1078 __isl_give isl_basic_map *isl_basic_map_apply_range(
1079 __isl_take isl_basic_map *bmap1,
1080 __isl_take isl_basic_map *bmap2);
1081 __isl_give isl_map *isl_map_apply_domain(
1082 __isl_take isl_map *map1,
1083 __isl_take isl_map *map2);
1084 __isl_give isl_map *isl_map_apply_range(
1085 __isl_take isl_map *map1,
1086 __isl_take isl_map *map2);
1088 =item * Simplification
1090 __isl_give isl_basic_set *isl_basic_set_gist(
1091 __isl_take isl_basic_set *bset,
1092 __isl_take isl_basic_set *context);
1093 __isl_give isl_set *isl_set_gist(__isl_take isl_set *set,
1094 __isl_take isl_set *context);
1095 __isl_give isl_basic_map *isl_basic_map_gist(
1096 __isl_take isl_basic_map *bmap,
1097 __isl_take isl_basic_map *context);
1098 __isl_give isl_map *isl_map_gist(__isl_take isl_map *map,
1099 __isl_take isl_map *context);
1101 The gist operation returns a set or relation that has the
1102 same intersection with the context as the input set or relation.
1103 Any implicit equality in the intersection is made explicit in the result,
1104 while all inequalities that are redundant with respect to the intersection
1109 =head3 Lexicographic Optimization
1111 Given a (basic) set C<set> (or C<bset>) and a zero-dimensional domain C<dom>,
1112 the following functions
1113 compute a set that contains the lexicographic minimum or maximum
1114 of the elements in C<set> (or C<bset>) for those values of the parameters
1115 that satisfy C<dom>.
1116 If C<empty> is not C<NULL>, then C<*empty> is assigned a set
1117 that contains the parameter values in C<dom> for which C<set> (or C<bset>)
1119 In other words, the union of the parameter values
1120 for which the result is non-empty and of C<*empty>
1123 __isl_give isl_set *isl_basic_set_partial_lexmin(
1124 __isl_take isl_basic_set *bset,
1125 __isl_take isl_basic_set *dom,
1126 __isl_give isl_set **empty);
1127 __isl_give isl_set *isl_basic_set_partial_lexmax(
1128 __isl_take isl_basic_set *bset,
1129 __isl_take isl_basic_set *dom,
1130 __isl_give isl_set **empty);
1131 __isl_give isl_set *isl_set_partial_lexmin(
1132 __isl_take isl_set *set, __isl_take isl_set *dom,
1133 __isl_give isl_set **empty);
1134 __isl_give isl_set *isl_set_partial_lexmax(
1135 __isl_take isl_set *set, __isl_take isl_set *dom,
1136 __isl_give isl_set **empty);
1138 Given a (basic) set C<set> (or C<bset>), the following functions simply
1139 return a set containing the lexicographic minimum or maximum
1140 of the elements in C<set> (or C<bset>).
1142 __isl_give isl_set *isl_basic_set_lexmin(
1143 __isl_take isl_basic_set *bset);
1144 __isl_give isl_set *isl_basic_set_lexmax(
1145 __isl_take isl_basic_set *bset);
1146 __isl_give isl_set *isl_set_lexmin(
1147 __isl_take isl_set *set);
1148 __isl_give isl_set *isl_set_lexmax(
1149 __isl_take isl_set *set);
1151 Given a (basic) relation C<map> (or C<bmap>) and a domain C<dom>,
1152 the following functions
1153 compute a relation that maps each element of C<dom>
1154 to the single lexicographic minimum or maximum
1155 of the elements that are associated to that same
1156 element in C<map> (or C<bmap>).
1157 If C<empty> is not C<NULL>, then C<*empty> is assigned a set
1158 that contains the elements in C<dom> that do not map
1159 to any elements in C<map> (or C<bmap>).
1160 In other words, the union of the domain of the result and of C<*empty>
1163 __isl_give isl_map *isl_basic_map_partial_lexmax(
1164 __isl_take isl_basic_map *bmap,
1165 __isl_take isl_basic_set *dom,
1166 __isl_give isl_set **empty);
1167 __isl_give isl_map *isl_basic_map_partial_lexmin(
1168 __isl_take isl_basic_map *bmap,
1169 __isl_take isl_basic_set *dom,
1170 __isl_give isl_set **empty);
1171 __isl_give isl_map *isl_map_partial_lexmax(
1172 __isl_take isl_map *map, __isl_take isl_set *dom,
1173 __isl_give isl_set **empty);
1174 __isl_give isl_map *isl_map_partial_lexmin(
1175 __isl_take isl_map *map, __isl_take isl_set *dom,
1176 __isl_give isl_set **empty);
1178 Given a (basic) map C<map> (or C<bmap>), the following functions simply
1179 return a map mapping each element in the domain of
1180 C<map> (or C<bmap>) to the lexicographic minimum or maximum
1181 of all elements associated to that element.
1183 __isl_give isl_map *isl_basic_map_lexmin(
1184 __isl_take isl_basic_map *bmap);
1185 __isl_give isl_map *isl_basic_map_lexmax(
1186 __isl_take isl_basic_map *bmap);
1187 __isl_give isl_map *isl_map_lexmin(
1188 __isl_take isl_map *map);
1189 __isl_give isl_map *isl_map_lexmax(
1190 __isl_take isl_map *map);
1194 Points are elements of a set. They can be used to construct
1195 simple sets (boxes) or they can be used to represent the
1196 individual elements of a set.
1197 The zero point (the origin) can be created using
1199 __isl_give isl_point *isl_point_zero(__isl_take isl_dim *dim);
1201 The coordinates of a point can be inspected, set and changed
1204 void isl_point_get_coordinate(__isl_keep isl_point *pnt,
1205 enum isl_dim_type type, int pos, isl_int *v);
1206 __isl_give isl_point *isl_point_set_coordinate(
1207 __isl_take isl_point *pnt,
1208 enum isl_dim_type type, int pos, isl_int v);
1210 __isl_give isl_point *isl_point_add_ui(
1211 __isl_take isl_point *pnt,
1212 enum isl_dim_type type, int pos, unsigned val);
1213 __isl_give isl_point *isl_point_sub_ui(
1214 __isl_take isl_point *pnt,
1215 enum isl_dim_type type, int pos, unsigned val);
1217 Points can be copied or freed using
1219 __isl_give isl_point *isl_point_copy(
1220 __isl_keep isl_point *pnt);
1221 void isl_point_free(__isl_take isl_point *pnt);
1223 A singleton set can be created from a point using
1225 __isl_give isl_set *isl_set_from_point(
1226 __isl_take isl_point *pnt);
1228 and a box can be created from two opposite extremal points using
1230 __isl_give isl_set *isl_set_box_from_points(
1231 __isl_take isl_point *pnt1,
1232 __isl_take isl_point *pnt2);
1234 All elements of a B<bounded> set can be enumerated using
1235 the following function.
1237 int isl_set_foreach_point(__isl_keep isl_set *set,
1238 int (*fn)(__isl_take isl_point *pnt, void *user),
1241 The function C<fn> is called for each integer point in
1242 C<set> with as second argument the last argument of
1243 the C<isl_set_foreach_point> call. The function C<fn>
1244 should return C<0> on success and C<-1> on failure.
1245 In the latter case, C<isl_set_foreach_point> will stop
1246 enumerating and return C<-1> as well.
1247 If the enumeration is performed successfully and to completion,
1248 then C<isl_set_foreach_point> returns C<0>.
1250 To obtain a single point of a set, use
1252 __isl_give isl_point *isl_set_sample_point(
1253 __isl_take isl_set *set);
1255 If C<set> does not contain any (integer) points, then the
1256 resulting point will be ``void'', a property that can be
1259 int isl_point_is_void(__isl_keep isl_point *pnt);
1261 =head2 Piecewise Quasipolynomials
1263 A piecewise quasipolynomial is a particular kind of function that maps
1264 a parametric point to a rational value.
1265 More specifically, a quasipolynomial is a polynomial expression in greatest
1266 integer parts of affine expressions of parameters and variables.
1267 A piecewise quasipolynomial is a subdivision of a given parametric
1268 domain into disjoint cells with a quasipolynomial associated to
1269 each cell. The value of the piecewise quasipolynomial at a given
1270 point is the value of the quasipolynomial associated to the cell
1271 that contains the point. Outside of the union of cells,
1272 the value is assumed to be zero.
1273 For example, the piecewise quasipolynomial
1275 [n] -> { [x] -> ((1 + n) - x) : x <= n and x >= 0 }
1277 maps C<x> to C<1 + n - x> for values of C<x> between C<0> and C<n>.
1278 Piecewise quasipolynomials are mainly used by the C<barvinok>
1279 library for representing the number of elements in a parametric set or map.
1280 For example, the piecewise quasipolynomial above represents
1281 the number of points in the map
1283 [n] -> { [x] -> [y] : x,y >= 0 and 0 <= x + y <= n }
1285 =head3 Printing (Piecewise) Quasipolynomials
1287 Quasipolynomials and piecewise quasipolynomials can be printed
1288 using the following functions.
1290 __isl_give isl_printer *isl_printer_print_qpolynomial(
1291 __isl_take isl_printer *p,
1292 __isl_keep isl_qpolynomial *qp);
1294 __isl_give isl_printer *isl_printer_print_pw_qpolynomial(
1295 __isl_take isl_printer *p,
1296 __isl_keep isl_pw_qpolynomial *pwqp);
1298 The output format of the printer
1299 needs to be set to either C<ISL_FORMAT_ISL> or C<ISL_FORMAT_C>.
1301 =head3 Creating New (Piecewise) Quasipolynomials
1303 Some simple quasipolynomials can be created using the following functions.
1304 More complicated quasipolynomials can be created by applying
1305 operations such as addition and multiplication
1306 on the resulting quasipolynomials
1308 __isl_give isl_qpolynomial *isl_qpolynomial_zero(
1309 __isl_take isl_dim *dim);
1310 __isl_give isl_qpolynomial *isl_qpolynomial_infty(
1311 __isl_take isl_dim *dim);
1312 __isl_give isl_qpolynomial *isl_qpolynomial_neginfty(
1313 __isl_take isl_dim *dim);
1314 __isl_give isl_qpolynomial *isl_qpolynomial_nan(
1315 __isl_take isl_dim *dim);
1316 __isl_give isl_qpolynomial *isl_qpolynomial_rat_cst(
1317 __isl_take isl_dim *dim,
1318 const isl_int n, const isl_int d);
1319 __isl_give isl_qpolynomial *isl_qpolynomial_div(
1320 __isl_take isl_div *div);
1321 __isl_give isl_qpolynomial *isl_qpolynomial_var(
1322 __isl_take isl_dim *dim,
1323 enum isl_dim_type type, unsigned pos);
1325 The zero piecewise quasipolynomial or a piecewise quasipolynomial
1326 with a single cell can be created using the following functions.
1327 Multiple of these single cell piecewise quasipolynomials can
1328 be combined to create more complicated piecewise quasipolynomials.
1330 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero(
1331 __isl_take isl_dim *dim);
1332 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_alloc(
1333 __isl_take isl_set *set,
1334 __isl_take isl_qpolynomial *qp);
1336 Quasipolynomials can be copied and freed again using the following
1339 __isl_give isl_qpolynomial *isl_qpolynomial_copy(
1340 __isl_keep isl_qpolynomial *qp);
1341 void isl_qpolynomial_free(__isl_take isl_qpolynomial *qp);
1343 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_copy(
1344 __isl_keep isl_pw_qpolynomial *pwqp);
1345 void isl_pw_qpolynomial_free(
1346 __isl_take isl_pw_qpolynomial *pwqp);
1348 =head3 Inspecting (Piecewise) Quasipolynomials
1350 To iterate over the cells in a piecewise quasipolynomial,
1351 use either of the following two functions
1353 int isl_pw_qpolynomial_foreach_piece(
1354 __isl_keep isl_pw_qpolynomial *pwqp,
1355 int (*fn)(__isl_take isl_set *set,
1356 __isl_take isl_qpolynomial *qp,
1357 void *user), void *user);
1358 int isl_pw_qpolynomial_foreach_lifted_piece(
1359 __isl_keep isl_pw_qpolynomial *pwqp,
1360 int (*fn)(__isl_take isl_set *set,
1361 __isl_take isl_qpolynomial *qp,
1362 void *user), void *user);
1364 As usual, the function C<fn> should return C<0> on success
1365 and C<-1> on failure. The difference between
1366 C<isl_pw_qpolynomial_foreach_piece> and
1367 C<isl_pw_qpolynomial_foreach_lifted_piece> is that
1368 C<isl_pw_qpolynomial_foreach_lifted_piece> will first
1369 compute unique representations for all existentially quantified
1370 variables and then turn these existentially quantified variables
1371 into extra set variables, adapting the associated quasipolynomial
1372 accordingly. This means that the C<set> passed to C<fn>
1373 will not have any existentially quantified variables, but that
1374 the dimensions of the sets may be different for different
1375 invocations of C<fn>.
1377 To iterate over all terms in a quasipolynomial,
1380 int isl_qpolynomial_foreach_term(
1381 __isl_keep isl_qpolynomial *qp,
1382 int (*fn)(__isl_take isl_term *term,
1383 void *user), void *user);
1385 The terms themselves can be inspected and freed using
1388 unsigned isl_term_dim(__isl_keep isl_term *term,
1389 enum isl_dim_type type);
1390 void isl_term_get_num(__isl_keep isl_term *term,
1392 void isl_term_get_den(__isl_keep isl_term *term,
1394 int isl_term_get_exp(__isl_keep isl_term *term,
1395 enum isl_dim_type type, unsigned pos);
1396 __isl_give isl_div *isl_term_get_div(
1397 __isl_keep isl_term *term, unsigned pos);
1398 void isl_term_free(__isl_take isl_term *term);
1400 Each term is a product of parameters, set variables and
1401 integer divisions. The function C<isl_term_get_exp>
1402 returns the exponent of a given dimensions in the given term.
1403 The C<isl_int>s in the arguments of C<isl_term_get_num>
1404 and C<isl_term_get_den> need to have been initialized
1405 using C<isl_int_init> before calling these functions.
1407 =head3 Properties of (Piecewise) Quasipolynomials
1409 To check whether a quasipolynomial is actually a constant,
1410 use the following function.
1412 int isl_qpolynomial_is_cst(__isl_keep isl_qpolynomial *qp,
1413 isl_int *n, isl_int *d);
1415 If C<qp> is a constant and if C<n> and C<d> are not C<NULL>
1416 then the numerator and denominator of the constant
1417 are returned in C<*n> and C<*d>, respectively.
1419 =head3 Operations on (Piecewise) Quasipolynomials
1421 __isl_give isl_qpolynomial *isl_qpolynomial_neg(
1422 __isl_take isl_qpolynomial *qp);
1423 __isl_give isl_qpolynomial *isl_qpolynomial_add(
1424 __isl_take isl_qpolynomial *qp1,
1425 __isl_take isl_qpolynomial *qp2);
1426 __isl_give isl_qpolynomial *isl_qpolynomial_sub(
1427 __isl_take isl_qpolynomial *qp1,
1428 __isl_take isl_qpolynomial *qp2);
1429 __isl_give isl_qpolynomial *isl_qpolynomial_mul(
1430 __isl_take isl_qpolynomial *qp1,
1431 __isl_take isl_qpolynomial *qp2);
1433 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add(
1434 __isl_take isl_pw_qpolynomial *pwqp1,
1435 __isl_take isl_pw_qpolynomial *pwqp2);
1436 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_sub(
1437 __isl_take isl_pw_qpolynomial *pwqp1,
1438 __isl_take isl_pw_qpolynomial *pwqp2);
1439 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add_disjoint(
1440 __isl_take isl_pw_qpolynomial *pwqp1,
1441 __isl_take isl_pw_qpolynomial *pwqp2);
1442 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_neg(
1443 __isl_take isl_pw_qpolynomial *pwqp);
1444 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul(
1445 __isl_take isl_pw_qpolynomial *pwqp1,
1446 __isl_take isl_pw_qpolynomial *pwqp2);
1448 __isl_give isl_qpolynomial *isl_pw_qpolynomial_eval(
1449 __isl_take isl_pw_qpolynomial *pwqp,
1450 __isl_take isl_point *pnt);
1452 __isl_give isl_set *isl_pw_qpolynomial_domain(
1453 __isl_take isl_pw_qpolynomial *pwqp);
1454 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_intersect_domain(
1455 __isl_take isl_pw_qpolynomial *pwpq,
1456 __isl_take isl_set *set);
1458 __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_gist(
1459 __isl_take isl_pw_qpolynomial *pwqp,
1460 __isl_take isl_set *context);
1462 The gist operation applies the gist operation to each of
1463 the cells in the domain of the input piecewise quasipolynomial.
1464 In future, the operation will also exploit the context
1465 to simplify the quasipolynomials associated to each cell.
1467 =head2 Bounds on Piecewise Quasipolynomials and Piecewise Quasipolynomial Reductions
1469 A piecewise quasipolynomial reduction is a piecewise
1470 reduction (or fold) of quasipolynomials.
1471 In particular, the reduction can be maximum or a minimum.
1472 The objects are mainly used to represent the result of
1473 an upper or lower bound on a quasipolynomial over its domain,
1474 i.e., as the result of the following function.
1476 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_bound(
1477 __isl_take isl_pw_qpolynomial *pwqp,
1478 enum isl_fold type, int *tight);
1480 The C<type> argument may be either C<isl_fold_min> or C<isl_fold_max>.
1481 If C<tight> is not C<NULL>, then C<*tight> is set to C<1>
1482 is the returned bound is known be tight, i.e., for each value
1483 of the parameters there is at least
1484 one element in the domain that reaches the bound.
1486 A (piecewise) quasipolynomial reduction can be copied or freed using the
1487 following functions.
1489 __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_copy(
1490 __isl_keep isl_qpolynomial_fold *fold);
1491 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_copy(
1492 __isl_keep isl_pw_qpolynomial_fold *pwf);
1493 void isl_qpolynomial_fold_free(
1494 __isl_take isl_qpolynomial_fold *fold);
1495 void isl_pw_qpolynomial_fold_free(
1496 __isl_take isl_pw_qpolynomial_fold *pwf);
1498 =head3 Printing Piecewise Quasipolynomial Reductions
1500 Piecewise quasipolynomial reductions can be printed
1501 using the following function.
1503 __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold(
1504 __isl_take isl_printer *p,
1505 __isl_keep isl_pw_qpolynomial_fold *pwf);
1507 The output format of the printer
1508 needs to be set to either C<ISL_FORMAT_ISL> or C<ISL_FORMAT_C>.
1510 =head3 Inspecting (Piecewise) Quasipolynomial Reductions
1512 To iterate over the cells in a piecewise quasipolynomial reduction,
1513 use either of the following two functions
1515 int isl_pw_qpolynomial_fold_foreach_piece(
1516 __isl_keep isl_pw_qpolynomial_fold *pwf,
1517 int (*fn)(__isl_take isl_set *set,
1518 __isl_take isl_qpolynomial_fold *fold,
1519 void *user), void *user);
1520 int isl_pw_qpolynomial_fold_foreach_lifted_piece(
1521 __isl_keep isl_pw_qpolynomial_fold *pwf,
1522 int (*fn)(__isl_take isl_set *set,
1523 __isl_take isl_qpolynomial_fold *fold,
1524 void *user), void *user);
1526 See L<Inspecting (Piecewise) Quasipolynomials> for an explanation
1527 of the difference between these two functions.
1529 To iterate over all quasipolynomials in a reduction, use
1531 int isl_qpolynomial_fold_foreach_qpolynomial(
1532 __isl_keep isl_qpolynomial_fold *fold,
1533 int (*fn)(__isl_take isl_qpolynomial *qp,
1534 void *user), void *user);
1536 =head3 Operations on Piecewise Quasipolynomial Reductions
1538 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_add(
1539 __isl_take isl_pw_qpolynomial_fold *pwf1,
1540 __isl_take isl_pw_qpolynomial_fold *pwf2);
1542 __isl_give isl_qpolynomial *isl_pw_qpolynomial_fold_eval(
1543 __isl_take isl_pw_qpolynomial_fold *pwf,
1544 __isl_take isl_point *pnt);
1546 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_coalesce(
1547 __isl_take isl_pw_qpolynomial_fold *pwf);
1549 __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_gist(
1550 __isl_take isl_pw_qpolynomial_fold *pwf,
1551 __isl_take isl_set *context);
1553 The gist operation applies the gist operation to each of
1554 the cells in the domain of the input piecewise quasipolynomial reduction.
1555 In future, the operation will also exploit the context
1556 to simplify the quasipolynomial reductions associated to each cell.
1558 =head2 Dependence Analysis
1560 C<isl> contains specialized functionality for performing
1561 array dataflow analysis. That is, given a I<sink> access relation
1562 and a collection of possible I<source> access relations,
1563 C<isl> can compute relations that describe
1564 for each iteration of the sink access, which iteration
1565 of which of the source access relations was the last
1566 to access the same data element before the given iteration
1568 To compute standard flow dependences, the sink should be
1569 a read, while the sources should be writes.
1570 If any of the source accesses are marked as being I<may>
1571 accesses, then there will be a dependence to the last
1572 I<must> access B<and> to any I<may> access that follows
1573 this last I<must> access.
1574 In particular, if I<all> sources are I<may> accesses,
1575 then memory based dependence analysis is performed.
1576 If, on the other hand, all sources are I<must> accesses,
1577 then value based dependence analysis is performed.
1579 #include <isl_flow.h>
1581 __isl_give isl_access_info *isl_access_info_alloc(
1582 __isl_take isl_map *sink,
1583 void *sink_user, isl_access_level_before fn,
1585 __isl_give isl_access_info *isl_access_info_add_source(
1586 __isl_take isl_access_info *acc,
1587 __isl_take isl_map *source, int must,
1590 __isl_give isl_flow *isl_access_info_compute_flow(
1591 __isl_take isl_access_info *acc);
1593 int isl_flow_foreach(__isl_keep isl_flow *deps,
1594 int (*fn)(__isl_take isl_map *dep, int must,
1595 void *dep_user, void *user),
1597 __isl_give isl_set *isl_flow_get_no_source(
1598 __isl_keep isl_flow *deps, int must);
1599 void isl_flow_free(__isl_take isl_flow *deps);
1601 The function C<isl_access_info_compute_flow> performs the actual
1602 dependence analysis. The other functions are used to construct
1603 the input for this function or to read off the output.
1605 The input is collected in an C<isl_access_info>, which can
1606 be created through a call to C<isl_access_info_alloc>.
1607 The arguments to this functions are the sink access relation
1608 C<sink>, a token C<sink_user> used to identify the sink
1609 access to the user, a callback function for specifying the
1610 relative order of source and sink accesses, and the number
1611 of source access relations that will be added.
1612 The callback function has type C<int (*)(void *first, void *second)>.
1613 The function is called with two user supplied tokens identifying
1614 either a source or the sink and it should return the shared nesting
1615 level and the relative order of the two accesses.
1616 In particular, let I<n> be the number of loops shared by
1617 the two accesses. If C<first> precedes C<second> textually,
1618 then the function should return I<2 * n + 1>; otherwise,
1619 it should return I<2 * n>.
1620 The sources can be added to the C<isl_access_info> by performing
1621 (at most) C<max_source> calls to C<isl_access_info_add_source>.
1622 C<must> indicates whether the source is a I<must> access
1623 or a I<may> access. Note that a multi-valued access relation
1624 should only be marked I<must> if every iteration in the domain
1625 of the relation accesses I<all> elements in its image.
1626 The C<source_user> token is again used to identify
1627 the source access. The range of the source access relation
1628 C<source> should have the same dimension as the range
1629 of the sink access relation.
1631 The result of the dependence analysis is collected in an
1632 C<isl_flow>. There may be elements in the domain of
1633 the sink access for which no preceding source access could be
1634 found or for which all preceding sources are I<may> accesses.
1635 The sets of these elements can be obtained through
1636 calls to C<isl_flow_get_no_source>, the first with C<must> set
1637 and the second with C<must> unset.
1638 In the case of standard flow dependence analysis,
1639 with the sink a read and the sources I<must> writes,
1640 the first set corresponds to the reads from uninitialized
1641 array elements and the second set is empty.
1642 The actual flow dependences can be extracted using
1643 C<isl_flow_foreach>. This function will call the user-specified
1644 callback function C<fn> for each B<non-empty> dependence between
1645 a source and the sink. The callback function is called
1646 with four arguments, the actual flow dependence relation
1647 mapping source iterations to sink iterations, a boolean that
1648 indicates whether it is a I<must> or I<may> dependence, a token
1649 identifying the source and an additional C<void *> with value
1650 equal to the third argument of the C<isl_flow_foreach> call.
1651 A dependence is marked I<must> if it originates from a I<must>
1652 source and if it is not followed by any I<may> sources.
1654 After finishing with an C<isl_flow>, the user should call
1655 C<isl_flow_free> to free all associated memory.
1657 =head2 Parametric Vertex Enumeration
1659 The parametric vertex enumeration described in this section
1660 is mainly intended to be used internally and by the C<barvinok>
1663 #include <isl_vertices.h>
1664 __isl_give isl_vertices *isl_basic_set_compute_vertices(
1665 __isl_keep isl_basic_set *bset);
1667 The function C<isl_basic_set_compute_vertices> performs the
1668 actual computation of the parametric vertices and the chamber
1669 decomposition and store the result in an C<isl_vertices> object.
1670 This information can be queried by either iterating over all
1671 the vertices or iterating over all the chambers or cells
1672 and then iterating over all vertices that are active on the chamber.
1674 int isl_vertices_foreach_vertex(
1675 __isl_keep isl_vertices *vertices,
1676 int (*fn)(__isl_take isl_vertex *vertex, void *user),
1679 int isl_vertices_foreach_cell(
1680 __isl_keep isl_vertices *vertices,
1681 int (*fn)(__isl_take isl_cell *cell, void *user),
1683 int isl_cell_foreach_vertex(__isl_keep isl_cell *cell,
1684 int (*fn)(__isl_take isl_vertex *vertex, void *user),
1687 Other operations that can be performed on an C<isl_vertices> object are
1690 isl_ctx *isl_vertices_get_ctx(
1691 __isl_keep isl_vertices *vertices);
1692 int isl_vertices_get_n_vertices(
1693 __isl_keep isl_vertices *vertices);
1694 void isl_vertices_free(__isl_take isl_vertices *vertices);
1696 Vertices can be inspected and destroyed using the following functions.
1698 isl_ctx *isl_vertex_get_ctx(__isl_keep isl_vertex *vertex);
1699 int isl_vertex_get_id(__isl_keep isl_vertex *vertex);
1700 __isl_give isl_basic_set *isl_vertex_get_domain(
1701 __isl_keep isl_vertex *vertex);
1702 __isl_give isl_basic_set *isl_vertex_get_expr(
1703 __isl_keep isl_vertex *vertex);
1704 void isl_vertex_free(__isl_take isl_vertex *vertex);
1706 C<isl_vertex_get_expr> returns a singleton parametric set describing
1707 the vertex, while C<isl_vertex_get_domain> returns the activity domain
1709 Note that C<isl_vertex_get_domain> and C<isl_vertex_get_expr> return
1710 B<rational> basic sets, so they should mainly be used for inspection
1711 and should not be mixed with integer sets.
1713 Chambers can be inspected and destroyed using the following functions.
1715 isl_ctx *isl_cell_get_ctx(__isl_keep isl_cell *cell);
1716 __isl_give isl_basic_set *isl_cell_get_domain(
1717 __isl_keep isl_cell *cell);
1718 void isl_cell_free(__isl_take isl_cell *cell);
1722 Although C<isl> is mainly meant to be used as a library,
1723 it also contains some basic applications that use some
1724 of the functionality of C<isl>.
1725 The input may be specified in either the L<isl format>
1726 or the L<PolyLib format>.
1728 =head2 C<isl_polyhedron_sample>
1730 C<isl_polyhedron_sample> takes a polyhedron as input and prints
1731 an integer element of the polyhedron, if there is any.
1732 The first column in the output is the denominator and is always
1733 equal to 1. If the polyhedron contains no integer points,
1734 then a vector of length zero is printed.
1738 C<isl_pip> takes the same input as the C<example> program
1739 from the C<piplib> distribution, i.e., a set of constraints
1740 on the parameters, a line contains only -1 and finally a set
1741 of constraints on a parametric polyhedron.
1742 The coefficients of the parameters appear in the last columns
1743 (but before the final constant column).
1744 The output is the lexicographic minimum of the parametric polyhedron.
1745 As C<isl> currently does not have its own output format, the output
1746 is just a dump of the internal state.
1748 =head2 C<isl_polyhedron_minimize>
1750 C<isl_polyhedron_minimize> computes the minimum of some linear
1751 or affine objective function over the integer points in a polyhedron.
1752 If an affine objective function
1753 is given, then the constant should appear in the last column.
1755 =head2 C<isl_polytope_scan>
1757 Given a polytope, C<isl_polytope_scan> prints
1758 all integer points in the polytope.
1760 =head1 C<isl-polylib>
1762 The C<isl-polylib> library provides the following functions for converting
1763 between C<isl> objects and C<PolyLib> objects.
1764 The library is distributed separately for licensing reasons.
1766 #include <isl_set_polylib.h>
1767 __isl_give isl_basic_set *isl_basic_set_new_from_polylib(
1768 Polyhedron *P, __isl_take isl_dim *dim);
1769 Polyhedron *isl_basic_set_to_polylib(
1770 __isl_keep isl_basic_set *bset);
1771 __isl_give isl_set *isl_set_new_from_polylib(Polyhedron *D,
1772 __isl_take isl_dim *dim);
1773 Polyhedron *isl_set_to_polylib(__isl_keep isl_set *set);
1775 #include <isl_map_polylib.h>
1776 __isl_give isl_basic_map *isl_basic_map_new_from_polylib(
1777 Polyhedron *P, __isl_take isl_dim *dim);
1778 __isl_give isl_map *isl_map_new_from_polylib(Polyhedron *D,
1779 __isl_take isl_dim *dim);
1780 Polyhedron *isl_basic_map_to_polylib(
1781 __isl_keep isl_basic_map *bmap);
1782 Polyhedron *isl_map_to_polylib(__isl_keep isl_map *map);